Skip to content

Commit

Permalink
add failed backend test
Browse files Browse the repository at this point in the history
  • Loading branch information
javdet committed Mar 17, 2023
1 parent 280b4d8 commit b54c49e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rules/backend_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewBackendTypeRule() *Rule {
}

for _, backend := range body.Blocks {
if backend.Type != requiredBackendType || backend.Labels[0] != requiredYCBackendType {
if backend.Type != requiredYCBackendType && backend.Type != requiredBackendType {
return runner.EmitIssue(
rule,
fmt.Sprintf(
Expand Down
27 changes: 21 additions & 6 deletions rules/backend_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ terraform {
Name: "issue found",
Content: `
terraform {
backend "s3" {
bucket = "mybucket"
key = "path/to/my/key"
region = "us-east-1"
backend "oss" {
bucket = "bucket-for-terraform-state"
prefix = "path/mystate"
key = "version-1.tfstate"
region = "cn-beijing"
tablestore_endpoint = "https://terraform-remote.cn-hangzhou.ots.aliyuncs.com"
tablestore_table = "statelock"
}
}`,
Expected: helper.Issues{
Expand All @@ -44,16 +47,28 @@ terraform {
Message: fmt.Sprintf(
backendTypeMessageTemplate,
requiredBackendType,
"s3",
"oss",
),
Range: hcl.Range{
Filename: filename,
Start: hcl.Pos{Line: 3, Column: 3},
End: hcl.Pos{Line: 3, Column: 15},
End: hcl.Pos{Line: 3, Column: 16},
},
},
},
},
{
Name: "no issues",
Content: `
terraform {
backend "s3" {
bucket = "mybucket"
key = "path/to/my/key"
region = "us-east-1"
}
}`,
Expected: helper.Issues{},
},
}

rule := NewBackendTypeRule()
Expand Down

0 comments on commit b54c49e

Please sign in to comment.