Terraform Cloud Backend Support for !terraform.output
The !terraform.output YAML function now works seamlessly with Terraform Cloud and Terraform Enterprise backends, enabling cross-component dependencies without switching backend types.
What Changed
Atmos now correctly generates backend.tf.json configuration for Terraform Cloud and Terraform Enterprise backends when using the !terraform.output YAML function. This was previously broken because Terraform Cloud requires a different backend structure than other backend types.
Why This Matters
The !terraform.output YAML function is powerful—it lets you reference outputs from one component in another component's configuration, creating declarative dependencies between infrastructure components. However, this feature was silently failing for teams using Terraform Cloud or Terraform Enterprise backends.
When Atmos needed to fetch outputs from a dependency component, it would generate an incorrect backend configuration that Terraform would reject:
Error: Unsupported backend type on backend.tf.json line 4, in terraform.backend: 4:
"cloud": { There is no explicit backend type named "cloud". To configure HCP
Terraform, declare a 'cloud' block instead.
This forced teams to either:
- Avoid using
!terraform.outputwith Terraform Cloud - Switch to S3/Azure/GCS backends just to use this feature
- Manually work around the limitation with
terraform_remote_statedata sources
The Problem
Terraform Cloud has a unique backend configuration structure. Unlike other backends (S3, Azure, GCS) that nest under terraform.backend.<type>, Terraform Cloud's configuration must be placed directly under terraform.cloud:
Incorrect (what Atmos was generating):
{
"terraform": {
"backend": {
"cloud": {
"organization": "my-org",
"workspaces": {
"name": "my-workspace"
}
}
}
}
}
Correct (what Terraform Cloud expects):
{
"terraform": {
"cloud": {
"organization": "my-org",
"workspaces": {
"name": "my-workspace"
}
}
}
}
This subtle difference caused Terraform to fail during initialization, preventing the !terraform.output function from fetching outputs.
How It Works
Atmos now detects when a component uses a Terraform Cloud backend and generates the correct JSON structure automatically. The fix is applied in the generateBackendConfig function within the pkg/terraform/output package.
When you use !terraform.output to reference another component's outputs, Atmos:
- Determines the backend type of the dependency component
- Generates the appropriate
backend.tf.jsonstructure - For Terraform Cloud/Enterprise backends specifically, places the configuration under
terraform.cloudinstead ofterraform.backend.cloud - Runs
terraform initandterraform outputto fetch the values - Returns the output values for use in your stack configuration
Example Usage
Define your EKS cluster component with a Terraform Cloud backend:
# stacks/eks-cluster.yaml
components:
terraform:
cluster:
backend_type: cloud
backend:
cloud:
organization: "my-org"
workspaces:
name: "eks-cluster-prod"
vars:
cluster_version: "1.29"
# ... other cluster configuration
Now reference the cluster outputs in your application component:
# stacks/my-app.yaml
components:
terraform:
my-app:
backend_type: cloud
backend:
cloud:
organization: "my-org"
workspaces:
name: "my-app-prod"
vars:
# Reference cluster outputs using !terraform.output
cluster_endpoint: !terraform.output cluster.cluster_endpoint
cluster_ca_cert: !terraform.output cluster.cluster_certificate_authority_data
cluster_name: !terraform.output cluster.cluster_name
When Atmos processes my-app, it will:
- Detect that
clusteruses a Terraform Cloud backend - Generate the correct backend configuration
- Fetch the outputs from the
eks-cluster-prodworkspace - Make them available to your
my-appcomponent
What's Next
This fix ensures feature parity across all backend types. Whether you're using S3, Azure Blob Storage, GCS, or Terraform Cloud, the !terraform.output function now works consistently.
For teams already using Terraform Cloud, this unlocks the full power of declarative component dependencies without manual workarounds.
Get Involved
Try out the enhanced !terraform.output function with Terraform Cloud and let us know what you think! File issues or feature requests on GitHub.
