Skip to content

Tags are removed from EBS volumes #17074

@mdelagrange

Description

@mdelagrange

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.14.4

  • provider registry.terraform.io/hashicorp/aws v3.23.0

Affected Resource(s)

  • aws_ebs_volume
  • aws_volume_attachment
  • aws_instance

Terraform Configuration Files

resource "aws_instance" "web" {
  ami               = "ami-089668cd321f3cf82"
  instance_type     = "t3.micro"
  availability_zone = "us-west-2a"

  lifecycle {
    ignore_changes = [
      root_block_device,
    ]
  }
}

resource "aws_ebs_volume" "example1" {
  availability_zone = "us-west-2a"

  tags = {
    Name = "example1"
  }
}

resource "aws_volume_attachment" "example1" {
  device_name = "/dev/sdh"
  volume_id   = aws_ebs_volume.example1.id
  instance_id = aws_instance.web.id
}

Expected Behavior

The first apply and subsequent applies result in an EBS volume with a "Name" tag set to "example1".

Actual Behavior

The first apply creates the volume with the correct tag, but subsequent applies alternatively remove and recreate the tag.

Steps to Reproduce

  1. terraform apply. The volume will be created correctly with the "Name" tag set to "example1".
  2. terraform apply again. The "Name" tag will be removed from the volume.
  3. terraform apply again. The "Name" tag will be added to the volume.
  4. terraform apply again. The "Name" tag will be removed from the volume.
  5. terraform apply again. The "Name" tag will be added to the volume.

Important Factoids

Applies that remove the tag from the volume have the following plan. This is unexpected, because the instance resource does not specify volume_tags:

Terraform will perform the following actions:

  # aws_instance.web will be updated in-place
  ~ resource "aws_instance" "web" {
        id                           = "i-06ccbb7893d13d8cf"
        tags                         = {}
      ~ volume_tags                  = {
          - "Name" = "example1" -> null
        }
        # (26 unchanged attributes hidden)

        # (5 unchanged blocks hidden)
    }

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

Removing root_block_device from the ignored changes on aws_instance will prevent volume tags from being removed. However, I'm seeing other examples in my Terraform environment of tags being removed from volumes which do not ignore changes to root_block_device. This was just the first example that I could reproduce simply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/ec2Issues and PRs that pertain to the ec2 service.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions