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

cli: Fix for missing provider requirements in JSON plan #27697

Merged
merged 1 commit into from
Feb 16, 2021

Conversation

alisdair
Copy link
Contributor

@alisdair alisdair commented Feb 5, 2021

The JSON plan output format includes a serialized, simplified version of the configuration. One component of this config is a map of provider configurations, which includes version constraints.

Until now, only version constraints specified in the provider config blocks were exposed in the JSON plan output. This is a deprecated method of specifying provider versions, and the recommended use of a required_providers block resulted in the version constraints being omitted.

This commit fixes this with two changes:

  • When processing the provider configurations from a module, output the fully-merged version constraints for the entire module, instead of any constraints set in the provider configuration block itself;
  • After all provider configurations are processed, iterate over the required_providers entries to ensure that any configuration-less providers are output to the JSON plan too.

No changes are necessary to the structure of the JSON plan output, so this is effectively a semantic level bug fix.

The JSON plan output format includes a serialized, simplified version of
the configuration. One component of this config is a map of provider
configurations, which includes version constraints.

Until now, only version constraints specified in the provider config
blocks were exposed in the JSON plan output. This is a deprecated method
of specifying provider versions, and the recommended use of a
required_providers block resulted in the version constraints being
omitted.

This commit fixes this with two changes:

- When processing the provider configurations from a module, output the
  fully-merged version constraints for the entire module, instead of any
  constraints set in the provider configuration block itself;
- After all provider configurations are processed, iterate over the
  required_providers entries to ensure that any configuration-less
  providers are output to the JSON plan too.

No changes are necessary to the structure of the JSON plan output, so
this is effectively a semantic level bug fix.
@alisdair alisdair added the cli label Feb 5, 2021
@alisdair alisdair requested a review from a team February 5, 2021 19:44
@alisdair alisdair self-assigned this Feb 5, 2021
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #27697 (7cae763) into master (32d2084) will decrease coverage by 0.00%.
The diff coverage is 14.28%.

Impacted Files Coverage Δ
command/jsonconfig/config.go 0.00% <0.00%> (ø)
configs/config.go 69.29% <100.00%> (+0.82%) ⬆️

@alisdair alisdair requested a review from vancluever February 5, 2021 21:24
@alisdair
Copy link
Contributor Author

alisdair commented Feb 5, 2021

@vancluever This is in response to a Sentinel-related issue, so I was hoping you could take a quick look and see if these semantics line up with what Sentinel expects from the JSON plan format.

Copy link
Contributor

@vancluever vancluever left a comment

Choose a reason for hiding this comment

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

I have no problems with a no-impact change 😉

@vancluever
Copy link
Contributor

PS: Structure lines up. 👍 We currently expose version_constraint directly without any additional processing, so this works.

To my note above, while I definitely don't have a problem with this approach, generally the pattern has been so far that separate semantic elements in the Terraform config get exposed separately, so I almost expected to see a separate "RequiredProviders" section exposed separately. I don't know if that's entirely needed though, and if we can't see any value in that kind of semantic exposure and there would never be any conflict here, I'm fine with this approach!

@pkolyvas
Copy link
Contributor

pkolyvas commented Feb 5, 2021

PS: Structure lines up. 👍 We currently expose version_constraint directly without any additional processing, so this works.

To my note above, while I definitely don't have a problem with this approach, generally the pattern has been so far that separate semantic elements in the Terraform config get exposed separately, so I almost expected to see a separate "RequiredProviders" section exposed separately. I don't know if that's entirely needed though, and if we can't see any value in that kind of semantic exposure and there would never be any conflict here, I'm fine with this approach!

I should add @vancluever that I asked if there was a way to get this information without breaking existing policies.

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.

LGTM, if @vancluever is happy I'm happy !

@alisdair alisdair added the 0.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Feb 16, 2021
@alisdair
Copy link
Contributor Author

@vancluever Thanks for looking at this! I'm going to merge for now as I think it most expediently addresses the problem the Sentinel user is having, while still being a logical bug fix of the existing JSON config semantics.

For Sentinel to be able to inspect the contents of required_providers (e.g. provider source, version and the upcoming configuration aliases) we'd have to extend the JSON config schema. I'd be happy to help with that if it's an enhancement that you'd like to build on.

@alisdair alisdair merged commit bb3f59b into master Feb 16, 2021
@alisdair alisdair deleted the alisdair/json-plan-provider-required-versions branch February 16, 2021 14:05
@vancluever
Copy link
Contributor

That will definitely something we will want to pursue, but I'll leave it to product to roadmap accordingly.

cc @hcrhall @dylanegan

@ghost
Copy link

ghost commented Mar 19, 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 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
0.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged cli
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants