Skip to content

stacks: Don't require built-in providers to be listed under required providers. #37234

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

Merged
merged 9 commits into from
Jun 18, 2025

Conversation

matejrisek
Copy link
Contributor

@matejrisek matejrisek commented Jun 13, 2025

stacks: Do NOT require built-in providers to have to be listed under required providers.

Target Release

1.13.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

N/A

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this file is in the package builtin/providers so I don't think we need to repeat that in the file name - just providers.go or maybe factories.go or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I'll go with factories
6aa4881

provider "github.com/hashicorp/terraform/internal/providers"
)

func BuiltInProviders() map[string]provider.Factory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be a static map wrapped in a var () block I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that make it globally mutable? If I had to choose between immutability that the factory function offers and the global var - I'd rather choose immutability.

Let me know if I'm missing something here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, yeah that's fair. I think we do have the pattern of global vars elsewhere in Terraform, and we save some level of computation by not creating the map every time something just wants to list the built in providers.

Either way, I don't feel that strongly about this - so happy to just do what you think is best 👍

// occurring later in the process.
if _, ok := builtinProviders.BuiltInProviders()[localName]; ok {
return addrs.Provider{}, true
}
return addrs.Provider{}, false
}
obj, ok := pr.Requirements[localName]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised you didn't need to change here as well - what if the provider requirements block was written but it doesn't have the builtin provider present? Perhaps adding another test where there is a different provider defined in the required providers but not the builtin, but the builtin is then referred to would expose this?

There could also be another explanation as to why this isn't required!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're surprised for valid reasons. I made an oversight. This should be fixed here 45136b4

Thanks for catching on this!

// built-in provider names. In that case, customers will see an error
// occurring later in the process.
if _, ok := builtinProviders.BuiltInProviders()[localName]; ok {
return addrs.Provider{}, true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's like an addrs.BuiltinProvider(localName) function you can call to return a proper address here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - there is addrs.NewDefaultProvider - I believe this function does what's necessary here.

@matejrisek matejrisek requested a review from liamcervante June 13, 2025 13:58
@matejrisek matejrisek marked this pull request as ready for review June 16, 2025 11:12
@matejrisek matejrisek requested a review from a team as a code owner June 16, 2025 11:12
Copy link
Member

@liamcervante liamcervante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! just some style nits that will fix the quick checks

}
}

for providerName, _ := range builtinProviders.BuiltInProviders() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need the second assignment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 61 to 62
ret = includeBuiltInProviders(ret)
return ret, diags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret = includeBuiltInProviders(ret)
return ret, diags
return includeBuiltInProviders(ret), diags

style nit! optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 224 to 226
ret = includeBuiltInProviders(ret)

return ret, diags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret = includeBuiltInProviders(ret)
return ret, diags
return includeBuiltInProviders(ret), diags

style nit, optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liamcervante liamcervante added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Jun 17, 2025
Copy link
Member

@liamcervante liamcervante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@matejrisek matejrisek closed this Jun 18, 2025
@matejrisek matejrisek reopened this Jun 18, 2025
@matejrisek matejrisek merged commit a9b67a6 into main Jun 18, 2025
19 of 20 checks passed
@matejrisek matejrisek deleted the feature/stacks/ignore-required-providers-if-builtin branch June 18, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants