Generating meaningful outputs with Terraform
Wouldn't it be great if Terraform could show us useful, informational output after a successful run? Following what we've done so far, it would be helpful to know how to connect to the instance, what are the local and public IP addresses, or see the security groups used. That's what Terraform's outputs are for.
Getting ready
To step through this recipe, you will need the following:
A working Terraform installation
An AWS provider and an EC2 instance (using a SSH keypair and a Security Group), all configured in Terraform (refer to the previous recipes)
An Internet connection
How to do it…
Thankfully, we can use the same syntax we're already using to access variables and attributes of references, but this time in an output
resource.
Let's start by simply adding a line in outputs.tf
that would show us how to connect to our virtual machine, using the public_ip
attribute of our dev
EC2 instance:
output "login" { value = "ssh ubuntu@${aws_instance.dev.public_ip...