diff --git a/terraform/aws/simple-module/main.tf b/terraform/aws/simple-module/main.tf new file mode 100644 index 0000000..8a47463 --- /dev/null +++ b/terraform/aws/simple-module/main.tf @@ -0,0 +1,23 @@ +module "vpc20" { + source = "./modules/vpc" + + name = "test-vpc-1" + vpc_cidr_block = "10.20.0.0/16" + vpc_dns_hostnames = "true" + vpc_dns_support = "true" + + subnet_cidr_block = "10.20.1.0/24" + subnet_map_pub_ip = "true" +} + +module "vpc50" { + source = "./modules/vpc" + + name = "test-vpc-1" + vpc_cidr_block = "10.50.0.0/16" + vpc_dns_hostnames = "true" + vpc_dns_support = "true" + + subnet_cidr_block = "10.50.1.0/24" + subnet_map_pub_ip = "true" +} diff --git a/terraform/aws/simple-module/modules/vpc/main.tf b/terraform/aws/simple-module/modules/vpc/main.tf new file mode 100644 index 0000000..8b29d73 --- /dev/null +++ b/terraform/aws/simple-module/modules/vpc/main.tf @@ -0,0 +1,36 @@ +# Create a new VPC +resource "aws_vpc" "vpc" { + cidr_block = "${var.vpc_cidr_block}" + enable_dns_hostnames = "${var.vpc_dns_hostnames}" + enable_dns_support = "${var.vpc_dns_support}" +} + +# Create a public subnet in the new VPC +resource "aws_subnet" "subnet" { + vpc_id = "${aws_vpc.vpc.id}" + cidr_block = "${var.subnet_cidr_block}" + map_public_ip_on_launch = "${var.subnet_map_pub_ip}" +} + +# Create a new Internet gateway +resource "aws_internet_gateway" "gateway" { + vpc_id = "${aws_vpc.vpc.id}" +} + +# Create a route table for the new VPC +resource "aws_route_table" "routes" { + vpc_id = "${aws_vpc.vpc.id}" +} + +# Create a route in new route table +resource "aws_route" "default_route" { + route_table_id = "${aws_route_table.routes.id}" + destination_cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.gateway.id}" +} + +# Associate route table with subnet in VPC +resource "aws_route_table_association" "rte_tbl_assoc" { + subnet_id = "${aws_subnet.subnet.id}" + route_table_id = "${aws_route_table.routes.id}" +} diff --git a/terraform/aws/simple-module/modules/vpc/output.tf b/terraform/aws/simple-module/modules/vpc/output.tf new file mode 100644 index 0000000..a41b292 --- /dev/null +++ b/terraform/aws/simple-module/modules/vpc/output.tf @@ -0,0 +1,11 @@ +output "new_vpc_id" { + value = "${aws_vpc.vpc.id}" +} + +output "new_subnet_id" { + value = "${aws_subnet.subnet.id}" +} + +output "new_subnet_az" { + value = "${aws_subnet.subnet.availability_zone}" +} diff --git a/terraform/aws/simple-module/modules/vpc/variables.tf b/terraform/aws/simple-module/modules/vpc/variables.tf new file mode 100644 index 0000000..2201506 --- /dev/null +++ b/terraform/aws/simple-module/modules/vpc/variables.tf @@ -0,0 +1,29 @@ +variable "name" { + type = "string" + description = "Name prefix to use for networking resources" +} + +variable "vpc_cidr_block" { + type = "string" + description = "CIDR block to use for new VPC" +} + +variable "vpc_dns_hostnames" { + type = "string" + description = "True/False to enable DNS hostnames in new VPC" +} + +variable "vpc_dns_support" { + type = "string" + description = "True/False to enable DNS support in new VPC" +} + +variable "subnet_cidr_block" { + type = "string" + description = "CIDR block (in VPC CIDR block) to use for new subnet" +} + +variable "subnet_map_pub_ip" { + type = "string" + description = "True/False to map public IP addresses on launch" +} diff --git a/terraform/aws/simple-module/provider.tf b/terraform/aws/simple-module/provider.tf new file mode 100644 index 0000000..d7c130e --- /dev/null +++ b/terraform/aws/simple-module/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "${var.user_region}" +} diff --git a/terraform/aws/simple-module/variables.tf b/terraform/aws/simple-module/variables.tf new file mode 100644 index 0000000..7b8a12a --- /dev/null +++ b/terraform/aws/simple-module/variables.tf @@ -0,0 +1,4 @@ +variable "user_region" { + type = "string" + description = "AWS region to use for all resources" +}