Query data with outputs
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 Define Input Variables tutorial, do so before following this one.
Initial configuration
After following the previous tutorials, you will have a
directory named learn-terraform-aws-instance
with the following configuration.
Ensure that your configuration matches this, and that you have initialized your configuration in the learn-terraform-aws-instance
directory.
Apply the configuration before continuing this tutorial. Respond to the confirmation prompt with a yes
.
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.
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 prints output values to the screen when you apply your configuration.
Query the outputs with the terraform output
command.
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, Output Data from Terraform.
Destroy infrastructure
Tip
If you plan to continue to later tutorials, skip this destroy step.
Destroy your infrastructure. Respond to the confirmation prompt with yes
.