How to toggle ASG to use launch_configuration or launch_templated

76 Views Asked by At

I am working on migrating our infrastructure code from launch_configuration to launch_template. I want to use either launch_configuration and launch_template based on the AWS region.

How can i use aws_autoscaling_group resource to pick launch_configuration or launch_template?

resource "aws_autoscaling_group" "asg" {
launch_configuration = xyz

or 

launch_template {
 id = 123
 version = $LATEST
}

I could use dynamic block for launch_template block based on the condition but i am not able to figure out how to include or exclude launch_configuration argument based on the condition

1

There are 1 best solutions below

4
On

how to include or exclude launch_configuration argument based on the condition

You do this with null:

resource "aws_autoscaling_group" "asg" {
   launch_configuration = var.use_lc ? aws_launch_configuration.lc.id : null
}