可以通过 Terraform 为 Cloud Function 设置机密吗?

Jay*_*522 2 google-cloud-platform terraform google-cloud-functions

Terraformgoogle_cloudfunctions_function资源文档将秘密环境变量列为可选参数。我要么没有正确使用它,要么与文档相反,它实际上不受支持。

resource "google_cloudfunctions_function" "function" {
  name        = var.function_name
  runtime     = "nodejs16"

  available_memory_mb   = 128
  source_archive_bucket = google_storage_bucket.bucket.name
  source_archive_object = google_storage_bucket_object.zip.name
  trigger_http          = true
  entry_point           = var.function_entry_point

  secret_environment_variables = []
}
Run Code Online (Sandbox Code Playgroud)

结果是:

错误:modules/cloud-function/main.tf 第 51 行不受支持的参数,在资源“google_cloudfunctions_function”“function”中:51:secret_environment_variables = {} 此处不需要名为“secret_environment_variables”的参数。您的意思是定义一个“secret_environment_variables”类型的块吗?

这是以下结果terraform version

Terraform v1.1.9
on darwin_amd64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/google v4.18.0
Run Code Online (Sandbox Code Playgroud)

jor*_*anm 5

根据文档,该密钥应该被阻止。这是一个例子:

resource "google_cloudfunctions_function" "function" {
  name        = var.function_name
  runtime     = "nodejs16"

  available_memory_mb   = 128
  source_archive_bucket = google_storage_bucket.bucket.name
  source_archive_object = google_storage_bucket_object.zip.name
  trigger_http          = true
  entry_point           = var.function_entry_point

  secret_environment_variables {
    key = "myvar"
    secret = "mysecret_id"
  }
}
Run Code Online (Sandbox Code Playgroud)