Last active
April 16, 2020 17:53
-
-
Save syedrakib/24105d88e7243e51d9942e6e1b3a12e0 to your computer and use it in GitHub Desktop.
Terraform on GCP - impersonating with short-lived AccessTokens & ServiceAccounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "google" { | |
credentials = file(var.path_to_tf_executor_service_account_json_file) | |
alias = "tf_executor" | |
} | |
data "google_service_account_access_token" "impersonated" { | |
provider = google.tf_executor | |
target_service_account = var.tf_owner_service_account_email | |
scopes = [ "cloud-platform" ] | |
lifetime = "1800s" # 30 minutes - max can be set up to 60 minutes | |
} | |
provider "google" { | |
access_token = data.google_service_account_access_token.impersonated.access_token | |
project = var.gcp_project_id | |
region = var.region | |
} | |
provider "google-beta" { | |
access_token = data.google_service_account_access_token.impersonated.access_token | |
project = var.gcp_project_id | |
region = var.region | |
} | |
# Terraform v0.12.24 | |
# provider.google v3.13.0 | |
# provider.google-beta v3.13.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Embedded in my Medium article about Terraform on GCP — impersonating with short-lived AccessTokens & ServiceAccounts