您可以在 Terraform Cloud UI 中将凭据作为名为google_credentials的多行值提供,并将其标记为敏感值,然后使用您的帐户的正确值输入类似这样的内容(可能只是您的 account.json 文件的复制粘贴)已经有):
{
"type": "service_account",
"project_id": "project-id",
"private_key_id": "key-id",
"private_key": "-----BEGIN PRIVATE KEY-----\nprivate-key\n-----END PRIVATE KEY-----\n",
"client_email": "service-account-email",
"client_id": "client-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service-account-email"
}
然后,您可以将工作空间变量中的凭据提供给 Terraform 模块中的google提供程序,如下所示作为将被解释为 JSON 的单个变量:
provider "google" {
project = var.project
region = var.region
credentials = var.google_credentials
}
variable "google_credentials" {
description = "the contents of a service account key file in JSON format."
type = string
}
凭据 -(可选)JSON 格式的服务帐户密钥文件的路径或内容。您可以使用 Cloud Console 管理密钥文件。
来自Google Provider Configuration Reference。