amazon-web-servicesterraforminfrastructure-as-codehcl

terraform resource creation - this keyword


I came across a pattern in couple of terraform code in Github.

resource "aws_vpc" "this"

I wanted to know how keyword this provides a particular advantage over a named resource. I can't find a Hashicorp documentation on this keyword.

https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/3210728ee26665fab6b1f07417bcb0e518573a1d/main.tf

https://github.com/cloudposse/terraform-aws-vpn-connection/blob/master/context.tf


Solution

  • No, there is nothing special about this in terms of TF syntax or handling. Its just a name that may indicate that you have only one VPC in your setup. But this is not enforced by TF mechanism. Other common names are main or just vpc.