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

tags support for *_block_device within aws_instance resources #4017

Closed
mr-olson opened this issue Apr 3, 2018 · 15 comments
Closed

tags support for *_block_device within aws_instance resources #4017

mr-olson opened this issue Apr 3, 2018 · 15 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. proposal Proposes new design or functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@mr-olson
Copy link

mr-olson commented Apr 3, 2018

It would be useful if tags could be provided inline with EBS volumes in aws_instance resources - via the *_block_device stanzas.

I'm aware of volume_tags, which sprays all volume with the same tags. That is expected because the EC2 API just works that way, but not ideal for instances where different volumes have different tag needs.

Terraform Version

Terraform v0.11.3

  • provider.archive v1.0.0
  • provider.aws v1.11.0

Affected Resource(s)

  • aws_instance

Terraform Configuration Files

resource "aws_instance" "example" {
  ami = "${var.my_ami}"
  tags = {
    InstanceName = "${var.server_name}"
  }
  root_block_device {
    volume_size = "${var.root_volume_size}"
    volume_type = "gp2"
    tags = {
      EBSVol = "RootVol"
    }
  }
  ebs_block_device {
    device_name = "/dev/sdb"  
    volume_size = "${var.data_volume_size}"
    volume_type = "gp2"
    delete_on_termination = true
    tags = {
      Data = "SecretFiles"
    }
  }
}

References

Opening new issue per ask in hashicorp/terraform#3531

@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 Apr 3, 2018
@klose
Copy link

klose commented Apr 9, 2018

hi, @mr-olson

Error: aws_spot_fleet_request.XXX: launch_specification.0.ebs_block_device.0: invalid or unknown key: tags

$ terraform -version
Terraform v0.11.5

  • provider.aws v1.13.0

spot_fleet_request's configuration cannot support EBS tags?

@leventyalcin
Copy link

@mr-olson not only different tag needs, also volume_tags are not stateful. If I add a key/value pair to volume_tags, Terraform does not upgrade those changes.

@heldersepu
Copy link
Contributor

It will be nice to also have support for count under the *_block_device

@bflad
Copy link
Contributor

bflad commented Jul 5, 2018

@heldersepu handling dynamic sub-resource configurations should be handled in the upcoming Terraform 0.12 release using a new for and for_each syntax within the configuration language (HCL). Further tracking for that specific feature request can be found here: hashicorp/terraform#7034

A high level preview of this feature and others coming in that version can be found in: https://www.hashicorp.com/blog/terraform-0-1-2-preview -- I believe we will be releasing additional blog posts going into additional details about some of these as well.

@heldersepu
Copy link
Contributor

@bflad Awesome! Looking forward to 0.12

Can you give us a code example of how something like that would look under the new release?

@bflad
Copy link
Contributor

bflad commented Jul 5, 2018

Please see the comments in the upstream issue for draft implementations: hashicorp/terraform#7034 (comment)

I believe this will specifically be its own blog post in the coming weeks.

(Aside: I would suggest commenting on the upstream Terraform core issue about this topic rather than this one as its unrelated to the original issue and messaging all the issue followers.)

@stephan2012
Copy link

Just stumbled over this issue, too. When assigning many ebs_block_device inline with an aws_instance it is difficult to identify them later on. Since aws_ebs_volume supports tags already, it should not be a general issue.

@zenbiking
Copy link

Could someone please give a status update on this when they have a spare moment? I also have some use cases where this would be useful (setting tags to implement DLM policies on certain devices attached to an EC2 instance)

@FearlessHyena
Copy link

This is a really needed feature. Not being able to add Name and other custom tags to the volumes makes tag-based resource grouping incomplete. Adding them manually later or using separate script defeats the purpose of managing everything via Terraform :(

@bflad bflad added the proposal Proposes new design or functionality. label Jul 7, 2020
@bflad bflad added this to the v4.0.0 milestone Jul 7, 2020
@ArturZurawski
Copy link

For now I'm using null_resource to tag instance's root volumes. Maybe someone will find it handy:

resource "null_resource" "tag_volumes" {
  provisioner "local-exec" {
    command = <<EOF
aws ec2 create-tags \
  --resources ${aws_instance.this.root_block_device.0.volume_id} \
  --region ${data.aws_region.current.name} \
  --tags \
    Key=Name,Value=${aws_instance.this.tags["Name"]} \
    Key=DLMSnapshotsPolicyName,Value=daily2d
EOF
  }
}

@bitle
Copy link

bitle commented Sep 8, 2020

For anyone considering the workaround above, you may try using the aws_ec2_tag resource.

resource "aws_ec2_tag" "example" {
  resource_id = element(tolist(aws_instance.example.ebs_block_device.*.volume_id), 0)
  key         = "Name2"
  value       = "Hello World!"
}

@francotel
Copy link

If you want tag the root volume:
resource "aws_ec2_tag" "example" { resource_id = element(tolist(aws_instance.example.root_block_device.*.volume_id), 0) key = "Name2" value = "Hello World!" }

@YakDriver
Copy link
Member

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.

@YakDriver YakDriver modified the milestones: v4.0.0, v3.24.0 Jan 13, 2021
@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. proposal Proposes new design or functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests