Skip to content

Commit

Permalink
Merge pull request #12 from tbobm/feat/variabilize-loadbalancer
Browse files Browse the repository at this point in the history
feat(lb): variabilize Load Balancer addon
  • Loading branch information
tbobm authored Nov 14, 2021
2 parents 1e76cfd + 310659a commit 61905be
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ No modules.
| <a name="output_ecr_url"></a> [ecr\_url](#output\_ecr\_url) | The ECR repository URL |
| <a name="output_ecs_cluster"></a> [ecs\_cluster](#output\_ecs\_cluster) | The ECS cluster name |
| <a name="output_ecs_service"></a> [ecs\_service](#output\_ecs\_service) | The ECS service name |
| <a name="output_loadbalancer"></a> [loadbalancer](#output\_loadbalancer) | The AWS Load Balancer resources (`loadbalancer`, `target_group` and `lb_listener`) |
| <a name="output_publisher_access_key"></a> [publisher\_access\_key](#output\_publisher\_access\_key) | AWS\_ACCESS\_KEY to publish to ECR |
| <a name="output_publisher_secret_key"></a> [publisher\_secret\_key](#output\_publisher\_secret\_key) | AWS\_SECRET\_ACCESS\_KEY to upload to the ECR |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
37 changes: 34 additions & 3 deletions lb.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
resource "aws_lb" "this" {
count = local.addons.loadbalancer.enable == true ? 1 : 0
count = local.addons.loadbalancer.enable ? 1 : 0

name = lookup(local.lb, "name", null)
name_prefix = lookup(local.lb, "name_prefix", null)

name = local.lb["name"]
internal = local.lb["internal"]
load_balancer_type = "application"
subnets = var.networking["subnet_ids"]

subnets = var.networking["subnet_ids"]
security_groups = lookup(local.lb, "security_groups", [])

enable_deletion_protection = lookup(local.lb, "enable_deletion_protection", false)

dynamic "access_logs" {
for_each = lookup(local.lb, "access_logs", {}) != {} ? [1] : []

content {
bucket = local.lb.access_logs["bucket"]

prefix = lookup(local.lb.access_logs, "prefix", "")
enabled = lookup(local.lb.access_logs, "enabled", false)
}
}

dynamic "subnet_mapping" {
for_each = lookup(local.lb, "subnet_mapping", {}) != {} ? [1] : []

content {
subnet_id = local.lb.subnet_mapping["subnet_id"]

allocation_id = lookup(local.lb.subnet_mapping, "allocation_id", "")
private_ipv4_address = lookup(local.lb.subnet_mapping, "private_ipv4_address", "")
ipv6_address = lookup(local.lb.subnet_mapping, "ipv6_address", "")
}
}

tags = lookup(local.lb, "tags", {})
}

resource "aws_lb_target_group" "this" {
Expand Down
1 change: 0 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ locals {
ecs = merge(local.ecs_defaults, var.ecs_values)

lb_defaults = {
name = "tf-alb"
internal = false
target_group = {
name = "tf-alb-tg"
Expand Down
9 changes: 9 additions & 0 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ output "app_url" {
description = "The public ALB DNS"
}

output "loadbalancer" {
value = !local.addons.loadbalancer.enable ? null : {
loadbalancer = aws_lb.this.0
target_group = aws_lb_target_group.this.0
lb_listener = aws_lb_listener.this.0
}
description = "The AWS Load Balancer resources (`loadbalancer`, `target_group` and `lb_listener`)"
}

output "publisher_access_key" {
value = local.addons.iam.enable ? aws_iam_access_key.publisher.0.id : ""
description = "AWS_ACCESS_KEY to publish to ECR"
Expand Down

0 comments on commit 61905be

Please sign in to comment.