1. How to print the public_ip of aws_instance? This is one of the most classic examples for terraform output values. As we know terraform ...
1. How to print the public_ip of aws_instance?
This is one of the most classic examples for terraform output values. As we know terraform is used as Infrastructure as code, so with the help of terraform you can provision many resources such - , etc.
But is there a way by which you can know the
address of the instance which you are planning to provision using terraform?Yes, there is a really convenient and easy way to achieve that.
Here is my
which I have defined as inside my -You can simply append following terraform output value code inside your
file so that it can print the public ip of yourBreak down of the above script
- - It is the keyword which you need write as is.
- - The name which we have given at the time of creating
- attributes reference page to get all the attribute which you want to print on console. - You can use
The same approach can be followed to print -
, , , , , , etc.2. How to create output.tf for terraform output values?
In the previous point we have seen how to create your first terraform output values. But if you have noticed we have created the terraform output values inside the same file.
It is completely okay to create terraform output values inside the but this practice is certainly not recommended in the industry.
The recommended way is to create a separate terraform output values, so that all the output values can be stored there.
specially of theThe only change which you need to do over here is to create a new
and store the following terraform code init -output.tf
Your directory structure should look like this -
3. How to prevent printing sensitive info on the console?
As terraform output values help us to print the attributes reference values but sometimes you can not print all the values on console.
So to prevent from printing sensitive values on the console you need to set
.Here is an example of the terraform code where we want to prevent showing the public ip to console -
In the above code if you noticed we are using
which tells terraform not to show on console.
COMMENTS