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
.
Related issues
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:
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:
Then:
- Declare it in
_variables.tf
(code example) - Add it to
_config.auto.tfvars.json
(code example). - Replace references to
local.
withvar.
(code example).
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
}
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.