-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Plan-time project validation #5761
Comments
@preston-hf, during plan there is no syntax error thus it allowed. During apply provider checks if project attribute has any value passed, if not it checks env variable You need to pass the project name in the config or use the environment variable for apply command to be successful. |
I understand how to use it, it doesn't mean this isn't an issue. This breaks git-ops, especially with modules. It should be smart enough to figure out if the project needed when planning instead of breaking the "build" after it's merged. Are you saying it's totally impossible to fix this? Could the check not be done when the plan is run? |
And there are other errors that aren't syntax errors that fail the plan, like not including a required parameter, which this is, or a string not fitting a regex. |
Actually we can't make the project attribute as mandatory for this resource, as it would break the code for others using the project at provider level or as environment variable. Let me discuss with my team and see the possibilities of adding that validation to plan phase. |
Thanks for re-opening! I hope there's some way to resolve it because the only thing I see is defining a provider block in every module to make configure it, and that gets messy with a bunch of modules. It's also a footgun because most of the examples in the docs don't have project set so you don't find out until after the code is merged in, then it requires manual admin intervention. |
@emilymye what are your thoughts on this issue ? How would we ensure project id isn't blank during the plan run ? |
Hi @preston-hf - this is true for almost all our resources with In fact, we ended up making
Can you elaborate how this is breaking your workflow? I'm not sure I follow. |
I would prefer to be explicit for every resource. It's just a simple line or two of code, that is especially helpful at preventing footguns if you've got more than one project in the module. I think the best of both worlds would be to allow explicit configuration of the default (instead of inferring it from gcloud/service account credentials), let me pull it from an environment variable or config variable myself, if I want that behavior. If it's not explicitly provided in the provider config, do not infer it and there should be no default. I believe this is the current behavior, and it should not change. This should also be able to be checked at plan time, so these issues are found before merging using a gitops workflow as outlined roughly in GCP's docs here. When following this roughly, you do your plan when a pull request is sent, and it passes with the changes you expect shown in the output. Many of the resources do not have a If you have a provider default somewhere, the behavior is even worse. Whatever resource you omitted silently uses the wrong project if you forgot to specify one. |
Split this issue, so we'll track adding plan-time validation of projects here (as it's a non-straightforward task to do so, we can't promise we'll get to it ASAP). I've filed a separate issue (#5787) to track making project required for _member/_binding, since that will need to be released as a breaking change. |
Just reporting in more resources: |
Signed-off-by: Modular Magician <[email protected]>
Signed-off-by: Modular Magician <[email protected]>
Maybe the proposed #11339 would help? Now (I'm getting a better understanding of why it's a breaking change, though. With the beta provider, I'm actually seeing a somewhat similar issue (though with the project implicitly present, in that case) even on resources where the beta provider marks Based on what @rileykarson told me on Slack, though, I thought plans should fail when project is required but not set? I agree that the cases where it's required but validation and plans both succeed are extremely unfortunate and annoying. In fact, I would want these to be caught on Of course there will always be some cases where a plan bails for reasons terraform cannot predict, but this seems like a clear case where apply time surprises could (and should) be easily avoided. |
Also, I personally like / rely on it being implicit from the provider set project (and optional on resources), and I can understand why the "magic" behavior of using |
Community Note
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 tohashibot
, a community member has claimed the issue already.Terraform Version
v0.12.21
Affected Resource(s)
Terraform Configuration Files
Debug Output
At plan time, shows adding a member as expected, all is good.
When applying:
Expected Behavior
The project not being present should be known when the plan is run.
Actual Behavior
Plan works fine, the error only appears when applying.
Steps to Reproduce
terraform apply
with no provider-configured project and no project specified.Important Factoids
References
The text was updated successfully, but these errors were encountered: