0

I have a trivial deployment manager configuration as I try to understand using references and outputs from templates. Note that all examples are overly-simplified just to demonstrate the problem; obviously in a final version much more would be dynamic.

My first file is a low-level template designed to create a bucket with a dynamic name:

file: bucket.jinja

{% set NAME = properties['name'] %}

resources:
  - name: templated-{{ NAME }}
    type: storage.v1.bucket
    properties:
      location: us-central1
      kind: storage#bucket
      storageClass: STANDARD
      versioning:
        enabled: false

outputs:
  - name: outValue
    value: out-{{ NAME }}

My second file is a higher-level template to control the deployment:

file config.yaml

imports:
  - path: bucket.jinja

resources:
  - name: softcoded-1
    type: bucket.jinja
    properties:
      name: testbucket

  - name: hardcoded-$(ref.softcoded-1.outValue)
    type: storage.v1.bucket
    properties:
      location: us-central1
      kind: storage#bucket
      storageClass: STANDARD
      versioning:
        enabled: false

  - name: softcoded-2
    type: bucket.jinja
    properties:
      name: noref
    metadata:
      dependsOn:
        - softcoded-1

  - name: softcoded-3
    type: bucket.jinja
    properties:
      name: $(ref.softcoded-1.outValue)
    metadata:
      dependsOn:
        - softcoded-1

When I try to run this, I get the following error:

% gcloud --project myproject deployment-manager deployments update test-deploy --config config.yaml --preview
The fingerprint of the deployment is b'5Hesgz1ujBJIotnjwJHJsg=='
Waiting for update [operation-1709425554385-612b6a6f06adf-8d791850-cffb5f4a]...failed.                                                                         
ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1709425554385-612b6a6f06adf-8d791850-cffb5f4a]: errors:
- code: CONDITION_NOT_MET
  message: Referenced resource softcoded-1 could not be found. In 'finalValue' section
    of 'outputs' in the manifest layout.

However, if I remove the softcoded-3 resource, everything deploys as expected:

gcloud --project myproject deployment-manager deployments update test-deploy --config config.yaml --preview
The fingerprint of the deployment is b'mBk3HFf8zrIx1QQu0qEX9w=='
Waiting for update [operation-1709425600759-612b6a9b406a3-1d4b478a-b4f12123]...done.                                                                           
Update operation operation-1709425600759-612b6a9b406a3-1d4b478a-b4f12123 completed successfully.
NAME                      TYPE               STATE       ERRORS  INTENT
hardcoded-out-testbucket  storage.v1.bucket  IN_PREVIEW  []      CREATE_OR_ACQUIRE
templated-noref           storage.v1.bucket  IN_PREVIEW  []      CREATE_OR_ACQUIRE
templated-testbucket      storage.v1.bucket  IN_PREVIEW  []      CREATE_OR_ACQUIRE

If I restore the softcoded-3 resource, I would expect an additional bucket to be created with the resolved name templated-out-testbucket.

This seems to be in direct conflict with this example in Google's own docs, which shows a template outputting a value and the calling template then consuming that value as a property on another resource.

What am I missing in order to make this create the softcoded-3 resource without errors?

7
  • Check your deployment file and verify if all conditions are correctly defined.According to this official doc, You get a validation error when a field in your configuration fails validation, such as if it uses a string value when a boolean is expected. Commented Mar 3 at 12:36
  • Have done. Note closely that the only difference between softcoded-2 and softcoded-3 is the use of the reference, and the reference (exactly the same) is used successfully in hardcoded-3 but just on the top-level name property of the resource instead of on the properties.name nested property.
    – seawolf
    Commented Mar 4 at 2:29
  • As per the error the resource softcoded-1 could not be found when trying to resolve the reference in softcoded-3 and also the reference you provided with softcoded-3 should be correctly matched to hardcoded-3. Try adding a dependency on the softcoded-1 resource to the softcoded-3 resource. This will ensure that the softcoded-1 resource is created before the softcoded-3 resource is created, which may help to resolve your issue. Commented Mar 4 at 10:56
  • I believe this reference already exists, in the softcoded-3.metadata.dependsOn.softcoded-1 lines above... is there a different way to indicate this dependence?
    – seawolf
    Commented Mar 5 at 4:34
  • I included hardcoded-1 to show that the dependency is properly handled when the reference is part of the name of the resource; the only difference between hardcoded-1 and softcoded-3 with respect to the reference is that in softcoded-3 the reference is not in the top-level name property but rather in a nested property further within the object, yet hardcoded-1 works correctly (even with no dependsOn reference, while softcoded-3 does not at all work as expected or documented. The example in the link from Google's docs shows exactly the outcome I expect but am not seeing.
    – seawolf
    Commented Mar 5 at 4:38

0