Skip to content

Commit

Permalink
Use terraform locals to set tags for ASG
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Dec 11, 2024
1 parent e33c8e4 commit a7fb079
Showing 1 changed file with 58 additions and 47 deletions.
105 changes: 58 additions & 47 deletions compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ resource "aws_launch_configuration" "main" {
}
}

locals { common_tags = [
{
key = "OwnerList"
value = var.owner
propagate_at_launch = true
},
{
key = "EndDate"
value = var.end_date
propagate_at_launch = true
},
{
key = "EnvironmentList"
value = var.env
propagate_at_launch = true
},
{
key = "ProjectList"
value = var.project
propagate_at_launch = true
},
{
key = "DeploymentType"
value = var.deployment_type
propagate_at_launch = true
},
{
key = "App"
value = var.deployed_app
propagate_at_launch = true
},
{
key = "SoftwareVersion"
value = var.software_version
propagate_at_launch = true
},
] }

resource "aws_autoscaling_group" "main" {
count = var.deployed ? 1 : 0
name = "asg-${var.project_id}-${var.env}-${var.deployed_app}-${var.deployment}"
Expand All @@ -39,53 +77,26 @@ resource "aws_autoscaling_group" "main" {
create_before_destroy = true
}

tags = [
{
key = "Name"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}-${count.index}"
propagate_at_launch = true
},
{
key = "Group"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}"
propagate_at_launch = true
},
{
key = "OwnerList"
value = var.owner
propagate_at_launch = true
},
{
key = "EndDate"
value = var.end_date
propagate_at_launch = true
},
{
key = "EnvironmentList"
value = var.env
propagate_at_launch = true
},
{
key = "ProjectList"
value = var.project
propagate_at_launch = true
},
{
key = "DeploymentType"
value = var.deployment_type
propagate_at_launch = true
},
{
key = "App"
value = var.deployed_app
propagate_at_launch = true
},
{
key = "SoftwareVersion"
value = var.software_version
propagate_at_launch = true
},
]
tag {
key = "Name"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}-${count.index}"
propagate_at_launch = true
}
tag {
key = "Group"
value = "${var.deployed_app}-${var.project}-${var.env}-${var.deployment}"
propagate_at_launch = true
}

dynamic "tag" {
for_each = local.common_tags
content {
key = tag.value.key
propagate_at_launch = tag.value.propagate_at_launch
value = tag.value.value
}
}

}

resource "aws_cloudwatch_metric_alarm" "cpu_utilization" {
Expand Down

0 comments on commit a7fb079

Please sign in to comment.