Skip to content

Use new file pattern for stacks

All new stacks created with the ok scaffold command will return a new file pattern which is more descriptive. Instead of two files common.tf and config.tf, four files will be created: _config.auto.tfvars.json, _config.tf, _variables.tf. _versions.tf.

Affected versions

All stacks containing the files common.tf and config.tf.

Pull request #927

Details

ok scaffold <name of stack> now creates files with the following names:

  • _config.auto.tfvars.json - contains variables set automatically for you whenever you run Terraform
  • _config.tf - common locals shared between multiple resources
  • _variables.tf - all variables used throughout the stack
  • _versions.tf - versions of the different Terraform providers used in the stack

This new file pattern intends to make it more obvious what goes in each of the files. These are suggestions to make it easier to understand what goes where, but can be adapted as needed.

Step 1: Apply the new file pattern to existing stacks

For each stack in your IaC repository, replace the files common.tf and config.tf with the new files using ok scaffold <name of stack> (current directory must be the parent of the stack).

To help this migration, we've made a helper environment variable DELETE_OLD_STYLE_CONFIG. This makes the ok tool delete the old style configuration files before adding the new files. It can be used like this:

DELETE_OLD_STYLE_CONFIG=true ok scaffold <name_of_stack>

Step 2: Move declarations (if any)

If common.tf or config.tf contained custom declarations, the new files must keep these. If not, skip to the next step.

For example, if common.tf contained:

locals {
  # ...
  zone_name_prefix = local.environment
}

Then:

Step 3: Remove tags from resources (if any)

Because the new file pattern includes the default_tags (code example), the tags on most resources can be removed. Example:

diff --git a/stacks/prod/certificates/certificates.tf b/stacks/prod/certificates/certificates.tf
-  tags = local.common_tags
 }

Code example

Step 4: Verify that there are no changes

There should be no changes to the infrastructure. However, due to a known issue, terraform plan might show changes to tags. This is a bug in Terraform, and can be ignored, as long as the tags are as expected.

Run terraform plan and verify that there are no changes, except as mentioned regarding tags.