Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_cloudfunctions_function Unable to reference a secret #9946

Closed
philippeboyd opened this issue Aug 31, 2021 · 10 comments
Closed

google_cloudfunctions_function Unable to reference a secret #9946

philippeboyd opened this issue Aug 31, 2021 · 10 comments

Comments

@philippeboyd
Copy link

philippeboyd commented Aug 31, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment. If the issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If the issue is assigned to a user, that user is claiming responsibility for the issue. If the issue is assigned to "hashibot", a community member has claimed the issue already.

Description

Currently, there doesn't seem to be a way to reference a secret stored in Google's Secret manager when creating a function with the TF resource (available in the UI)

image

New or Affected Resource(s)

  • google_cloudfunctions_function

Potential Terraform Configuration

resource "google_cloudfunctions_function" "func" {
  project   = var.project_id
  name        = "my-func"
  runtime     = "python38"

  ...

  secrets {
      secret_id = "my-secret-1"
      reference_method = "VOLUME"
      mount_path = "/my-secret-1"
      paths = [
        {
          path = "/v1"
          version = "1"
        }
      ]
  }

  secrets {
      secret_id = "my-secret-2"
      reference_method = "ENVIRONMENT_VARIABLE"
      variables = [
        {
          name = "MY_SECRET_2"
          version = "latest"
        }
      ]
  }
}
@upodroid
Copy link
Contributor

upodroid commented Sep 1, 2021

Hi

The provider doesn't implement features in Private Preview. Also, the provider doesn't support the new version of Functions yet as it is in Private Preview.

Thank you

@vponnam
Copy link

vponnam commented Sep 7, 2021

As a side note: while the support for this feature is yet to be added to the provider, assuming the other dependencies are met, an interim option to automate this secret manager integration is by wrapping the gcloud command in a gcloud module or as a local-exec step.

@slevenick slevenick changed the title google_cloudfunctions_function Unable to reference a secret like in the UI google_cloudfunctions_function Unable to reference a secret Sep 13, 2021
@rileykarson rileykarson added this to the Goals milestone Sep 27, 2021
@slevenick slevenick removed their assignment Oct 6, 2021
@aweberlopes
Copy link

aweberlopes commented Oct 20, 2021

When we can see this feature in the google or google-beta provider?

@upodroid
Copy link
Contributor

upodroid commented Oct 20, 2021

Hmm

The feature exists in v1 of the API but it isn't undocumented here https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions

The command gcloud beta functions deploy NAME(this function has to exist) --runtime dev --set-secrets '/etc/foo=dev:latest' --log-http

yields a payload that looks like this:

{
  "availableMemoryMb": 128,
  "description": "CloudSQL Backup Function",
  "entryPoint": "exportDatabase",
  "environmentVariables": {
    "INSTANCE_NAME": "gitlab",
  },
  "httpsTrigger": {
    "securityLevel": "SECURE_OPTIONAL",
    "url": "https://REDACTED.cloudfunctions.net/cloudsql-exporter"
  },
  "ingressSettings": "ALLOW_ALL",
  "labels": {
    "deployment-tool": "cli-gcloud",
    "env": "prod",
    "role": "sql-backup"
  },
  "name": "projects/REDACTEDlocations/europe-west2/functions/cloudsql-exporter",
  "runtime": "dev",
  "secretVolumes": [
    {
      "mountPath": "/etc",
      "projectId": "550924169191",
      "secret": "dev",
      "versions": [
        {
          "path": "/foo",
          "version": "latest"
        }
      ]
    }
  ],
  "serviceAccountEmail": "[email protected]",
  "sourceArchiveUrl": "REDACTED",
  "status": "ACTIVE",
  "timeout": "60s",
  "updateTime": "2020-08-11T17:39:24.989Z",
  "versionId": "4"
}

Lets wait a bit for the API docs to be updated.

@millouzgc
Copy link

When we can see this feature in the google or google-beta provider?

the feature has arrived in beta

[--clear-secrets
          | --set-secrets=[SECRET_ENV_VAR=SECRET_VALUE_REF,
          /secret_path=SECRET_VALUE_REF,
          /mount_path:/secret_file_path=SECRET_VALUE_REF,...]
          | --remove-secrets=[SECRET_ENV_VAR,
          /secret_path,/mount_path:/secret_file_path,...]
          --update-secrets=[SECRET_ENV_VAR=SECRET_VALUE_REF,
          /secret_path=SECRET_VALUE_REF,
          /mount_path:/secret_file_path=SECRET_VALUE_REF,...]]

https://cloud.google.com/sdk/gcloud/reference/beta/functions/deploy

@jenshonkan84
Copy link

Any updates on this?

@djfinnoy
Copy link

djfinnoy commented Nov 23, 2021

+1

This is blocking us from adopting Terraform for our cloud functions. Eagerly awaiting support for function secrets in the provider.

@kakarott1511
Copy link

Really need this feature in terraform as we are blocked and can't go in prod. We don't want to do workaround to use this feature.

@binamov
Copy link
Contributor

binamov commented Feb 17, 2022

This should've rolled out already, can we close this?

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests