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

"missing provider" when attempting to override default #27409

Closed
jbardin opened this issue Jan 5, 2021 · 4 comments · Fixed by #27739
Closed

"missing provider" when attempting to override default #27409

jbardin opened this issue Jan 5, 2021 · 4 comments · Fixed by #27739
Labels
bug config explained a Terraform Core team member has described the root cause of this issue in code v0.14 Issues (primarily bugs) reported against v0.14 releases

Comments

@jbardin
Copy link
Member

jbardin commented Jan 5, 2021

If a user attempts to override a default provider in a module, init will still find and store the default provider, but plan and apply will indicate that the provider cannot be found.

Config

# main.tf
terraform {
  required_providers {
    null = {
      source = "terraform.io/local/null"
    }
  }
}

module "mod" {
  source = "./mod"
  providers = {
    null = null
  }
}
# ./mod/main.tf
resource "null_resource" "a" {
}

Output

% tf init
Initializing provider plugins...
- Reusing previous version of terraform.io/local/null from the dependency lock file
- Reusing previous version of hashicorp/null from the dependency lock file
- Installing terraform.io/local/null v1.0.0...
- Installed terraform.io/local/null v1.0.0 (unauthenticated)
- Installing hashicorp/null v3.0.0...
- Installed hashicorp/null v3.0.0 (signed by HashiCorp)

% tf plan
Error: missing provider provider["registry.terraform.io/hashicorp/null"]

Adding a "proxy provider block" to the module config does not change the error condition.

Expected Result

The specific error is not useful because the provider does appear to be found. We can either allow this type of override, or catch the invalid configuration and indicate what needs to be changed.

@jbardin jbardin added bug config v0.14 Issues (primarily bugs) reported against v0.14 releases labels Jan 5, 2021
@mildwonkey
Copy link
Contributor

Interesting! This definitely should not work; you cannot override a module's provider's namespace. That's a very deliberate design choice. We should catch that situation and return an error that the configuration is invalid.

@mildwonkey mildwonkey added the explained a Terraform Core team member has described the root cause of this issue in code label Jan 14, 2021
@jbardin
Copy link
Member Author

jbardin commented Jan 27, 2021

Updating with an example that probably should work. It seems passing in providers that don't use the default name is not working. Again it continues to fail even with a proxy provider block. The foo identifier was used here to avoid any possible conflict with the null keyword, but using null makes no difference. The mod module source does work correctly in isolation.

# main.tf
terraform {
  required_providers {
    foo = {
      source = "terraform.io/local/null"
    }
  }
}

module "mod" {
  source = "./mod"
  providers = {
    test = foo
  }
}
# ./mod/main.tf
terraform {
  required_providers {
    test = {
      source = "terraform.io/local/null"
    }
  }
}

resource "null_resource" "a" {
  provider = test
}

@jbardin
Copy link
Member Author

jbardin commented Jan 27, 2021

Ah, found where the inconsistency lies. The providers map is looking for a configuration block, not the provider itself, but we're not reporting the missing config in any sort of validation. If everything is using the default provider names, the module gets the default provider rather than what is passed in. There is usually no distinction between the two when the config is empty, but internally we're silently resolving the provider differently.

@ghost
Copy link

ghost commented Mar 14, 2021

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.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config explained a Terraform Core team member has described the root cause of this issue in code v0.14 Issues (primarily bugs) reported against v0.14 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants