-1

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

Marcin
  • 215,873
  • 14
  • 235
  • 294
Karthik
  • 107
  • 1
  • 10

1 Answers1

0

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
}
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • I am using Terraform v0.11.x and using null throwing error. * module.controller_asg.aws_autoscaling_group.asg: invalid variable syntax: "null". Did you mean 'var.null'? If this is part of inline `template` parameter then you must escape the interpolation with two dollar signs. – Karthik May 26 '22 at 06:56
  • launch_configuration = "${var.is_launch_template ? null : var.launch_config_id}" – Karthik May 26 '22 at 07:04
  • 1
    @Karthik How come you are using tf 11? Your wrote that you can use dynamic blocks, which are not even supported in tf 0.11? – Marcin May 26 '22 at 07:10
  • My bad, i couldn't use dynamic block either i was thinking TF version was 0.12 – Karthik Jun 08 '22 at 04:29