Storing Complex Variables
Describes how to store complex Terraform variable types within Spacelift Contexts and/or a Spacelift Stack's environment.
Terraform supports a variety of variable types such as string, number, list, bool, and map. The full list of Terraform's variable types can be found in the Terraform documentation here.
When using "complex" variable types with Spacelift such as map and list you'll need to utilize Terraform's jsonencode function when storing these variables as an environment variable in your Spacelift Stack environment or context.

Usage Example

1
locals {
2
map = {
3
foo = "bar"
4
}
5
list = ["this", "is", "a", "list"]
6
}
7
8
resource "spacelift_context" "example" {
9
description = "Example of storing complex variable types"
10
name = "Terraform Complex Variable Types Example"
11
}
12
13
resource "spacelift_environment_variable" "map_example" {
14
context_id = spacelift_context.example.id
15
name = "map_example"
16
value = jsonencode(local.map)
17
write_only = false
18
}
19
20
resource "spacelift_environment_variable" "list_example" {
21
context_id = spacelift_context.example.id
22
name = "list_example"
23
value = jsonencode(local.list)
24
write_only = false
25
}
Copied!
Notice the use of the jsonencode function when storing these complex variable types. This will allow you to successfully store these variable types within Spacelift.

Consuming Stored Variables

When consuming complex variable types in your environment, there is no need to use the jsondecode() function.