Skip to content

Commit

Permalink
resource/aws_waf_sql_injection_match_set: Properly set sql_injection_…
Browse files Browse the repository at this point in the history
…match_tuples into Terraform state (#11498)

Reference: #9954

Previously:

```
/Users/bflad/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_waf_sql_injection_match_set.go:101:38: R004: ResourceData.Set() incompatible value type: []*github.com/aws/aws-sdk-go/service/waf.SqlInjectionMatchTuple
```

Fixes `d.Set()` handling for this attribute with existing flatten function (used by `aws_wafregional_sql_injection_match_set` resource) and one associated test configuration so that it matches API canonicalization, which is now enforced by the testing since the value is being properly read into the Terraform state.

Output from acceptance testing:

```
--- PASS: TestAccAWSWafSqlInjectionMatchSet_noTuples (13.29s)
--- PASS: TestAccAWSWafSqlInjectionMatchSet_disappears (17.63s)
--- PASS: TestAccAWSWafSqlInjectionMatchSet_basic (17.65s)
--- PASS: TestAccAWSWafSqlInjectionMatchSet_changeTuples (23.46s)
--- PASS: TestAccAWSWafSqlInjectionMatchSet_changeNameForceNew (31.73s)
```
  • Loading branch information
bflad authored Jan 17, 2020
1 parent 9bd77e1 commit 880473c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
5 changes: 4 additions & 1 deletion aws/resource_aws_waf_sql_injection_match_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ func resourceAwsWafSqlInjectionMatchSetRead(d *schema.ResourceData, meta interfa
}

d.Set("name", resp.SqlInjectionMatchSet.Name)
d.Set("sql_injection_match_tuples", resp.SqlInjectionMatchSet.SqlInjectionMatchTuples)

if err := d.Set("sql_injection_match_tuples", flattenWafSqlInjectionMatchTuples(resp.SqlInjectionMatchSet.SqlInjectionMatchTuples)); err != nil {
return fmt.Errorf("error setting sql_injection_match_tuples: %s", err)
}

return nil
}
Expand Down
9 changes: 0 additions & 9 deletions aws/resource_aws_waf_sql_injection_match_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ func TestAccAWSWafSqlInjectionMatchSet_changeTuples(t *testing.T) {
"aws_waf_sql_injection_match_set.sql_injection_match_set", "name", setName),
resource.TestCheckResourceAttr(
"aws_waf_sql_injection_match_set.sql_injection_match_set", "sql_injection_match_tuples.#", "1"),
resource.TestCheckResourceAttr(
"aws_waf_sql_injection_match_set.sql_injection_match_set", "sql_injection_match_tuples.3333510133.field_to_match.#", "1"),
resource.TestCheckResourceAttr(
"aws_waf_sql_injection_match_set.sql_injection_match_set", "sql_injection_match_tuples.3333510133.field_to_match.4253810390.data", "GET"),
resource.TestCheckResourceAttr(
"aws_waf_sql_injection_match_set.sql_injection_match_set", "sql_injection_match_tuples.3333510133.field_to_match.4253810390.type", "METHOD"),
resource.TestCheckResourceAttr(
"aws_waf_sql_injection_match_set.sql_injection_match_set", "sql_injection_match_tuples.3333510133.text_transformation", "NONE"),
),
},
},
Expand Down Expand Up @@ -314,7 +306,6 @@ resource "aws_waf_sql_injection_match_set" "sql_injection_match_set" {
field_to_match {
type = "METHOD"
data = "GET"
}
}
}
Expand Down

0 comments on commit 880473c

Please sign in to comment.