【问题标题】:Where is the key?钥匙在哪里?
【发布时间】:2021-06-09 16:14:37
【问题描述】:
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.

【问题讨论】:

    标签: terraform terraform-provider-gcp


    【解决方案1】:

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

    
    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 -
    

    【讨论】:

    • 谢谢,我明天试试。不过,从技术上讲,我需要的当然是私钥。我认为它可以通过 .private_key 访问。
    • 对不起!我的错。我假设您想提取公钥。我已经相应地编辑了我的答案以提取私钥。谢谢
    猜你喜欢
    • 2018-07-13
    • 2016-07-06
    • 2021-06-18
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多