Spacelift
PrivacyT&Cs
  • πŸ‘‹Hello, Spacelift!
  • πŸš€Getting Started
  • 🌠Main concepts
    • Stack
      • Creating a stack
      • Stack settings
      • Organizing stacks
      • Stack locking
      • Drift detection
    • Configuration
      • Environment
      • Context
      • Runtime configuration
        • YAML reference
    • Run
      • Task
      • Proposed run (preview)
      • Tracked run (deployment)
      • Module test case
      • User-Provided Metadata
      • Run Promotion
      • Pull Request Comments
    • Policy
      • Login policy
      • Access policy
      • Approval policy
      • Initialization policy
      • Plan policy
      • Push policy
      • Task policy
      • Trigger policy
    • Resources
    • Worker pools
    • VCS Agent Pools
  • πŸ›°οΈPlatforms
    • Terraform
      • Module registry
      • External modules
      • Provider
      • State management
      • Terragrunt
      • Version management
      • Handling .tfvars
      • CLI Configuration
      • Cost Estimation
      • Resource Sanitization
      • Storing Complex Variables
      • Debugging Guide
    • Pulumi
      • Getting started
        • C#
        • Go
        • JavaScript
        • Python
      • State management
      • Version management
    • CloudFormation
      • Getting Started
      • Reference
      • Integrating with SAM
      • Integrating with the serverless framework
    • Kubernetes
      • Getting Started
      • Authenticating
      • Custom Resources
      • Helm
      • Kustomize
  • βš™οΈIntegrations
    • Audit trail
    • Cloud Integrations
      • Amazon Web Services (AWS)
      • Microsoft Azure
      • Google Cloud Platform (GCP)
    • Source Control
      • GitHub
      • GitLab
      • Azure DevOps
      • Bitbucket Cloud
      • Bitbucket Datacenter/Server
    • Docker
    • GraphQL API
    • Single sign-on
      • GitLab OIDC Setup Guide
      • Okta OIDC Setup Guide
      • OneLogin OIDC Setup Guide
      • Azure AD OIDC Setup Guide
      • AWS IAM Identity SAML 2.0 Setup Guide
    • Slack
    • Webhooks
  • πŸ“–Product
    • Privacy
    • Security
    • Support
      • Statement of Support
    • Disaster Continuity
    • Billing
      • Stripe
      • AWS Marketplace
    • Terms and conditions
    • Refund Policy
  • Cookie Policy
Powered by GitBook
On this page
  • Usage Example
  • Consuming Stored Variables

Was this helpful?

  1. Platforms
  2. Terraform

Storing Complex Variables

Describes how to store complex Terraform variable types within Spacelift Contexts and/or a Spacelift Stack's environment.

PreviousResource SanitizationNextDebugging Guide

Last updated 3 years ago

Was this helpful?

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 .

When using "complex" variable types with Spacelift such as map and list you'll need to utilize Terraform's function when storing these variables as an environment variable in your Spacelift Stack or .

Usage Example

locals {
  map = {
    foo = "bar"
  }
  list = ["this", "is", "a", "list"]
}
  
resource "spacelift_context" "example" {
  description = "Example of storing complex variable types"
  name        = "Terraform Complex Variable Types Example"
}

resource "spacelift_environment_variable" "map_example" {
  context_id = spacelift_context.example.id
  name       = "map_example"
  value      = jsonencode(local.map)
  write_only = false
}

resource "spacelift_environment_variable" "list_example" {
  context_id = spacelift_context.example.id
  name       = "list_example"
  value      = jsonencode(local.list)
  write_only = false
}

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.

πŸ›°οΈ
here
jsonencode
environment
context