Skip to content

Commit

Permalink
Add prefix to IAM role
Browse files Browse the repository at this point in the history
  • Loading branch information
qbart committed Jul 19, 2022
1 parent 99e8f94 commit b55a284
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions modules/ecs-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ resource "aws_autoscaling_group" "this" {
launch_configuration = aws_launch_configuration.this.name
vpc_zone_identifier = var.subnet_ids

min_size = var.autoscaling_group.min_size
desired_capacity = var.autoscaling_group.desired_capacity
max_size = var.autoscaling_group.max_size
min_size = var.autoscaling_group.min_size
desired_capacity = var.autoscaling_group.desired_capacity
max_size = var.autoscaling_group.max_size
protect_from_scale_in = var.protect_from_scale_in

placement_group = aws_placement_group.this.id
termination_policies = ["OldestInstance"]
Expand Down
6 changes: 6 additions & 0 deletions modules/ecs-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ variable "ssm_tag_value" {
default = "true"
}

variable "protect_from_scale_in" {
type = bool
description = "If protect from scale in is enabled, newly launched instances will be protected from scale in by default."
default = false
}

variable "ami" {
type = string
description = "Image ID for Autoscaling group. If left blank, latest ECS-optimized version will be used."
Expand Down
7 changes: 6 additions & 1 deletion modules/ecs-service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ locals {
)}"
}

resource "random_id" "prefix" {
byte_length = 4
prefix = "${var.name}-"
}

resource "aws_cloudwatch_log_group" "this" {
name = var.name
retention_in_days = var.log_retention_in_days
Expand Down Expand Up @@ -101,7 +106,7 @@ resource "aws_ecs_service" "this" {
}

resource "aws_iam_role" "ecs" {
name = "${var.name}-ecs-role"
name = "${random_id.prefix.hex}-ecs"
assume_role_policy = data.aws_iam_policy_document.ecs.json

tags = var.tags
Expand Down

0 comments on commit b55a284

Please sign in to comment.