2
votes

Trying to learn to use Terraform (v 0.3.7) with Amazon Web Services.

When I create a VPC using Terraform via the following:

resource "aws_vpc" "test-vpc" {
  cidr_block = "${var.vpc_cidr}"
  enable_dns_hostnames = true
  tags {
    Name = "test-vpc"
  }
}

The VPC will have a main routing table and a "default" security group automatically created (I assume by AWS, rather than Terraform); these can be identified by the attributes on the created VPC: main_route_table_id and default_security_group_id.

While following this tutorial it talks about creating your own default security group and routing table - it makes no mention of the default ones that will get created (even if you create your own routing table, the "main" one created by default will just remain sitting there, associated with no subnets or anything).

Shouldn't we be using the default resource that created with a VPC? Especially the routing table, will there be any effects because of not using the "main" routing table?

And if I should be using the default resources, how do I do that with Terraform?

I couldn't see anything in the Terraform documentation about these default resources, and if I try to override them (for example by telling Terraform to create a security group with name default, I get errors).

1

1 Answers

2
votes

AWS creates these default routing tables and sec groups. If you don't use them ( I know we don't) they are fine to get deleted. Terraform throws errors if you require it to create default sec group as probably the group is already there or maybe this sec group name is reserved. You can create one new resource "aws_security_group" ( https://terraform.io/docs/providers/aws/r/security_group.html )and have a dependency listed on the resource with

depends_on = ["aws_instance.instance-name-from-resource"]

for the instance thus sec group will be created first and then assign sec groups to the instance with "security_groups"