title: In a Jinja template file, how to load a bash script for the startup-script of an instance
body: <p>We have a template <code>container_instance_template.jinja</code> which define our instance properties for our Deployment Manager of GCP.</p>
  
  <p>For the <code>startup-script</code> metatag we have a <code>_startup-script.sh</code> the file we would like to load. But we keep getting template load error.</p>
  
  <p>Our template:</p>
  
  <pre><code>resources:
  - name: {{ IT_NAME }}
    type: compute.v1.instanceTemplate
    properties:
      properties:
        metadata:
          items:
          - key: gce-container-declaration
            value: |
              {{ GenerateManifest(env['name'], properties['port'],properties['dockerImage'], properties['dockerEnv'])|indent(12) }}
          - key: startup-script
            value: ????????????
  </code></pre>
  
  <p>We've tried everything:</p>
  
  <pre><code> key: startup-script
   value: |
    {{ properties['startupScript'] }}
  
  # This one does not work, because as it's just the reference to the file, GCP doesn't pick up the contents and doesn't execute the script. As far as we understood, it should though, anyways.
  </code></pre>
  
  <pre><code>key: startup-script
   value: |
    {% include properties['startupScript'] %}
  
  # This one does not work, because we get the error TemplateNotFound: ./_startup-script.sh
  </code></pre>
  
  <p>This is the error we get:</p>
  
  <pre><code>- code: MANIFEST_EXPANSION_USER_ERROR
    location: /deployments/app/manifests/manifest-14723924
    message: |-
      Manifest expansion encountered the following errors: Exception in container_instance_template.jinja
      Traceback (most recent call last):
          return template.render(resource)
          return self.environment.handle_exception(exc_info, True)
          reraise(exc_type, exc_value, tb)
        File "&lt;template&gt;", line 22, in top-level template code
          raise TemplateNotFound(template)
      TemplateNotFound: ./_startup-script.sh
       Resource: container_instance_template.jinja Resource: config
  </code></pre>
  
  <p>In our last attempt we were trying to create a Python function and import it to the template, but no success:</p>
  
  <pre><code># container_instance_template.jinja
  imports:
  - path: helpers.py 
  - path: properties['startupScript']
  
  # And then using:
  
  {{ include_file(properties['startupScript']) }}
  
  
  # helpers.py
  
  import jinja2
  
  def include_file(name):
      return jinja2.Markup(loader.get_source(env, name)[0])
  
  loader = jinja2.PackageLoader(__name__, 'templates')
  env = jinja2.Environment(loader=loader)
  env.globals['include_file'] = include_file
  </code></pre>
  
  <p>We can't find any GCP examples, guide, documentation or anything else. If we inline the bash script it works, but then it's a hacky solution.</p>
  
  <p>We tried all types of reference to the file. It's there, other files work normally.</p>