Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Covert to TF0.12 #24

Closed
wants to merge 7 commits into from
Prev Previous commit
Upgrade module to support Terraform 0.12
  • Loading branch information
mholttech committed Jul 18, 2019
commit d0d532f5fbeeca3ec8ece63060198a2e0fae1220
143 changes: 73 additions & 70 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module "default_label" {
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.4.0"
attributes = "${var.attributes}"
delimiter = "${var.delimiter}"
name = "${var.name}"
namespace = "${var.namespace}"
stage = "${var.stage}"
tags = "${var.tags}"
attributes = var.attributes
delimiter = var.delimiter
name = var.name
namespace = var.namespace
stage = var.stage
tags = var.tags
}

resource "aws_security_group" "default" {
description = "Controls access to the ALB (HTTP/HTTPS)"
vpc_id = "${var.vpc_id}"
name = "${module.default_label.id}"
tags = "${module.default_label.tags}"
vpc_id = var.vpc_id
name = module.default_label.id
tags = module.default_label.tags
}

resource "aws_security_group_rule" "egress" {
Expand All @@ -21,88 +21,90 @@ resource "aws_security_group_rule" "egress" {
to_port = "0"
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.default.id}"
security_group_id = aws_security_group.default.id
}

resource "aws_security_group_rule" "http_ingress" {
count = "${var.http_enabled == "true" ? 1 : 0}"
count = var.http_enabled == "true" ? 1 : 0
type = "ingress"
from_port = "${var.http_port}"
to_port = "${var.http_port}"
from_port = var.http_port
to_port = var.http_port
protocol = "tcp"
cidr_blocks = ["${var.http_ingress_cidr_blocks}"]
prefix_list_ids = ["${var.http_ingress_prefix_list_ids}"]
security_group_id = "${aws_security_group.default.id}"
cidr_blocks = var.http_ingress_cidr_blocks
prefix_list_ids = var.http_ingress_prefix_list_ids
security_group_id = aws_security_group.default.id
}

resource "aws_security_group_rule" "https_ingress" {
count = "${var.https_enabled == "true" ? 1 : 0}"
count = var.https_enabled == "true" ? 1 : 0
type = "ingress"
from_port = "${var.https_port}"
to_port = "${var.https_port}"
from_port = var.https_port
to_port = var.https_port
protocol = "tcp"
cidr_blocks = ["${var.https_ingress_cidr_blocks}"]
prefix_list_ids = ["${var.https_ingress_prefix_list_ids}"]
security_group_id = "${aws_security_group.default.id}"
cidr_blocks = var.https_ingress_cidr_blocks
prefix_list_ids = var.https_ingress_prefix_list_ids
security_group_id = aws_security_group.default.id
}

module "access_logs" {
source = "git::https://github.com/cloudposse/terraform-aws-lb-s3-bucket.git?ref=tags/0.2.0"
attributes = "${compact(concat(var.attributes, list("alb", "access", "logs")))}"
delimiter = "${var.delimiter}"
name = "${var.name}"
namespace = "${var.namespace}"
stage = "${var.stage}"
tags = "${var.tags}"
region = "${var.access_logs_region}"
force_destroy = "${var.alb_access_logs_s3_bucket_force_destroy}"
attributes = compact(concat(var.attributes, ["alb", "access", "logs"]))
delimiter = var.delimiter
name = var.name
namespace = var.namespace
stage = var.stage
tags = var.tags
region = var.access_logs_region
force_destroy = var.alb_access_logs_s3_bucket_force_destroy
}

resource "aws_lb" "default" {
name = "${module.default_label.id}"
tags = "${module.default_label.tags}"
internal = "${var.internal}"
load_balancer_type = "application"
security_groups = ["${compact(concat(var.security_group_ids, list(aws_security_group.default.id)))}"]
subnets = ["${var.subnet_ids}"]
enable_cross_zone_load_balancing = "${var.cross_zone_load_balancing_enabled}"
enable_http2 = "${var.http2_enabled}"
idle_timeout = "${var.idle_timeout}"
ip_address_type = "${var.ip_address_type}"
enable_deletion_protection = "${var.deletion_protection_enabled}"
name = module.default_label.id
tags = module.default_label.tags
internal = var.internal
load_balancer_type = "application"
security_groups = compact(
concat(var.security_group_ids, [aws_security_group.default.id]),
)
subnets = var.subnet_ids
enable_cross_zone_load_balancing = var.cross_zone_load_balancing_enabled
enable_http2 = var.http2_enabled
idle_timeout = var.idle_timeout
ip_address_type = var.ip_address_type
enable_deletion_protection = var.deletion_protection_enabled

access_logs {
bucket = "${module.access_logs.bucket_id}"
prefix = "${var.access_logs_prefix}"
enabled = "${var.access_logs_enabled}"
bucket = module.access_logs.bucket_id
prefix = var.access_logs_prefix
enabled = var.access_logs_enabled
}
}

