Playing with Terraform graph

Let's play around with our VPC a bit to better understand how resource dependencies are handled. Instead of adding a subnet, let's destroy complete infrastructure we have so far and then plan creation from scratch:

$> terraform destroy
$> terraform plan
      # ... 
+ aws_subnet.public
    availability_zone:       "<computed>"
    cidr_block:              "10.0.1.0/24"    map_public_ip_on_launch: "false"
    vpc_id:                  "${aws_vpc.my_vpc.id}"
# ...

Terraform doesn't know the VPC ID yet, so it doesn't show it to you in the plan. Let's apply the template and observe the order of resource creation:

$> terraform apply
aws_vpc.my_vpc: Creating...
  cidr_block:                "" => "10.0.0.0/16"
  default_network_acl_id:    "" => "<computed>"
 default_security_group_id: "" => "<computed>" ...

Get Getting Started with Terraform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.