Sneek Peak: Stacks, Terraform tests
Documentation updates
I have started looking at the Terraform documentation PRs a lot more as it is usually a good indicator of what is incoming from the feature set. The two which interested me were around Terraform Stacks and Terraform tests. The Stacks one was rumoured since it is similar to the run triggers option which exists on workspaces currently.
Terraform Stacks update
From the PR terraform/PR-36372 :
If you have multiple Stacks that do not share a provisioning lifecycle, there are situations where you want to pass information between Stacks. To export data from one Stack to another, use a publish_output block to output data from one Stack, and use an upstream_input block in another Stack to consume that output.If the output value of a Stack changes after a run, HCP Terraform automatically triggers runs for any Stacks that depend on those outputs.
Introducing publish_output
Look at a sample configuration for a Stack which publishes an output relevant for other stacks; similar to the outputs on your Terraform configuration.
# Networking Stack deployment configuration
publish_output "vpc_id" {
description = "The networking Stack's VPC's ID."
# You can directly reference a deployment's values with the
# deployment.deployment_name syntax
value = deployment.network.vpc_id
}
Add on upstream_input
How do you access it from some other Stacks ? Apparently upstream_input
lets you specify the upstream stack. This doesn’t seem to be tied to a key, but rather a Stack. That makes it necessary that you know the output id ( vpc_id in this case).
# Application Stack deployment configuration
upstream_input "networking_stack" {
type = "Stack"
source = "app.terraform.io/hashicorp/Default Project/networking-stack"
}
deployment "application" {
inputs = {
# This Stack depends on the networking Stack for this value
vpc_id = upstream_input.network_stack.vpc_id
}
}
Why is this important ?
Even though Stacks are supposed to contain the entire infrastructure stack
into a single deployment, there could be a situation when they are managed by different teams and you essentially need some mechanism to link the reference of an output from one Stack with another.
Terraform tests update
From the PR terraform/PR-36408, a new field parallel
is being introduced into the Terraform tests.
- Target Release : 1.11.x
Field or Block Name | Description | Default Value |
---|---|---|
parallel |
An optional boolean attribute, which sets each run to be parallelized, unless overridden at the run level. | false |
test {
parallel = true
}
I wonder if there is a way to exclude any tests which need to run in an order and cannot be run in parallel. I am excited to see where this leads.