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

terraform: Remove unused internal packages impl #1158

Merged
merged 1 commit into from Jul 11, 2021
Merged

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Jul 7, 2021

See also #1141

In #1141, I just copied the internal packages needed to build TFLint from Terraform v1.0. However, this includes obviously unused implementations. This PR reduces the implementations that need to be maintained by reviewing some features such as evaluation.

This change is made without changing the TFLint interface. Changing the interface may reduce more implementations, but it will be done in other PRs.

GetForEachAttr(addrs.ForEachAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
GetResource(addrs.Resource, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
GetLocalValue(addrs.LocalValue, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
GetModule(addrs.ModuleCall, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
Copy link
Member Author

@wata727 wata727 Jul 11, 2021

Choose a reason for hiding this comment

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

Currently, evaluation is only supported for input variables, path, and terraform attributes, so remove the others.

// object and instance key data. References to the object must use self, and the
// key data will only contain count.index or each.key. The static values for
// terraform and path will also be available in this context.
func (s *Scope) EvalSelfBlock(body hcl.Body, self cty.Value, schema *configschema.Block, keyData instances.RepetitionData) (cty.Value, tfdiags.Diagnostics) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly, evaluation of self.* is not supported by TFLint.

// First we'll do static validation of the references. This catches things
// early that might otherwise not get caught due to unknown values being
// present in the scope during planning.
if staticDiags := s.Data.StaticValidateReferences(refs, selfAddr); staticDiags.HasErrors() {
Copy link
Member Author

Choose a reason for hiding this comment

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

StaticValidateReferences mainly detect reference errors of resources, data attributes, module attributes early. However, TFLint does not support the evaluation of these attributes.

@@ -72,7 +48,7 @@ func (e *Evaluator) Scope(data lang.Data, self addrs.Referenceable) *lang.Scope
return &lang.Scope{
Data: data,
SelfAddr: self,
PureOnly: e.Operation != walkApply && e.Operation != walkDestroy && e.Operation != walkEval,
PureOnly: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

The initial value is always used for the e.Operation. This affects the behavior of some functions, and it is arguable whether this PureOnly: true is appropriate for TFLint evaluation, but it follows current behavior.

@wata727 wata727 marked this pull request as ready for review July 11, 2021 07:38
@wata727 wata727 merged commit fc569c8 into master Jul 11, 2021
@wata727 wata727 deleted the remove_unused_funcs branch July 11, 2021 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant