Query data with outputs
In this tutorial, you will use output values to display data about your infrastructure back to the Terraform user.
If you haven't yet completed the Define Input Variables tutorial, do so before following this one.
Prerequisites
This tutorial assumes that you are continuing from the previous tutorial, which we highly recommend. If not, we've summarized the prerequisites here for your convenience. To follow this tutorial you will need:
OCI Tenancy. Note your region, you will use it throughout the tutorial.
The Terraform CLI installed.
The OCI CLI installed. Configure the CLI with a token by following the session authentication flow.
Create a directory named
learn-terraform-oci
and paste the following configuration into a file namedmain.tf
.Customize the
region
and both instances ofcompartment_id
to match the ones listed on your OCI tenancy page in the web console.Initialize the configuration.
Apply the configuration.
Once you have successfully initialized the configuration, you can continue with the rest of this tutorial.
Output VCN state and CIDR
Create a file called outputs.tf
in your learn-terraform-oci
directory.
Add outputs to the new file for your VCN's status and CIDR block.
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 read the documentation on Outputs.
Destroy infrastructure
Destroy your infrastructure. Respond to the confirmation prompt with yes
.
Next steps
Over the course of these tutorials you created, modified, and destroyed infrastructure as code using the Terraform CLI. You made your configurations more flexible with inputs, and more informative with outputs.
That concludes the getting started tutorials for Terraform. Hopefully you're now able to not only see what Terraform is useful for, but you're also able to use this knowledge to improve building your own infrastructure.
To learn more of the Terraform basics, refer to the following resources:
Configuration language tutorial tutorials - Get more familiar with variables, outputs, dependencies, meta-arguments, and other language features to write more sophisticated Terraform configurations. Reference documentation is also available.
Modules documentation - Organize and re-use Terraform configuration with modules.
OCI provider documentation - Learn about all the resources and modules available in the OCI provider.
OCI documentation - Learn more about OCI itself.