patternbashterraformModerate
Terraform outputs must be defined to pass values between modules or to external tools
Viewed 0 times
outputsmodule outputsremote stateterraform_remote_statesensitive outputcross-module
Error Messages
Problem
Values created inside a Terraform root module or child module are not accessible externally unless explicitly declared as outputs. Forgetting to output a resource attribute (like a VPC ID or load balancer ARN) forces manual lookups and breaks automation pipelines.
Solution
Define
Access outputs from a remote state:
output blocks for all values that downstream modules, other Terraform workspaces, or CI/CD pipelines need. Use sensitive = true for secrets.output "vpc_id" {
description = "The ID of the VPC"
value = aws_vpc.main.id
}
output "db_password" {
description = "Database master password"
value = random_password.db.result
sensitive = true
}Access outputs from a remote state:
data "terraform_remote_state" "networking" {
backend = "s3"
config = {
bucket = "my-tfstate"
key = "networking/terraform.tfstate"
region = "us-east-1"
}
}
resource "aws_subnet" "app" {
vpc_id = data.terraform_remote_state.networking.outputs.vpc_id
}Why
Terraform state is opaque to external consumers. Outputs are the explicit contract of what a module or workspace exposes. Sensitive outputs are redacted in CLI output but still accessible programmatically.
Gotchas
- Removing an output that another module consumes via
terraform_remote_statecauses a plan error in the consuming module sensitive = trueprevents the value from appearing in logs but does not encrypt it in state- Root module outputs are printed to stdout after apply — avoid outputting secrets unless
sensitive = true
Context
Multi-module Terraform architectures and CI/CD pipelines consuming Terraform output values
Revisions (0)
No revisions yet.