-
Notifications
You must be signed in to change notification settings - Fork 89
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
fix: fail the provider when env vars are expected but no value is set #1085
Conversation
Signed-off-by: Chris Doyle <[email protected]>
Hello again @cdsre Could you please run below commands and push the change: Also, We require all commits on the contributing PR to be signed. |
Signed-off-by: Chris Doyle <[email protected]>
Hi @duedares-rvj I have run both Other than that there was no changes to the docs. In regards to signing the commits, I am not sure if that comment is just in general or if I have missed something as generally on open source projects I sign my commits anyway. The two commits were done using
Let me know if you need anything more. Chris. |
I Have just clicked the |
@cdsre Thanks for signing the commits, lint and generating the docs! Thanks! |
Thanks @duedares-rvj I will have a look at the tests today. |
So the tests are mostly failing because the This then causes tests like For now I think the best course of action is to close this PR. I will have a think a bit more about the problem and update issue #1074 . The more I look at it the more I wonder if this is an issue to be solved in the SDK rather than the provider. Since the original issue #1023 is for an error that actually arises in the SDK rather then the provider. Its just propagated back to the provider. https://github.com/search?q=repo%3Aauth0%2Fgo-auth0%20%22failed%20to%20send%20the%20request%22&type=code |
Closing this PR for now, if we want to go down this route then we would need to remove the provider builtin scheama checks like |
🔧 Changes
This fix is to address #1074 which is a result of changes in #1053 and #1065 . It appears that the aim of both these PR's was to fail the provider when no value was provided directly in the provider hcl, and no value was found from the ENV vars using the
EnvDefaultFunc
from the terraform schema.However this solution fails to address the case where the value configured in the provider block is not static, but instead comes from either a data lookup, or module which may not be evaluated to its value until later in the terraform flow. The current logic checks the value of each attribute at the provider initialization. If the value is configured in the provider block but is a reference to another resource that has not yet been applied it will evaluate to "" and will look the same as when missing env vars evaluate to "".
In order to address this I have taken the approach that since the
EnvDefaultFunc
function is only invoked when the attribute is not directly configured in the provider block. I.E meaning that we don't have a static or a reference to another resource or data block. Then we look for the value in the environment.The
EnvDefaultFunc
takes 2 parameters, thekey
to look up, and a default value. Instead of passing anil
default which will evaluate as an empty string, instead pass a string value called "MISSING". This allows for us to differentiate between a provider attribute that is empty at initialization because its dynamically provided later, and a provider attribute that was not configured so we have defaulted to the ENV var and its still not set.This achieves the objective of being able to validate missing ENV vars while allowing us to keep the backwards compatibility of provider attributes that are configured with a value that comes from another resource or data block.
📚 References
#1074
#1053
#1065
🔬 Testing
See #1074 for an example on how to reproduce this bug in the current provider and which is solved by this PR
📝 Checklist