从 Terraform 中的 Vault 读取 GCP 凭据?

Read GCP credentials from Vault in Terraform?

我们决定使用 Vault 来管理它们,而不是将 GCP 凭据放在本地。

下面的代码应该可以发挥作用。但是,当 运行 terraform plan 我总是收到错误消息:

Error: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

我们使用的代码如下:

# Requires env variables VAULT_ADDR and VAULT_TOKEN set.
provider "vault" {
  token_name = "terraform"
}

data "vault_generic_secret" "gcp_credentials" {
  path = "kv/terraform/gcp/credentials"
}

provider "google-beta" {
  credentials = data.vault_generic_secret.gcp_credentials.data_json
  project     = "mip-ppr"
}

原来我还需要创建一个普通的 google 供应商。

添加这个解决了我的问题:

provider "google" {
  credentials = data.vault_generic_secret.gcp_credentials.data_json
  project     = "mip-ppr"
}