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

AWS EC2 volume tag errors #190

Closed
terenho-jobber opened this issue Mar 1, 2024 · 1 comment · Fixed by #191
Closed

AWS EC2 volume tag errors #190

terenho-jobber opened this issue Mar 1, 2024 · 1 comment · Fixed by #191
Assignees
Labels
bug Something isn't working

Comments

@terenho-jobber
Copy link

terenho-jobber commented Mar 1, 2024

Describe the bug
After the merging of #187 for #186, we get "root_block_device.0.tags": conflicts with volume_tags when running terraform plan after running terratag.

To Reproduce
A minimal Terraform configuration reproducing the issue:

resource "aws_instance" "test" {
  ami                         = "ami-0f5daaa3a7fb3378b"
  instance_type               = "t2.micro"
  subnet_id                   = "subnet-0000000000000"
  vpc_security_group_ids      = ["sg-0000000000000"]

  root_block_device {
    volume_size           = 8
    tags = {
      Name = "test"
    }
  }
}

run

terratag -tags="terratag=yes"
terraform plan

Expected behavior
terraform plan should add the terratag=yes tag and the original Name=test test to the ec2 root volume

Screenshots
We are getting the following error

terraform plan
╷
│ Error: Conflicting configuration arguments
│
│   with aws_instance.test,
│   on main.terratag.tf line 9, in resource "aws_instance" "test":
│    9:     tags = {
│   10:       Name = "test"
│   11:     }
│
│ "root_block_device.0.tags": conflicts with volume_tags

Desktop (please complete the following information):

  • Terraform version: 1.5.7
  • terratag version: 0.3.2

Additional context
The result tf file after running terratag is

resource "aws_instance" "test" {
  ami                    = "ami-0f5daaa3a7fb3378b"
  instance_type          = "t2.micro"
  subnet_id              = "subnet-0000000000000"
  vpc_security_group_ids = ["sg-0000000000000"]

  root_block_device {
    volume_size = 8
    tags = {
      Name = "test"
    }
  }
  tags        = local.terratag_added_main
  volume_tags = local.terratag_added_main
}

locals {
  terratag_added_main = {"terratag"="yes"}
}

Workaround

ditching the root_block_device[0].tags, and instead putting them as volume_tags

@TomerHeber TomerHeber added the bug Something isn't working label Mar 1, 2024
@TomerHeber TomerHeber self-assigned this Mar 1, 2024
@TomerHeber
Copy link
Collaborator

Hi @terenho-jobber - I'm releasing version 0.3.3.

We have decided to apply the following strategy:

if there's volume_tags add tags to it
else
  for each ebs_block_device add tags to it
  add tags to the root_block_device (and create it if it does not exist)

This would mean that if there's no "volume_tags" in current terraform, nothing would be added to it.

Note this comment in the AWS terraform documentation:
Do not use volume_tags if you plan to manage block device tags outside the aws_instance configuration, such as using tags in an aws_ebs_volume resource attached via aws_volume_attachment. Doing so will result in resource cycling and inconsistent behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants