From 264e3712a05d0761c472194c99c1d59c61a61101 Mon Sep 17 00:00:00 2001 From: Jean-Marc Fontaine Date: Fri, 27 Jan 2023 17:47:54 -0500 Subject: [PATCH] Add support for HCL env vars --- exporters/tfc/main.tf | 1 + generator/generator.tftpl | 2 +- generator/variables.tf | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/exporters/tfc/main.tf b/exporters/tfc/main.tf index fc53914..4537927 100644 --- a/exporters/tfc/main.tf +++ b/exporters/tfc/main.tf @@ -4,6 +4,7 @@ locals { stacks = [for i, v in data.tfe_workspace_ids.all.ids : { autodeploy = data.tfe_workspace.all[i].auto_apply env_vars = [for i, v in data.tfe_variables.all[v].variables : { + hcl = v.hcl name = v.category == "terraform" ? "TF_VAR_${v.name}" : v.name sensitive = v.sensitive value = v.value diff --git a/generator/generator.tftpl b/generator/generator.tftpl index 5386a56..4972c33 100644 --- a/generator/generator.tftpl +++ b/generator/generator.tftpl @@ -33,7 +33,7 @@ resource "spacelift_stack" "${replace(lower(stack.name), "-", "_")}" { resource "spacelift_environment_variable" "${replace(lower(env_var.name), "-", "_")}" { stack_id = spacelift_stack.${replace(lower(stack.name), "-", "_")}.id name = "${env_var.name}" - value = "${env_var.value}" + value = %{if env_var.hcl ~}jsonencode(${env_var.value})%{else}"${env_var.value}"%{~endif} write_only = ${env_var.sensitive} } %{ endfor ~} diff --git a/generator/variables.tf b/generator/variables.tf index 231d70c..aa72fcd 100644 --- a/generator/variables.tf +++ b/generator/variables.tf @@ -3,6 +3,7 @@ variable "stacks" { type = list(object({ autodeploy = bool env_vars = list(object({ + hcl = bool name = string sensitive = bool value = string