2

I see in the list of Supported Resource Types that Google Cloud Deployment Manager has at least some support for the storage.v1.object type. I'm hoping this gives me the ability to write files to GCS based on data in my DM template. I'm stuck, though, on how to even compose the properties for the resource in a way that DM likes. When I use the following template:

resources:
  - name: foo.txt
    type: storage.v1.object
    properties:
      bucket: my-bucket
      name: foo.txt
      uploadType: media

I get the following error from gcloud deployment-manager:

ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1522258413242-5687c67fa4691-c89f17c6-c0b96018]: errors:
- code: RESOURCE_ERROR
  location: /deployments/test-serviceaccount/resources/foo.txt
  message: '{"ResourceType":"storage.v1.object","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"errors":[{"domain":"global","message":"Upload
    requests must include an uploadType URL parameter and a URL path beginning with
    /upload/","reason":"wrongUrlForUpload","extendedHelp":"https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload"}],"message":"Upload
    requests must include an uploadType URL parameter and a URL path beginning with
    /upload/","statusMessage":"Bad Request","requestPath":"https://www.googleapis.com/storage/v1/b/my-bucket/o","httpMethod":"POST"}}'

What am I missing here? How do I construct a valid storage.v1.object resource in a Deployment Manager template?

1 Answer 1

3

As per this Github thread:

"uploading objects to Cloud Storage isn't really a supported use case" in Deployment Manager.

However, the proposed workarounds in the thread to upload an object from Deployment Manager are:

You can use the following example as a reference for Cloud Builder. It clones a repository (you can use your own image instead and run a custom script) and uploads the directory to a bucket.

resources:
  - name: my-build
    action: gcp-types/cloudbuild-v1:cloudbuild.projects.builds.create
    metadata:
      runtimePolicy:
      - CREATE
    properties:
      steps:
      - name: gcr.io/cloud-builders/git
        args: ['clone', 'https://github.com/GoogleCloudPlatform/appengine-helloworld-php.git']
      - name: gcr.io/cloud-builders/gsutil
        args: ['-m', 'cp', '-r', 'appengine-helloworld-php', 'gs://<MY_BUCKET>/']
      timeout: 120s

Not the answer you're looking for? Browse other questions tagged or ask your own question.