Created
February 28, 2024 08:43
-
-
Save jaybrueder/8b25fbcd6d69f8d8ccda4b91c1be957f to your computer and use it in GitHub Desktop.
TFE Provider - variable distribution
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
variable "workspaces" { | |
type = set(string) | |
} | |
variable "common_environment_variables" { | |
type = map(string) | |
} | |
provider "tfe" { | |
hostname = "app.terraform.io" # Terraform Cloud | |
} | |
resource "tfe_workspace" "example" { | |
for_each = var.workspaces | |
organization = "your-organization-name" | |
name = each.key | |
} | |
resource "tfe_variable" "example" { | |
# We'll need one tfe_variable instance for each | |
# combination of workspace and environment variable, | |
# so this one has a more complicated for_each expression. | |
for_each = { | |
for pair in setproduct(var.workspaces, keys(var.common_environment_variables)) : "${pair[0]}/${pair[1]}" => { | |
workspace_name = pair[0] | |
workspace_id = tfe_workspace.example[pair[0]].id | |
name = pair[1] | |
value = var.common_environment_variables[pair[1]] | |
} | |
} | |
workspace_id = each.value.workspace_id | |
category = "env" | |
key = each.value.name | |
value = each.value.value | |
sensitive = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment