GoogleCloudPlatform / marketplace-tools

Apache License 2.0
20 stars 15 forks source link

Question: How do we access/refer environment variables in different sections of the autogen config file #49

Open KishoreNamala opened 3 years ago

KishoreNamala commented 3 years ago

We want to access the name of the deployment inside the code we are executing on the VM. How do we refer to that in the configuration.yaml

For deployment manager, we see the instructions here. https://cloud.google.com/deployment-manager/docs/configuration/templates/use-environment-variables

we are looking for something similar for the autogen config file.

gibbleyg commented 3 years ago

Running mpdev apply -f configurations.yaml generates jinja files. Within these jinja files we can reference the environment variables.

For example, we could reference the deployment in a gceStartupScript in configurations.yaml

  deploymentSpec:
    singleVm:
      gceStartupScript:
        bashScriptContent: echo "{{ env["deployment"] }}"

If you unzip the template then the solution.jinja file will contain

          - key: startup-script
            value: |-
              #!/bin/bash
              echo "{{ env["deployment"] }}"