Skip to content

Commit

Permalink
Merge branch 'develop' into feature/encrypt-everywhere--wild-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Carlucci committed Nov 28, 2023
2 parents 240b78b + 311585d commit a2fcc6d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
on:
workflow_call:
inputs:
additional_certificate_arns:
# Arrays are not supported by Github resuable workflow inputs. It might be best to
# move back to defining each environment workflow completely independently.
default: "[]"
description: "A set of additional ACM certificate ARNs to be assigned to the ALB listener."
required: false
type: string
aws_region:
description: The AWS region target for deployment
required: true
Expand Down Expand Up @@ -96,6 +103,7 @@ jobs:
id: terraform-apply
run: |
terraform apply -auto-approve \
-var="additional_certificate_arns=${{ inputs.additional_certificate_arns }}" \
-var="aws_region=${{ inputs.aws_region }}" \
-var="aws_replication_region=${{ inputs.aws_replication_region }}" \
-var="dns_name=${{ inputs.dns_name }}" \
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ jobs:
# So now we're hardcoding the values here and using it as a manifest. Please see
# commit 1ec7a0346abc04b73c03e35c0e228e9dba14300c for the previous implementation.
with:
additional_certificate_arns: '[\"arn:aws:acm:us-east-1:510777193308:certificate/9a15e75a-1d74-4349-9ed0-65b0df777a22\"]'
aws_region: us-east-1
aws_replication_region: us-west-2
aws_s3_terraform_state_object_key: production.tfstate
dns_name: aws-ecs-demo.carlucci.network
dns_name: prod.aws-ecs-demo.carlucci.network
environment_name: prod
vpc_cidr_index: 0
secrets:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.3.0

* Additional ACM certificate assignment

# 0.2.1

* HOTFIX: Fix production dns_name in manifest
Expand Down
16 changes: 15 additions & 1 deletion terraform/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ resource "aws_security_group_rule" "alb_egress_all" {
# TODO: adopt "Encryption Everywhere" policy by protecting internal traffic
# between the ALB and the application service as well (#15)
resource "aws_lb_target_group" "alb" {
name = local.namespace
# name not specified as it creates conflicts when resource needs to be replaced. Depend
# on tags to identify target groups in the console.
port = 443
protocol = "HTTPS"
target_type = "ip"
Expand All @@ -59,6 +60,11 @@ resource "aws_lb_target_group" "alb" {
}

vpc_id = aws_vpc.vpc.id

lifecycle {
# For if/when ports change
create_before_destroy = true
}
}

resource "aws_lb" "alb" {
Expand Down Expand Up @@ -96,3 +102,11 @@ resource "aws_lb_listener" "https" {
port = 443
protocol = "HTTPS"
}

# Support the assigment of external certificates by ARN
resource "aws_lb_listener_certificate" "additional" {
for_each = var.additional_certificate_arns

listener_arn = aws_lb_listener.https.arn
certificate_arn = each.value
}
12 changes: 11 additions & 1 deletion terraform/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ data "aws_iam_policy_document" "ecs_task_assume_role" {
identifiers = ["ecs-tasks.amazonaws.com"]
type = "Service"
}
condition {
test = "ArnLike"
values = ["arn:aws:ecs:${var.aws_region}:${local.account_id}:*"]
variable = "aws:SourceArn"
}
condition {
test = "StringEquals"
values = [local.account_id]
variable = "aws:SourceAccount"
}
}
}

Expand All @@ -42,7 +52,7 @@ resource "aws_iam_role" "ecs_task_execution" {
}

# Use the AWS-provided managed role for basic logging and ECR repository permissions
resource "aws_iam_role_policy_attachment" "legacy_listener_aws_task_execution_role_policy" {
resource "aws_iam_role_policy_attachment" "hello_world_aws_task_execution_role_policy" {
role = aws_iam_role.ecs_task_execution.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
Expand Down
6 changes: 6 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
variable "additional_certificate_arns" {
default = []
description = "A set of additional ACM certificate ARNs to be assigned to the ALB listener."
type = set(string)
}

variable "aws_region" {
default = "us-east-1"
description = "The AWS region name in which the main infrastructure should be deployed."
Expand Down

0 comments on commit a2fcc6d

Please sign in to comment.