module "default_target_group_label" {
source = "git::https://github.com/cloudposse/terraform-terraform-label.git?ref=tags/0.4.0"
attributes = "${concat(var.attributes, list("default"))}"
delimiter = "${var.delimiter}"
name = "${var.name}"
namespace = "${var.namespace}"
stage = "${var.stage}"
tags = "${var.tags}"
attributes = concat(var.attributes, ["default"])
delimiter = var.delimiter
name = var.name
namespace = var.namespace
stage = var.stage
tags = var.tags
}

resource "aws_lb_target_group" "default" {
name = "${module.default_target_group_label.id}"
port = "${var.target_group_port}"
name = module.default_target_group_label.id
port = var.target_group_port
protocol = "HTTP"
vpc_id = "${var.vpc_id}"
vpc_id = var.vpc_id
target_type = "ip"
deregistration_delay = "${var.deregistration_delay}"
deregistration_delay = var.deregistration_delay

health_check {
path = "${var.health_check_path}"
timeout = "${var.health_check_timeout}"
healthy_threshold = "${var.health_check_healthy_threshold}"
unhealthy_threshold = "${var.health_check_unhealthy_threshold}"
interval = "${var.health_check_interval}"
matcher = "${var.health_check_matcher}"
path = var.health_check_path
timeout = var.health_check_timeout
healthy_threshold = var.health_check_healthy_threshold
unhealthy_threshold = var.health_check_unhealthy_threshold
interval = var.health_check_interval
matcher = var.health_check_matcher
}

lifecycle {
Expand All @@ -111,28 +113,29 @@ resource "aws_lb_target_group" "default" {
}

resource "aws_lb_listener" "http" {
count = "${var.http_enabled == "true" ? 1 : 0}"
load_balancer_arn = "${aws_lb.default.arn}"
port = "${var.http_port}"
count = var.http_enabled == "true" ? 1 : 0
load_balancer_arn = aws_lb.default.arn
port = var.http_port
protocol = "HTTP"

default_action {
target_group_arn = "${aws_lb_target_group.default.arn}"
target_group_arn = aws_lb_target_group.default.arn
type = "forward"
}
}

resource "aws_lb_listener" "https" {
count = "${var.https_enabled == "true" ? 1 : 0}"
load_balancer_arn = "${aws_lb.default.arn}"
count = var.https_enabled == "true" ? 1 : 0
load_balancer_arn = aws_lb.default.arn

port = "${var.https_port}"
port = var.https_port
protocol = "HTTPS"
ssl_policy = "${var.https_ssl_policy}"
certificate_arn = "${var.certificate_arn}"
ssl_policy = var.https_ssl_policy
certificate_arn = var.certificate_arn

default_action {
target_group_arn = "${aws_lb_target_group.default.arn}"
target_group_arn = aws_lb_target_group.default.arn
type = "forward"
}
}

25 changes: 14 additions & 11 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
output "alb_name" {
description = "The ARN suffix of the ALB"
value = "${aws_lb.default.name}"
value = aws_lb.default.name
}

output "alb_arn" {
description = "The ARN of the ALB"
value = "${aws_lb.default.arn}"
value = aws_lb.default.arn
}

output "alb_arn_suffix" {
description = "The ARN suffix of the ALB"
value = "${aws_lb.default.arn_suffix}"
value = aws_lb.default.arn_suffix
}

output "alb_dns_name" {
description = "DNS name of ALB"
value = "${aws_lb.default.dns_name}"
value = aws_lb.default.dns_name
}

output "alb_zone_id" {
description = "The ID of the zone which ALB is provisioned"
value = "${aws_lb.default.zone_id}"
value = aws_lb.default.zone_id
}

output "security_group_id" {
description = "The security group ID of the ALB"
value = "${aws_security_group.default.id}"
value = aws_security_group.default.id
}

output "default_target_group_arn" {
description = "The default target group ARN"
value = "${aws_lb_target_group.default.arn}"
value = aws_lb_target_group.default.arn
}

output "http_listener_arn" {
description = "The ARN of the HTTP listener"
value = "${join("", aws_lb_listener.http.*.arn)}"
value = join("", aws_lb_listener.http.*.arn)
}

output "https_listener_arn" {
description = "The ARN of the HTTPS listener"
value = "${join("", aws_lb_listener.https.*.arn)}"
value = join("", aws_lb_listener.https.*.arn)
}

output "listener_arns" {
description = "A list of all the listener ARNs"
value = "${compact(concat(aws_lb_listener.http.*.arn, aws_lb_listener.https.*.arn))}"
value = compact(
concat(aws_lb_listener.http.*.arn, aws_lb_listener.https.*.arn),
)
}

output "access_logs_bucket_id" {
description = "The S3 bucket ID for access logs"
value = "${module.access_logs.bucket_id}"
value = module.access_logs.bucket_id
}

Loading