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

allow parsing of required_providers containing ref #59

Merged
merged 1 commit into from
Feb 9, 2021

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Feb 8, 2021

The syntax for configuration_aliases contains bare references to match
their use in other parts of the configuration. These however cannot be
decoded directly without an EvalContext, as they represent variables.

Refactor decodeRequiredProvidersBlock to use the lower level
hcl.ExprMap function.

While configuration_aliases does define an alternate configuration name for a provider, this PR does not add the alias names to provider_configs because that field is specifically documented as representing a provider block. This is consistent with the handling of un-aliased providers too, since they may also be referenced and have requirements without an explicit configuration block.

The syntax for configuration_aliases contains bare references to match
their use in other parts of the configuration. These however cannot be
decoded directly without an EvalContext, as they represent variables.

Refactor decodeRequiredProvidersBlock to use the lower level ExprMap
function.
@jbardin jbardin requested a review from a team as a code owner February 8, 2021 21:15
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.

The code looks great, but I don't think we should return an error if an unexpected field is encountered. My thoughts on that are inline.

if key.Type() != cty.String {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid Attribute",
Copy link
Contributor

Choose a reason for hiding this comment

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

I would drop this error, or at least make it a warning instead (though I'm not sure if we have many warnings, so that might not be a good idea either).

We generally ignore unexpected fields as part of the (vague, hand-wavey) future-proofing. terraform-config-inspect is intended to be a very permissive tool that only knows what it knows directly and ignores anything extra.

Copy link
Member Author

Choose a reason for hiding this comment

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

I put this in since it was in the category of "should never happen", and would have generated a parsing error before as well. Come to think of it though, I'm not sure if we could ever get here without a string at all 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at hcl.ExprMap, the returned values are entirely up to the expression implementation, however they should only be returning a value at all if there this is a valid map, which requires string keys/attributes. We can probably just drop this error altogether.

Copy link
Member

Choose a reason for hiding this comment

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

I would generally lean also towards permissiveness in the behaviour, esp. because we also use it in the language server, where we expect to be parsing invalid configs pretty often.

That said as long as we continue parsing the rest of the config (which seems to be the case here) and not "stop & return nil and diags", I'm ok with that as diags can always be dealt with.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to note, the old code would have returned an error if this is even possible at some level. The string check is basically a failsafe in case a faulty ExprMap implementation returns something incorrect for the key value, but maybe that's overkill here and we should just let it panic in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Er .... looking at this again I just misread the error case :(

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Approving this to unblock and also because I understand this is rather a fix, than a new feature from tfconfig perspective.

That said I think we'll need to come up with a way of actually exposing these new aliases somehow. At least we'll need it in LS, see #54

@jbardin
Copy link
Member Author

jbardin commented Feb 8, 2021

Thanks @radeksimko

Yeah, like I mentioned, I specifically avoided adding these in, because we are currently only exposing configurations. Providers in modules don't always have an associated configuration, aliased or not, and It wasn't clear if we want the information presented to represent only literal configuration blocks.

I can follow up if we want all provider names (which are in essence conceptually referred to as configurations) to be present in the output.

@jbardin jbardin merged commit 4fd17a0 into master Feb 9, 2021
@jbardin jbardin deleted the jbardin/required-providers branch February 9, 2021 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants