简体   繁体   中英

Google Cloud Compute, using environment variables

I have found lots of information on how to use environment variables in Google App Engine projects.

However I am yet to find some best practice on what to do with environment variables on compute engine.

Is it possible to use Google Cloud Deployment Manager to achieve this? My main goal is to simplify deployment between prod/stag/dev.

Right now I am moving towards using dotenv files.

Stack is webpack 4, express, node 10, vuejs 2.

For Compute Engine instances I'd suggest to use custom metadata. You can find detailed documentation about this here . From within your instance, you can access your custom metadata by performing an empty request to the instance().get method, for example:

GET https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-instance

Now, to set your custom metadata, you can indeed use the Google Cloud Deployment Manager. As per the doc here , you just need to add the metadata property and the relevant metadata keys and values for your VM resource, for example:

resources:
- name: my-first-vm-template
  type: compute.v1.instance
  properties:
   zone: us-central1-a
   machineType:
   ...[snip]...
   metadata:
     items:
     - key: custom-key
       value: "custom-value"

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