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

Data sources with non-deterministic IDs show perpetual diff with Terraform 0.13 #7348

Closed
Justin-W opened this issue Sep 24, 2020 · 4 comments · Fixed by GoogleCloudPlatform/magic-modules#4018, #7375 or hashicorp/terraform-provider-google-beta#2522
Assignees
Labels

Comments

@Justin-W
Copy link

Justin-W commented Sep 24, 2020

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.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Summary

Data sources whose ID is set to a non-deterministic value (e.g. the current timestamp or a unique ID) that changes every time a refresh (the data source's Read method) runs show a perpetual diff starting with Terraform 0.13.0.

Issue #7092, and the related fix PR, show one possible way to fix data sources affected by this bug.

This has also been reported for the aws provider (hashicorp/terraform-provider-aws#14579) and other providers (see references below).

Comment posted by @jbardin in hashicorp/terraform#25805 (comment)

In general, correctly working data sources should not show up in the plan when there are no changes to the data source configuration or depends_on references. These particular data sources should be reported to the associated provider so they can be fixed.

Comment posted by @bflad in hashicorp/terraform-provider-aws#14579 (comment)

...
New tfproviderlint/awsproviderlint checks are now available for this specific issue (not enabled in our CI yet, fresh off the press):

...

Terraform Version

Terraform v0.13.3
Google Provider v2.20.3, and v3.39.0

Affected Resource(s)

  • data google_compute_zones: this line appears to be the root cause of the problem (for this data source)
  • plus many other data sources

To find the data sources affected, see this github repo search,
or run:

$ grep 'd.SetId' google/data_source*.go | grep Now

Terraform Configuration Files

data "google_compute_zones" "acme-web-services-guide-rails-customer-vpc-sn-0-available" {
  provider = google
  status = "UP"
}

Expected Behavior

TF v0.12 output from terraform plan (immediately after a terraform apply):

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

Actual Behavior

TF v0.13.3 output excerpt from terraform plan (immediately after a terraform apply):

...

  # data.google_compute_zones.zones-up will be read during apply
  # (config refers to values not yet known)
 <= data "google_compute_zones" "zones-up"  {
      + id      = "2020-09-23 21:11:42.856222 +0000 UTC"
      + names   = [
          + "us-west2-a",
          + "us-west2-b",
          + "us-west2-c",
        ]
      + project = "my-project"
      + region  = "us-west2"
      + status  = "UP"
    }

...

Note that the value of the id attribute in the above output is different every time that terraform plan is executed.

Steps to Reproduce

  1. terraform apply
  2. terraform plan > plan1.txt
  3. terraform plan > plan2.txt
  4. diff plan1.txt plan2.txt

Important Factoids

We use the output from terraform plan in our CI process. So if the terraform plan output is not completely idempotent, then that is a big problem for us.

References

@edwardmedia
Copy link
Contributor

edwardmedia commented Sep 24, 2020

I see id difference with 0.13.0, not with 0.12.18

@oscarwest
Copy link

oscarwest commented Sep 24, 2020

We also see ID difference, e.g.

<= data "aws_acm_certificate" "wildcard"  {
        arn         = "arn:aws:acm:us-east-1:...:certificate/...-...-..-...-..."
        domain      = "staging.some.domain"
      ~ id          = "2020-09-24 13:57:35.730091589 +0000 UTC" -> "2020-09-24 13:59:40.610712375 +0000 UTC"
        most_recent = false
        statuses    = [
            "ISSUED",
        ]
        tags        = {}
    }

@bflad
Copy link
Contributor

bflad commented Sep 24, 2020

Drive-by comment: This problem can have a few causes -- while the data source difference will show the more obvious id attribute change, there can actually be other data source schema issues which are at play as well including:

We have experimentally seen in the AWS Provider that sometimes these non-obvious fixes can actually hide the unexpected difference output of a data source even without stabilizing the id attribute (since in some contexts it may be considered a breaking change).

@ghost
Copy link

ghost commented Oct 29, 2020

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. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.