LoginSignup
4
5

More than 3 years have passed since last update.

TerraformでGCPのService Account Keyを作成し、ローカルにファイルとして保存する

Last updated at Posted at 2020-05-01

動作確認環境

  • terraform v0.12.24
  • terraform-provider-google v3.19.0

TL;DR

下のようなコードで実現できます。

main.tf
resource "google_service_account" "my-account" {
  account_id = "my-account"
}

resource "google_service_account_key" "my-account-key" {
  service_account_id = google_service_account.my-account.name
}

resource "local_file" "my-account-key" {
  filename             = "./output/secrets/my-account-key.json"
  content              = base64decode(google_service_account_key.my-account-key.private_key)
  file_permission      = "0600"
  directory_permission = "0755"
}

local_fileとは

その名の通りで、Terraformでローカルにファイルを作成できるリソースです。

参考

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5