Example- Creating a public IP(Elastic IP) and outputting the value of this resource in different ways.
provider "aws" {
}
resource "aws_eip" "lb" {
domain = "vpc"
}
output "public-ip" {
value = aws_eip.lb.public_ip
}
output "public-ip-url" {
value = "https://${aws_eip.lb.public_ip}:8080"
}
output "all-attributes" {
value = aws_eip.lb
}
output "public-ip"
: This block defines an output variable namedpublic-ip
, which will hold the value of the public IP address of the EIPlb
. Output variables are a way to tell Terraform what data is important. This data can be used to inspect a Terraform state or plan.
2. output "public-ip-url"
: This block defines an output variable named public-ip-url
, which will hold the value of the URL constructed using the public IP address of the EIP lb
and port 8080. This could be useful if you want to quickly access a service running on port 8080 of the instance associated with the EIP.
3.output "all-attributes"
: This block defines an output variable named all-attributes
, which will hold all the attributes of the EIP lb
. This could be useful if you want to inspect the properties of the EIP.
Remember, to see the values of these output variables after running terraform apply
, you can use the terraform output
command.