Skip to content

Commit

Permalink
Add support import for aws_waf_byte_match_set resource (#10477)
Browse files Browse the repository at this point in the history
Output from acceptance testing:

```
--- PASS: TestAccAWSWafByteMatchSet_noTuples (21.34s)
--- FAIL: TestAccAWSWafByteMatchSet_changeTuples (33.66s)
--- PASS: TestAccAWSWafByteMatchSet_basic (36.76s)
--- PASS: TestAccAWSWafByteMatchSet_changeNameForceNew (39.74s)
--- PASS: TestAccAWSWafByteMatchSet_disappears (48.34s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Oct 11, 2019
1 parent 5b8a522 commit b6e1c44
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 61 deletions.
3 changes: 3 additions & 0 deletions aws/resource_aws_waf_byte_match_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func resourceAwsWafByteMatchSet() *schema.Resource {
Read: resourceAwsWafByteMatchSetRead,
Update: resourceAwsWafByteMatchSetUpdate,
Delete: resourceAwsWafByteMatchSetDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down
141 changes: 80 additions & 61 deletions aws/resource_aws_waf_byte_match_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
func TestAccAWSWafByteMatchSet_basic(t *testing.T) {
var v waf.ByteMatchSet
byteMatchSet := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
resourceName := "aws_waf_byte_match_set.byte_set"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWaf(t) },
Expand All @@ -25,23 +26,28 @@ func TestAccAWSWafByteMatchSet_basic(t *testing.T) {
{
Config: testAccAWSWafByteMatchSetConfig(byteMatchSet),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &v),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "name", byteMatchSet),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "2"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.#", "1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.field_to_match.#", "1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.text_transformation", "NONE"),
testAccCheckAWSWafByteMatchSetExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "name", byteMatchSet),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.#", "2"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.field_to_match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.text_transformation", "NONE"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -50,6 +56,7 @@ func TestAccAWSWafByteMatchSet_changeNameForceNew(t *testing.T) {
var before, after waf.ByteMatchSet
byteMatchSet := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
byteMatchSetNewName := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
resourceName := "aws_waf_byte_match_set.byte_set"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWaf(t) },
Expand All @@ -59,30 +66,32 @@ func TestAccAWSWafByteMatchSet_changeNameForceNew(t *testing.T) {
{
Config: testAccAWSWafByteMatchSetConfig(byteMatchSet),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &before),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "name", byteMatchSet),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "2"),
testAccCheckAWSWafByteMatchSetExists(resourceName, &before),
resource.TestCheckResourceAttr(resourceName, "name", byteMatchSet),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.#", "2"),
),
},
{
Config: testAccAWSWafByteMatchSetConfigChangeName(byteMatchSetNewName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &after),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "name", byteMatchSetNewName),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "2"),
testAccCheckAWSWafByteMatchSetExists(resourceName, &after),
resource.TestCheckResourceAttr(resourceName, "name", byteMatchSetNewName),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.#", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSWafByteMatchSet_changeTuples(t *testing.T) {
var before, after waf.ByteMatchSet
byteMatchSetName := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
resourceName := "aws_waf_byte_match_set.byte_set"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWaf(t) },
Expand All @@ -92,50 +101,56 @@ func TestAccAWSWafByteMatchSet_changeTuples(t *testing.T) {
{
Config: testAccAWSWafByteMatchSetConfig(byteMatchSetName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &before),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "name", byteMatchSetName),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "2"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.#", "1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.field_to_match.#", "1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.839525137.text_transformation", "NONE"),
testAccCheckAWSWafByteMatchSetExists(resourceName, &before),
resource.TestCheckResourceAttr(resourceName, "name", byteMatchSetName),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.#", "2"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.field_to_match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.target_string", "badrefer2"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.839525137.text_transformation", "NONE"),
),
},
{
Config: testAccAWSWafByteMatchSetConfig_changeTuples(byteMatchSetName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &after),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "name", byteMatchSetName),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "2"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.#", "1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.4224486115.field_to_match.#", "1"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.4224486115.field_to_match.4253810390.data", "GET"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.4224486115.field_to_match.4253810390.type", "METHOD"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.4224486115.positional_constraint", "CONTAINS_WORD"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.4224486115.target_string", "blah"),
resource.TestCheckResourceAttr("aws_waf_byte_match_set.byte_set", "byte_match_tuples.4224486115.text_transformation", "URL_DECODE"),
testAccCheckAWSWafByteMatchSetExists(resourceName, &after),
resource.TestCheckResourceAttr(resourceName, "name", byteMatchSetName),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.#", "2"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.2991901334.data", "referer"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.field_to_match.2991901334.type", "HEADER"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.positional_constraint", "CONTAINS"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.target_string", "badrefer1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.2174619346.text_transformation", "NONE"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.4224486115.field_to_match.#", "1"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.4224486115.field_to_match.4253810390.data", "GET"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.4224486115.field_to_match.4253810390.type", "METHOD"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.4224486115.positional_constraint", "CONTAINS_WORD"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.4224486115.target_string", "blah"),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.4224486115.text_transformation", "URL_DECODE"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSWafByteMatchSet_noTuples(t *testing.T) {
var byteSet waf.ByteMatchSet
byteMatchSetName := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
resourceName := "aws_waf_byte_match_set.byte_set"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWaf(t) },
Expand All @@ -145,20 +160,24 @@ func TestAccAWSWafByteMatchSet_noTuples(t *testing.T) {
{
Config: testAccAWSWafByteMatchSetConfig_noTuples(byteMatchSetName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &byteSet),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "name", byteMatchSetName),
resource.TestCheckResourceAttr(
"aws_waf_byte_match_set.byte_set", "byte_match_tuples.#", "0"),
testAccCheckAWSWafByteMatchSetExists(resourceName, &byteSet),
resource.TestCheckResourceAttr(resourceName, "name", byteMatchSetName),
resource.TestCheckResourceAttr(resourceName, "byte_match_tuples.#", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSWafByteMatchSet_disappears(t *testing.T) {
var v waf.ByteMatchSet
byteMatchSet := fmt.Sprintf("byteMatchSet-%s", acctest.RandString(5))
resourceName := "aws_waf_byte_match_set.byte_set"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSWaf(t) },
Expand All @@ -168,7 +187,7 @@ func TestAccAWSWafByteMatchSet_disappears(t *testing.T) {
{
Config: testAccAWSWafByteMatchSetConfig(byteMatchSet),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSWafByteMatchSetExists("aws_waf_byte_match_set.byte_set", &v),
testAccCheckAWSWafByteMatchSetExists(resourceName, &v),
testAccCheckAWSWafByteMatchSetDisappears(&v),
),
ExpectNonEmptyPlan: true,
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/waf_byte_match_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the WAF Byte Match Set.

## Import

WAF Byte Match Set can be imported using the id, e.g.

```
$ terraform import aws_waf_byte_match_set.byte_set a1b2c3d4-d5f6-7777-8888-9999aaaabbbbcccc
```

0 comments on commit b6e1c44

Please sign in to comment.