Kaynağa Gözat

refactor variable names on vpc module

Roberto Barbosa 8 yıl önce
ebeveyn
işleme
8654123035
4 değiştirilmiş dosya ile 139 ekleme ve 50 silme
  1. 89 0
      elb/main.tf
  2. 38 36
      vpc/main.tf
  3. 7 7
      vpc/outputs.tf
  4. 5 7
      vpc/variables.tf

+ 89 - 0
elb/main.tf

@@ -0,0 +1,89 @@
+resource "aws_elb" "main" {
+    name                        = "fifthsun"
+    subnets                     = ["subnet-03a35875"]
+    security_groups             = ["sg-308eab57"]
+    instances                   = ["i-9ef3dd46"]
+    cross_zone_load_balancing   = false
+    idle_timeout                = 250
+    connection_draining         = false
+    connection_draining_timeout = 300
+    internal                    = false
+
+    access_logs {
+        bucket        = "5thsunelblogs"
+        bucket_prefix = ""
+        interval      = 5
+    }
+
+    listener {
+        instance_port      = 80
+        instance_protocol  = "http"
+        lb_port            = 80
+        lb_protocol        = "http"
+        ssl_certificate_id = ""
+    }
+
+    listener {
+        instance_port      = 80
+        instance_protocol  = "http"
+        lb_port            = 443
+        lb_protocol        = "https"
+        ssl_certificate_id = "arn:aws:iam::531003974115:server-certificate/nuxeocloud2016"
+    }
+
+    health_check {
+        healthy_threshold   = 2
+        unhealthy_threshold = 4
+        interval            = 30
+        target              = "TCP:8080"
+        timeout             = 10
+    }
+
+    tags {
+        "billing-category" = "customer"
+        "billing-subcategory" = "fifthsun"
+        "Name" = "fifthsun"
+    }
+}
+
+resource "aws_elb" "internal" {
+    name                        = "fifthsun-internal"
+    subnets                     = ["subnet-03a35875"]
+    security_groups             = ["sg-308eab57"]
+    instances                   = ["i-9ef3dd46"]
+    cross_zone_load_balancing   = false
+    idle_timeout                = 1800
+    connection_draining         = false
+    connection_draining_timeout = 300
+    internal                    = true
+
+    listener {
+        instance_port      = 80
+        instance_protocol  = "http"
+        lb_port            = 80
+        lb_protocol        = "http"
+        ssl_certificate_id = ""
+    }
+
+    listener {
+        instance_port      = 80
+        instance_protocol  = "http"
+        lb_port            = 443
+        lb_protocol        = "https"
+        ssl_certificate_id = "arn:aws:iam::531003974115:server-certificate/nuxeocloud2016"
+    }
+
+    health_check {
+        healthy_threshold   = 2
+        unhealthy_threshold = 3
+        interval            = 30
+        target              = "TCP:8080"
+        timeout             = 5
+    }
+
+    tags {
+        "billing-category" = "customer"
+        "billing-subcategory" = "fifthsun"
+        "Name" = "fifthsun-internal"
+    }
+}

+ 38 - 36
vpc/main.tf

@@ -1,75 +1,77 @@
-resource "aws_vpc" "main" {
+data "aws_availability_zones" "az" {}
+
+resource "aws_vpc" "vpc" {
   cidr_block           = "${var.cidr}"
   enable_dns_hostnames = "${var.enable_dns_hostnames}"
   enable_dns_support   = "${var.enable_dns_support}"
 
   tags {
-    Name = "${var.name}"
+    Name = "${var.cloud_name}"
     managed_by	= "terraform"
   }
 }
 
-resource "aws_internet_gateway" "main" {
-  vpc_id = "${aws_vpc.main.id}"
+resource "aws_internet_gateway" "igw" {
+  vpc_id = "${aws_vpc.vpc.id}"
 
   tags {
-    Name = "${var.name}-igw"
+    Name = "${var.cloud_name}-igw"
     managed_by	= "terraform"
   }
 }
 
-resource "aws_route_table" "public" {
-  vpc_id           = "${aws_vpc.main.id}"
+resource "aws_route_table" "rtb_public" {
+  vpc_id           = "${aws_vpc.vpc.id}"
   propagating_vgws = ["${var.public_propagating_vgws}"]
 
   tags {
-    Name = "${var.name}-rt-public"
+    Name = "${var.cloud_name}-rt-public"
     managed_by	= "terraform"
   }
 }
 
-resource "aws_route" "public_internet_gateway" {
-  route_table_id         = "${aws_route_table.public.id}"
+resource "aws_route" "rt_public_igw" {
+  route_table_id         = "${aws_route_table.rtb_public.id}"
   destination_cidr_block = "0.0.0.0/0"
-  gateway_id             = "${aws_internet_gateway.main.id}"
+  gateway_id             = "${aws_internet_gateway.igw.id}"
 }
 
-resource "aws_route" "private_nat_gateway" {
-  route_table_id         = "${aws_route_table.private.id}"
+resource "aws_route" "rt_private_natgw" {
+  route_table_id         = "${aws_route_table.rtb_private.id}"
   destination_cidr_block = "0.0.0.0/0"
   nat_gateway_id         = "${aws_nat_gateway.natgw.id}"
 }
 
-resource "aws_route_table" "private" {
-  vpc_id           = "${aws_vpc.main.id}"
+resource "aws_route_table" "rtb_private" {
+  vpc_id           = "${aws_vpc.vpc.id}"
   propagating_vgws = ["${var.private_propagating_vgws}"]
 
   tags {
-    Name = "${var.name}-rt-private-${data.aws_availability_zones.available.names[1]}"
+    Name = "${var.cloud_name}-rt-private-${data.aws_availability_zones.az.names[1]}"
     managed_by	= "terraform"
   }
 }
 
-resource "aws_subnet" "public" {
-  vpc_id            = "${aws_vpc.main.id}"
-  cidr_block        = "${var.public_subnet}"
-  availability_zone = "${data.aws_availability_zones.available.names[0]}"
+resource "aws_subnet" "sn_public" {
+  vpc_id            = "${aws_vpc.vpc.id}"
+  cidr_block        = "${var.sn_public_cidr}"
+  availability_zone = "${data.aws_availability_zones.az.names[0]}"
 
   tags {
-    Name = "${var.name}-subnet-public-${data.aws_availability_zones.available.names[0]}"
+    Name = "${var.cloud_name}-subnet-public-${data.aws_availability_zones.az.names[0]}"
     managed_by	= "terraform"
   }
 
   map_public_ip_on_launch = "${var.map_public_ip_on_launch}"
 }
 
-resource "aws_subnet" "private" {
-  vpc_id            = "${aws_vpc.main.id}"
-  cidr_block        = "${var.private_subnet}"
-  availability_zone = "${data.aws_availability_zones.available.names[1]}"
+resource "aws_subnet" "sn_private" {
+  vpc_id            = "${aws_vpc.vpc.id}"
+  cidr_block        = "${var.sn_private_cidr}"
+  availability_zone = "${data.aws_availability_zones.az.names[1]}"
 
   tags {
-    Name = "${var.name}-rt-private-${data.aws_availability_zones.available.names[1]}"
+    Name = "${var.cloud_name}-rt-private-${data.aws_availability_zones.az.names[1]}"
     managed_by	= "terraform"
   }
 }
@@ -81,24 +83,24 @@ resource "aws_eip" "nateip" {
 
 resource "aws_nat_gateway" "natgw" {
   allocation_id = "${aws_eip.nateip.id}"
-  subnet_id     = "${aws_subnet.public.id}"
+  subnet_id     = "${aws_subnet.sn_public.id}"
 
-  depends_on = ["aws_internet_gateway.main"]
+  depends_on = ["aws_internet_gateway.igw"]
 }
 
-resource "aws_route_table_association" "public" {
-  subnet_id      = "${aws_subnet.public.id}"
-  route_table_id = "${aws_route_table.public.id}"
+resource "aws_route_table_association" "rta_public" {
+  subnet_id      = "${aws_subnet.sn_public.id}"
+  route_table_id = "${aws_route_table.rtb_public.id}"
 }
 
-resource "aws_route_table_association" "private" {
-  subnet_id      = "${aws_subnet.private.id}"
-  route_table_id = "${aws_route_table.private.id}"
+resource "aws_route_table_association" "rta_private" {
+  subnet_id      = "${aws_subnet.sn_private.id}"
+  route_table_id = "${aws_route_table.rtb_private.id}"
 }
 
-resource "aws_security_group" "inbound" {
+resource "aws_security_group" "sg_vpc_in_std" {
   name        = "allow-ssh-wnb"
-  vpc_id      = "${aws_vpc.main.id}"
+  vpc_id      = "${aws_vpc.vpc.id}"
   description = "Allows external incoming ssh and web traffic"
 
   ingress {

+ 7 - 7
vpc/outputs.tf

@@ -1,25 +1,25 @@
 output "private_subnet" {
-  value = "${aws_subnet.private.id}"
+  value = "${aws_subnet.sn_private.id}"
 }
 
 output "public_subnet" {
-  value = "${aws_subnet.public.id}"
+  value = "${aws_subnet.sn_public.id}"
 }
 
 output "vpc_id" {
-  value = "${aws_vpc.main.id}"
+  value = "${aws_vpc.vpc.id}"
 }
 
 output "public_route_table_ids" {
-  value = ["${aws_route_table.public.*.id}"]
+  value = ["${aws_route_table.rtb_public.*.id}"]
 }
 
 output "private_route_table_ids" {
-  value = ["${aws_route_table.private.*.id}"]
+  value = ["${aws_route_table.rtb_private.*.id}"]
 }
 
 output "default_security_group_id" {
-  value = "${aws_vpc.main.default_security_group_id}"
+  value = "${aws_vpc.vpc.default_security_group_id}"
 }
 
 output "nat_eips" {
@@ -27,5 +27,5 @@ output "nat_eips" {
 }
 
 output "sg_inbound" {
-	value = "${aws_security_group.inbound.id}"
+	value = "${aws_security_group.sg_vpc_in_std.id}"
 }

+ 5 - 7
vpc/variables.tf

@@ -1,15 +1,15 @@
-variable "name" {}
+variable "cloud_name" {}
 
 variable "cidr" {
   default  = "10.0.0.0/16"
 }
 
-variable "public_subnet" {
+variable "sn_public_cidr" {
   description = "Default public subnet inside the VPC."
   default  = "10.0.1.0/24"
 }
 
-variable "private_subnet" {
+variable "sn_private_cidr" {
   description = "Default private subnet inside the VPC."
   default      = "10.0.2.0/24"
 }
@@ -31,7 +31,7 @@ variable "enable_nat_gateway" {
 
 variable "map_public_ip_on_launch" {
   description = "should be false if you do not want to auto-assign public IP on launch"
-  default     = true
+  default     = false
 }
 
 variable "private_propagating_vgws" {
@@ -42,6 +42,4 @@ variable "private_propagating_vgws" {
 variable "public_propagating_vgws" {
   description = "A list of VGWs the public route table should propagate."
   default     = []
-}
-
-data "aws_availability_zones" "available" {}
+}