Skip to content

Commit 2ca2206

Browse files
committed
feat: switching to using prefixes
1 parent ab690bb commit 2ca2206

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

cloudwatch.tf

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
## Provision a events IAM role, this is used within the cloudwatch trigger,
2+
## Provision a events IAM role, this is used within the cloudwatch trigger,
33
## permitting the event to trigger the ECS task
44

55
## Provision the ECS events IAM role, which is used to trigger the ECS task
66
resource "aws_iam_role" "cloudwatch" {
7-
name = var.cloudwatch_event_role_name
8-
tags = var.tags
7+
name_prefix = var.cloudwatch_event_role_name_prefix
8+
tags = var.tags
99

1010
assume_role_policy = jsonencode({
1111
Version = "2012-10-17",
@@ -21,13 +21,13 @@ resource "aws_iam_role" "cloudwatch" {
2121
})
2222
}
2323

24-
## Attach the ECS events policy to the role
24+
## Attach the ECS events policy to the role
2525
resource "aws_iam_role_policy_attachment" "cloudwatch" {
2626
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceEventsRole"
2727
role = aws_iam_role.cloudwatch.name
2828
}
2929

30-
## Provision a CloudWatch Log Group for the task to use
30+
## Provision a CloudWatch Log Group for the task to use
3131
# trivy:ignore:AVD-AWS-0017
3232
resource "aws_cloudwatch_log_group" "tasks" {
3333
for_each = var.tasks
@@ -38,8 +38,8 @@ resource "aws_cloudwatch_log_group" "tasks" {
3838
tags = var.tags
3939
}
4040

41-
## Provision the cloudwatch event rule to trigger the task - we need to provision
42-
## an event rule per task
41+
## Provision the cloudwatch event rule to trigger the task - we need to provision
42+
## an event rule per task
4343
resource "aws_cloudwatch_event_rule" "tasks" {
4444
for_each = var.tasks
4545

@@ -49,7 +49,7 @@ resource "aws_cloudwatch_event_rule" "tasks" {
4949
tags = var.tags
5050
}
5151

52-
## Provision the cloudwatch event target to run the task
52+
## Provision the cloudwatch event target to run the task
5353
resource "aws_cloudwatch_event_target" "tasks" {
5454
for_each = var.tasks
5555

ecs.tf

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
## Provision the ECS Cluster used to run the task
2+
## Provision the ECS Cluster used to run the task
33
# tfsec:ignore:aws-ecs-enable-container-insight
44
resource "aws_ecs_cluster" "current" {
55
name = var.ecs_cluster_name
@@ -11,13 +11,13 @@ resource "aws_ecs_cluster" "current" {
1111
}
1212
}
1313

14-
## Provision the ECS execution IAM role; this is used by the task to execute within
14+
## Provision the ECS execution IAM role; this is used by the task to execute within
1515
## the ECS cluster
1616
resource "aws_iam_role" "execution" {
1717
for_each = var.tasks
1818

1919
description = format("Used by the ECS task to execute within the ECS cluster by the nuke service: '%s'", each.key)
20-
name = format("%s%s", var.iam_execution_role_prefix, each.key)
20+
name_prefix = format("%s%s", var.iam_execution_role_prefix, each.key)
2121
tags = var.tags
2222

2323
assume_role_policy = jsonencode({
@@ -34,12 +34,12 @@ resource "aws_iam_role" "execution" {
3434
})
3535
}
3636

37-
## Provision a role for the task to use, this is used to perform actions and remove
37+
## Provision a role for the task to use, this is used to perform actions and remove
3838
resource "aws_iam_role" "task" {
3939
for_each = var.tasks
4040

4141
description = format("Permissions for the ECS nuke task: '%s' to run under", each.key)
42-
name = format("%s%s", var.iam_task_role_prefix, each.key)
42+
name_prefix = format("%s%s", var.iam_task_role_prefix, each.key)
4343
permissions_boundary = each.value.permission_boundary_arn
4444
tags = var.tags
4545

@@ -57,7 +57,7 @@ resource "aws_iam_role" "task" {
5757
})
5858
}
5959

60-
## Attach any managed polices to the task role - i.e the permissions which the task can
60+
## Attach any managed polices to the task role - i.e the permissions which the task can
6161
## perform within the AWS account/s
6262
resource "aws_iam_role_policy_attachment" "task_permissions_arns" {
6363
for_each = local.task_permissions_arns
@@ -66,7 +66,7 @@ resource "aws_iam_role_policy_attachment" "task_permissions_arns" {
6666
policy_arn = each.value.permission_arn
6767
}
6868

69-
## Allow any additional permissions to be attached to the task role - these are inline
69+
## Allow any additional permissions to be attached to the task role - these are inline
7070
## policies applied to the task
7171
resource "aws_iam_role_policy" "task_additional_permissions" {
7272
for_each = local.task_additional_permissions
@@ -84,7 +84,7 @@ resource "aws_iam_role_policy_attachment" "execution" {
8484
role = aws_iam_role.execution[each.key].name
8585
}
8686

87-
## Allow the ECS task access to the ECR repository to pull the image
87+
## Allow the ECS task access to the ECR repository to pull the image
8888
resource "aws_iam_role_policy" "execution_ecr" {
8989
for_each = var.tasks
9090

@@ -104,7 +104,7 @@ resource "aws_iam_role_policy" "execution_ecr" {
104104
})
105105
}
106106

107-
## Allow the ECS task to retrieve the secret from the secrets manager
107+
## Allow the ECS task to retrieve the secret from the secrets manager
108108
resource "aws_iam_role_policy" "execution_secrets" {
109109
for_each = var.tasks
110110

@@ -126,8 +126,8 @@ resource "aws_iam_role_policy" "execution_secrets" {
126126
})
127127
}
128128

129-
## Provision the task definition for the nuke (aws-nuke) to remove all the resources,
130-
## Also, we mount the secret from secrets manager to the task
129+
## Provision the task definition for the nuke (aws-nuke) to remove all the resources,
130+
## Also, we mount the secret from secrets manager to the task
131131
resource "aws_ecs_task_definition" "tasks" {
132132
for_each = var.tasks
133133

variables.tf

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ variable "ecs_cluster_name" {
2121
default = "nuke"
2222
}
2323

24-
variable "cloudwatch_event_role_name" {
24+
variable "cloudwatch_event_role_name_prefix" {
2525
description = "The name of the role to use for the cloudwatch event rule"
2626
type = string
27-
default = "nuke-cloudwatch"
27+
default = "nuke-cloudwatch-"
2828
}
2929

3030
variable "cloudwatch_event_rule_prefix" {
@@ -53,13 +53,13 @@ variable "tasks" {
5353
schedule = string
5454
}))
5555

56-
## The tast must have a configuration
56+
## The tast must have a configuration
5757
validation {
5858
condition = alltrue([for task in keys(var.tasks) : contains(keys(var.tasks[task]), "configuration")])
5959
error_message = "The task must have a configuration"
6060
}
6161

62-
## The task configuration must not be empty
62+
## The task configuration must not be empty
6363
validation {
6464
condition = alltrue([for task in keys(var.tasks) : length(var.tasks[task].configuration) > 0])
6565
error_message = "The task configuration must not be empty"
@@ -71,7 +71,7 @@ variable "tasks" {
7171
error_message = "The task key must be all lowercase and contain only alphanumeric characters"
7272
}
7373

74-
## The task name cannot be longer than 32
74+
## The task name cannot be longer than 32
7575
validation {
7676
condition = alltrue([for task in keys(var.tasks) : length(task) <= 32])
7777
error_message = "The task name cannot be longer than 32 characters"

0 commit comments

Comments
 (0)