MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Terraform Output Variable Tutorials with Example

Terraform will store hundreds or even thousands of attribute values for all the defined resources in our infrastructure in state file.

An outputed attributes can not only be used for the user reference but it can also act as an input to other resources being created via Terraform.

Output variables provide a convenient way to get useful information about your infrastructure. Terraform output values allow you to export structured data about your resources. You can use this data to configure other parts of your infrastructure with automation tools, or as a data source for another Terraform workspace. Outputs are also necessary to share data from a child module to your root module.

Resource instances managed by Terraform each export attributes whose values can be used elsewhere in configuration. Output values are a way to expose some of that information to the user of your module.

We can use output variables to organize data to be easily queried and shown back to the Terraform user.

While Terraform stores hundreds or thousands of attribute values for all our resources, we are more likely to be interested in a few values of importance, such as a load balancer IP, VPN address, etc.

Output values are like the return values of a Terraform module, and have several uses:

  • A child module can use outputs to expose a subset of its resource attributes to a parent module.
  • A root module can use outputs to print certain values in the CLI output after running terraform apply.
  • When using remote state, root module outputs can be accessed by other configurations via a terraform_remote_state data source.

Terraform example code for output value of string type

Terraform output block named example_string with the string value Hello, World!

String Type – Terraform example code for output value of aws_instance public_dns


output "instance_public_dns" {
  value = aws_instance.example.public_dns
}Code language: JavaScript (javascript)

Map Type – Terraform example code for output value of aws_instance root_block_device


output "instance_root_block_device" {
  value = aws_instance.example.root_block_device[0].volume_id
}Code language: JavaScript (javascript)

List Type – Terraform example code for output value of aws_instance security group


output "instance_security_group" {
  value = aws_instance.example.security_groups[0]
}Code language: JavaScript (javascript)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Terraform Architecture and Components through diagram

Terraform Architecture & End-to-End Workflow This reference architecture covers the standard Terraform CLI workflow, including execution from a developer machine or CI/CD runner. It shows the relationship…

Read More

Complete Guide to HashiCorp Terraform Certification

Hashicorp Terraform is understood as the standard tool for managing modern cloud environments through code. It is defined as a software that allows for the creation and…

Read More

Terraform Tutorials: Step-by-Step Tutorial for Using the removed Block

Step-by-Step Tutorial for Using the removed Block in Terraform The removed block in Terraform (introduced in version 1.7) provides a safe way to remove resources from the…

Read More

How to Import Existing IaC Resources into Terraform

DevOps teams the world over rely on Terraform as an infrastructure-as-code (IaC) tool for building, changing, and managing cloud resources. Last summer’s Terraform version 1.5 release included…

Read More

Top 50 Terraform interview questions and answers

Q1. Are callbacks possible with Terraform on Azure? Q2. What is Terraform init? Q3. What is Terraform D? Q4. What do you understand about Terraform in AWS?…

Read More

Interview Questions & Answers for Terraform

Explain what Terraform is and how does it works What benefits infrastructure-as-code has? Why Terraform and not other technologies? (e.g. Ansible, Puppet, CloufFormation) True or False? Terraform…

Read More