A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/terraform/tutorials/azure-get-started/azure-outputs below:

Query data with output values | Terraform

In the previous tutorial, you used input variables to parameterize your Terraform configuration. In this tutorial, you will use output values to organize data to be easily queried and displayed to the Terraform user.

When building complex infrastructure, Terraform stores hundreds or thousands of attribute values for all your resources. As a user of Terraform, you may only be interested in a few values of importance. Outputs designate which data to display. This data is outputted when apply is called, and can be queried using the terraform output command.

Note

This tutorial builds on configuration from an earlier tutorial. If you have not yet completed it, do so now.

Create a file called outputs.tf in your learn-terraform-azure directory. Add the following output definition to outputs.tf.

outputs.tf

output "resource_group_id" {
  value = azurerm_resource_group.rg.id
}

This defines an output variable named resource_group_id. The name of the variable must conform to Terraform variable naming conventions if it is to be used as an input to other modules. The value field specifies the value, the id attribute of your resource group.

You can define multiple output blocks to specify multiple output variables.

When you add an output to a previously applied configuration, you must re-run terraform apply to observe the new output.

Apply your configuration. Remember to confirm the apply with a yes.

$ terraform apply

## ...

Changes to Outputs:
  + resource_group_id = "/subscriptions/c9ed8610-47a3-4107-a2b2-a322114dfb29/resourceGroups/myTFResourceGroup"

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:

resource_group_id = "/subscriptions/c9ed8610-47a3-4107-a2b2-a322114dfb29/resourceGroups/myTFResourceGroup"

Notice that the apply run returns the outputs. Query the output using the output command with the output ID.

$ terraform output resource_group_id
"/subscriptions/c9ed8610-47a3-4107-a2b2-a322114dfb29/resourceGroups/myTFResourceGroup"

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4