瀏覽代碼

siwtch to 1 tier

Chris Mague 6 年之前
父節點
當前提交
7e7a5ab000
共有 5 個文件被更改,包括 67 次插入73 次删除
  1. 3 2
      main.tf
  2. 13 10
      outputs.tf
  3. 35 35
      private_subnets.tf
  4. 14 13
      public_subnets.tf
  5. 2 13
      variables.tf

+ 3 - 2
main.tf

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

+ 13 - 10
outputs.tf

@@ -1,19 +1,22 @@
 output "vpc-id" {
-  value = "${aws_vpc.vpc.id}"
+  value = aws_vpc.vpc.id
 }
 
 output "vpc-cidr" {
-  value = "${var.vpc-cidr}"
+  value = var.vpc-cidr
 }
+
 output "subnets-public" {
-  value = ["${aws_subnet.public.*.id}"]
-}
-output "subnets-private" {
-  value = ["${aws_subnet.private.*.id}"]
+  value = aws_subnet.public[*].id
 }
+
 output "vpc-azs" {
-  value = "${var.vpc-azs}"
-}
-output "private-nats" {
-  value = ["${aws_eip.private-nat-eip.*.public_ip}"]
+  value = var.vpc-azs
 }
+
+#output "subnets-private" {
+#  value = ["${aws_subnet.private.*.id}"]
+#}
+#output "private-nats" {
+#  value = ["${aws_eip.private-nat-eip.*.public_ip}"]
+#}

+ 35 - 35
private_subnets.tf

@@ -1,35 +1,35 @@
-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
-  tags       = merge({ Name = "${var.vpc-name}-nat-eip-${count.index}" }, var.common-tags)
-  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"]
-  tags          = merge({ Name = "${var.vpc-name}-private-${element(var.vpc-azs, count.index)}" }, var.common-tags)
-}
-
-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)
-}
+#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
+#  tags       = merge({ Name = "${var.vpc-name}-nat-eip-${count.index}" }, var.common-tags)
+#  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"]
+#  tags          = merge({ Name = "${var.vpc-name}-private-${element(var.vpc-azs, count.index)}" }, var.common-tags)
+#}
+#
+#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)
+#}

+ 14 - 13
public_subnets.tf

@@ -1,27 +1,28 @@
 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}"
+  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)}"
+  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)}"
+  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)}"
+  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}"
+  count  = length(var.vpc-azs)
+  vpc_id = aws_vpc.vpc.id
   tags   = merge({ Name = "${var.vpc-name}-public-${element(var.vpc-azs, count.index)}" }, var.common-tags)
 }
+

+ 2 - 13
variables.tf

@@ -25,23 +25,12 @@ variable "map-public-ip-on-launch" {
 }
 
 variable "vpc-azs" {
-  type        = "list"
+  type        = list(string)
   description = "The list of approved azs eg: ['us-west-1a', 'us-west-1c']"
 }
 
 variable "common-tags" {
-  type        = map
+  type        = map(string)
   description = "Tags that go everywhere"
 }
 
-
-
-
-
-
-
-
-
-
-
-