* Creates a global parameter with kms_key using the Parameter Manager SDK. * * @param {string} projectId - The Google Cloud project ID where the parameter is to be created. * @param {string} parameterId - The ID of the parameter to create. This ID must be unique within the project. * @param {str
(projectId, parameterId, kmsKey)
| 22 | * @param {string} kmsKey - The ID of the KMS key to be used for encryption. |
| 23 | */ |
| 24 | async function main(projectId, parameterId, kmsKey) { |
| 25 | // [START parametermanager_create_param_with_kms_key] |
| 26 | /** |
| 27 | * TODO(developer): Uncomment these variables before running the sample. |
| 28 | */ |
| 29 | // const projectId = 'YOUR_PROJECT_ID'; |
| 30 | // const parameterId = 'YOUR_PARAMETER_ID'; |
| 31 | // const kmsKey = 'YOUR_KMS_KEY' |
| 32 | |
| 33 | // Imports the Parameter Manager library |
| 34 | const {ParameterManagerClient} = require('@google-cloud/parametermanager'); |
| 35 | |
| 36 | // Instantiates a client |
| 37 | const client = new ParameterManagerClient(); |
| 38 | |
| 39 | async function createParamWithKmsKey() { |
| 40 | const parent = client.locationPath(projectId, 'global'); |
| 41 | const request = { |
| 42 | parent: parent, |
| 43 | parameterId: parameterId, |
| 44 | parameter: { |
| 45 | kmsKey: kmsKey, |
| 46 | }, |
| 47 | }; |
| 48 | |
| 49 | const [parameter] = await client.createParameter(request); |
| 50 | console.log( |
| 51 | `Created parameter ${parameter.name} with kms_key ${parameter.kmsKey}` |
| 52 | ); |
| 53 | return parameter; |
| 54 | } |
| 55 | |
| 56 | return await createParamWithKmsKey(); |
| 57 | // [END parametermanager_create_param_with_kms_key] |
| 58 | } |
| 59 | module.exports.main = main; |
| 60 | |
| 61 | /* c8 ignore next 10 */ |
no test coverage detected