HistoryPurge: Clearing 219 old commits
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# Terraform config for creating VPC and subnets
|
||||
|
||||
These config will create the following resources on AWS. The VPC CIDR is hard-coded as 10.0.0.0/16. The subnets will sit in different availablity zones for redundancy. Resources are all tagged from a globaltag list.
|
||||
|
||||
* 1 VPC
|
||||
* public subnets in all AZs
|
||||
* private subnets in all AZs
|
||||
* 1 internet gateway
|
||||
* 1 nat gateway
|
||||
|
||||
## Variables to TF
|
||||
These are required variables, which can be set in terraform.tfvars
|
||||
|
||||
```
|
||||
# general variables
|
||||
resource_prefix = "unspecified"
|
||||
globalTags {
|
||||
"Environment" = "KFLAB"
|
||||
"TerraformiCliVersion" = "0.12.24"
|
||||
"TerraformMode" = "InitialDeploymentOnly"
|
||||
"Ticket" = "NotApplicable"
|
||||
}
|
||||
|
||||
# aws provider variables
|
||||
aws_access_key = "redacted"
|
||||
aws_secret_key = "redacted"
|
||||
aws_region = "ap-east-1"
|
||||
resource_prefix = "kflab-dev"
|
||||
|
||||
```
|
||||
|
||||
## Revision notes
|
||||
* Previously terraform plan would fail to compute the count for routing table association. This is now corrected by setting count = number of AZs
|
||||
@@ -0,0 +1,9 @@
|
||||
variable "aws_access_key" {}
|
||||
variable "aws_secret_key" {}
|
||||
variable "aws_region" {}
|
||||
|
||||
provider "aws" {
|
||||
access_key = "${var.aws_access_key}"
|
||||
secret_key = "${var.aws_secret_key}"
|
||||
region = "${var.aws_region}"
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
variable "globalTags" {
|
||||
type = "map"
|
||||
default {}
|
||||
}
|
||||
|
||||
variable "resource_prefix" {}
|
||||
|
||||
terraform {
|
||||
required_version = ">= 0.9.9"
|
||||
}
|
||||
|
||||
# VPC
|
||||
resource "aws_vpc" "tf-vpc1" {
|
||||
cidr_block = "10.10.0.0/16"
|
||||
|
||||
tags = "${merge(var.globalTags, map("Name","KFLAB"))}"
|
||||
}
|
||||
|
||||
# Get all AZs
|
||||
data "aws_availability_zones" "available" {
|
||||
state = "available"
|
||||
}
|
||||
|
||||
# 2 az, 1 public subnet in each
|
||||
resource "aws_subnet" "PublicSubnet" {
|
||||
vpc_id = "${aws_vpc.tf-vpc1.id}"
|
||||
cidr_block = "10.10.${count.index + 1}.0/24"
|
||||
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
|
||||
|
||||
tags = "${merge(var.globalTags, map("Name","PublicSubnet-${count.index + 1}"))}"
|
||||
|
||||
count = "${length(data.aws_availability_zones.available.names)}"
|
||||
}
|
||||
|
||||
|
||||
# 2 az, 1 private subnet in each
|
||||
resource "aws_subnet" "PrivateSubnet" {
|
||||
vpc_id = "${aws_vpc.tf-vpc1.id}"
|
||||
cidr_block = "10.10.${count.index + 21}.0/24"
|
||||
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
|
||||
|
||||
tags = "${merge(var.globalTags, map("Name","PrivateSubnet-${count.index + 1}"))}"
|
||||
|
||||
count = "${length(data.aws_availability_zones.available.names)}"
|
||||
}
|
||||
|
||||
# IGW
|
||||
resource "aws_internet_gateway" "igw1" {
|
||||
vpc_id = "${aws_vpc.tf-vpc1.id}"
|
||||
|
||||
tags = "${merge(var.globalTags, map("Name","IGW1"))}"
|
||||
}
|
||||
|
||||
# Public RT
|
||||
resource "aws_route_table" "PublicRouteTable" {
|
||||
vpc_id = "${aws_vpc.tf-vpc1.id}"
|
||||
|
||||
route {
|
||||
cidr_block = "0.0.0.0/0"
|
||||
gateway_id = "${aws_internet_gateway.igw1.id}"
|
||||
}
|
||||
|
||||
tags = "${merge(var.globalTags, map("Name","PublicRouteTable"))}"
|
||||
}
|
||||
|
||||
# Associate Public RT
|
||||
resource "aws_route_table_association" "PublicRTAsso" {
|
||||
subnet_id = "${element(aws_subnet.PublicSubnet.*.id, count.index)}"
|
||||
route_table_id = "${aws_route_table.PublicRouteTable.id}"
|
||||
count = "${length(data.aws_availability_zones.available.names)}"
|
||||
}
|
||||
|
||||
# NAT Gateway
|
||||
resource "aws_eip" "ngw1-eip" {
|
||||
vpc = true
|
||||
tags = "${var.globalTags}"
|
||||
}
|
||||
|
||||
resource "aws_nat_gateway" "ngw1" {
|
||||
allocation_id = "${aws_eip.ngw1-eip.id}"
|
||||
subnet_id = "${aws_subnet.PublicSubnet.0.id}"
|
||||
tags = "${merge(var.globalTags, map("Name","NGW1"))}"
|
||||
}
|
||||
|
||||
# Private RT
|
||||
resource "aws_route_table" "PrivateRouteTable" {
|
||||
vpc_id = "${aws_vpc.tf-vpc1.id}"
|
||||
|
||||
route {
|
||||
cidr_block = "0.0.0.0/0"
|
||||
nat_gateway_id = "${aws_nat_gateway.ngw1.id}"
|
||||
}
|
||||
|
||||
tags = "${merge(var.globalTags, map("Name","PrivateRouteTable"))}"
|
||||
}
|
||||
|
||||
# Associate Private RT
|
||||
resource "aws_route_table_association" "PrivateRTAsso" {
|
||||
subnet_id = "${element(aws_subnet.PrivateSubnet.*.id, count.index)}"
|
||||
route_table_id = "${aws_route_table.PrivateRouteTable.id}"
|
||||
count = "${length(data.aws_availability_zones.available.names)}"
|
||||
}
|
||||
|
||||
output "NGW IP" {
|
||||
value = "${aws_nat_gateway.ngw1.public_ip}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user