I am trying to add a dynamic block to our ec2 autoscalinggroup module that adds spot instance options without impacting existing deployed resources that already use this module.
variable "instance_market_opts" {
description = "instance market options"
type = object({
market_type = string
spot_options = object({
instance_interruption_behavior = string
max_price = string
spot_instance_type = string
})
})
default = null
}
resource "aws_launch_template" "eks_worker_lt" {
disable_api_termination = var.disable_api_termination
ebs_optimized = var.ebs_optimized
image_id = data.aws_ami.eks_worker.id
instance_type = var.instance_type
key_name = var.key_name
vpc_security_group_ids = flatten([aws_security_group.eks_worker_sg.id, var.security_group_ids])
user_data = base64encode(local.userdata_by_role[format("%s_userdata", replace(replace(var.role, "-${var.bluegreen}", ""), "-", "_"))])
dynamic "instance_market_options" {
for_each = var.instance_market_opts[*]
content {
market_type = instance_market_options.value.market_type
dynamic "spot_options" {
for_each = instance_market_opts.value.spot_options
content {
instance_interruption_behavior = spot_options.value.instance_interruption_behavior
max_price = spot_options.value.max_price
spot_instance_type = spot_options.value.spot_instance_type
}
}
}
}
}
However, the plan is erroring out on
226: for_each = var.instance_market_opts[*]
There is no variable named "var".
231: for_each = instance_market_opts.value.spot_options
A managed resource "instance_market_opts" "value" has not been declared in
ec2_worker.
What am I missing?