Interview Prep/Terraform/Resources Variables and Expressions

A script needs the load balancer DNS name after apply. How do you expose it?

BeginnerScenarioResources Variables and Expressions
Answer

Situation read → Outputs are the interface between Terraform and the outside world.

What I'd do →

output "alb_dns_name" {
  value       = aws_lb.main.dns_name
  description = "Public DNS name of the ALB"
}
terraform output -raw alb_dns_name
terraform output -json | jq .

Why → -raw prints a bare string suitable for shell use; -json is for structured data.

Interview tip → Outputs from the root module are also what other stacks read through terraform_remote_state, so treat them as a contract.

All Terraform questions Roadmap: Terraform

More on Resources Variables and Expressions