Skip to content

Commit

Permalink
CW Agent param ARN not being passed to user-data fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RaJiska committed Nov 14, 2023
1 parent a851312 commit 88346ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ data "aws_ami" "main" {
}
}

data "aws_arn" "ssm_param" {
count = var.use_cloudwatch_agent && var.cloudwatch_agent_configuration_param_arn != null ? 1 : 0

arn = var.cloudwatch_agent_configuration_param_arn
}

resource "aws_launch_template" "main" {
name = var.name
image_id = local.ami_id
Expand Down Expand Up @@ -76,7 +82,7 @@ resource "aws_launch_template" "main" {
TERRAFORM_ENI_ID = aws_network_interface.main.id
TERRAFORM_EIP_ID = length(var.eip_allocation_ids) != 0 ? var.eip_allocation_ids[0] : ""
TERRAFORM_CWAGENT_ENABLED = var.use_cloudwatch_agent ? "true" : ""
TERRAFORM_CWAGENT_CFG_PARAM_NAME = var.use_cloudwatch_agent ? aws_ssm_parameter.cloudwatch_agent_config[0].name : ""
TERRAFORM_CWAGENT_CFG_PARAM_NAME = local.cwagent_param_name != null ? local.cwagent_param_name : ""
}))

tags = var.tags
Expand Down
7 changes: 4 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
locals {
is_arm = regex("[a-zA-Z]+\\d+g[a-z]*\\..+", var.instance_type) == var.instance_type
ami_id = var.ami_id != null ? var.ami_id : data.aws_ami.main[0].id
cwagent_param_arn = var.use_cloudwatch_agent ? var.cloudwatch_agent_configuration_param_arn != null ? var.cloudwatch_agent_configuration_param_arn : aws_ssm_parameter.cloudwatch_agent_config[0].arn : null
is_arm = regex("[a-zA-Z]+\\d+g[a-z]*\\..+", var.instance_type) == var.instance_type
ami_id = var.ami_id != null ? var.ami_id : data.aws_ami.main[0].id
cwagent_param_arn = var.use_cloudwatch_agent ? var.cloudwatch_agent_configuration_param_arn != null ? var.cloudwatch_agent_configuration_param_arn : aws_ssm_parameter.cloudwatch_agent_config[0].arn : null
cwagent_param_name = var.use_cloudwatch_agent ? var.cloudwatch_agent_configuration_param_arn != null ? split("/", data.aws_arn.ssm_param[0].resource)[1] : aws_ssm_parameter.cloudwatch_agent_config[0].name : null
}

data "aws_region" "current" {}
Expand Down

0 comments on commit 88346ff

Please sign in to comment.