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

Feat/add output alb zone #94

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ locals {

# Atlantis
atlantis_image = var.atlantis_image == "" ? "runatlantis/atlantis:${var.atlantis_version}" : var.atlantis_image
atlantis_url = "https://${coalesce(
atlantis_url = "https://${coalesce(var.overwrite_atlantis_fqdn,
element(concat(aws_route53_record.atlantis.*.fqdn, [""]), 0),
module.alb.dns_name,
module.alb.this_lb_dns_name,
"_"
)}"
atlantis_url_events = "${local.atlantis_url}/events"
Expand Down Expand Up @@ -165,16 +165,17 @@ module "vpc" {
###################
module "alb" {
source = "terraform-aws-modules/alb/aws"
version = "v4.0.0"
version = "v5.0.0"

load_balancer_name = var.name
name = var.name

vpc_id = local.vpc_id
subnets = local.public_subnet_ids
security_groups = flatten([module.alb_https_sg.this_security_group_id, module.alb_http_sg.this_security_group_id, var.security_group_ids])

logging_enabled = var.alb_logging_enabled
log_bucket_name = var.alb_log_bucket_name

access_logs = var.alb_logging_enabled ? { bucket = var.alb_log_bucket_name } : {}

log_location_prefix = var.alb_log_location_prefix

https_listeners = [
Expand All @@ -184,17 +185,13 @@ module "alb" {
},
]

https_listeners_count = 1

http_tcp_listeners = [
{
port = 80
protocol = "HTTP"
},
]

http_tcp_listeners_count = 1

target_groups = [
{
name = var.name
Expand All @@ -205,8 +202,6 @@ module "alb" {
},
]

target_groups_count = 1

tags = local.tags
}

Expand All @@ -224,8 +219,9 @@ resource "aws_lb_listener_rule" "redirect_http_to_https" {
}

condition {
field = "path-pattern"
values = ["*"]
path_pattern {
values = ["*"]
}
}
}

Expand Down Expand Up @@ -310,8 +306,8 @@ resource "aws_route53_record" "atlantis" {
type = "A"

alias {
name = module.alb.dns_name
zone_id = module.alb.load_balancer_zone_id
name = module.alb.this_lb_dns_name
zone_id = module.alb.this_lb_zone_id
evaluate_target_health = true
}
}
Expand Down Expand Up @@ -405,7 +401,7 @@ resource "aws_iam_role_policy" "ecs_task_access_secrets" {

module "container_definition_github_gitlab" {
source = "cloudposse/ecs-container-definition/aws"
version = "v0.15.0"
version = "v0.23.0"

container_name = var.name
container_image = local.atlantis_image
Expand All @@ -422,10 +418,14 @@ module "container_definition_github_gitlab" {
},
]

log_options = {
"awslogs-region" = data.aws_region.current.name
"awslogs-group" = aws_cloudwatch_log_group.atlantis.name
"awslogs-stream-prefix" = "ecs"
log_configuration = {
options = {
awslogs-region = data.aws_region.current.name
awslogs-group = aws_cloudwatch_log_group.atlantis.name
awslogs-stream-prefix = "ecs"
}
secretOptions = []
logDriver = "awslogs"
}

environment = concat(
Expand All @@ -442,7 +442,7 @@ module "container_definition_github_gitlab" {

module "container_definition_bitbucket" {
source = "cloudposse/ecs-container-definition/aws"
version = "v0.15.0"
version = "v0.23.0"

container_name = var.name
container_image = local.atlantis_image
Expand All @@ -459,10 +459,14 @@ module "container_definition_bitbucket" {
},
]

log_options = {
"awslogs-region" = data.aws_region.current.name
"awslogs-group" = aws_cloudwatch_log_group.atlantis.name
"awslogs-stream-prefix" = "ecs"
log_configuration = {
options = {
awslogs-region = data.aws_region.current.name
awslogs-group = aws_cloudwatch_log_group.atlantis.name
awslogs-stream-prefix = "ecs"
}
secretOptions = []
logDriver = "awslogs"
}

environment = concat(
Expand Down
7 changes: 6 additions & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ output "webhook_secret" {

output "alb_dns_name" {
description = "Dns name of alb"
value = module.alb.dns_name
value = module.alb.this_lb_dns_name
}

output "alb_zone_id" {
description = "Zone ID of alb"
value = module.alb.this_lb_zone_id
}

output "ecs_task_definition" {
Expand Down
23 changes: 19 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ variable "tags" {
default = {}
}

variable "overwrite_atlantis_fqdn" {
type = "string"
default = null
}

# VPC
variable "vpc_id" {
description = "ID of an existing VPC where resources will be created"
Expand Down Expand Up @@ -280,14 +285,24 @@ variable "atlantis_bitbucket_user_token" {

variable "custom_environment_secrets" {
description = "List of additional secrets the container will use (list should contain maps with `name` and `valueFrom`)"
type = list(map(string))
default = []
type = list(object(
{
name = string
valueFrom = string
}
))
default = []
}

variable "custom_environment_variables" {
description = "List of additional environment variables the container will use (list should contain maps with `name` and `value`)"
type = list(map(string))
default = []
type = list(object(
{
name = string
value = string
}
))
default = []
}

variable "security_group_ids" {
Expand Down