Skip to content

Commit

Permalink
terraformlint: add passing test case for locations as part of an object
Browse files Browse the repository at this point in the history
Refs #310
  • Loading branch information
sethvargo committed Mar 18, 2024
1 parent cec59ae commit 088e817
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 27 additions & 4 deletions internal/tools/terraformlinter/terraform_linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestTerraformLinter_FindViolations(t *testing.T) {
filename: "/test/test.tf",
expect: []*ViolationInstance{
{
Message: `The attribute "project" must me below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Message: `The attribute "project" must be below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Path: "/test/test.tf",
Line: 4,
},
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestTerraformLinter_FindViolations(t *testing.T) {
Line: 9,
},
{
Message: `The attribute "organization" must me below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Message: `The attribute "organization" must be below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Path: "/test/test.tf",
Line: 12,
},
Expand Down Expand Up @@ -613,12 +613,12 @@ func TestTerraformLinter_FindViolations(t *testing.T) {
filename: "/test/test.tf",
expect: []*ViolationInstance{
{
Message: `The attribute "folder" must me below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Message: `The attribute "folder" must be below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Path: "/test/test.tf",
Line: 4,
},
{
Message: `The attribute "organization" must me below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Message: `The attribute "organization" must be below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`,
Path: "/test/test.tf",
Line: 5,
},
Expand Down Expand Up @@ -677,6 +677,29 @@ func TestTerraformLinter_FindViolations(t *testing.T) {
}
`,
},
{
name: "folder_project_as_object",
content: `
module "environment" {
source = "./my-module"
data_containers = concat(
[for cd_project_id in local.organization.common_data_project_ids :
{
folder_id = local.organization.common_data_folder_id[0]
project_id = cd_project_id
is_shared = true
researchers = [for r in local.researchers : {
project_id = local.organization.researcher_vpe_project_ids[r.id]
email = r.email
}]
}],
)
}
`,
filename: "/test/test.tf",
},
}

for _, tc := range cases {
Expand Down
2 changes: 1 addition & 1 deletion internal/tools/terraformlinter/violations.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newMetaBlockNewlineViolation(token hclsyntax.Token) *ViolationInstance {
}

func newProviderAttributesViolation(token hclsyntax.Token, attr string) *ViolationInstance {
message := fmt.Sprintf(`The attribute %q must me below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`, attr)
message := fmt.Sprintf(`The attribute %q must be below any meta attributes (e.g. "for_each", "count") but above all other attributes. Attributes must be ordered organization > folder > project.`, attr)
return newViolation(token, message)
}

Expand Down

0 comments on commit 088e817

Please sign in to comment.