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

bug with required provider attributes w/ env variables #12

Open
ryanking opened this issue Dec 9, 2020 · 1 comment
Open

bug with required provider attributes w/ env variables #12

ryanking opened this issue Dec 9, 2020 · 1 comment

Comments

@ryanking
Copy link

ryanking commented Dec 9, 2020

I have been trying to make use of this project with terraform-provider-snowflake and am very excited for it, since it means I could delete my half-baked code that did similar work.

We have run into one limitation – required provider configuration which accepts environment variables.

When using this configuration, running terraform providers schema -json will vary its configuration for these inputs based on whether or not the environment variables are present. For the linked example, if the SNOWFLAKE_USER environment variable is set, then username will be marked as "optional". If the env variable is not preset, it will be set as "required".

For purposes of documentation, it seems like it should always be marked as "required".

ryanking added a commit to Snowflake-Labs/terraform-provider-snowflake that referenced this issue Dec 9, 2020
ryanking added a commit to Snowflake-Labs/terraform-provider-snowflake that referenced this issue Dec 9, 2020
@paultyng
Copy link
Contributor

This is a tough one and I agree its confusing. In terms of how Terraform views this flag (ie. if someone were to run terraform validate) it would allow no env var to be set and also for the value to be missing from configuration, as it treats it as fully optional.
The presences of a value is only asserted at different phases of the Terraform lifecycle, so while its "required" at runtime, its not "required" in the schema sense.

Typically how I solve this now though is to just indicate in the description if there is some defaulting mechanism or an environment variable read for a value. For example see this: https://github.com/paultyng/terraform-provider-unifi/blob/464f55255fafedf62fd3edcd7df678aa9d61e517/internal/provider/provider.go#L38-L39

You can override how the description text is generated in the SDK as well if you want to further customize those strings, see this example: https://github.com/hashicorp/terraform-provider-scaffolding/blob/bec212504f3fc7ad42e5f3a80425cb95872dda28/internal/provider/provider.go#L15-L23

gjv9491 pushed a commit to gjv9491/terraform-provider-snowflake that referenced this issue Mar 19, 2021
anton-chekanov pushed a commit to anton-chekanov/terraform-provider-snowflake that referenced this issue Jan 25, 2022
daniepett pushed a commit to daniepett/terraform-provider-snowflake that referenced this issue Feb 9, 2022
stephenwan-opal added a commit to opalsecurity/terraform-provider-opal that referenced this issue Sep 21, 2022
UnicornGlobal/has-changes-action#5

There is a bug in ghe generator where the presence of the env var
will cause a diff during generation. We hack around this by blanking out the env var
during generation.

hashicorp/terraform-plugin-docs#12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants