Skip to content

Commit

Permalink
Use encode_expr instead of a hack to convert values to strings for te…
Browse files Browse the repository at this point in the history
…rraform variables
  • Loading branch information
samsimpson1 committed Jan 27, 2025
1 parent 46f2b5d commit 4afbb28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 10 additions & 2 deletions terraform/deployments/tfc-configuration/variable-set/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
terraform = {
source = "terraform.io/builtin/terraform"
}
}
}

resource "tfe_variable_set" "set" {
name = var.name
organization = "govuk"
Expand All @@ -10,7 +18,7 @@ resource "tfe_variable" "vars" {

variable_set_id = tfe_variable_set.set.id
key = each.key
value = try(tostring(each.value), replace(jsonencode(each.value), ":", "="))
hcl = try(tostring(each.value), "nostring") == "nostring" ? true : false
value = provider::terraform::encode_expr(each.value)
hcl = true
category = "terraform"
}
14 changes: 2 additions & 12 deletions terraform/deployments/tfc-configuration/variables-production.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,14 @@ module "variable-set-ecr-production" {
name = "ecr-production"
tfvars = {
emails = ["govuk-platform-engineering+ecr-inspector@digital.cabinet-office.gov.uk"]
}
}

# This has to be separate because the ':' get replaced with '='
# by the var set module
resource "tfe_variable" "ecr-puller-arns" {
variable_set_id = module.variable-set-ecr-production.variable_set_id
key = "puller_arns"
category = "terraform"
value = jsonencode(
[
puller_arns = [
"arn:aws:iam::172025368201:root", # Production
"arn:aws:iam::696911096973:root", # Staging
"arn:aws:iam::210287912431:root", # Integration
"arn:aws:iam::430354129336:root", # Test
]
)
hcl = true
}
}

module "variable-set-chat-production" {
Expand Down

0 comments on commit 4afbb28

Please sign in to comment.