Skip to content

Commit

Permalink
correctly added test for #207. able to reproduce
Browse files Browse the repository at this point in the history
  • Loading branch information
milldr committed Jul 7, 2020
1 parent 4cccf6f commit 55cfb5b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,3 @@ resource "aws_redshift_parameter_group" "require_ssl_set_to_true" {
value = "example"
}
}

# PASS: require_ssl is set to true with alternate syntax -- issue #207
resource "aws_redshift_parameter_group" "require_ssl_set_to_true" {
name = "foobar"
family = "redshift-1.0"

parameter = [
{
name = "enable_user_activity_logging"
value = "true"
},
{
name = "require_ssl"
value = "true"
},
{
name = "query_group"
value = "example"
}
]
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ require (
github.com/stretchr/testify v1.5.1
github.com/zclconf/go-cty v1.1.1
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/tools v0.0.0-20200707211228-9c9572d6f9fb // indirect
golang.org/x/tools v0.0.0-20200707222132-065b96d36cf8 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ golang.org/x/tools v0.0.0-20200406213809-066fd1390ee0 h1:PaUgOASiqoF4KlotK7/3XKY
golang.org/x/tools v0.0.0-20200406213809-066fd1390ee0/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200707211228-9c9572d6f9fb h1:KQNKAKmUcuTOUHJ3yVtHJ1lNDB7uZqmmlLDqtNsylgk=
golang.org/x/tools v0.0.0-20200707211228-9c9572d6f9fb/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200707222132-065b96d36cf8 h1:rYNDdbWDFG7Q3X/d8ahsWyc08Xjn0Ac2DeTzF54X+DM=
golang.org/x/tools v0.0.0-20200707222132-065b96d36cf8/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
7 changes: 7 additions & 0 deletions linter/terraform_v12_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ func TestTerraform12LinterCases(t *testing.T) {
1,
"CHECK_FOR_COLON",
},
// Test added for issue #207 alternate attr syntax as a block - DM
"TF12AttrBlock": {
"./testdata/resources/attr_block_syntax.tf",
"./testdata/rules/attr_block_syntax.yml",
2,
"ATTR_BLOCK",
},
}

for name, tc := range testCases {
Expand Down
61 changes: 61 additions & 0 deletions linter/testdata/resources/attr_block_syntax.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# PASS with best syntax
resource "aws_redshift_parameter_group" "pass_best" {
name = "foo"
family = "redshift-1.0"

parameter {
name = "tls"
value = "enabled"
}
parameter {
name = "audit_logs"
value = "enabled"
}
}

# PASS with Alternate syntax
resource "aws_redshift_parameter_group" "pass_alt" {
name = "bar"
family = "redshift-1.0"

parameter =
[{
name = "tls"
value = "enabled"
},
{
name = "audit_logs"
value = "enabled"
}]
}

# FAIL with best syntax
resource "aws_redshift_parameter_group" "fail_best" {
name = "fail_foo"
family = "redshift-1.0"

parameter {
name = "tls"
value = "disabled"
}
parameter {
name = "audit_logs"
value = "enabled"
}
}

# FAIL with Alternate syntax
resource "aws_redshift_parameter_group" "fail_alt" {
name = "fail_bar"
family = "redshift-1.0"

parameter =
[{
name = "tls"
value = "disabled"
},
{
name = "audit_logs"
value = "enabled"
}]
}
26 changes: 26 additions & 0 deletions linter/testdata/rules/attr_block_syntax.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
version: 1
description: Terraform v12 rules
type: Terraform12
files:
- "*.tf"
- "*.tfvars"
rules:
# This test rule is intended to recreate a reported bug, issue 207
- id: "ATTR_BLOCK"
message: "test: alternate syntax is allowed"
resources:
- aws_redshift_parameter_group
category: resource
severity: FAILURE
assertions:
- some:
key: parameter
expressions:
- and:
- key: name
op: eq
value: tls
- key: value
op: eq
value: enabled

0 comments on commit 55cfb5b

Please sign in to comment.