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

New Check: Avoid Unstable (*helper/schema.ResourceData).SetId() Call Expressions with time.Now() #192

Closed
bflad opened this issue Aug 11, 2020 · 0 comments · Fixed by #193
Assignees
Labels
ast AST Handling check/resource Resource Check new-check New Lint Check
Milestone

Comments

@bflad
Copy link
Owner

bflad commented Aug 11, 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 other comments that do not add relevant new information or questions, 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

Description

Terraform 0.13.0 is currently exhibiting behavior where data sources are showing up in plans more often. One common issue with this plan output is that it appears to be caused by the data source ID attribute changing, which may or may not be the actual cause for the new plan output. e.g.

$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.aws_availability_zones.a: Refreshing state... [id=2020-08-11 20:23:09.61125009 +0000 UTC]

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

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
 <= read (data resources)

Terraform will perform the following actions:

  # data.aws_availability_zones.a will be read during apply
  # (config refers to values not yet known)
 <= data "aws_availability_zones" "a"  {
        group_names = [
            "us-west-2",
            "us-west-2-lax-1",
        ]
      ~ id          = "2020-08-11 20:23:19.963587604 +0000 UTC" -> "2020-08-11 20:23:21.360002629 +0000 UTC"
        names       = [
            "us-west-2-lax-1a",
            "us-west-2a",
            "us-west-2b",
            "us-west-2c",
            "us-west-2d",
        ]
        zone_ids    = [
            "usw2-lax1-az1",
            "usw2-az1",
            "usw2-az2",
            "usw2-az3",
            "usw2-az4",
        ]
    }

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

The core team developers have confirmed that this will eventually be the behavior for data source handling in the future, so this check is twofold: to catch common problems now and to prevent them in the future.

New Checks(s)

  • R016

Flagged Provider Code

d.SetId(time.Now().Format(time.RFC3339))

Passing Provider Code

d.SetId(/* some stable value */)

References

@bflad bflad added ast AST Handling new-check New Lint Check check/resource Resource Check labels Aug 11, 2020
@bflad bflad added this to the v0.17.0 milestone Aug 11, 2020
@bflad bflad self-assigned this Aug 12, 2020
bflad added a commit that referenced this issue Aug 12, 2020
bflad added a commit that referenced this issue Aug 12, 2020
bflad added a commit that referenced this issue Aug 12, 2020
…d library package helpers (#193)

* Introduce standard library helpers and pass for fmt.Sprintf() calls

Functionality to replace current Terraform AWS Provider handling and generally will be useful in the future.

* passes: New Checks for common unstable d.SetId() values

Reference: #191
Reference: #192
Mikechoi78 added a commit to Mikechoi78/tfproviderlint that referenced this issue May 23, 2022
…d library package helpers (#193)

* Introduce standard library helpers and pass for fmt.Sprintf() calls

Functionality to replace current Terraform AWS Provider handling and generally will be useful in the future.

* passes: New Checks for common unstable d.SetId() values

Reference: bflad/tfproviderlint#191
Reference: bflad/tfproviderlint#192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast AST Handling check/resource Resource Check new-check New Lint Check
Projects
None yet
1 participant