-
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
Providers can no longer be configured using a mix of environment variables and explicit configuration. #1074
Comments
@dylanCz Hello! I tried reproducing this but it is working as expected on our end. Please find the logs below:
|
@dylanCz Did you get a chance to try this out? |
@duedares-rvj Thanks for your update. I have taken a look at this and its not related to a mix of variables but instead to do with the design pattern that we have been using for a long while. So to first explain the logic. We have an M2M token that is responsible for creating another environment scoped M2M tokens. This first M2M token is set at the environment level and applied to the default auth0 provider. We then call off to an auth0 module we have written that does things like create a new org, new api resources etc and a new M2M token for that environment. We then use that Newley generated M2M token as the input to the aliased provider to then create additional environment specific resources. In export AUTH0_DOMAIN=example.com
export AUTH0_CLIENT_ID=foo_client
export AUTH0_CLIENT_SECRET=foo_secret I have mocked up an example for you that you can use to reproduce the issue. some_auth0_module.tf terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "3.6.2"
}
}
}
# Use this is fake way to generate a client ID at apply time. This would normally be "auth0_client" rsource
resource "random_string" "user_management_m2m_token" {
length = 16
}
output "m2m_user_management_client_id" {
value = random_string.user_management_m2m_token.result
} root modules main.tf terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "3.6.2"
}
auth0 = {
source = "auth0/auth0"
version = "1.7.3"
}
}
}
module "auth0_config" {
source = "./some_auth_module"
}
# This is added in the root module to avoid using the output from the auth0_config module as the data lookup can be
# delayed due to dependencies, as otherwise this causes reads on the provider alias to fail during the object refresh when planning
data "auth0_client" "user_management_m2m" {
client_id = module.auth0_config.m2m_user_management_client_id
}
provider "auth0" {
alias = "user_management_auth0"
client_id = module.auth0_config.m2m_user_management_client_id
client_secret = data.auth0_client.user_management_m2m.client_secret
}
resource "auth0_user" "internal_admin_user" {
provider = auth0.user_management_auth0
connection_name = "foo"
email = "[email protected]"
email_verified = true
} Now if i run this with version 1.7.1 then it plans fine, and when its applied, the value of the client_id will be set on the provider before the provider is invoked. 1.7.1 plan
However if we upgrade to
|
This change in behaviour seems to have come from these to pull requests. #1053 - This added validation on required ENV vars meaning that was the only way to configure the provider #1065 then changed this behaviour and moved this validation into the ProviderConfig to validate if its value is not empty. I.E it was either set directly or it was from the defaultFunc. However this doesn't take into account lazy loading of values that might not be known until the provider is actually invoked rather than when the provider is initialized. From my perspective this is a Breaking Change because it fundamentally changes how the provider works and is not backwards compatible. |
@duedares-rvj I have submitted a PR with what I see as a potential solution to this issue that allows you to keep your validation logic to check for missing env vars when we fell back to the |
@duedares-rvj Following the conversation on PR #1085 it doesn't seem there is an easy or clean way to solve environment variable validation in the provider without then blocking dynamic provider attributes that come from resources or delayed data lookups. Until a more consistent way is found is it possible to remove the environment variables validation in the provider? |
It would be troublesome to go back and forth on the provider's validation. Once a more consistent way is found, we could add the required checks. |
Checklist
Description
Since 1.7.3 where this commit added a check on provider's configuration for required env vars, this prevents providers from using a mix of env vars and explicit configuration.
We set our auth0_domain as an environment variable, and then create multiple auth0 providers in our terraform code, supplying the client_id and client_secret as part of the provider block. In provider version 1.7.1, this works fine, where it used the client_id and secret supplied to the provider and resolved the domain from the environment variable.
Expectation
If a provider block does not have all the required configuration explicitly defined, it should check env vars for any missing configuration.
Reproduction
Set the auth0 domain environment variable
export AUTH0_DOMAIN=fake_domain
Create a provider with version 1.7.3, without explicitly passing a domain
Run terraform plan, see that it errors (because the domain has not been set in the provider block)
╷
│ Error: Missing environment variables
│
│ with provider["registry.terraform.io/auth0/auth0"].additional-provider,
│ on auth0.tf line 12, in provider "auth0":
│ 12: provider "auth0" {
│
│ Either AUTH0_API_TOKEN or AUTH0_DOMAIN:AUTH0_CLIENT_ID:AUTH0_CLIENT_SECRET must be configured. Ref: https://registry.terraform.io/providers/auth0/auth0/latest/docs
╵
The issue can be resolved by adding an explicit domain to the provider
Auth0 Terraform Provider version
1.7.3
Terraform version
1.9.8
The text was updated successfully, but these errors were encountered: