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

configs: Simplify required_providers blocks #24763

Merged
merged 1 commit into from
Apr 27, 2020

Conversation

alisdair
Copy link
Contributor

We now permit at most one required_providers block per module (except for overrides). This prevents users (and Terraform) from struggling to understand how to merge multiple required_providers configurations, with version and source attributes split across multiple blocks.

Because only one required_providers block is permitted, there is no need to concatenate version constraints and resolve them. This allows us to simplify the structs used to represent provider requirements, aligning more closely with other structs in this package.

This commit also fixes a semantic use-before-initialize bug, where resources defined before a required_providers block would be unable to use its source attribute. We achieve this by processing the module's required_providers configuration (and overrides) before resources.

Overrides for required_providers work as before, replacing the entire block per provider.

We now permit at most one `required_providers` block per module (except
for overrides). This prevents users (and Terraform) from struggling to
understand how to merge multiple `required_providers` configurations,
with `version` and `source` attributes split across multiple blocks.

Because only one `required_providers` block is permitted, there is no
need to concatenate version constraints and resolve them. This allows us
to simplify the structs used to represent provider requirements,
aligning more closely with other structs in this package.

This commit also fixes a semantic use-before-initialize bug, where
resources defined before a `required_providers` block would be unable to
use its source attribute. We achieve this by processing the module's
`required_providers` configuration (and overrides) before resources.

Overrides for `required_providers` work as before, replacing the entire
block per provider.
@alisdair alisdair requested review from apparentlymart, mildwonkey and a team April 24, 2020 17:50
@alisdair alisdair self-assigned this Apr 24, 2020
@ghost ghost added the sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK label Apr 24, 2020
@codecov
Copy link

codecov bot commented Apr 24, 2020

Codecov Report

Merging #24763 into master will increase coverage by 0.02%.
The diff coverage is 98.64%.

Impacted Files Coverage Δ
configs/module.go 39.86% <96.96%> (+2.44%) ⬆️
configs/config.go 72.13% <100.00%> (-0.23%) ⬇️
configs/module_merge.go 38.70% <100.00%> (-4.58%) ⬇️
configs/parser_config.go 88.77% <100.00%> (ø)
configs/provider_requirements.go 96.82% <100.00%> (+20.73%) ⬆️
dag/marshal.go 52.27% <0.00%> (-1.14%) ⬇️
backend/remote/backend_common.go 53.60% <0.00%> (-0.69%) ⬇️

Copy link
Contributor

@mildwonkey mildwonkey left a comment

Choose a reason for hiding this comment

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

This looks great @alisdair ! Having those two types, ProviderRequirements and RequiredProviders, drove me a little batty and it's lovely to see a solution using one type in both files & modules.

default:
// should not happen
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid provider_requirements syntax",
Detail: "provider_requirements entries must be strings or objects.",
Summary: "Invalid required_providers syntax",
Copy link
Contributor

Choose a reason for hiding this comment

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

🤦 I'm so glad you caught that!

@alisdair alisdair merged commit c113743 into master Apr 27, 2020
@alisdair alisdair deleted the alisdair/required-providers-refactor branch April 27, 2020 15:16
@ghost
Copy link

ghost commented May 28, 2020

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 and limited conversation to collaborators May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants