Skip to content

Commit

Permalink
added mandatory tags
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyBarros committed Dec 16, 2020
1 parent cba3510 commit 8631bba
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 119 deletions.
42 changes: 14 additions & 28 deletions modules/aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,21 @@ resource "aws_vpc" "demostack" {
cidr_block = var.vpc_cidr_block
enable_dns_hostnames = true

tags = {
Name = var.namespace
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags

}

resource "aws_internet_gateway" "demostack" {
vpc_id = aws_vpc.demostack.id

tags = {
Name = var.namespace
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_route" "internet_access" {
route_table_id = aws_vpc.demostack.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.demostack.id

}

data "aws_availability_zones" "available" {}
Expand All @@ -68,13 +58,7 @@ resource "aws_subnet" "demostack" {
cidr_block = var.cidr_blocks[count.index]
map_public_ip_on_launch = true

tags = {
Name = var.namespace
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}


Expand All @@ -83,6 +67,7 @@ resource "aws_security_group" "demostack" {
name_prefix = var.namespace
vpc_id = aws_vpc.demostack.id

tags = local.common_tags
#Allow internal communication between nodes
ingress {
from_port = -1
Expand Down Expand Up @@ -199,43 +184,44 @@ resource "aws_security_group" "demostack" {
resource "aws_key_pair" "demostack" {
key_name = var.namespace
public_key = var.public_key

tags = local.common_tags
}

resource "aws_iam_instance_profile" "consul-join" {
name = "${var.namespace}-consul-join"
role = aws_iam_role.consul-join.name

}

resource "aws_kms_key" "demostackVaultKeys" {
description = "KMS for the Consul Demo Vault"
deletion_window_in_days = 10

tags = {
Name = var.namespace
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_iam_policy" "consul-join" {
name = "${var.namespace}-consul-join"
description = "Allows Consul nodes to describe instances for joining."

policy = data.aws_iam_policy_document.vault-server.json

}


resource "aws_iam_role" "consul-join" {
name = "${var.namespace}-consul-join"
assume_role_policy = file("${path.module}/templates/policies/assume-role.json")

tags = local.common_tags
}

resource "aws_iam_policy_attachment" "consul-join" {
name = "${var.namespace}-consul-join"
roles = [aws_iam_role.consul-join.name]
policy_arn = aws_iam_policy.consul-join.arn

}


Expand Down
16 changes: 2 additions & 14 deletions modules/boundary-lb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ resource "aws_lb" "boundary-controller" {
internal = false
subnets = aws_subnet.demostack.*.id

tags = {
Name = "${var.namespace}-boundary-controller"
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_lb_target_group" "boundary-controller" {
Expand All @@ -24,13 +18,7 @@ resource "aws_lb_target_group" "boundary-controller" {
enabled = false
type = "lb_cookie"
}
tags = {
Name = "${var.namespace}-boundary-controller"
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_lb_target_group_attachment" "boundary-controller" {
Expand Down
8 changes: 1 addition & 7 deletions modules/consul-lb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ resource "aws_alb" "consul" {
security_groups = [aws_security_group.demostack.id]
subnets = aws_subnet.demostack.*.id

tags = {
Name = "${var.namespace}-consul"
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_alb_target_group" "consul" {
Expand Down
12 changes: 12 additions & 0 deletions modules/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ resource "aws_route53_record" "boundary" {
type = "CNAME"
records = [aws_lb.boundary-controller.dns_name]
ttl = "300"

}


Expand All @@ -17,6 +18,7 @@ resource "aws_route53_record" "traefik" {
type = "CNAME"
records = [aws_alb.traefik.dns_name]
ttl = "300"

}
resource "aws_route53_record" "fabio" {
zone_id = var.zone_id
Expand All @@ -25,6 +27,7 @@ resource "aws_route53_record" "fabio" {
type = "CNAME"
records = [aws_alb.fabio.dns_name]
ttl = "300"

}
resource "aws_route53_record" "consul" {
zone_id = var.zone_id
Expand All @@ -33,6 +36,7 @@ resource "aws_route53_record" "consul" {
type = "CNAME"
records = [aws_alb.consul.dns_name]
ttl = "300"

}
resource "aws_route53_record" "nomad" {
zone_id = var.zone_id
Expand All @@ -41,6 +45,8 @@ resource "aws_route53_record" "nomad" {
type = "CNAME"
records = [aws_alb.nomad.dns_name]
ttl = "300"


}
resource "aws_route53_record" "vault" {
zone_id = var.zone_id
Expand All @@ -49,6 +55,8 @@ resource "aws_route53_record" "vault" {
type = "CNAME"
records = [aws_alb.vault.dns_name]
ttl = "300"


}

resource "aws_route53_record" "servers" {
Expand All @@ -59,6 +67,8 @@ resource "aws_route53_record" "servers" {
type = "CNAME"
records = [element(aws_instance.servers.*.public_dns, count.index)]
ttl = "300"


}

resource "aws_route53_record" "workers" {
Expand All @@ -69,5 +79,7 @@ resource "aws_route53_record" "workers" {
type = "CNAME"
records = [element(aws_instance.workers.*.public_dns, count.index)]
ttl = "300"


}

15 changes: 6 additions & 9 deletions modules/fabio-lb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ resource "aws_alb" "fabio" {
security_groups = [aws_security_group.demostack.id]
subnets = aws_subnet.demostack.*.id

tags = {
Name = "${var.namespace}-fabio"
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_alb_target_group" "fabio" {
name = "${var.namespace}-fabio"
port = "9999"
vpc_id = aws_vpc.demostack.id
protocol = "HTTP"
tags = local.common_tags

health_check {
interval = "5"
Expand All @@ -35,6 +30,7 @@ resource "aws_alb_target_group" "fabio-ui" {
port = "9998"
vpc_id = aws_vpc.demostack.id
protocol = "HTTP"
tags = local.common_tags

health_check {
interval = "5"
Expand All @@ -49,7 +45,7 @@ resource "aws_alb_target_group" "fabio-ui" {

resource "aws_alb_listener" "fabio" {
load_balancer_arn = aws_alb.fabio.arn

port = "9999"
protocol = "HTTP"

Expand All @@ -61,7 +57,6 @@ resource "aws_alb_listener" "fabio" {

resource "aws_alb_listener" "fabio-ui" {
load_balancer_arn = aws_alb.fabio.arn

port = "9998"
protocol = "HTTP"

Expand All @@ -76,11 +71,13 @@ resource "aws_alb_target_group_attachment" "fabio" {
target_group_arn = aws_alb_target_group.fabio.arn
target_id = element(aws_instance.workers.*.id, count.index)
port = "9999"

}

resource "aws_alb_target_group_attachment" "fabio-ui" {
count = var.workers
target_group_arn = aws_alb_target_group.fabio-ui.arn
target_id = element(aws_instance.workers.*.id, count.index)
port = "9998"

}
13 changes: 4 additions & 9 deletions modules/nomad-lb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ resource "aws_alb" "nomad" {
security_groups = [aws_security_group.demostack.id]
subnets = aws_subnet.demostack.*.id

tags = {
Name = "${var.namespace}-nomad"
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_alb_target_group" "nomad" {
name = "${var.namespace}-nomad"

port = "4646"
vpc_id = aws_vpc.demostack.id
protocol = "HTTPS"
Expand All @@ -37,7 +31,7 @@ resource "aws_alb_listener" "nomad" {
]

load_balancer_arn = aws_alb.nomad.arn

port = "4646"
protocol = "HTTPS"
certificate_arn = aws_acm_certificate_validation.cert.certificate_arn
Expand All @@ -54,4 +48,5 @@ resource "aws_alb_target_group_attachment" "nomad" {
target_group_arn = aws_alb_target_group.nomad.arn
target_id = element(aws_instance.servers.*.id, count.index)
port = "4646"

}
19 changes: 7 additions & 12 deletions modules/server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,13 @@ resource "aws_instance" "servers" {
delete_on_termination = "true"
}

tags = {
Name = "${var.namespace}-server-${count.index}"
namespace = var.namespace
function = "server"
Owner = var.owner
Region = var.hashi_region
Purpose = "demostack"
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
ConsulJoin = var.consul_join_tag_value
}

tags = merge(local.common_tags ,{
ConsulJoin = "${var.consul_join_tag_value}" ,
Purpose = "demostack" ,
function = "server"
}
)

user_data = element(data.template_cloudinit_config.servers.*.rendered, count.index)
}
8 changes: 1 addition & 7 deletions modules/tls.tf
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,7 @@ resource "aws_acm_certificate" "cert" {
domain_name = "*.${var.namespace}.${data.aws_route53_zone.fdqn.name}"
validation_method = "DNS"

tags = {
Name = "${var.namespace}-vault"
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags

lifecycle {
create_before_destroy = true
Expand Down
10 changes: 2 additions & 8 deletions modules/traefik.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ resource "aws_alb" "traefik" {
security_groups = [aws_security_group.demostack.id]
subnets = aws_subnet.demostack.*.id

tags = {
Name = "${var.namespace}-traefik"
owner = var.owner
created-by = var.created-by
sleep-at-night = var.sleep-at-night
TTL = var.TTL
}
tags = local.common_tags
}

resource "aws_alb_target_group" "traefik" {
name = "${var.namespace}-traefik"
port = "8080"
vpc_id = aws_vpc.demostack.id
protocol = "HTTP"

health_check {
interval = "5"
timeout = "2"
Expand Down
Loading

0 comments on commit 8631bba

Please sign in to comment.