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

Not idempotent for aws_route_table_association #6556

Closed
ghost opened this issue Nov 22, 2018 · 3 comments
Closed

Not idempotent for aws_route_table_association #6556

ghost opened this issue Nov 22, 2018 · 3 comments
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. upstream-terraform Addresses functionality related to the Terraform core binary.

Comments

@ghost
Copy link

ghost commented Nov 22, 2018

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


Terraform Version

Terraform v0.11.10

  • provider.aws v1.46.0

Affected resources

aws_route_table_association

Expected Behavior

I have a var that defines subnets with tags to indicate if a subnet is public
I create a resource aws_route_table that I associate to certain subnets found by data aws_subnet_ids
It's expected to be idempotent if I run many times terraform apply
The subnet id to be associated needs to be computed (in my case) and after gather all information, terraform should check that association exists or not instead of delete and create the same association.

Actual Behavior

Between first and second apply the route_table_association gets removed and recreated again for each apply:

plan:

-/+ aws_route_table_association.public-rt (new resource required)
      id:                   "rtbassoc-00fa56a88a4080a05" => <computed> (forces new resource)
      route_table_id:       "rtb-044e7ab173eb7dd2e" => "rtb-044e7ab173eb7dd2e"
      subnet_id:            "subnet-0b8bee3f1d5b755ec" => "${data.aws_subnet_ids.public.ids[count.index]}" (forces new resource)

apply:

aws_route_table_association.public-rt: Creating...
  route_table_id: "" => "rtb-044e7ab173eb7dd2e"
  subnet_id:      "" => "subnet-0b8bee3f1d5b755ec"
...
aws_route_table_association.public-rt: Creation complete after 5s (ID: rtbassoc-03e0dbad4543d6ff4)

Steps to Reproduce

  1. terraform plan
  2. terraform apply
  3. terraform apply

Output
Debug log

Additional Context

data "aws_subnet_ids" "public" {
  depends_on = ["aws_subnet.subnet"] //creation of subnets
  vpc_id = "${aws_vpc.main.id}"
  tags {
    public = true
  }
}
resource "aws_route_table_association" "public-rt" {
  /*
  workaround count can't be computed
 https:/hashicorp/terraform/issues/10857#issuecomment-368059147
  count = "${length(data.aws_subnet_ids.public.ids)}"
  */
  count = "${var.subnets_public_count}"
  subnet_id = "${data.aws_subnet_ids.public.ids[count.index]}"
  route_table_id = "${aws_route_table.public-route.id}"
}

References

@bflad bflad added upstream-terraform Addresses functionality related to the Terraform core binary. service/ec2 Issues and PRs that pertain to the ec2 service. terraform-0.12 labels Nov 25, 2018
@aries1980
Copy link
Contributor

I think this is related to #561 .

@bflad
Copy link
Contributor

bflad commented Jul 31, 2019

Hi folks 👋 My suggestion here would be to try this in Terraform 0.12 and later to see if the issue still persists. There are also notable improvements for the aws_route_table_association resource releasing in version 2.20.0 of the Terraform AWS Provider tomorrow. If you are still encountering issues, please feel free to open a new Bug Report following the issue template for further triage.

Of note: Terraform 0.12.6 which was just released, now has support for the resource-level for_each argument. This can be used so resources are indexed in the Terraform state based on a string map or set, rather than the simple numeric list with the resource-level count argument. Resources switched to for_each over count will no longer have issues with removing elements in the middle of a list or general rearranging of elements as the resource index keys are stable.

@bflad bflad closed this as completed Jul 31, 2019
@ghost
Copy link
Author

ghost commented Nov 2, 2019

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 and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. upstream-terraform Addresses functionality related to the Terraform core binary.
Projects
None yet
Development

No branches or pull requests

2 participants