Chris Mague vor 6 Jahren
Commit
c04e459c48
10 geänderte Dateien mit 154 neuen und 0 gelöschten Zeilen
  1. 5 0
      .gitignore
  2. 1 0
      .terraform-version
  3. 4 0
      main.tf
  4. 4 0
      outputs.tf
  5. 33 0
      private_subnets.tf
  6. 27 0
      public_subnets.tf
  7. 17 0
      test/main.tf
  8. 47 0
      variables.tf
  9. 4 0
      versions.tf
  10. 12 0
      vpc.tf

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+.terraform/*
+test/.terraform/*
+Gemfile.lock
+ansible/*.retry
+ansible/roles/*

+ 1 - 0
.terraform-version

@@ -0,0 +1 @@
+0.12.0-beta2

+ 4 - 0
main.tf

@@ -0,0 +1,4 @@
+provider "aws" {
+  region  = "${var.region}"
+  profile = "${var.profile}"
+}

+ 4 - 0
outputs.tf

@@ -0,0 +1,4 @@
+output "vpc-id" {
+  value = "${aws_vpc.vpc.id}"
+}
+

+ 33 - 0
private_subnets.tf

@@ -0,0 +1,33 @@
+resource "aws_subnet" "private" {
+  count             = "${length(var.vpc-azs)}"
+  vpc_id            = "${aws_vpc.vpc.id}"
+  cidr_block        = "${cidrsubnet(var.vpc-cidr, length(var.vpc-azs) * 2, count.index + length(var.vpc-azs))}"
+  availability_zone = "${var.vpc-azs[count.index]}"
+  tags              = merge({ Name = "${var.vpc-name}-private-${element(var.vpc-azs, count.index)}" }, var.common-tags)
+}
+
+resource "aws_eip" "private-nat-eip" {
+  count      = "${length(var.vpc-azs)}"
+  vpc        = true
+  depends_on = ["aws_internet_gateway.vpc"]
+}
+
+resource "aws_nat_gateway" "private" {
+  count         = "${length(var.vpc-azs)}"
+  allocation_id = "${element(aws_eip.private-nat-eip.*.id, count.index)}"
+  subnet_id     = "${element(aws_subnet.public.*.id, count.index)}"
+  depends_on    = ["aws_internet_gateway.vpc"]
+}
+
+resource "aws_route" "nat_gateway" {
+  count                  = "${length(var.vpc-azs)}"
+  route_table_id         = "${element(aws_route_table.private.*.id, count.index)}"
+  destination_cidr_block = "0.0.0.0/0"
+  nat_gateway_id         = "${element(aws_nat_gateway.private.*.id, count.index)}"
+}
+
+resource "aws_route_table" "private" {
+  count  = "${length(var.vpc-azs)}"
+  vpc_id = "${aws_vpc.vpc.id}"
+  tags   = merge({ Name = "${var.vpc-name}-private-${element(var.vpc-azs, count.index)}" }, var.common-tags)
+}

+ 27 - 0
public_subnets.tf

@@ -0,0 +1,27 @@
+resource "aws_subnet" "public" {
+  count                   = "${length(var.vpc-azs)}"
+  vpc_id                  = "${aws_vpc.vpc.id}"
+  cidr_block              = "${cidrsubnet(var.vpc-cidr, length(var.vpc-azs) * 2, count.index)}"
+  availability_zone       = "${var.vpc-azs[count.index]}"
+  map_public_ip_on_launch = "${var.map-public-ip-on-launch}"
+  tags                    = merge({ Name = "${var.vpc-name}-public-${element(var.vpc-azs, count.index)}" }, var.common-tags)
+}
+
+resource "aws_route" "public_internet_gateway" {
+  route_table_id         = "${element(aws_route_table.public_route_table.*.id, count.index)}"
+  destination_cidr_block = "0.0.0.0/0"
+  gateway_id             = "${aws_internet_gateway.vpc.id}"
+  count                  = "${length(var.vpc-azs)}"
+}
+
+resource "aws_route_table_association" "public" {
+  count          = "${length(var.vpc-azs)}"
+  subnet_id      = "${element(aws_subnet.public.*.id, count.index)}"
+  route_table_id = "${element(aws_route_table.public_route_table.*.id, count.index)}"
+}
+
+resource "aws_route_table" "public_route_table" {
+  count  = "${length(var.vpc-azs)}"
+  vpc_id = "${aws_vpc.vpc.id}"
+  tags   = merge({ Name = "${var.vpc-name}-Public}" }, var.common-tags)
+}

+ 17 - 0
test/main.tf

@@ -0,0 +1,17 @@
+provider "aws" {
+  region  = "us-east-1"
+  profile = "redislabs"
+}
+
+module "awx" {
+  source   = "../"
+  profile  = "redislabs"
+  region   = "us-east-1"
+  vpc-name = "rltest1"
+  vpc-cidr = "10.0.0.0/8"
+  vpc-azs  = ["us-east-1a", "us-east-1b"]
+  common-tags = {
+    "Owner"   = "maguec"
+    "Project" = "example"
+  }
+}

+ 47 - 0
variables.tf

@@ -0,0 +1,47 @@
+variable "vpc-name" {
+  description = "The name of the VPC eg: maguetest"
+}
+
+variable "profile" {
+  description = "The AWS profile to use"
+}
+
+variable "region" {
+  description = "The AWS region to run in"
+}
+
+variable "vpc-cidr" {
+  description = "The network CIDR to use for the VPC"
+}
+
+variable "enable-vpc-dns" {
+  description = "Enable vpc dns"
+  default     = true
+}
+
+variable "map-public-ip-on-launch" {
+  description = "Specify true to indicate that instances launched into the subnet should be assigned a public IP address."
+  default     = "false"
+}
+
+variable "vpc-azs" {
+  type        = "list"
+  description = "The list of approved azs eg: ['us-west-1a', 'us-west-1c']"
+}
+
+variable "common-tags" {
+  type        = map
+  description = "Tags that go everywhere"
+}
+
+
+
+
+
+
+
+
+
+
+
+

+ 4 - 0
versions.tf

@@ -0,0 +1,4 @@
+
+terraform {
+  required_version = ">= 0.12"
+}

+ 12 - 0
vpc.tf

@@ -0,0 +1,12 @@
+resource "aws_vpc" "vpc" {
+  cidr_block           = var.vpc-cidr
+  enable_dns_hostnames = var.enable-vpc-dns
+  enable_dns_support   = var.enable-vpc-dns
+  tags                 = merge({ Name = "${var.vpc-name}-VPC" }, var.common-tags)
+}
+
+resource "aws_internet_gateway" "vpc" {
+  vpc_id = aws_vpc.vpc.id
+  tags   = merge({ Name = "${var.vpc-name}-IGW" }, var.common-tags)
+}
+