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.64k stars 9.02k forks source link

[Bug]: default_tags are propagated to aws_instance/root_block_device tags only at creation time #38301

Open nantiferov opened 2 weeks ago

nantiferov commented 2 weeks ago

Terraform Core Version

1.8.3

AWS Provider Version

5.57.0

Affected Resource(s)

Expected Behavior

Basically after https://github.com/hashicorp/terraform-provider-aws/issues/19890 issue was fixed in https://github.com/hashicorp/terraform-provider-aws/pull/33769 (aws provider v5.39), tags from default_tags propagated correctly to root_block_device in aws_instance when EC2 first created.

And when tags changed in default_tags, they should be changed properly for root_block_device in aws_instance.

Actual Behavior

But issue is that when tag value changed in default_tags, tag got removed from root_block_device and not added back on next apply as well, example:

Terraform will perform the following actions:

  # aws_instance.this will be updated in-place
  ~ resource "aws_instance" "this" {
        id                                   = "i-xxxxxxx"
      ~ tags                                 = {
          - "SomeTag" = "FOO" -> null
            "OtherTag"    = "123"
        }
      ~ tags_all                             = {
          ~ "SomeTag" = "FOO" -> "BAR"
            # (4 unchanged elements hidden)
        }
        # (39 unchanged attributes hidden)

      ~ root_block_device {
          ~ tags                  = {
              - "SomeTag" = "FOO" -> null
                "OtherTag"    = "123"
            }
            # (10 unchanged attributes hidden)
        }

        # (7 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

Something like this

resource "aws_instance" "ec2" {
  ami                     = "ami-xxxx"
  instance_type           = "t4g.micro"
  subnet_id               = "subnet-xxxxxx"
  vpc_security_group_ids  = "sg-xxxxxx"

  root_block_device {
    volume_size           = 8
    volume_type           = "gp3"
    tags                  = var.volume_tags
  }
}

provider "aws" {
  region = "eu-north-1"

  default_tags { tags = { SomeTag = "FOO", OtherTag = 123 } }
}

terraform {
  required_version = ">= 1.8"

  backend "s3" {}

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 5.39"
    }
  }
}

Steps to Reproduce

I tested as well different provider versions between 5.39 till 5.57 without any difference.

Right now I had to return hackish way to merge tags on root_block_device from data.aws_default_tags

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 2 weeks ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue