Terraform v0.11.13
+ provider.archive v1.2.1
+ provider.aws v2.7.0
+ provider.local v1.2.1
+ provider.null v2.1.1
+ provider.random v2.1.1
+ provider.template v2.1.1
resource "aws_autoscaling_group" "test" {
name = "test"
desired_capacity = 1
max_size = 1
min_size = 1
mixed_instances_policy {
launch_template {
launch_template_specification {
launch_template_id = "lt-02dde2f87b200ea75"
version = "$Latest"
}
override {
instance_type = "t3.medium"
}
override {
instance_type = "c4.large"
}
override {
instance_type = ""
}
}
}
vpc_zone_identifier = ["subnet-030dd08b792455d65"]
}
Every apply is clean on every run. Note the last override of instance_type = "".
Terraform applies this on every run:
~ aws_autoscaling_group.test
mixed_instances_policy.0.launch_template.0.override.#: "2" => "3"
terraform applyIn the EC2 console, it looks good, there's only 2 instances specified for the ASG.
The reason for wanting to be able to set the instance_type to "" is because I want to define the aws_autoscaling_group resource inside a module and be able to pass optional extra instance types to the module that default to "". e.g.
module "my_asg_module" {
name = "test"
instance_type_1 = "t2.medium"
instance_type_2 = "t3.large"
instance_type_3 = "m4.large"
instance_type_4 = "m5.large"
instance_type_5 = "r4.xlarge"
}
The real example is here: https://github.com/terraform-aws-modules/terraform-aws-eks/blob/18baeea1fce469a95170889b52d6e3aebb15727e/workers_launch_template.tf#L28-L34
whats the reason "instance_type" is not a list type in override map?
Why not just use a _dynamic_ block in terraform?
https://www.terraform.io/docs/configuration/expressions.html#dynamic-blocks
Your module could look like this:
dynamic override {
for_each = var.instances
content {
instance_type = override.key
weighted_capacity = override.value
}
}
And your code looks like that:
module "spot" {
instances = {
# instance_type = weighted_capacity
"t3a.medium" = 1
"t3.medium" = 1
}
}
No need to do that weird empty string thing.
Any known workarounds for Terraform v0.11?