๐Ÿ“‘
docs
  • Initial page
  • Golang Shippets
    • PII Data Check
  • Docker
    • Concepts
  • NGINX Web Server Deep Dive
    • What's NGINX
  • AWS CloudFormation
    • Introduction
    • Infrastructure as Code
    • What's CloudFormation?
    • CloudFormation - Lab #1
    • CloudFormation Concepts
  • Kubernetes
    • Introduction
    • Untitled
  • Jenkins Engineer - (CJE)
    • Topics
  • Microsoft Azure - AZ-104
    • ๐Ÿ““Manage Azure AD Users
  • Terraform - Certified Associate
  • ๐Ÿฆ What is Terraform?
  • ๐ŸงฌInfrastructure as Code
  • ๐Ÿ“ฎGetting Started
    • ๐ŸงซBuild Infrastructure
    • ๐ŸงชChange Infrastructure
    • ๐ŸงบDefine Input Variables
    • ๐ŸšฐQuery Data with Outputs
    • ๐Ÿ’พStore Remote State
  • ๐ŸŽƒConfiguration Language
    • ๐ŸงผTerraform Resources
    • ๐Ÿ’ŠTerraform Variables
  • ๐Ÿ”ŽOverview
    • ๐Ÿ—ƒ๏ธConfiguration Syntax
  • ๐ŸŽฒCheat Sheet
  • GCP - Data Engineer
    • Overview
    • Big Data and Machine Learning Fundamentals
Powered by GitBook
On this page
  • Output EC2 instance configuration
  • Inspect output values

Was this helpful?

Edit on GitHub
  1. Getting Started

Query Data with Outputs

PreviousDefine Input VariablesNextStore Remote State

Last updated 1 year ago

Was this helpful?

In the previous tutorial, you used an input variable to parameterize your Terraform configuration. In this tutorial, you will use output values to present useful information to the Terraform user.

If you have not yet completed the tutorial, do so before following this one.

Output EC2 instance configuration

Create a file called outputs.tf in your learn-terraform-aws-instance directory.

Add the configuration below to outputs.tf to define outputs for your EC2 instance's ID and IP address.

output "instance_id" {
  description = "ID of the EC2 instance"
  value       = aws_instance.app_server.id
}

output "instance_public_ip" {
  description = "Public IP address of the EC2 instance"
  value       = aws_instance.app_server.public_ip
}

Inspect output values

You must apply this configuration before you can use these output values. Apply your configuration now. Respond to the confirmation prompt with yes.

$ terraform apply
aws_instance.app_server: Refreshing state... [id=i-0bf954919ed765de1]

Changes to Outputs:
  + instance_id        = "i-0bf954919ed765de1"
  + instance_public_ip = "54.186.202.254"

You can apply this plan to save these new output values to the Terraform state,
without changing any real infrastructure.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes


Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

instance_id = "i-0bf954919ed765de1"
instance_public_ip = "54.186.202.254"

Terraform prints output values to the screen when you apply your configuration. Query the outputs with the terraform output command.

$ terraform output
instance_id = "i-0bf954919ed765de1"
instance_public_ip = "54.186.202.254"

You can use Terraform outputs to connect your Terraform projects with other parts of your infrastructure, or with other Terraform projects. To learn more, follow our in-depth tutorial, .

๐Ÿ“ฎ
๐Ÿšฐ
Define Input Variables
Output Data from Terraform