Skip to content
Draft
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ for example.
| <a name="input_otel"></a> [otel](#input\_otel) | Configuration for (optional) AWS Distro für OpenTelemetry sidecar. | <pre>object({<br/> container_definition = optional(any, {})<br/> enabled = optional(bool, false)<br/> })</pre> | `{}` | no |
| <a name="input_platform_version"></a> [platform\_version](#input\_platform\_version) | The platform version on which to run your service. Defaults to LATEST. | `string` | `"LATEST"` | no |
| <a name="input_policy_document"></a> [policy\_document](#input\_policy\_document) | AWS Policy JSON describing the permissions required for this service. | `string` | `""` | no |
| <a name="input_region"></a> [region](#input\_region) | Alternative region used in all region-aware resources. If not set, the provider's region will be used. | `string` | `null` | no |
| <a name="input_requires_compatibilities"></a> [requires\_compatibilities](#input\_requires\_compatibilities) | The launch type the task is using. This enables a check to ensure that all of the parameters used in the task definition meet the requirements of the launch type. | `set(string)` | <pre>[<br/> "EC2",<br/> "FARGATE"<br/>]</pre> | no |
| <a name="input_security_groups"></a> [security\_groups](#input\_security\_groups) | A list of security group ids that will be attached additionally to the ecs deployment. | `list(string)` | `[]` | no |
| <a name="input_service_discovery_dns_namespace"></a> [service\_discovery\_dns\_namespace](#input\_service\_discovery\_dns\_namespace) | The ID of a Service Discovery private DNS namespace. If provided, the module will create a Route 53 Auto Naming Service to enable service discovery using Cloud Map. | `string` | `""` | no |
Expand Down
4 changes: 4 additions & 0 deletions alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
resource "aws_alb_target_group" "main" {
count = length(var.target_groups)

region = var.region

name = lookup(var.target_groups[count.index], "name", null)
name_prefix = lookup(var.target_groups[count.index], "name_prefix", null)

Expand Down Expand Up @@ -47,6 +49,8 @@ resource "aws_alb_target_group" "main" {
resource "aws_alb_listener_rule" "public" {
count = length(var.https_listener_rules)

region = var.region

listener_arn = lookup(var.https_listener_rules[count.index], "listener_arn", null)
priority = lookup(var.https_listener_rules[count.index], "priority", null)

Expand Down
2 changes: 2 additions & 0 deletions cloudwatch_logs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
resource "aws_cloudwatch_log_group" "containers" {
count = var.cloudwatch_logs.enabled && var.cloudwatch_logs.name == "" ? 1 : 0

region = var.region

name = var.cloudwatch_logs.name == "" ? "/aws/ecs/${var.service_name}" : var.cloudwatch_logs.name
retention_in_days = var.cloudwatch_logs.retention_in_days
tags = var.tags
Expand Down
5 changes: 4 additions & 1 deletion data.tf
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
data "aws_region" "current" {}
data "aws_region" "current" {
region = var.region
Comment thread
moritzzimmer marked this conversation as resolved.
}

data "aws_caller_identity" "current" {}
2 changes: 1 addition & 1 deletion examples/fixtures/context/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12-alpine
FROM python:3.13-alpine
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low IaC Finding

Add Instead of Copy
on resource FROM python:3.13-alpine AS python:3.13-alpine.ADD index.html

More Details
Should use COPY instead of ADD unless, running a tar file

Expected

'COPY index.html'

Found

'ADD index.html'

Rule ID: 90792b6a-36b2-4ffa-ad6c-fb8240b79470

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low IaC Finding

Add Instead of Copy
on resource FROM python:3.13-alpine AS python:3.13-alpine.ADD server.py

More Details
Should use COPY instead of ADD unless, running a tar file

Expected

'COPY server.py'

Found

'ADD server.py'

Rule ID: 90792b6a-36b2-4ffa-ad6c-fb8240b79470

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low IaC Finding

Healthcheck Instruction Missing
on resource FROM python:3.13-alpine AS python:3.13-alpine

More Details
Ensure that HEALTHCHECK is being used. The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working

Expected

Dockerfile should contain instruction 'HEALTHCHECK'

Found

Dockerfile doesn't contain instruction 'HEALTHCHECK'

Rule ID: 39e62251-8073-455f-b8f1-5c2b6178d4ea


RUN addgroup -S app && adduser -S app -G app
WORKDIR /home/app
Expand Down
19 changes: 18 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ data "aws_subnets" "selected" {
}
}

// FIXME: the module is currently not upgraded to aws 6.x and doesn't support the `region` variable, see https://github.com/terraform-aws-modules/terraform-aws-security-group/issues/341
// update the complete example using a different region as soon as the module is fixed
module "sg" {
count = var.create_ingress_security_group && length(local.ingress_targets) > 0 ? 1 : 0
source = "registry.terraform.io/terraform-aws-modules/security-group/aws"
Expand All @@ -73,7 +75,10 @@ module "sg" {
}

resource "aws_vpc_security_group_egress_rule" "trusted_egress_attachment" {
depends_on = [data.aws_lb.public]
depends_on = [data.aws_lb.public]

region = var.region

Comment thread
moritzzimmer marked this conversation as resolved.
for_each = { for route in local.ingress_targets : "${route["prefix"]}-${route["protocol"]}-${route["from_port"]}-${route["to_port"]}" => route }
from_port = each.value["from_port"]
to_port = each.value["to_port"]
Expand All @@ -84,6 +89,8 @@ resource "aws_vpc_security_group_egress_rule" "trusted_egress_attachment" {
}

resource "aws_ecs_service" "this" {
region = var.region

Comment thread
moritzzimmer marked this conversation as resolved.
availability_zone_rebalancing = var.availability_zone_rebalancing
cluster = var.cluster_id
deployment_maximum_percent = var.deployment_maximum_percent
Expand Down Expand Up @@ -164,6 +171,8 @@ resource "aws_ecs_task_definition" "this" {
aws_iam_role.ecs_task_role
]

region = var.region

Comment thread
moritzzimmer marked this conversation as resolved.
container_definitions = local.container_definitions_string
cpu = var.cpu
execution_role_arn = var.task_execution_role_arn == "" ? aws_iam_role.task_execution_role[0].arn : var.task_execution_role_arn
Expand Down Expand Up @@ -236,6 +245,8 @@ module "ecr" {
source = "./modules/ecr"
count = var.create_ecr_repository ? 1 : 0

region = var.region

custom_lifecycle_policy = var.ecr_custom_lifecycle_policy
enable_default_lifecycle_policy = var.ecr_enable_default_lifecycle_policy
force_delete = var.ecr_force_delete
Expand All @@ -249,6 +260,8 @@ module "code_deploy" {
source = "./modules/deployment"
count = var.create_deployment_pipeline && (var.create_ecr_repository || var.ecr_repository_name != "") ? 1 : 0

region = var.region

cluster_name = var.cluster_id
container_name = local.container_name
code_build_environment_compute_type = var.code_build_environment_compute_type
Expand Down Expand Up @@ -279,6 +292,8 @@ module "code_deploy" {
resource "aws_appautoscaling_target" "ecs" {
count = var.appautoscaling_settings != null ? 1 : 0

region = var.region

max_capacity = lookup(var.appautoscaling_settings, "max_capacity", var.desired_count)
min_capacity = lookup(var.appautoscaling_settings, "min_capacity", var.desired_count)
resource_id = "service/${var.cluster_id}/${aws_ecs_service.this.name}"
Expand All @@ -289,6 +304,8 @@ resource "aws_appautoscaling_target" "ecs" {
resource "aws_appautoscaling_policy" "ecs" {
count = var.appautoscaling_settings != null ? 1 : 0

region = var.region

name = "${var.service_name}-auto-scaling"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.ecs[count.index].resource_id
Expand Down
4 changes: 4 additions & 0 deletions modules/deployment/code_build.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
resource "aws_cloudwatch_log_group" "this" {
region = var.region

name = "/aws/codebuild/${var.service_name}-deployment"
retention_in_days = var.code_build_log_retention_in_days

Expand All @@ -8,6 +10,8 @@ resource "aws_cloudwatch_log_group" "this" {
}

resource "aws_codebuild_project" "this" {
region = var.region

name = "${var.service_name}-deployment"
service_role = var.code_build_role == "" ? aws_iam_role.code_build_role[0].arn : data.aws_iam_role.code_build[0].arn

Expand Down
2 changes: 2 additions & 0 deletions modules/deployment/code_pipeline.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
resource "aws_codepipeline" "codepipeline" {
region = var.region

name = var.service_name
pipeline_type = var.code_pipeline_type
role_arn = var.code_pipeline_role == "" ? aws_iam_role.code_pipeline_role[0].arn : data.aws_iam_role.code_pipeline[0].arn
Expand Down
4 changes: 3 additions & 1 deletion modules/deployment/data.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_region" "current" {
region = var.region
Comment thread
moritzzimmer marked this conversation as resolved.
}

data "aws_iam_role" "code_build" {
count = var.code_build_role != "" ? 1 : 0
Expand Down
5 changes: 5 additions & 0 deletions modules/deployment/notification.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data "aws_iam_policy_document" "sns_codestar_policy" {
}

resource "aws_codestarnotifications_notification_rule" "notification" {
region = var.region

detail_type = var.codestar_notifications_detail_type
event_type_ids = var.codestar_notifications_event_type_ids
Expand All @@ -32,6 +33,8 @@ resource "aws_codestarnotifications_notification_rule" "notification" {
resource "aws_sns_topic" "notifications" {
count = var.codestar_notifications_target_arn == "" ? 1 : 0

region = var.region

name = "${var.service_name}-notifications"
kms_master_key_id = var.codestar_notification_kms_master_key_id
tags = merge(var.tags, {
Expand All @@ -42,6 +45,8 @@ resource "aws_sns_topic" "notifications" {
resource "aws_sns_topic_policy" "notifications" {
count = var.codestar_notifications_target_arn == "" ? 1 : 0

region = var.region

arn = aws_sns_topic.notifications[count.index].arn
policy = data.aws_iam_policy_document.sns_codestar_policy[count.index].json
}
4 changes: 3 additions & 1 deletion modules/deployment/s3.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "5.6.0"
create_bucket = var.artifact_bucket == "" ? true : false

region = var.region

create_bucket = var.artifact_bucket == "" ? true : false
bucket = "codepipeline-bucket-${var.service_name}-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.region}"
force_destroy = true

Expand Down
2 changes: 2 additions & 0 deletions modules/deployment/trigger.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
resource "aws_cloudwatch_event_rule" "this" {
region = var.region
Comment thread
moritzzimmer marked this conversation as resolved.

name = "${var.service_name}-ecr-trigger"
description = "Capture ECR push events."

Expand Down
6 changes: 6 additions & 0 deletions modules/deployment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ variable "ecr_image_tag" {
description = "Tag of the new image pushed to the Amazon ECR repository to trigger the deployment pipeline."
type = string
}

variable "region" {
description = "Alternative region used in all region-aware resources. If not set, the provider's region will be used."
default = null
type = string
}
6 changes: 6 additions & 0 deletions modules/ecr/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
resource "aws_ecr_repository" "this" {
region = var.region
Comment thread
moritzzimmer marked this conversation as resolved.

force_delete = var.force_delete
image_tag_mutability = var.image_tag_mutability #tfsec:ignore:aws-ecr-enforce-immutable-repository
name = var.name
Expand All @@ -12,13 +14,17 @@ resource "aws_ecr_repository" "this" {
resource "aws_ecr_lifecycle_policy" "custom_lifecycle_policy" {
count = var.custom_lifecycle_policy != null && !var.enable_default_lifecycle_policy ? 1 : 0

region = var.region

Comment thread
moritzzimmer marked this conversation as resolved.
repository = aws_ecr_repository.this.name
policy = var.custom_lifecycle_policy
}

resource "aws_ecr_lifecycle_policy" "default_lifecycle_policy" {
count = var.enable_default_lifecycle_policy ? 1 : 0

region = var.region

Comment thread
moritzzimmer marked this conversation as resolved.
repository = aws_ecr_repository.this.name
policy = jsonencode({
rules : [
Expand Down
6 changes: 6 additions & 0 deletions modules/ecr/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ variable "tags" {
description = "A mapping of tags to assign to the repository."
type = map(string)
}

variable "region" {
description = "Alternative region used in all region-aware resources. If not set, the provider's region will be used."
default = null
type = string
}
2 changes: 2 additions & 0 deletions route53.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
resource "aws_service_discovery_service" "this" {
count = var.service_discovery_dns_namespace != "" ? 1 : 0

region = var.region

Comment thread
moritzzimmer marked this conversation as resolved.
description = "Route 53 Auto Naming Service for ${var.service_name}"
name = var.service_name

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,9 @@ variable "task_role_arn" {
description = "ARN of the IAM role that allows your Amazon ECS container task to make calls to other AWS services. If not specified, the default ECS task role created in this module will be used."
type = string
}

variable "region" {
description = "Alternative region used in all region-aware resources. If not set, the provider's region will be used."
default = null
type = string
}
Loading