Skip to content

Commit

Permalink
terraformrules: Get module contents with IncludeNotCreated: true (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored Jul 29, 2022
1 parent 36628eb commit c40ee70
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_documented_outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *TerraformDocumentedOutputsRule) Check(runner *tflint.Runner) error {
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_documented_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *TerraformDocumentedVariablesRule) Check(runner *tflint.Runner) error {
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_module_pinned_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *TerraformModulePinnedSourceRule) Check(runner *tflint.Runner) error {
return err
}

body, diags := runner.GetModuleContent(moduleCallSchema, sdk.GetModuleContentOption{})
body, diags := runner.GetModuleContent(moduleCallSchema, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_module_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *TerraformModuleVersionRule) Check(runner *tflint.Runner) error {
return err
}

body, diags := runner.GetModuleContent(moduleCallSchema, sdk.GetModuleContentOption{})
body, diags := runner.GetModuleContent(moduleCallSchema, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_naming_convention.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (r *TerraformNamingConventionRule) Check(runner *tflint.Runner) error {
Body: &hclext.BodySchema{},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
4 changes: 2 additions & 2 deletions rules/terraformrules/terraform_required_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *TerraformRequiredProvidersRule) Check(runner *tflint.Runner) error {
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func (r *TerraformRequiredProvidersRule) Check(runner *tflint.Runner) error {
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_required_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *TerraformRequiredVersionRule) Check(runner *tflint.Runner) error {
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *TerraformStandardModuleStructureRule) Check(runner *tflint.Runner) erro
Body: &hclext.BodySchema{},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_typed_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *TerraformTypedVariablesRule) Check(runner *tflint.Runner) error {
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_unused_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *TerraformUnusedDeclarationsRule) declarations(runner *tflint.Runner) (*
Body: &hclext.BodySchema{},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return decl, diags
}
Expand Down
19 changes: 19 additions & 0 deletions rules/terraformrules/terraform_unused_required_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ func Test_TerraformUnusedRequiredProvidersRule(t *testing.T) {
},
},
},
{
Name: "used - unevaluated resource",
Content: `
terraform {
required_providers {
null = {
source = "hashicorp/null"
}
}
}
variable "foo" {}
resource "null_resource" "foo" {
count = var.foo
}
`,
Expected: tflint.Issues{},
},
}

rule := NewTerraformUnusedRequiredProvidersRule()
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/terraform_workspace_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (r *TerraformWorkspaceRemoteRule) Check(runner *tflint.Runner) error {
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return diags
}
Expand Down
2 changes: 1 addition & 1 deletion rules/terraformrules/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func getProviderRefs(runner *tflint.Runner) (map[string]*providerRef, hcl.Diagno
},
},
},
}, sdk.GetModuleContentOption{})
}, sdk.GetModuleContentOption{IncludeNotCreated: true})
if diags.HasErrors() {
return providerRefs, diags
}
Expand Down

0 comments on commit c40ee70

Please sign in to comment.