钥匙在哪里?

Where is the key?

resource "google_service_account" "myaccount" {
  account_id = "dev-foo-account"
}

resource "google_service_account_key" "mykey" {
  service_account_id = google_service_account.myaccount.name
}

data "google_service_account_key" "mykey" {
  name            = google_service_account_key.mykey.name
  public_key_type = "TYPE_X509_PEM_FILE"
}

如果我像这样创建服务帐户和密钥 - 之后如何获取密钥?

terraform output 产量:

$ terraform output -json google_service_account_key
The output variable requested could not be found in the state
file. If you recently added this to your configuration, be
sure to run `terraform apply`, since the state won't be updated
with new output variables until that command is run.

如果要在应用计划后使用该变量,则必须将该变量作为输出:


output "my_private_key" {
  value = data.google_service_account_key.mykey.private_key
}

要输出“my_private_key”的值:

$ terraform output my_private_key

获取凭据作为 JSON 稍后可用于身份验证:

$ terraform output -raw key | base64 -d -