I am using a null_resource in Terraform to execute an AWS CLI command for terraform version 1.5.1.
resource "null_resource" "update_aws_service" {
depends_on = [aws_service.subservice]
triggers = {
always_run = "${timestamp()}"
}
provisioner "local-exec" {
command = <<EOF
aws service update-service
--aws-account-id ${var.aws_account_id}
--flag-a "${var.flag_a_value}"
EOF
when = create
}
}
I want to conditionally include the flag –flag-b ‘${var.flag_b_value}’ in the command only if the variable flag_b_value is defined and not empty. The command needs to remain valid and exclude the flag when the variable is not provided or is empty.
I attempted to use a conditional expression like this.
${var.flag_b != "" ? "--flag-b'${var.flag_b_value}'" : ""}
But I’m unsure if this is the best or correct way to achieve this.
Any guidance or alternative approaches would be appreciated!
user23568598 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.