hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.8k stars 9.15k forks source link

Dynamic block in module fails to de-provision resource configuration #10776

Open ghost opened 4 years ago

ghost commented 4 years ago

This issue was originally opened by @shedimon as hashicorp/terraform#23303. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.12.13
+ provider.aws v2.34.0

Terraform Configuration Files

main.tf:

module "lc" {
    source = "./module"
    extra_block_devices = {
        "/dev/xvdb" = "1"
    }
}

module/module.tf:

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_launch_configuration" "as_conf" {
  name_prefix          = "test-lc-"
  image_id      = "${data.aws_ami.ubuntu.id}"
  instance_type = "t2.micro"

  lifecycle {
    create_before_destroy = true
  }

  dynamic "ebs_block_device" {
    for_each = var.extra_block_devices

    content {
      device_name           = ebs_block_device.key
      volume_size           = ebs_block_device.value
      volume_type           = "gp2"
      delete_on_termination = true
    }
  }
}

variable extra_block_devices {
  description = "Extra block devices for the instances in ASG"
  type        = map(string)
  default     = {}
}

Debug Output

Crash Output

Expected Behavior

When you apply the configuration above and after that delete extra_block_devices variable in module invocation terraform removes the ebs_block_device config from launch configuration.

Actual Behavior

Terraform doesn't remove dynamic ebs_block_device from launch configuration and report false state of the configuration:

module.lc.data.aws_ami.ubuntu: Refreshing state...
module.lc.aws_launch_configuration.as_conf: Refreshing state... [id=test-lc-20191106203109303600000001]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Although launch configuratin test-lc-20191106203109303600000001 contains ebs_block_device attachment in AWS, terraform reports, that everything is up-to-date.

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. Delete extra_block_devices in main.tf lc module invocation
  4. terraform apply

    Additional Context

References

justinretzolk commented 2 years ago

Hey @shedimon 👋 Thank you for taking the time to file this issue! Given that there's been a number of Terraform and AWS provider releases since you initially filed it, can you confirm whether you're still experiencing this behavior?

shedimon commented 2 years ago

Hey @justinretzolk, I've tried it with hashicorp/aws provider v3.69.0 and Terraform v1.1.0 and it's still the same behavior.

adriannieto-attechnest commented 2 years ago

This issue is still happening in the last version.