diff --git a/terraform/aws/bastion-aws/data.tf b/terraform/aws/bastion-aws/data.tf index 8fc86d9..64a74dd 100644 --- a/terraform/aws/bastion-aws/data.tf +++ b/terraform/aws/bastion-aws/data.tf @@ -1,25 +1,29 @@ data "aws_ami" "atomic_ami" { - most_recent = true - owners = ["410186602215"] - filter { - name = "name" - values = ["CentOS Atomic Host 7*"] - } - filter { - name = "virtualization-type" - values = ["hvm"] - } + most_recent = true + owners = ["410186602215"] + + filter { + name = "name" + values = ["CentOS Atomic Host 7*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } } data "aws_ami" "centos_ami" { - most_recent = true - owners = ["410186602215"] - filter { - name = "name" - values = ["CentOS Linux 7*"] - } - filter { - name = "virtualization-type" - values = ["hvm"] - } + most_recent = true + owners = ["410186602215"] + + filter { + name = "name" + values = ["CentOS Linux 7*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } } diff --git a/terraform/aws/bastion-aws/instances.tf b/terraform/aws/bastion-aws/instances.tf index bf8180f..d2afc61 100644 --- a/terraform/aws/bastion-aws/instances.tf +++ b/terraform/aws/bastion-aws/instances.tf @@ -1,32 +1,34 @@ # Launch a CentOS 7 instance to serve as bastion host resource "aws_instance" "bastion" { - ami = "${data.aws_ami.centos_ami.id}" - instance_type = "${var.flavor}" - key_name = "${var.keypair}" - vpc_security_group_ids = ["${aws_security_group.bastion_sg.id}"] - subnet_id = "${aws_subnet.bastion_net.id}" - depends_on = ["aws_internet_gateway.bastion_gw"] - tags { - Name = "bastion" - tool = "terraform" - demo = "bastion-aws" - area = "instances" - } + ami = "${data.aws_ami.centos_ami.id}" + instance_type = "${var.flavor}" + key_name = "${var.keypair}" + vpc_security_group_ids = ["${aws_security_group.bastion_sg.id}"] + subnet_id = "${aws_subnet.bastion_net.id}" + depends_on = ["aws_internet_gateway.bastion_gw"] + + tags { + Name = "bastion" + tool = "terraform" + demo = "bastion-aws" + area = "instances" + } } # Launch a CentOS Atomic Host instance to serve as a private host resource "aws_instance" "private" { - ami = "${data.aws_ami.atomic_ami.id}" - instance_type = "${var.flavor}" - key_name = "${var.keypair}" - vpc_security_group_ids = ["${aws_security_group.private_sg.id}"] - subnet_id = "${aws_subnet.private_net.id}" - depends_on = ["aws_internet_gateway.bastion_gw"] - associate_public_ip_address = false - tags { - Name = "private" - tool = "terraform" - demo = "bastion-aws" - area = "instances" - } + ami = "${data.aws_ami.atomic_ami.id}" + instance_type = "${var.flavor}" + key_name = "${var.keypair}" + vpc_security_group_ids = ["${aws_security_group.private_sg.id}"] + subnet_id = "${aws_subnet.private_net.id}" + depends_on = ["aws_internet_gateway.bastion_gw"] + associate_public_ip_address = false + + tags { + Name = "private" + tool = "terraform" + demo = "bastion-aws" + area = "instances" + } } diff --git a/terraform/aws/bastion-aws/networking.tf b/terraform/aws/bastion-aws/networking.tf index f2d2813..1915282 100644 --- a/terraform/aws/bastion-aws/networking.tf +++ b/terraform/aws/bastion-aws/networking.tf @@ -1,65 +1,71 @@ # Create a new VPC resource "aws_vpc" "bastion_vpc" { - cidr_block = "10.2.0.0/16" - enable_dns_hostnames = true - enable_dns_support = true - tags { - tool = "terraform" - demo = "bastion-aws" - area = "networking" - } + cidr_block = "10.2.0.0/16" + enable_dns_hostnames = true + enable_dns_support = true + + tags { + tool = "terraform" + demo = "bastion-aws" + area = "networking" + } } # Create a public subnet in the new VPC resource "aws_subnet" "bastion_net" { - vpc_id = "${aws_vpc.bastion_vpc.id}" - cidr_block = "10.2.1.0/24" - map_public_ip_on_launch = true - tags { - tool = "terraform" - demo = "bastion-aws" - area = "networking" - } + vpc_id = "${aws_vpc.bastion_vpc.id}" + cidr_block = "10.2.1.0/24" + map_public_ip_on_launch = true + + tags { + tool = "terraform" + demo = "bastion-aws" + area = "networking" + } } # Create a private subnet in the new VPC resource "aws_subnet" "private_net" { - vpc_id = "${aws_vpc.bastion_vpc.id}" - cidr_block = "10.2.2.0/24" - map_public_ip_on_launch = false - tags { - tool = "terraform" - demo = "bastion-aws" - area = "networking" - } + vpc_id = "${aws_vpc.bastion_vpc.id}" + cidr_block = "10.2.2.0/24" + map_public_ip_on_launch = false + + tags { + tool = "terraform" + demo = "bastion-aws" + area = "networking" + } } # Create a new Internet gateway resource "aws_internet_gateway" "bastion_gw" { - vpc_id = "${aws_vpc.bastion_vpc.id}" - tags { - tool = "terraform" - demo = "bastion-aws" - area = "networking" - } + vpc_id = "${aws_vpc.bastion_vpc.id}" + + tags { + tool = "terraform" + demo = "bastion-aws" + area = "networking" + } } # Create a route table for the new VPC resource "aws_route_table" "bastion_routes" { - vpc_id = "${aws_vpc.bastion_vpc.id}" - route { - cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.bastion_gw.id}" - } - tags { - tool = "terraform" - demo = "bastion-aws" - area = "networking" - } + vpc_id = "${aws_vpc.bastion_vpc.id}" + + route { + cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.bastion_gw.id}" + } + + tags { + tool = "terraform" + demo = "bastion-aws" + area = "networking" + } } # Associate route table with subnet in VPC resource "aws_route_table_association" "bastion_rt_assoc" { - subnet_id = "${aws_subnet.bastion_net.id}" - route_table_id = "${aws_route_table.bastion_routes.id}" + subnet_id = "${aws_subnet.bastion_net.id}" + route_table_id = "${aws_route_table.bastion_routes.id}" } diff --git a/terraform/aws/bastion-aws/output.tf b/terraform/aws/bastion-aws/output.tf index 36cad07..44bd9a9 100644 --- a/terraform/aws/bastion-aws/output.tf +++ b/terraform/aws/bastion-aws/output.tf @@ -1,11 +1,11 @@ output "bastion_pub_ip" { - value = ["${aws_instance.bastion.public_ip}"] + value = ["${aws_instance.bastion.public_ip}"] } output "bastion_priv_ip" { - value = ["${aws_instance.bastion.private_ip}"] + value = ["${aws_instance.bastion.private_ip}"] } output "remote_priv_ip" { - value = ["${aws_instance.private.private_ip}"] + value = ["${aws_instance.private.private_ip}"] } diff --git a/terraform/aws/bastion-aws/provider.tf b/terraform/aws/bastion-aws/provider.tf index d7c130e..28d3bb0 100644 --- a/terraform/aws/bastion-aws/provider.tf +++ b/terraform/aws/bastion-aws/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "${var.user_region}" + region = "${var.user_region}" } diff --git a/terraform/aws/bastion-aws/security.tf b/terraform/aws/bastion-aws/security.tf index e1871fe..218a40a 100644 --- a/terraform/aws/bastion-aws/security.tf +++ b/terraform/aws/bastion-aws/security.tf @@ -1,47 +1,53 @@ # Create a security group to allow SSH traffic to private host(s) only from bastion resource "aws_security_group" "private_sg" { - vpc_id = "${aws_vpc.bastion_vpc.id}" - name = "private-sg" - description = "Security group for web traffic to private hosts" - ingress { - from_port = "22" - to_port = "22" - protocol = "tcp" - cidr_blocks = ["10.2.1.0/24"] - } - egress { - from_port = "0" - to_port = "0" - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } - tags { - tool = "terraform" - demo = "bastion-aws" - area = "security" - } + vpc_id = "${aws_vpc.bastion_vpc.id}" + name = "private-sg" + description = "Security group for web traffic to private hosts" + + ingress { + from_port = "22" + to_port = "22" + protocol = "tcp" + cidr_blocks = ["10.2.1.0/24"] + } + + egress { + from_port = "0" + to_port = "0" + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags { + tool = "terraform" + demo = "bastion-aws" + area = "security" + } } # Create a security group to allow inbound SSH (for bastion only) resource "aws_security_group" "bastion_sg" { - vpc_id = "${aws_vpc.bastion_vpc.id}" - name = "bastion-sg" - description = "Security group for SSH bastion host" - ingress { - from_port = "22" - to_port = "22" - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - egress { - from_port = "0" - to_port = "0" - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } - tags { - tool = "terraform" - demo = "bastion-aws" - area = "security" - } + vpc_id = "${aws_vpc.bastion_vpc.id}" + name = "bastion-sg" + description = "Security group for SSH bastion host" + + ingress { + from_port = "22" + to_port = "22" + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = "0" + to_port = "0" + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags { + tool = "terraform" + demo = "bastion-aws" + area = "security" + } } diff --git a/terraform/aws/bastion-aws/variables.tf b/terraform/aws/bastion-aws/variables.tf index 128d6f5..7e2d489 100644 --- a/terraform/aws/bastion-aws/variables.tf +++ b/terraform/aws/bastion-aws/variables.tf @@ -1,14 +1,14 @@ variable "user_region" { - type = "string" - description = "AWS region in which all resources will be created" + type = "string" + description = "AWS region in which all resources will be created" } variable "keypair" { - type = "string" - description = "AWS SSH keypair to use to connect to instances" + type = "string" + description = "AWS SSH keypair to use to connect to instances" } variable "flavor" { - type = "string" - description = "AWS type to use when creating instances" + type = "string" + description = "AWS type to use when creating instances" } diff --git a/terraform/aws/ic-module-asg/data.tf b/terraform/aws/ic-module-asg/data.tf index b7e6322..6e26d31 100644 --- a/terraform/aws/ic-module-asg/data.tf +++ b/terraform/aws/ic-module-asg/data.tf @@ -1,16 +1,19 @@ data "aws_ami" "node_ami" { - most_recent = true - owners = ["099720109477"] - filter { - name = "name" - values = ["*ubuntu-xenial-16.04*"] - } - filter { - name = "virtualization-type" - values = ["hvm"] - } - filter { - name = "root-device-type" - values = ["ebs"] - } + most_recent = true + owners = ["099720109477"] + + filter { + name = "name" + values = ["*ubuntu-xenial-16.04*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "root-device-type" + values = ["ebs"] + } } diff --git a/terraform/aws/ic-module-asg/main.tf b/terraform/aws/ic-module-asg/main.tf index c9daa2f..4b1b5bd 100644 --- a/terraform/aws/ic-module-asg/main.tf +++ b/terraform/aws/ic-module-asg/main.tf @@ -1,23 +1,23 @@ module "vpc20" { - source = "./modules/vpc" + source = "./modules/vpc" - name = "etcd" - vpc_cidr_block = "10.20.0.0/16" - vpc_dns_hostnames = "true" - vpc_dns_support = "true" - subnet_map_pub_ip = "true" + name = "etcd" + vpc_cidr_block = "10.20.0.0/16" + vpc_dns_hostnames = "true" + vpc_dns_support = "true" + subnet_map_pub_ip = "true" } module "etcd" { - source = "./modules/ic-asg" + source = "./modules/ic-asg" - name = "etcd" - ami = "${data.aws_ami.node_ami.id}" - type = "${var.node_type}" - assign_pub_ip = true - ssh_key = "${var.key_pair}" - min_size = 3 - max_size = 5 - subnet_list = ["${module.vpc20.subnet_id}"] - sec_group_list = ["${module.vpc20.default_sg_id}"] + name = "etcd" + ami = "${data.aws_ami.node_ami.id}" + type = "${var.node_type}" + assign_pub_ip = true + ssh_key = "${var.key_pair}" + min_size = 3 + max_size = 5 + subnet_list = ["${module.vpc20.subnet_id}"] + sec_group_list = ["${module.vpc20.default_sg_id}"] } diff --git a/terraform/aws/ic-module-asg/modules/ic-asg/main.tf b/terraform/aws/ic-module-asg/modules/ic-asg/main.tf index 9fb715d..dc18e32 100644 --- a/terraform/aws/ic-module-asg/modules/ic-asg/main.tf +++ b/terraform/aws/ic-module-asg/modules/ic-asg/main.tf @@ -1,27 +1,27 @@ # Create a launch configuration for the instance cluster resource "aws_launch_configuration" "lc" { - name = "${var.name}-lc" - associate_public_ip_address = "${var.assign_pub_ip}" - image_id = "${var.ami}" - instance_type = "${var.type}" - key_name = "${var.ssh_key}" - security_groups = ["${var.sec_group_list}"] + name = "${var.name}-lc" + associate_public_ip_address = "${var.assign_pub_ip}" + image_id = "${var.ami}" + instance_type = "${var.type}" + key_name = "${var.ssh_key}" + security_groups = ["${var.sec_group_list}"] - lifecycle { - create_before_destroy = true - } + lifecycle { + create_before_destroy = true + } } # Create an Auto Scaling group for the instance cluster resource "aws_autoscaling_group" "asg" { - name = "${var.name}-asg" - min_size = "${var.min_size}" - max_size = "${var.max_size}" - desired_capacity = "${var.min_size}" - vpc_zone_identifier = ["${var.subnet_list}"] - launch_configuration = "${aws_launch_configuration.lc.name}" + name = "${var.name}-asg" + min_size = "${var.min_size}" + max_size = "${var.max_size}" + desired_capacity = "${var.min_size}" + vpc_zone_identifier = ["${var.subnet_list}"] + launch_configuration = "${aws_launch_configuration.lc.name}" - lifecycle { - create_before_destroy = true - } + lifecycle { + create_before_destroy = true + } } diff --git a/terraform/aws/ic-module-asg/modules/ic-asg/variables.tf b/terraform/aws/ic-module-asg/modules/ic-asg/variables.tf index 62e3fc9..83226eb 100644 --- a/terraform/aws/ic-module-asg/modules/ic-asg/variables.tf +++ b/terraform/aws/ic-module-asg/modules/ic-asg/variables.tf @@ -1,44 +1,44 @@ variable "name" { - type = "string" - description = "Name to use for instances in this instance cluster" + type = "string" + description = "Name to use for instances in this instance cluster" } variable "ami" { - type = "string" - description = "AMI to use for instances in this instance cluster" + type = "string" + description = "AMI to use for instances in this instance cluster" } variable "type" { - type = "string" - description = "Type to use for instances in this instance cluster" + type = "string" + description = "Type to use for instances in this instance cluster" } variable "ssh_key" { - type = "string" - description = "SSH key to inject into instances in this instance cluster" + type = "string" + description = "SSH key to inject into instances in this instance cluster" } variable "assign_pub_ip" { - type = "string" - description = "True/False to assign a public IP address" + type = "string" + description = "True/False to assign a public IP address" } variable "sec_group_list" { - type = "list" - description = "List of security group IDs for instances to use" + type = "list" + description = "List of security group IDs for instances to use" } variable "min_size" { - type = "string" - description = "Minimum number of instances in this instance cluster" + type = "string" + description = "Minimum number of instances in this instance cluster" } variable "max_size" { - type = "string" - description = "Maximum number of instances in this instance cluster" + type = "string" + description = "Maximum number of instances in this instance cluster" } variable "subnet_list" { - type = "list" - description = "List of subnets where instances should be launched" + type = "list" + description = "List of subnets where instances should be launched" } diff --git a/terraform/aws/ic-module-asg/modules/vpc/data.tf b/terraform/aws/ic-module-asg/modules/vpc/data.tf index 11315d1..9200ac7 100644 --- a/terraform/aws/ic-module-asg/modules/vpc/data.tf +++ b/terraform/aws/ic-module-asg/modules/vpc/data.tf @@ -1,3 +1,3 @@ data "aws_availability_zones" "az_list" { - state = "available" + state = "available" } diff --git a/terraform/aws/ic-module-asg/modules/vpc/main.tf b/terraform/aws/ic-module-asg/modules/vpc/main.tf index 710d56a..ed49d16 100644 --- a/terraform/aws/ic-module-asg/modules/vpc/main.tf +++ b/terraform/aws/ic-module-asg/modules/vpc/main.tf @@ -1,52 +1,52 @@ # 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}" + cidr_block = "${var.vpc_cidr_block}" + enable_dns_hostnames = "${var.vpc_dns_hostnames}" + enable_dns_support = "${var.vpc_dns_support}" - tags { - Name = "${var.name}_vpc" - tool = "terraform" - } + tags { + Name = "${var.name}_vpc" + tool = "terraform" + } } # Modify default VPC security group to allow inbound SSH resource "aws_security_group_rule" "allow_ssh" { - type = "ingress" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - security_group_id = "${aws_vpc.vpc.default_security_group_id}" + type = "ingress" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = "${aws_vpc.vpc.default_security_group_id}" } # Create a new Internet gateway resource "aws_internet_gateway" "gateway" { - vpc_id = "${aws_vpc.vpc.id}" + vpc_id = "${aws_vpc.vpc.id}" - tags { - Name = "${var.name}_igw" - tool = "terraform" - } + tags { + Name = "${var.name}_igw" + tool = "terraform" + } } # Add default route to VPC's main route table resource "aws_route" "default_route" { - route_table_id = "${aws_vpc.vpc.main_route_table_id}" - destination_cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.gateway.id}" + route_table_id = "${aws_vpc.vpc.main_route_table_id}" + destination_cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.gateway.id}" } # Create a public subnet in the new VPC resource "aws_subnet" "subnet" { - count = "${length(data.aws_availability_zones.az_list.names)}" - vpc_id = "${aws_vpc.vpc.id}" - cidr_block = "${cidrsubnet(var.vpc_cidr_block, 4, count.index)}" - availability_zone = "${element(data.aws_availability_zones.az_list.names, count.index)}" - map_public_ip_on_launch = "${var.subnet_map_pub_ip}" + count = "${length(data.aws_availability_zones.az_list.names)}" + vpc_id = "${aws_vpc.vpc.id}" + cidr_block = "${cidrsubnet(var.vpc_cidr_block, 4, count.index)}" + availability_zone = "${element(data.aws_availability_zones.az_list.names, count.index)}" + map_public_ip_on_launch = "${var.subnet_map_pub_ip}" - tags { - Name = "${var.name}_subnet_${count.index}" - tool = "terraform" - } + tags { + Name = "${var.name}_subnet_${count.index}" + tool = "terraform" + } } diff --git a/terraform/aws/ic-module-asg/modules/vpc/output.tf b/terraform/aws/ic-module-asg/modules/vpc/output.tf index 9f3641c..3422820 100644 --- a/terraform/aws/ic-module-asg/modules/vpc/output.tf +++ b/terraform/aws/ic-module-asg/modules/vpc/output.tf @@ -1,15 +1,15 @@ output "vpc_id" { - value = "${aws_vpc.vpc.id}" + value = "${aws_vpc.vpc.id}" } output "subnet_id" { - value = "${aws_subnet.subnet.*.id}" + value = "${aws_subnet.subnet.*.id}" } output "subnet_az" { - value = "${aws_subnet.subnet.*.availability_zone}" + value = "${aws_subnet.subnet.*.availability_zone}" } output "default_sg_id" { - value = "${aws_vpc.vpc.default_security_group_id}" + value = "${aws_vpc.vpc.default_security_group_id}" } diff --git a/terraform/aws/ic-module-asg/modules/vpc/variables.tf b/terraform/aws/ic-module-asg/modules/vpc/variables.tf index 912a40e..0bfc878 100644 --- a/terraform/aws/ic-module-asg/modules/vpc/variables.tf +++ b/terraform/aws/ic-module-asg/modules/vpc/variables.tf @@ -1,24 +1,24 @@ variable "name" { - type = "string" - description = "Name prefix to use for networking resources" + type = "string" + description = "Name prefix to use for networking resources" } variable "vpc_cidr_block" { - type = "string" - description = "CIDR block to use for new VPC" + 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" + 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" + type = "string" + description = "True/False to enable DNS support in new VPC" } variable "subnet_map_pub_ip" { - type = "string" - description = "True/False to map public IP addresses on launch" + type = "string" + description = "True/False to map public IP addresses on launch" } diff --git a/terraform/aws/ic-module-asg/provider.tf b/terraform/aws/ic-module-asg/provider.tf index d7c130e..28d3bb0 100644 --- a/terraform/aws/ic-module-asg/provider.tf +++ b/terraform/aws/ic-module-asg/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "${var.user_region}" + region = "${var.user_region}" } diff --git a/terraform/aws/ic-module-asg/variables.tf b/terraform/aws/ic-module-asg/variables.tf index a855134..c287cad 100644 --- a/terraform/aws/ic-module-asg/variables.tf +++ b/terraform/aws/ic-module-asg/variables.tf @@ -1,15 +1,15 @@ variable "user_region" { - type = "string" - description = "AWS region to use for all resources" + type = "string" + description = "AWS region to use for all resources" } variable "node_type" { - type = "string" - description = "Type of instance to use" - default = "t2.micro" + type = "string" + description = "Type of instance to use" + default = "t2.micro" } variable "key_pair" { - type = "string" - description = "SSH keypair to use for accessing instances" + type = "string" + description = "SSH keypair to use for accessing instances" } diff --git a/terraform/aws/ic-module/data.tf b/terraform/aws/ic-module/data.tf index b7e6322..6e26d31 100644 --- a/terraform/aws/ic-module/data.tf +++ b/terraform/aws/ic-module/data.tf @@ -1,16 +1,19 @@ data "aws_ami" "node_ami" { - most_recent = true - owners = ["099720109477"] - filter { - name = "name" - values = ["*ubuntu-xenial-16.04*"] - } - filter { - name = "virtualization-type" - values = ["hvm"] - } - filter { - name = "root-device-type" - values = ["ebs"] - } + most_recent = true + owners = ["099720109477"] + + filter { + name = "name" + values = ["*ubuntu-xenial-16.04*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "root-device-type" + values = ["ebs"] + } } diff --git a/terraform/aws/ic-module/main.tf b/terraform/aws/ic-module/main.tf index f7ac345..a6d8cef 100644 --- a/terraform/aws/ic-module/main.tf +++ b/terraform/aws/ic-module/main.tf @@ -1,33 +1,33 @@ module "vpc20" { - source = "./modules/vpc" + source = "./modules/vpc" - name = "etcd" - vpc_cidr_block = "10.20.0.0/16" - vpc_dns_hostnames = "true" - vpc_dns_support = "true" - subnet_map_pub_ip = "true" + name = "etcd" + vpc_cidr_block = "10.20.0.0/16" + vpc_dns_hostnames = "true" + vpc_dns_support = "true" + subnet_map_pub_ip = "true" } module "etcd" { - source = "./modules/instance-cluster" + source = "./modules/instance-cluster" - name = "etcd" - ami = "${data.aws_ami.node_ami.id}" - type = "${var.node_type}" - assign_pub_ip = true - ssh_key = "${var.key_pair}" - cluster_size = 3 - subnet_list = ["${module.vpc20.subnet_id}"] - sec_group_list = ["${module.vpc20.default_sg_id}"] - role = "etcd" + name = "etcd" + ami = "${data.aws_ami.node_ami.id}" + type = "${var.node_type}" + assign_pub_ip = true + ssh_key = "${var.key_pair}" + cluster_size = 3 + subnet_list = ["${module.vpc20.subnet_id}"] + sec_group_list = ["${module.vpc20.default_sg_id}"] + role = "etcd" } module "vpc50" { - source = "./modules/vpc" + source = "./modules/vpc" - name = "k8s" - vpc_cidr_block = "10.50.0.0/16" - vpc_dns_hostnames = "true" - vpc_dns_support = "true" - subnet_map_pub_ip = "true" + name = "k8s" + vpc_cidr_block = "10.50.0.0/16" + vpc_dns_hostnames = "true" + vpc_dns_support = "true" + subnet_map_pub_ip = "true" } diff --git a/terraform/aws/ic-module/modules/instance-cluster/main.tf b/terraform/aws/ic-module/modules/instance-cluster/main.tf index 16eec6a..0bd89dd 100644 --- a/terraform/aws/ic-module/modules/instance-cluster/main.tf +++ b/terraform/aws/ic-module/modules/instance-cluster/main.tf @@ -1,15 +1,15 @@ # Launch a cluster of instances resource "aws_instance" "instance" { - count = "${var.cluster_size}" - ami = "${var.ami}" - instance_type = "${var.type}" - subnet_id = "${element(var.subnet_list, count.index)}" - key_name = "${var.ssh_key}" - associate_public_ip_address = "${var.assign_pub_ip}" - vpc_security_group_ids = ["${var.sec_group_list}"] + count = "${var.cluster_size}" + ami = "${var.ami}" + instance_type = "${var.type}" + subnet_id = "${element(var.subnet_list, count.index)}" + key_name = "${var.ssh_key}" + associate_public_ip_address = "${var.assign_pub_ip}" + vpc_security_group_ids = ["${var.sec_group_list}"] - tags { - Name = "${var.name}-${count.index}" - Role = "${var.role}" - } + tags { + Name = "${var.name}-${count.index}" + Role = "${var.role}" + } } diff --git a/terraform/aws/ic-module/modules/instance-cluster/output.tf b/terraform/aws/ic-module/modules/instance-cluster/output.tf index e57f0f8..df8245b 100644 --- a/terraform/aws/ic-module/modules/instance-cluster/output.tf +++ b/terraform/aws/ic-module/modules/instance-cluster/output.tf @@ -1,11 +1,11 @@ output "cluster_instance_public_addresses" { - value = "${aws_instance.instance.*.public_ip}" + value = "${aws_instance.instance.*.public_ip}" } output "cluster_instance_private_addresses" { - value = "${aws_instance.instance.*.private_ip}" + value = "${aws_instance.instance.*.private_ip}" } output "cluster_instance_ids" { - value = "${aws_instance.instance.*.id}" + value = "${aws_instance.instance.*.id}" } diff --git a/terraform/aws/ic-module/modules/instance-cluster/variables.tf b/terraform/aws/ic-module/modules/instance-cluster/variables.tf index f498702..4347fc2 100644 --- a/terraform/aws/ic-module/modules/instance-cluster/variables.tf +++ b/terraform/aws/ic-module/modules/instance-cluster/variables.tf @@ -1,44 +1,44 @@ variable "name" { - type = "string" - description = "Name to use for instances in this instance cluster" + type = "string" + description = "Name to use for instances in this instance cluster" } variable "ami" { - type = "string" - description = "AMI to use for instances in this instance cluster" + type = "string" + description = "AMI to use for instances in this instance cluster" } variable "type" { - type = "string" - description = "Type to use for instances in this instance cluster" + type = "string" + description = "Type to use for instances in this instance cluster" } variable "assign_pub_ip" { - type = "string" - description = "True/False to assign a public IP address" + type = "string" + description = "True/False to assign a public IP address" } variable "ssh_key" { - type = "string" - description = "SSH key to inject into instances in this instance cluster" + type = "string" + description = "SSH key to inject into instances in this instance cluster" } variable "cluster_size" { - type = "string" - description = "Number of instances in this instance cluster" + type = "string" + description = "Number of instances in this instance cluster" } variable "subnet_list" { - type = "list" - description = "List of subnet IDs where to launch instances" + type = "list" + description = "List of subnet IDs where to launch instances" } variable "sec_group_list" { - type = "list" - description = "List of security group IDs for instances to use" + type = "list" + description = "List of security group IDs for instances to use" } variable "role" { - type = "string" - description = "Value to assign to the Role tag on instances" + type = "string" + description = "Value to assign to the Role tag on instances" } diff --git a/terraform/aws/ic-module/modules/vpc/data.tf b/terraform/aws/ic-module/modules/vpc/data.tf index 11315d1..9200ac7 100644 --- a/terraform/aws/ic-module/modules/vpc/data.tf +++ b/terraform/aws/ic-module/modules/vpc/data.tf @@ -1,3 +1,3 @@ data "aws_availability_zones" "az_list" { - state = "available" + state = "available" } diff --git a/terraform/aws/ic-module/modules/vpc/main.tf b/terraform/aws/ic-module/modules/vpc/main.tf index 710d56a..ed49d16 100644 --- a/terraform/aws/ic-module/modules/vpc/main.tf +++ b/terraform/aws/ic-module/modules/vpc/main.tf @@ -1,52 +1,52 @@ # 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}" + cidr_block = "${var.vpc_cidr_block}" + enable_dns_hostnames = "${var.vpc_dns_hostnames}" + enable_dns_support = "${var.vpc_dns_support}" - tags { - Name = "${var.name}_vpc" - tool = "terraform" - } + tags { + Name = "${var.name}_vpc" + tool = "terraform" + } } # Modify default VPC security group to allow inbound SSH resource "aws_security_group_rule" "allow_ssh" { - type = "ingress" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - security_group_id = "${aws_vpc.vpc.default_security_group_id}" + type = "ingress" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = "${aws_vpc.vpc.default_security_group_id}" } # Create a new Internet gateway resource "aws_internet_gateway" "gateway" { - vpc_id = "${aws_vpc.vpc.id}" + vpc_id = "${aws_vpc.vpc.id}" - tags { - Name = "${var.name}_igw" - tool = "terraform" - } + tags { + Name = "${var.name}_igw" + tool = "terraform" + } } # Add default route to VPC's main route table resource "aws_route" "default_route" { - route_table_id = "${aws_vpc.vpc.main_route_table_id}" - destination_cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.gateway.id}" + route_table_id = "${aws_vpc.vpc.main_route_table_id}" + destination_cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.gateway.id}" } # Create a public subnet in the new VPC resource "aws_subnet" "subnet" { - count = "${length(data.aws_availability_zones.az_list.names)}" - vpc_id = "${aws_vpc.vpc.id}" - cidr_block = "${cidrsubnet(var.vpc_cidr_block, 4, count.index)}" - availability_zone = "${element(data.aws_availability_zones.az_list.names, count.index)}" - map_public_ip_on_launch = "${var.subnet_map_pub_ip}" + count = "${length(data.aws_availability_zones.az_list.names)}" + vpc_id = "${aws_vpc.vpc.id}" + cidr_block = "${cidrsubnet(var.vpc_cidr_block, 4, count.index)}" + availability_zone = "${element(data.aws_availability_zones.az_list.names, count.index)}" + map_public_ip_on_launch = "${var.subnet_map_pub_ip}" - tags { - Name = "${var.name}_subnet_${count.index}" - tool = "terraform" - } + tags { + Name = "${var.name}_subnet_${count.index}" + tool = "terraform" + } } diff --git a/terraform/aws/ic-module/modules/vpc/output.tf b/terraform/aws/ic-module/modules/vpc/output.tf index 9f3641c..3422820 100644 --- a/terraform/aws/ic-module/modules/vpc/output.tf +++ b/terraform/aws/ic-module/modules/vpc/output.tf @@ -1,15 +1,15 @@ output "vpc_id" { - value = "${aws_vpc.vpc.id}" + value = "${aws_vpc.vpc.id}" } output "subnet_id" { - value = "${aws_subnet.subnet.*.id}" + value = "${aws_subnet.subnet.*.id}" } output "subnet_az" { - value = "${aws_subnet.subnet.*.availability_zone}" + value = "${aws_subnet.subnet.*.availability_zone}" } output "default_sg_id" { - value = "${aws_vpc.vpc.default_security_group_id}" + value = "${aws_vpc.vpc.default_security_group_id}" } diff --git a/terraform/aws/ic-module/modules/vpc/variables.tf b/terraform/aws/ic-module/modules/vpc/variables.tf index 912a40e..0bfc878 100644 --- a/terraform/aws/ic-module/modules/vpc/variables.tf +++ b/terraform/aws/ic-module/modules/vpc/variables.tf @@ -1,24 +1,24 @@ variable "name" { - type = "string" - description = "Name prefix to use for networking resources" + type = "string" + description = "Name prefix to use for networking resources" } variable "vpc_cidr_block" { - type = "string" - description = "CIDR block to use for new VPC" + 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" + 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" + type = "string" + description = "True/False to enable DNS support in new VPC" } variable "subnet_map_pub_ip" { - type = "string" - description = "True/False to map public IP addresses on launch" + type = "string" + description = "True/False to map public IP addresses on launch" } diff --git a/terraform/aws/ic-module/provider.tf b/terraform/aws/ic-module/provider.tf index d7c130e..28d3bb0 100644 --- a/terraform/aws/ic-module/provider.tf +++ b/terraform/aws/ic-module/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "${var.user_region}" + region = "${var.user_region}" } diff --git a/terraform/aws/ic-module/variables.tf b/terraform/aws/ic-module/variables.tf index 72b5354..f5e2440 100644 --- a/terraform/aws/ic-module/variables.tf +++ b/terraform/aws/ic-module/variables.tf @@ -1,14 +1,14 @@ variable "user_region" { - type = "string" - description = "AWS region to use for all resources" + type = "string" + description = "AWS region to use for all resources" } variable "node_type" { - type = "string" - description = "Type of instance to use" + type = "string" + description = "Type of instance to use" } variable "key_pair" { - type = "string" - description = "SSH keypair to use for accessing instances" + type = "string" + description = "SSH keypair to use for accessing instances" } diff --git a/terraform/aws/new-vpc/data.tf b/terraform/aws/new-vpc/data.tf index ecced8a..d004f6c 100644 --- a/terraform/aws/new-vpc/data.tf +++ b/terraform/aws/new-vpc/data.tf @@ -1,18 +1,21 @@ data "aws_ami" "coreos_stable" { - filter { - name = "root-device-type" - values = ["ebs"] - } - filter { - name = "architecture" - values = ["x86_64"] - } - filter { - name = "virtualization-type" - values = ["hvm"] - } - filter { - name = "name" - values = ["*1185.3.0*"] - } + filter { + name = "root-device-type" + values = ["ebs"] + } + + filter { + name = "architecture" + values = ["x86_64"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "name" + values = ["*1185.3.0*"] + } } diff --git a/terraform/aws/new-vpc/main.tf b/terraform/aws/new-vpc/main.tf index 0b2b080..95a5060 100644 --- a/terraform/aws/new-vpc/main.tf +++ b/terraform/aws/new-vpc/main.tf @@ -1,80 +1,89 @@ # Create a new VPC resource "aws_vpc" "coreos_vpc" { - cidr_block = "10.1.0.0/16" - enable_dns_hostnames = "true" - enable_dns_support = "true" - tags { - tool = "terraform" - } + cidr_block = "10.1.0.0/16" + enable_dns_hostnames = "true" + enable_dns_support = "true" + + tags { + tool = "terraform" + } } # Create a subnet in the new VPC resource "aws_subnet" "coreos_subnet" { - vpc_id = "${aws_vpc.coreos_vpc.id}" - cidr_block = "10.1.1.0/24" - map_public_ip_on_launch = "true" - tags { - tool = "terraform" - } + vpc_id = "${aws_vpc.coreos_vpc.id}" + cidr_block = "10.1.1.0/24" + map_public_ip_on_launch = "true" + + tags { + tool = "terraform" + } } # Create a new security group resource "aws_security_group" "allow_inbound_ssh" { - vpc_id = "${aws_vpc.coreos_vpc.id}" - name = "allow-inbound-ssh" - description = "Allows inbound SSH" - ingress { - from_port = "22" - to_port = "22" - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - egress { - from_port = "0" - to_port = "0" - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } - tags { - tool = "terraform" - } + vpc_id = "${aws_vpc.coreos_vpc.id}" + name = "allow-inbound-ssh" + description = "Allows inbound SSH" + + ingress { + from_port = "22" + to_port = "22" + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = "0" + to_port = "0" + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags { + tool = "terraform" + } } # Create a new Internet gateway resource "aws_internet_gateway" "coreos_gw" { - vpc_id = "${aws_vpc.coreos_vpc.id}" - tags { - tool = "terraform" - } + vpc_id = "${aws_vpc.coreos_vpc.id}" + + tags { + tool = "terraform" + } } # Create a route table for the new VPC resource "aws_route_table" "coreos_vpc_rt" { - vpc_id = "${aws_vpc.coreos_vpc.id}" - route { - cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.coreos_gw.id}" - } - tags { - tool = "terraform" - } + vpc_id = "${aws_vpc.coreos_vpc.id}" + + route { + cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.coreos_gw.id}" + } + + tags { + tool = "terraform" + } } # Associate route table with subnet in VPC resource "aws_route_table_association" "coreos_vpc_rta" { - subnet_id = "${aws_subnet.coreos_subnet.id}" - route_table_id = "${aws_route_table.coreos_vpc_rt.id}" + subnet_id = "${aws_subnet.coreos_subnet.id}" + route_table_id = "${aws_route_table.coreos_vpc_rt.id}" } # Launch a new CoreOS instance in the new subnet and VPC resource "aws_instance" "coreos01" { - ami = "${data.aws_ami.coreos_stable.id}" - instance_type = "${var.flavor}" - key_name = "${var.keypair}" - vpc_security_group_ids = ["${aws_security_group.allow_inbound_ssh.id}"] - subnet_id = "${aws_subnet.coreos_subnet.id}" - depends_on = ["aws_internet_gateway.coreos_gw"] - tags { - tool = "terraform" - } + ami = "${data.aws_ami.coreos_stable.id}" + instance_type = "${var.flavor}" + key_name = "${var.keypair}" + vpc_security_group_ids = ["${aws_security_group.allow_inbound_ssh.id}"] + subnet_id = "${aws_subnet.coreos_subnet.id}" + depends_on = ["aws_internet_gateway.coreos_gw"] + + tags { + tool = "terraform" + } } diff --git a/terraform/aws/new-vpc/output.tf b/terraform/aws/new-vpc/output.tf index e332695..ffcb948 100644 --- a/terraform/aws/new-vpc/output.tf +++ b/terraform/aws/new-vpc/output.tf @@ -1,3 +1,3 @@ output "instance_public_ip" { - value = "${aws_instance.coreos01.public_ip}" + value = "${aws_instance.coreos01.public_ip}" } diff --git a/terraform/aws/new-vpc/provider.tf b/terraform/aws/new-vpc/provider.tf index d7c130e..28d3bb0 100644 --- a/terraform/aws/new-vpc/provider.tf +++ b/terraform/aws/new-vpc/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "${var.user_region}" + region = "${var.user_region}" } diff --git a/terraform/aws/new-vpc/variables.tf b/terraform/aws/new-vpc/variables.tf index 128d6f5..7e2d489 100644 --- a/terraform/aws/new-vpc/variables.tf +++ b/terraform/aws/new-vpc/variables.tf @@ -1,14 +1,14 @@ variable "user_region" { - type = "string" - description = "AWS region in which all resources will be created" + type = "string" + description = "AWS region in which all resources will be created" } variable "keypair" { - type = "string" - description = "AWS SSH keypair to use to connect to instances" + type = "string" + description = "AWS SSH keypair to use to connect to instances" } variable "flavor" { - type = "string" - description = "AWS type to use when creating instances" + type = "string" + description = "AWS type to use when creating instances" } diff --git a/terraform/aws/simple-ec2/data.tf b/terraform/aws/simple-ec2/data.tf index b7aa9c8..8ef48a7 100644 --- a/terraform/aws/simple-ec2/data.tf +++ b/terraform/aws/simple-ec2/data.tf @@ -1,34 +1,38 @@ data "aws_ami" "ubuntu-1404-ami" { - most_recent = true - owners = ["099720109477"] - filter { - name = "root-device-type" - values = ["ebs"] - } - filter { - name = "architecture" - values = ["x86_64"] - } - filter { - name = "virtualization-type" - values = ["hvm"] - } - filter { - name = "name" - values = ["*ubuntu-trusty-14.04*"] - } + most_recent = true + owners = ["099720109477"] + + filter { + name = "root-device-type" + values = ["ebs"] + } + + filter { + name = "architecture" + values = ["x86_64"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "name" + values = ["*ubuntu-trusty-14.04*"] + } } data "aws_vpc" "default-vpc" { - filter { - name = "isDefault" - values = ["true"] - } + filter { + name = "isDefault" + values = ["true"] + } } data "aws_subnet" "default-subnet" { - filter { - name = "cidrBlock" - values = ["172.31.16.0/20"] - } + filter { + name = "cidrBlock" + values = ["172.31.16.0/20"] + } } diff --git a/terraform/aws/simple-ec2/main.tf b/terraform/aws/simple-ec2/main.tf index b8fe61a..15c7c7e 100644 --- a/terraform/aws/simple-ec2/main.tf +++ b/terraform/aws/simple-ec2/main.tf @@ -1,11 +1,12 @@ # Create a new Ubuntu 14.04 instance using values from vars.tf and data.tf resource "aws_instance" "test-01" { - ami = "${data.aws_ami.ubuntu-1404-ami.id}" - instance_type = "${var.flavor}" - key_name = "${var.keypair}" - vpc_security_group_ids = ["${var.sec-group}"] - subnet_id = "${data.aws_subnet.default-subnet.id}" - tags { - Name = "terraform" - } + ami = "${data.aws_ami.ubuntu-1404-ami.id}" + instance_type = "${var.flavor}" + key_name = "${var.keypair}" + vpc_security_group_ids = ["${var.sec-group}"] + subnet_id = "${data.aws_subnet.default-subnet.id}" + + tags { + Name = "terraform" + } } diff --git a/terraform/aws/simple-ec2/output.tf b/terraform/aws/simple-ec2/output.tf index 68eca57..d98e9cc 100644 --- a/terraform/aws/simple-ec2/output.tf +++ b/terraform/aws/simple-ec2/output.tf @@ -1,3 +1,3 @@ output "instance_ip_address" { - value = "${aws_instance.test-01.public_ip}" + value = "${aws_instance.test-01.public_ip}" } diff --git a/terraform/aws/simple-ec2/provider.tf b/terraform/aws/simple-ec2/provider.tf index d7c130e..28d3bb0 100644 --- a/terraform/aws/simple-ec2/provider.tf +++ b/terraform/aws/simple-ec2/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "${var.user_region}" + region = "${var.user_region}" } diff --git a/terraform/aws/simple-ec2/variables.tf b/terraform/aws/simple-ec2/variables.tf index 128b929..ec5ef1a 100644 --- a/terraform/aws/simple-ec2/variables.tf +++ b/terraform/aws/simple-ec2/variables.tf @@ -1,19 +1,19 @@ variable "user_region" { - type = "string" - description = "AWS region in which to create all resources" + type = "string" + description = "AWS region in which to create all resources" } variable "keypair" { - type = "string" - description = "AWS SSH keypair to use to connect to instances" + type = "string" + description = "AWS SSH keypair to use to connect to instances" } variable "flavor" { - type = "string" - description = "AWS type to use when creating instances" + type = "string" + description = "AWS type to use when creating instances" } variable "sec-group" { - type = "string" - description = "AWS security group to apply to instances" + type = "string" + description = "AWS security group to apply to instances" } diff --git a/terraform/aws/simple-module/main.tf b/terraform/aws/simple-module/main.tf index f5e391e..c8a92f6 100644 --- a/terraform/aws/simple-module/main.tf +++ b/terraform/aws/simple-module/main.tf @@ -1,23 +1,23 @@ module "vpc20" { - source = "./modules/vpc" + source = "./modules/vpc" - name = "test-vpc-1" - vpc_cidr_block = "10.20.0.0/16" - vpc_dns_hostnames = "true" - vpc_dns_support = "true" + 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" + subnet_cidr_block = "10.20.1.0/24" + subnet_map_pub_ip = "true" } module "vpc50" { - source = "./modules/vpc" + source = "./modules/vpc" - name = "test-vpc-2" - vpc_cidr_block = "10.50.0.0/16" - vpc_dns_hostnames = "true" - vpc_dns_support = "true" + name = "test-vpc-2" + 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" + 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 index 8b29d73..4344120 100644 --- a/terraform/aws/simple-module/modules/vpc/main.tf +++ b/terraform/aws/simple-module/modules/vpc/main.tf @@ -1,36 +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}" + 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}" + 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}" + 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}" + 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}" + 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}" + 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 index a41b292..a44aa34 100644 --- a/terraform/aws/simple-module/modules/vpc/output.tf +++ b/terraform/aws/simple-module/modules/vpc/output.tf @@ -1,11 +1,11 @@ output "new_vpc_id" { - value = "${aws_vpc.vpc.id}" + value = "${aws_vpc.vpc.id}" } output "new_subnet_id" { - value = "${aws_subnet.subnet.id}" + value = "${aws_subnet.subnet.id}" } output "new_subnet_az" { - value = "${aws_subnet.subnet.availability_zone}" + 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 index 2201506..5213311 100644 --- a/terraform/aws/simple-module/modules/vpc/variables.tf +++ b/terraform/aws/simple-module/modules/vpc/variables.tf @@ -1,29 +1,29 @@ variable "name" { - type = "string" - description = "Name prefix to use for networking resources" + type = "string" + description = "Name prefix to use for networking resources" } variable "vpc_cidr_block" { - type = "string" - description = "CIDR block to use for new VPC" + 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" + 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" + 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" + 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" + 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 index d7c130e..28d3bb0 100644 --- a/terraform/aws/simple-module/provider.tf +++ b/terraform/aws/simple-module/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "${var.user_region}" + region = "${var.user_region}" } diff --git a/terraform/aws/simple-module/variables.tf b/terraform/aws/simple-module/variables.tf index 7b8a12a..5c96bb0 100644 --- a/terraform/aws/simple-module/variables.tf +++ b/terraform/aws/simple-module/variables.tf @@ -1,4 +1,4 @@ variable "user_region" { - type = "string" - description = "AWS region to use for all resources" + type = "string" + description = "AWS region to use for all resources" } diff --git a/terraform/aws/vpc-all-azs/data.tf b/terraform/aws/vpc-all-azs/data.tf index 17ee05d..bd5eb42 100644 --- a/terraform/aws/vpc-all-azs/data.tf +++ b/terraform/aws/vpc-all-azs/data.tf @@ -1,20 +1,23 @@ data "aws_availability_zones" "avail_zones" { - state = "available" + state = "available" } data "aws_ami" "node_ami" { - most_recent = true - owners = ["099720109477"] - filter { - name = "name" - values = ["*ubuntu-xenial-16.04*"] - } - filter { - name = "virtualization-type" - values = ["hvm"] - } - filter { - name = "root-device-type" - values = ["ebs"] - } + most_recent = true + owners = ["099720109477"] + + filter { + name = "name" + values = ["*ubuntu-xenial-16.04*"] + } + + filter { + name = "virtualization-type" + values = ["hvm"] + } + + filter { + name = "root-device-type" + values = ["ebs"] + } } diff --git a/terraform/aws/vpc-all-azs/main.tf b/terraform/aws/vpc-all-azs/main.tf index 9b57db0..5a622f6 100644 --- a/terraform/aws/vpc-all-azs/main.tf +++ b/terraform/aws/vpc-all-azs/main.tf @@ -1,71 +1,75 @@ # Create a new VPC resource "aws_vpc" "demo_vpc" { - cidr_block = "${var.assigned_cidr}" - enable_dns_hostnames = "true" - enable_dns_support = "true" - tags { - Name = "multi_az_vpc" - tool = "terraform" - demo = "terraform" - area = "networking" - } + cidr_block = "${var.assigned_cidr}" + enable_dns_hostnames = "true" + enable_dns_support = "true" + + tags { + Name = "multi_az_vpc" + tool = "terraform" + demo = "terraform" + area = "networking" + } } # Modify default security group to allow inbound SSH resource "aws_security_group_rule" "allow_ssh" { - type = "ingress" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - security_group_id = "${aws_vpc.demo_vpc.default_security_group_id}" + type = "ingress" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + security_group_id = "${aws_vpc.demo_vpc.default_security_group_id}" } # Create a new Internet gateway resource "aws_internet_gateway" "demo_gw" { - vpc_id = "${aws_vpc.demo_vpc.id}" - tags { - Name = "multi_az_gw" - tool = "terraform" - demo = "terraform" - area = "networking" - } + vpc_id = "${aws_vpc.demo_vpc.id}" + + tags { + Name = "multi_az_gw" + tool = "terraform" + demo = "terraform" + area = "networking" + } } # Add default route to VPC's main route table resource "aws_route" "default" { - route_table_id = "${aws_vpc.demo_vpc.main_route_table_id}" - destination_cidr_block = "0.0.0.0/0" - gateway_id = "${aws_internet_gateway.demo_gw.id}" + route_table_id = "${aws_vpc.demo_vpc.main_route_table_id}" + destination_cidr_block = "0.0.0.0/0" + gateway_id = "${aws_internet_gateway.demo_gw.id}" } # Create public subnet(s) in the new VPC resource "aws_subnet" "demo_subnet" { - count = "${length(data.aws_availability_zones.avail_zones.names)}" - vpc_id = "${aws_vpc.demo_vpc.id}" - cidr_block = "${cidrsubnet(var.assigned_cidr, 8, count.index)}" - availability_zone = "${element(data.aws_availability_zones.avail_zones.names, count.index)}" - map_public_ip_on_launch = "true" - tags { - Name = "demo_subnet_${count.index}" - tool = "terraform" - demo = "terraform" - area = "networking" - } + count = "${length(data.aws_availability_zones.avail_zones.names)}" + vpc_id = "${aws_vpc.demo_vpc.id}" + cidr_block = "${cidrsubnet(var.assigned_cidr, 8, count.index)}" + availability_zone = "${element(data.aws_availability_zones.avail_zones.names, count.index)}" + map_public_ip_on_launch = "true" + + tags { + Name = "demo_subnet_${count.index}" + tool = "terraform" + demo = "terraform" + area = "networking" + } } # Launch instances across subnets/AZs resource "aws_instance" "node" { - count = "${var.num_nodes}" - ami = "${data.aws_ami.node_ami.id}" - instance_type = "${var.node_type}" - key_name = "${var.key_pair}" - vpc_security_group_ids = ["${aws_vpc.demo_vpc.default_security_group_id}"] - subnet_id = "${element(aws_subnet.demo_subnet.*.id, count.index)}" - tags { - Name = "node-${count.index}" - tool = "terraform" - demo = "terraform" - area = "compute" - } + count = "${var.num_nodes}" + ami = "${data.aws_ami.node_ami.id}" + instance_type = "${var.node_type}" + key_name = "${var.key_pair}" + vpc_security_group_ids = ["${aws_vpc.demo_vpc.default_security_group_id}"] + subnet_id = "${element(aws_subnet.demo_subnet.*.id, count.index)}" + + tags { + Name = "node-${count.index}" + tool = "terraform" + demo = "terraform" + area = "compute" + } } diff --git a/terraform/aws/vpc-all-azs/provider.tf b/terraform/aws/vpc-all-azs/provider.tf index d7c130e..28d3bb0 100644 --- a/terraform/aws/vpc-all-azs/provider.tf +++ b/terraform/aws/vpc-all-azs/provider.tf @@ -1,3 +1,3 @@ provider "aws" { - region = "${var.user_region}" + region = "${var.user_region}" } diff --git a/terraform/aws/vpc-all-azs/variables.tf b/terraform/aws/vpc-all-azs/variables.tf index b084636..5f9d2e0 100644 --- a/terraform/aws/vpc-all-azs/variables.tf +++ b/terraform/aws/vpc-all-azs/variables.tf @@ -1,24 +1,24 @@ variable "user_region" { - type = "string" - description = "AWS region to use for new resources" + type = "string" + description = "AWS region to use for new resources" } variable "assigned_cidr" { - type = "string" - description = "CIDR block to use for VPC and subnets" + type = "string" + description = "CIDR block to use for VPC and subnets" } variable "node_type" { - type = "string" - description = "Type of instance to launch (such as t2.micro)" + type = "string" + description = "Type of instance to launch (such as t2.micro)" } variable "key_pair" { - type = "string" - description = "SSH keypair to inject into launched instances" + type = "string" + description = "SSH keypair to inject into launched instances" } variable "num_nodes" { - type = "string" - description = "Number of nodes to launch" + type = "string" + description = "Number of nodes to launch" }