From b6e1c44d1b031df2d364aeae5a61866454665153 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Fri, 11 Oct 2019 23:36:34 +0300 Subject: [PATCH] Add support import for aws_waf_byte_match_set resource (#10477) 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) ``` --- aws/resource_aws_waf_byte_match_set.go | 3 + aws/resource_aws_waf_byte_match_set_test.go | 141 ++++++++++-------- .../docs/r/waf_byte_match_set.html.markdown | 8 + 3 files changed, 91 insertions(+), 61 deletions(-) diff --git a/aws/resource_aws_waf_byte_match_set.go b/aws/resource_aws_waf_byte_match_set.go index ec7f7b7f563..075438f45af 100644 --- a/aws/resource_aws_waf_byte_match_set.go +++ b/aws/resource_aws_waf_byte_match_set.go @@ -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": { diff --git a/aws/resource_aws_waf_byte_match_set_test.go b/aws/resource_aws_waf_byte_match_set_test.go index 0d6da476fa1..93c12896f13 100644 --- a/aws/resource_aws_waf_byte_match_set_test.go +++ b/aws/resource_aws_waf_byte_match_set_test.go @@ -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) }, @@ -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, + }, }, }) } @@ -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) }, @@ -59,23 +66,24 @@ 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, + }, }, }) } @@ -83,6 +91,7 @@ func TestAccAWSWafByteMatchSet_changeNameForceNew(t *testing.T) { 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) }, @@ -92,43 +101,48 @@ 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, + }, }, }) } @@ -136,6 +150,7 @@ func TestAccAWSWafByteMatchSet_changeTuples(t *testing.T) { 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) }, @@ -145,13 +160,16 @@ 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, + }, }, }) } @@ -159,6 +177,7 @@ func TestAccAWSWafByteMatchSet_noTuples(t *testing.T) { 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) }, @@ -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, diff --git a/website/docs/r/waf_byte_match_set.html.markdown b/website/docs/r/waf_byte_match_set.html.markdown index 44f2418fe91..b09165aa849 100644 --- a/website/docs/r/waf_byte_match_set.html.markdown +++ b/website/docs/r/waf_byte_match_set.html.markdown @@ -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 +``` \ No newline at end of file