简体   繁体   中英

How to set custom environment variables using Google Cloud Deployment Manager?

Google Cloud Deployment Manager provides deployment-specific environment variables like Project ID and Deployment name.

def GenerateConfig(context):
  resources = []
  resources.append ({
    'name': 'vm-' + context.env["deployment"],
    'type': 'compute.v1.instance',
    'properties': {
       'serviceAccounts': [{
         'email': context.env['project_number'] + '-compute@developer.gserviceaccount.com',
         'scopes': [...]
       }]
    }
    ...}]
  return {'resources': resources}

Reference: https://cloud.google.com/deployment-manager/docs/configuration/templates/use-environment-variables

I don't find any example to set any custom environment variable that can be used by my templates. If there is no support for this functionality, any hack on how to achieve this functionality will be very helpful

Google Cloud Deployment Manager, similar to terraform is an IaC service which will help us in provisioning, deleting and modifying the Infrastructure components. So, in general these variables will be fixed as they need to be understood by the cloud provider and in some cases like machine type the input is also selective that means you can't enter your desired value you have to select from the list of options available. Can you provide more details on why you require this feature and what are you trying to achieve here? It will help us in better understanding your problem or use case.

updates:

  1. Dinesh you can make use for template properties for encrypting your secrets instead of hard coding them into your code follow Best practices for using deployment manager document for more info. Defining template properties will help you in understanding how to use template properties in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM