Terraform: aws_instance volume_tags wants to remove tags from aws_attached_volume volumes

Created on 27 Apr 2017  ยท  2Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.9.4

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_instance
  • aws_volume_attachment
  • aws_ebs_volume

Terraform Configuration Files

resource "aws_instance" "mydb" {
  ami = "..."
  instance_type = "..."
  availability_zone = "..."

  vpc_security_group_ids = ["..."]

  root_block_device {
    volume_type = "gp2"
    volume_size = 30
  }
}

resource "aws_ebs_volume" "mydb_data" {
  availability_zone = "..."
  size = "10"
  type = "gp2"
  tags {
    Name = "mydb:/data"
  }
}

resource "aws_volume_attachment" "mydb_data" {
  device_name = "/dev/sdh"
  volume_id = "${aws_ebs_volume.mydb_data.id}"
  instance_id = "${aws_instance.mydb.id}"

  connection {
    host = "${aws_instance.mydb.public_ip}"
    user = "ec2-user"
    private_key = "..."
  }

  # Run a script to mount this volume as '/data'.
  provisioner "remote-exec" {
    scripts = [
      "${path.module}/scripts/mount-ebs-data-volume.sh"
    ]
  }
}

Debug Output

We can supply this if this proves difficult to reproduce, but we'll need to strip out proprietary data.

Panic Output

None.

Expected Behavior

Terraform should leave the Name of the volume alone, and not try to remove it.

Actual Behavior

The plan _always_ includes:

~ aws_instance.mydb
    volume_tags.%:    "1" => "0"
    volume_tags.Name: "mydb:/data" => ""

If run, this will strip the Name off our volume.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

We use a lot of aws_volume_attachment declarations.

References

None.

Workaround

It appears possible to fix/improve this by adding:

  lifecycle {
    # Don't allow Terraform to update volume tags, because if it does, it will
    # erase tags on volumes attached by aws_volume_attachment.
    ignore_changes = ["volume_tags"]
  }

...to each affected instance.

bug provideaws

Most helpful comment

Hi @emk

I just fixed this this afternoon in master - it will be released in Terraform 0.9.5 which i will try and ship soon!

Sorry for the issue

Paul

All 2 comments

Hi @emk

I just fixed this this afternoon in master - it will be released in Terraform 0.9.5 which i will try and ship soon!

Sorry for the issue

Paul

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.

Was this page helpful?
0 / 5 - 0 ratings