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

Terraform volume tags changes on alternate run if defined in both aws_instance and aws_ebs_volume resources #5609

Closed
ghost opened this issue Aug 20, 2018 · 15 comments · Fixed by #15474
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.

Comments

@ghost
Copy link

ghost commented Aug 20, 2018

This issue was originally opened by @saveshnshetty as hashicorp/terraform#18713. It was migrated here as a result of the provider split. The original body of the issue is below.


Hi team,
I've defined volume tags in aws_instance resource and aws_ebs_volume resource since I need to add tags to root volume also. But when I ran "terraform apply" second time. Ebs volumes tags got replaced with aws instance volume tags. On third run it got replaced with original ebs volume tags .
This tags changes alternatively . Can you please look into it .

syntax :
resource "aws_instance" "app" {
count = "1"
ami = "${lookup(var.ami,var.region)}"
ebs_optimized = "${var.ebs_optimized}"
instance_type = "${var.instance_type_app}"
monitoring = "${var.monitoring}"
key_name = "${var.key_name}"
user_data = "${data.template_file.userdata-app..rendered[count.index]}"
network_interface {
network_interface_id = "${element(aws_network_interface.network-interface-app.
.id, count.index)}"
device_index = 0
}
tags {
Name = "$app-${count.index + 1}"
Type = "app"
Env = "${var.env}"
Customer_id = "${var.customer_id}"
}

	root_block_device {
		volume_type           = "${var.root_volume_type}"
		volume_size           = "${var.root_volume_size}"
		delete_on_termination = "${var.root_delete_on_termination}"
	}


	volume_tags {
		Name                  = "${var.env}-s4hana-app-${count.index + 1}"
		Type                  = "root-volume"
		Env                   = "${var.env}"
        Customer_id           = "${var.customer_id}"
	}

}

resource "aws_ebs_volume" "ebs-app" {
count = "${var.app_count}"
availability_zone = "****"
size = "${var.ebs_volume_size[0]}"
type = "${var.ebs_volume_type[0]}"
tags {
Name = "app-tmp"
Type = "ebs-volume"
Env = "${var.env}"
Customer_id = "${var.customer_id}"
}
}

@af6140
Copy link

af6140 commented Aug 24, 2018

was seeing this also for a while.

@af6140
Copy link

af6140 commented Aug 24, 2018

similar issue with #5080

@radeksimko radeksimko added question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. service/ec2 Issues and PRs that pertain to the ec2 service. labels Sep 25, 2018
@soumitmishra
Copy link

+1

@sadok-f
Copy link

sadok-f commented Apr 9, 2019

we have a similar issue

@mrg2k8
Copy link

mrg2k8 commented Apr 23, 2019

I've also run into this issue.

@sushilchaudhari
Copy link

Same issue. Is there any solution?

@Nklya
Copy link

Nklya commented May 17, 2019

They don't actually change, so you can ignore it.

@tracypholmes tracypholmes added needs-triage Waiting for first response or review from a maintainer. and removed question A question about existing functionality; most questions are re-routed to discuss.hashicorp.com. labels Jul 16, 2019
@ryndaniels ryndaniels added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 11, 2019
sigsegv13 added a commit to sigsegv13/terraform-provider-aws that referenced this issue Sep 26, 2019
@marobota
Copy link

marobota commented Oct 8, 2019

I can see this happening too
Terraform v0.12.8

  • provider.aws v2.31.0
    Ignoring this (as suggested above) is not good enough as the plan should stay clean if nothing is to be changed..

@zenbiking
Copy link

To add on to what @marobota said,

  • this is still occurring with aws provider 2.31.0
  • Contrary to what @Nklya stated, the tags are getting changed on my aws_ebs_volume resources
  • I am also seeing only one of my 5 defined tags being applied to the root volume.

Something definitely isn't right.

@abhineetraj
Copy link

abhineetraj commented Dec 14, 2019

This is still happening.

An execution plan has been generated and is shown below.

Resource actions are indicated with the following symbols:
 ~ update in-place

Terraform will perform the following actions:

 ~ aws_instance.google-prod-app
     volume_tags.Name: "google-prod-app-001:/root" => "google-prod-app-001"


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

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

@VladislavAnd
Copy link

There is a workaround:
Remove volume_tags from your aws_instance and add the following aws_ec2_tag:

resource "aws_ec2_tag" "root_volume_tags" {
  resource_id = aws_instance.this.root_block_device[0].volume_id
  key         = "Name"
  value       = "VALUE"
}  

@PTATH81
Copy link

PTATH81 commented Nov 25, 2020

Are there any plans to address this? I am also seeing this issue

@mdelagrange
Copy link

The behavior seems to be worse with the latest versions of Terraform and the AWS provider. Now, under some circumstances, tags can be removed from volumes even if volume_tags isn't defined on the aws_instance resource. (See #17074 for an example.). It's the same alternating removal of volume tags, but now it's significantly more difficult to predict or avoid.

@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.

@ghost
Copy link
Author

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
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet