Search code examples
google-deployment-manager

Is there a way we can import a file into YAML in GCP Deployment Manager


I am trying to create a configuration file in GCP Deployment Manager and i have a metadata file which needs to imported as text.

I know on how do it in .py file, but wondering on how to do it in YAML.

I tried different but none seem to work.


Solution

  • Although Deployment Manager can use the imports statement to import Jinja2 or Python templates into the root configuration file, plain YAML cannot be imported. This is limitation of YAML. It does not have "import" or "include" functionality.

    A similar question has been discussed here: https://stackoverflow.com/a/15437697/11602913.

    In a pure YAML deployment file, metadata can be provided literally, as described in the document

    Google Cloud Platform for AWS Professionals: Infrastructure Deployment Tools:

    resources:
    - name: my-first-vm-template
      type: compute.v1.instance
      properties:
       ...
       metadata:
         items:
         - key: startup-script
           value: "STARTUP-SCRIPT-CONTENTS"
    

    If metadata should be loaded from a file, you have to use Jinja2 templates. There is an example at codelabs.developers.google.com:

    Deploy Your Infrastructure Using Deployment Manager > Creating your deployment configuration

    imports:
    - path: instance.jinja
    - path: ../startup-script.sh
      name: startup-script.sh
    resources:
    - name: my-instance
      type: instance.jinja
      properties:
        metadata-from-file:
          startup-script: startup-script.sh