google-deployment-manager

How do I add labels to a deployment?


I have this template:

resources:
  - name: resource-name
    type: 'gcp-types/cloudfunctions-v1:projects.locations.functions'
    properties:
      labels:
      - key: testlabel1
        value: testlabel1value
      - key: testlabel2
        value: testlabel2value
      parent: projects/sdfsfsdf/locations/us-central1
      location: us-central1
      function: function-name
      sourceArchiveUrl: 'gs://sdfsfsdf/b50d36e265ec71d457bb7ba5cc13e44c.zip'
      environmentVariables:
        TEST_ENV_VAR: 'zzzzzzzzz'
      entryPoint: handler
      httpsTrigger: {}
      timeout: 60s
      availableMemoryMb: 256
      runtime: nodejs8

which produces this error:

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation 
- code: CONDITION_NOT_MET
  location: /deployments/test-templates/resources/resource-name->$.properties
  message: |
    error: instance type (array) does not match any allowed primitive type (allowed: ["object"])
        level: "error"
        schema: {"loadingURI":"#","pointer":"/create/properties/labels"}
        instance: {"pointer":"/labels"}
        domain: "validation"
        keyword: "type"
        found: "array"
        expected: ["object"]

Solution

  • While there should have been an actual example of this in the docs i was being dumb. this is the correct format

    resources:
      - name: resource-name
        type: 'gcp-types/cloudfunctions-v1:projects.locations.functions'
        properties:
          labels:
            testlabel1: testlabel1value
            testlabel2: testlabel2value