Skip to content

Instantly share code, notes, and snippets.

@syedrakib
Last active April 16, 2020 17:53
Show Gist options
  • Save syedrakib/24105d88e7243e51d9942e6e1b3a12e0 to your computer and use it in GitHub Desktop.
Save syedrakib/24105d88e7243e51d9942e6e1b3a12e0 to your computer and use it in GitHub Desktop.
Terraform on GCP - impersonating with short-lived AccessTokens & ServiceAccounts
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
@syedrakib
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment