TrademarkTrademark
Features
Documentation
All articles

Introducing Native Support for Terraform Variable Files in Scalr

Scalr now natively supports variable files in the workspace configuration.
Ryan FeeJune 1, 2022
Introducing Native Support for Terraform Variable Files in Scalr

This post is part of a series on Terraform Variables and Outputs.

Scalr has now added native support for variable files in the workspace configuration! A common theme among our customers is to create reusable code and one of the core concepts of that is being able to inject variables per workspace to allow for the reusable code.

Previously, the way to do this was to pass in a shell variable and reference the file:

TF_CLI_ARGS_plan= -var-file=env/xxxx.tfvars

While this worked and will continue to work, the variable files are really part of the workspace configuration, which is why we have added the native support for it. Going forward, the best practice will be to add the .tfvar file(s) to the workspace configuration:

resource "scalr_workspace" "dev" {
  name = "manager-dev"
  environment_id = data.scalr_vcs_provider.manager.id
  vcs_provider_id = data.scalr_vcs_provider.manager.id
  working_directory = "module"
  var_files = ["common.tfvars", "dev.tfvars"]
 
  vcs_repo {
    identifier = "org/name"
    branch = "main"
  }
}
 
resource "scalr_workspace" "prod" {
  name = "manager-dev"
  environment_id = data.scalr_vcs_provider.manager.id
  vcs_provider_id = data.scalr_vcs_provider.manager.id
  working_directory = "module"
  var_files = ["common.tfvars", "prod.tfvars"]
 
  vcs_repo {
    identifier = "org/name"
    branch = "main"
  }
}

This now gives you the ability to add multiple files as part of the workspace configuration, and most importantly it is now part of the Scalr provider, which is the best practice in creating and maintaining workspaces. The ability to add files through the UI will follow very soon.

The combination of the Scalr module registry and variables in the workspace configuration now makes it even easier to structure your Terraform deployments at scale.

About the author
Ryan Feedirector of platform engineering at Scalr
Ryan Fee is the director of platform engineering at Scalr, with over 15 years of experience improving infrastructure experiences at companies large and small.