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

User-supplied, empty values in the provider configuration should not be ignored and unused #14447

Closed
SarahFrench opened this issue Apr 28, 2023 · 5 comments · Fixed by GoogleCloudPlatform/magic-modules#9050

Comments

@SarahFrench
Copy link
Member

SarahFrench commented Apr 28, 2023

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.

Terraform Version

N/A
This is related to a defect identified after introduction of v4.60.2
We have fixed the provider to have parity with the old behaviour, but in 5.0.0 we should remove the behaviour seen in <=4.59.0

Affected Resource(s)

N/A - is related to provider config

Terraform Configuration Files

Provider is configured by:

  • Running gcloud auth application-default login
  • Not having any ENVs for configuring the provider present
provider "google" {
  credentials = ""
}

Debug Output

N/A

Expected Behavior

When a user sets a value in their configuration it should override any environment variables. If a user sets credentials = "", or project="" (for example) then the provider should attempt to use that value.

Actual Behavior

In the old SDK version of the provider <=4.59.0 empty strings would be ignored and ENVs would be used instead.
After muxing was introduced to the provider the ignoring stopped, and we then changed to code to ensure parity with the un-muxed code.
Currently empty strings are ignored in provider configurations.

Steps to Reproduce

  1. Local environment setup
    a. Running gcloud auth application-default login
    b. Unset any ENVs for configuring the provider
  2. Make a TF config where the provider config block includes an empty string as an argument, e.g. credentials = ""
  3. terraform apply <- error occurs here

Important Factoids

The reason empty strings were ignored in the past is because the SDK made it hard to distinguish between Go's zero values and user-supplied values. After values were taken out of the ResourceData struct for the provider you lose any information about whether the value was set or not. Structs made using values from the provider config, i.e. the Config struct, have no way to distinguish between zero values and user values that match.

References

@SarahFrench SarahFrench added this to the 5.0.0 milestone Apr 28, 2023
@SarahFrench SarahFrench changed the title Empty values in the provider configuration should not be ignored and unused User-supplied, empty values in the provider configuration should not be ignored and unused Apr 28, 2023
@SarahFrench SarahFrench self-assigned this Apr 28, 2023
@SarahFrench
Copy link
Member Author

This change could include addition of validation functions like : https://developer.hashicorp.com/terraform/plugin/framework/providers/validate-configuration#validateconfig-method

@rileykarson
Copy link
Collaborator

Note: We may need to watch out for an intersection with GoogleCloudPlatform/magic-modules#8569, we probably just want to test a couple of cases

@SarahFrench
Copy link
Member Author

Issue is still open due because GoogleCloudPlatform/magic-modules#9050 is needed to add user-facing validation on provider config values

@c2thorn
Copy link
Collaborator

c2thorn commented Sep 26, 2023

Closed with GoogleCloudPlatform/magic-modules#9050

@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 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.