Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to provide different Tag for Root and EBS device #9033

Closed
kkundank opened this issue Jun 18, 2019 · 8 comments · Fixed by #15474
Closed

Unable to provide different Tag for Root and EBS device #9033

kkundank opened this issue Jun 18, 2019 · 8 comments · Fixed by #15474
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@kkundank
Copy link

kkundank commented Jun 18, 2019

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 "me too" comments, 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

Headline

How do we achieve different tags for root and ebs device under same resource aws_instance ?

Terraform Version

Terraform v0.12.1
provider.aws v2.14.0

Affected Resource(s)

  • aws_instance

Terraform Configuration Files

resource "aws_vpc" "vpc_01" {
  cidr_block           = "10.0.0.0/16"
  instance_tenancy     = "default"
  enable_dns_hostnames = true
  enable_dns_support   = true

  tags = {
    Name = "Project-vpc-01"
  }
}

resource "aws_subnet" "subnet" {
  vpc_id                  = "${aws_vpc.vpc_01.id}"
  cidr_block              = "10.0.1.0/24"
  map_public_ip_on_launch = true
  availability_zone       = "us-east-2a"
  tags = {
    Name = "Project-sn-01"
  }
}

resource "aws_security_group" "sg_all" {
  name   = "sg-01"
  vpc_id = "${aws_vpc.vpc_01.id}"
  tags = {
    Name = "Project-sg-01"
  }
}

resource "aws_instance" "my-instance" {
  count                  = "2"
  ami                    = "ami-00c79db59589996b9"
  instance_type          = "c5.large"
  subnet_id              = "${aws_subnet.subnet.id}"
  vpc_security_group_ids = "${aws_security_group.sg_all.id}"
  monitoring             = true

  root_block_device {
    volume_size           = "8"
    volume_type           = "gp2"
    delete_on_termination = false
  }
  ebs_block_device {
    volume_size           = "8"
    volume_type           = "gp2"
    delete_on_termination = false
    encrypted 		  = true
  }
  tags = {
    Name = "Instance-01"
  }
  volume_tags = {
    Name = "Volume-01"
  }
}

Debug Output

Panic Output

Expected Behavior

What I want is to have two different tags for root and ebs device. But volume_tag is giving same tag to both devices.

Something like this:

Root Device Tag: Volume-01-Root
EBS Device Tag: Volume-01-Data

Actual Behavior

It is creating same volume tag for both devices.

Steps to Reproduce

  1. terraform plan
  2. terraform apply

Important Factoids

References

  • #0000
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service. labels Jun 18, 2019
@kkundank
Copy link
Author

@bflad Any updates on the above issue ?

@biohazd
Copy link
Contributor

biohazd commented Nov 11, 2019

I'm also seeing this issue.

@cringham
Copy link

@Kundan123456 Have you tried breaking out additional volumes that aren't root from the aws_instance resource block? You can declare them with aws_ebs_volume and attach them with aws_volume_attachment. The resulting code would look something like:

resource "aws_vpc" "vpc_01" {
  cidr_block           = "10.0.0.0/16"
  instance_tenancy     = "default"
  enable_dns_hostnames = true
  enable_dns_support   = true

  tags = {
    Name = "Project-vpc-01"
  }
}

resource "aws_subnet" "subnet" {
  vpc_id                  = "${aws_vpc.vpc_01.id}"
  cidr_block              = "10.0.1.0/24"
  map_public_ip_on_launch = true
  availability_zone       = "us-east-2a"
  tags = {
    Name = "Project-sn-01"
  }
}

resource "aws_security_group" "sg_all" {
  name   = "sg-01"
  vpc_id = "${aws_vpc.vpc_01.id}"
  tags = {
    Name = "Project-sg-01"
  }
}

resource "aws_instance" "my-instance" {
  count                  = "2"
  ami                    = "ami-00c79db59589996b9"
  instance_type          = "c5.large"
  subnet_id              = "${aws_subnet.subnet.id}"
  vpc_security_group_ids = "${aws_security_group.sg_all.id}"
  monitoring             = true

  root_block_device {
    volume_size           = "8"
    volume_type           = "gp2"
    delete_on_termination = false
  }

  # Removed EBS block here

  tags = {
    Name = "Instance-01"
  }
  volume_tags = {
    Name = "Volume-01"
  }
}

# Added this
resource "aws_ebs_volume" "secondary" {
  availability_zone = "us-east-2a"
  size              = 8
  type              = "gp2"
  encrypted         = true

  tags = {
    Name = "Volume-02"
  }
}

# Added this
resource "aws_volume_attachment" "vol_2" {
  device_name = "/dev/sdh" # or something
  volume_id   = aws_ebs_volume.secondary.id
  instance_id = aws_instance.my-instance.id
}

@FearlessHyena
Copy link

FearlessHyena commented Jul 29, 2020

@cringham Thanks for the workaround. While that would work it seems to cause a different issue of the aws_ebs_volume.tags and volume_tags being overwritten in an alternate fashion (as mentioned in #12225)

Having a separate tags block in the *_block_device as proposed in #4017 would be a much cleaner and preferred solution

@artkrz
Copy link

artkrz commented Aug 25, 2020

@FearlessHyena I have it separate and I do see the same issue.

@YakDriver
Copy link
Member

YakDriver commented Jan 13, 2021

We have merged a fix to the volume_tags issue in #15474. We have added tests to cover the issues observed. Please note that using volume_tags in aws_instance is not compatible with using tags in aws_ebs_volume. You need to use one or the other. Prior to this fix, even following this rule, you would encounter errors. Along with the fix, we've added tags to the root_block_device and ebs_block_device configuration blocks in aws_instance.

Now that the fix is in place, if you find any problems with volume_tags, let us know by opening a new issue.

@ghost
Copy link

ghost commented Jan 15, 2021

This has been released in version 3.24.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Feb 13, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
7 participants