terraform-aws-modules / terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/autoscaling/aws
Apache License 2.0
292 stars 556 forks source link

Cannot create an ASG from scratch - "invalid new value for .tags: length changed from 1 to 2" #147

Closed marcinwyszynski closed 3 years ago

marcinwyszynski commented 3 years ago

Description

I'm authoring a module that uses this module. I want to support configuring the HTTP metadata endpoint, which requires bumping the major to "4", and even with a clean install this seems broken with the recent AWS provider:

module.this.aws_iam_instance_profile.this: Creation complete after 1s [id=sp5ft-sound-duckling]
╷
│ Error: Provider produced inconsistent final plan
│ 
│ When expanding the plan for
│ module.this.module.asg.aws_autoscaling_group.this[0] to include new values
│ learned so far during apply, provider "registry.terraform.io/hashicorp/aws"
│ produced an invalid new value for .tags: length changed from 1 to 2.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Versions

Reproduction

The full repro code can be found here. Since the is another module, the Terraform entry point (test case) is specified here.

Steps to reproduce the behavior:

Are you using workspaces?: no Have you cleared the local cache (see Notice section above)?: yes List steps in order that led up to the issue you encountered:

Expected behavior

The module applies cleanly.

Actual behavior

The module does not apply cleanly.

Terminal Output Screenshot(s)

Set_up_in_the_default_VPC_·_spacelift-workerpool-on-ec2

antonbabenko commented 3 years ago

Hi Marcin,

I checked the issue you have with your module and here are the missing bits:

  1. Missing create_lt = true and use_lt = true in asg.tf.
  2. tags contains an unknown value (coming from random_pet), so the length of tags changes as Terraform progressing the creation of the resources. It is weird, I know.
  3. The easiest solution is to use tags_as_map argument of this module and pass as key/value instead of lists of dynamic length:
    
    module "asg" {
    # omitted...
    tags_as_map = merge(var.tags_as_map, { WorkerPoolID = var.worker_pool_id })
    }

variable "tags_as_map" { type = map(string) default = {} }



This way module will make sure that tags are processed at the beginning and length will not change.
github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.