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

Use CustomizeDiff to infer the provider default values #11339

Closed
rileykarson opened this issue Mar 24, 2022 · 5 comments
Closed

Use CustomizeDiff to infer the provider default values #11339

rileykarson opened this issue Mar 24, 2022 · 5 comments

Comments

@rileykarson
Copy link
Collaborator

rileykarson commented Mar 24, 2022

Affected Resource(s)

  • google_*

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 the 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 the issue is assigned to a user, that user is claiming responsibility for the issue. If the issue is assigned to "hashibot", a community member has claimed the issue already.

The provider default project (project field) is substituted in for resources whose project field is empty at apply time across the provider using the getProject method, which checks state and then the provider config for the project. The config object holding provider configuration was only available at apply time, historically, but that's not true with CustomizeDiff around nowadays. We could, presumably, implement a standardised CustomizeDiff for all project-level resources, and determine the final value of the project field (and zone + region) at plan time. Given a config like the following:

provider "google" {
  project = "my-project"
}

resource "google_compute_address" "my-address" {}

Our provider would go from the following terraform plan on creation:

...
      + project            = (known after apply)
...

To the following:

...
      + project            = "my-project"
...

Additionally, we could return a plan-time error when the value is not set.

Note that the current behaviour where the project value is "sticky" was originally due to not having enough information at plan time. We could preserve the existing behaviour by only rewriting the new state to the provider project when both old and new state are empty, and eliminate the behaviour by rewriting whenever new is empty. That's clearly a breaking change, however, I feel that adding the plan-time display+error likely counts as one as well.

In short, I think we could use CustomizeDiff to improve our handling of default projects (but it would be a breaking change to do either of these):

  • Writing the provider project into the new state on create when the resource-level one is unset, displaying it in plan, and adding a check to return an error if it is empty
  • Writing the provider project into the new state on all plans when the resource-level one is unset, overriding old values and removing the current sticky behaviour

Also, as a note: we'd need to check for unknown values in CustomizeDiff! CD does not protect against them by default, in contrast to other schema functions, and unknown values appear to be empty without special handling.

@wyardley
Copy link

Thanks Riley - that would be super helpful!

@wyardley
Copy link

Maybe related: #5761?

@rileykarson
Copy link
Collaborator Author

Note: the actual change (or changing just generated resources) is likely size/s or size/m, but applying to all resources makes this size/xl

@rileykarson rileykarson added this to the Future Major Release milestone Mar 28, 2022
@rileykarson rileykarson changed the title Use CustomizeDiff to infer the provider default project Use CustomizeDiff to infer the provider default values Mar 20, 2023
@c2thorn
Copy link
Collaborator

c2thorn commented Sep 11, 2023

closed with GoogleCloudPlatform/magic-modules#8569

This will release with v5.0.0. Check #15582 for more details on the major release.

@c2thorn c2thorn closed this as completed Sep 11, 2023
@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants