From 2578c6c8c8c712a9cbda934edb4116a402720733 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Thu, 2 Apr 2020 22:58:16 +0300 Subject: [PATCH 1/6] add support for zero ttl --- aws/resource_aws_api_gateway_authorizer.go | 2 +- ...esource_aws_api_gateway_authorizer_test.go | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_api_gateway_authorizer.go b/aws/resource_aws_api_gateway_authorizer.go index 4d224292955..2c6fbfd733f 100644 --- a/aws/resource_aws_api_gateway_authorizer.go +++ b/aws/resource_aws_api_gateway_authorizer.go @@ -108,7 +108,7 @@ func resourceAwsApiGatewayAuthorizerCreate(d *schema.ResourceData, meta interfac if v, ok := d.GetOk("authorizer_credentials"); ok { input.AuthorizerCredentials = aws.String(v.(string)) } - if v, ok := d.GetOk("authorizer_result_ttl_in_seconds"); ok { + if v, ok := d.GetOkExists("authorizer_result_ttl_in_seconds"); ok { input.AuthorizerResultTtlInSeconds = aws.Int64(int64(v.(int))) } if v, ok := d.GetOk("identity_validation_expression"); ok { diff --git a/aws/resource_aws_api_gateway_authorizer_test.go b/aws/resource_aws_api_gateway_authorizer_test.go index 02fcbb9c04f..89075a60d7f 100644 --- a/aws/resource_aws_api_gateway_authorizer_test.go +++ b/aws/resource_aws_api_gateway_authorizer_test.go @@ -231,6 +231,35 @@ func TestAccAWSAPIGatewayAuthorizer_authTypeValidation(t *testing.T) { }) } +func TestAccAWSAPIGatewayAuthorizer_zero_ttl(t *testing.T) { + var conf apigateway.Authorizer + apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") + authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") + lambdaName := acctest.RandomWithPrefix("tf-acctest-igw-auth-lambda") + resourceName := "aws_api_gateway_authorizer.acctest" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaNoCache(apiGatewayName, authorizerName, lambdaName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSAPIGatewayAuthorizerImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSAPIGatewayAuthorizer_disappears(t *testing.T) { var conf apigateway.Authorizer apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") From 7f1ff9529590ce93b42b4da43ee6ee91f1e701a0 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 25 Jul 2020 01:09:58 +0300 Subject: [PATCH 2/6] add validation for `authorizer_uri`, `authorizer_credentials` changes for %w remove deprecated func --- aws/resource_aws_api_gateway_authorizer.go | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/aws/resource_aws_api_gateway_authorizer.go b/aws/resource_aws_api_gateway_authorizer.go index 2c6fbfd733f..4d31020e71e 100644 --- a/aws/resource_aws_api_gateway_authorizer.go +++ b/aws/resource_aws_api_gateway_authorizer.go @@ -36,8 +36,9 @@ func resourceAwsApiGatewayAuthorizer() *schema.Resource { Schema: map[string]*schema.Schema{ "authorizer_uri": { - Type: schema.TypeString, - Optional: true, // authorizer_uri is required for authorizer TOKEN/REQUEST + Type: schema.TypeString, + Optional: true, // authorizer_uri is required for authorizer TOKEN/REQUEST + ValidateFunc: validateArn, }, "identity_source": { Type: schema.TypeString, @@ -64,8 +65,9 @@ func resourceAwsApiGatewayAuthorizer() *schema.Resource { }, false), }, "authorizer_credentials": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "authorizer_result_ttl_in_seconds": { Type: schema.TypeInt, @@ -93,10 +95,11 @@ func resourceAwsApiGatewayAuthorizerCreate(d *schema.ResourceData, meta interfac conn := meta.(*AWSClient).apigatewayconn input := apigateway.CreateAuthorizerInput{ - IdentitySource: aws.String(d.Get("identity_source").(string)), - Name: aws.String(d.Get("name").(string)), - RestApiId: aws.String(d.Get("rest_api_id").(string)), - Type: aws.String(d.Get("type").(string)), + IdentitySource: aws.String(d.Get("identity_source").(string)), + Name: aws.String(d.Get("name").(string)), + RestApiId: aws.String(d.Get("rest_api_id").(string)), + Type: aws.String(d.Get("type").(string)), + AuthorizerResultTtlInSeconds: aws.Int64(int64(d.Get("authorizer_result_ttl_in_seconds").(int))), } if err := validateAuthorizerType(d); err != nil { @@ -108,23 +111,21 @@ func resourceAwsApiGatewayAuthorizerCreate(d *schema.ResourceData, meta interfac if v, ok := d.GetOk("authorizer_credentials"); ok { input.AuthorizerCredentials = aws.String(v.(string)) } - if v, ok := d.GetOkExists("authorizer_result_ttl_in_seconds"); ok { - input.AuthorizerResultTtlInSeconds = aws.Int64(int64(v.(int))) - } + if v, ok := d.GetOk("identity_validation_expression"); ok { input.IdentityValidationExpression = aws.String(v.(string)) } if v, ok := d.GetOk("provider_arns"); ok { - input.ProviderARNs = expandStringList(v.(*schema.Set).List()) + input.ProviderARNs = expandStringSet(v.(*schema.Set)) } log.Printf("[INFO] Creating API Gateway Authorizer: %s", input) out, err := conn.CreateAuthorizer(&input) if err != nil { - return fmt.Errorf("Error creating API Gateway Authorizer: %s", err) + return fmt.Errorf("error creating API Gateway Authorizer: %w", err) } - d.SetId(*out.Id) + d.SetId(aws.StringValue(out.Id)) return resourceAwsApiGatewayAuthorizerRead(d, meta) } @@ -162,7 +163,7 @@ func resourceAwsApiGatewayAuthorizerRead(d *schema.ResourceData, meta interface{ d.Set("identity_validation_expression", authorizer.IdentityValidationExpression) d.Set("name", authorizer.Name) d.Set("type", authorizer.Type) - d.Set("provider_arns", flattenStringList(authorizer.ProviderARNs)) + d.Set("provider_arns", flattenStringSet(authorizer.ProviderARNs)) return nil } @@ -254,7 +255,7 @@ func resourceAwsApiGatewayAuthorizerUpdate(d *schema.ResourceData, meta interfac log.Printf("[INFO] Updating API Gateway Authorizer: %s", input) _, err := conn.UpdateAuthorizer(&input) if err != nil { - return fmt.Errorf("Updating API Gateway Authorizer failed: %s", err) + return fmt.Errorf("updating API Gateway Authorizer failed: %w", err) } return resourceAwsApiGatewayAuthorizerRead(d, meta) @@ -272,7 +273,7 @@ func resourceAwsApiGatewayAuthorizerDelete(d *schema.ResourceData, meta interfac // XXX: Figure out a way to delete the method that depends on the authorizer first // otherwise the authorizer will be dangling until the API is deleted if !strings.Contains(err.Error(), apigateway.ErrCodeConflictException) { - return fmt.Errorf("Deleting API Gateway Authorizer failed: %s", err) + return fmt.Errorf("deleting API Gateway Authorizer failed: %w", err) } } From 927f76301a1064213dc64a4307860d3a9baa6e90 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 25 Jul 2020 01:19:48 +0300 Subject: [PATCH 3/6] use set len func --- aws/resource_aws_api_gateway_authorizer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_api_gateway_authorizer.go b/aws/resource_aws_api_gateway_authorizer.go index 4d31020e71e..2990c31bd33 100644 --- a/aws/resource_aws_api_gateway_authorizer.go +++ b/aws/resource_aws_api_gateway_authorizer.go @@ -304,7 +304,7 @@ func validateAuthorizerType(d *schema.ResourceData) error { } // provider_arns is required for authorizer COGNITO_USER_POOLS. if authType == apigateway.AuthorizerTypeCognitoUserPools { - if v, ok := d.GetOk("provider_arns"); !ok || len(v.(*schema.Set).List()) == 0 { + if v, ok := d.GetOk("provider_arns"); !ok || v.(*schema.Set).Len() == 0 { return fmt.Errorf("provider_arns must be set non-empty when authorizer type is %s", authType) } } From ee274f5aeb0d28ac4c74acaab1b5c7093bd146d6 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 25 Jul 2020 01:49:52 +0300 Subject: [PATCH 4/6] revert validation for `authorizer_uri` --- aws/resource_aws_api_gateway_authorizer.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_api_gateway_authorizer.go b/aws/resource_aws_api_gateway_authorizer.go index 2990c31bd33..f33680243b4 100644 --- a/aws/resource_aws_api_gateway_authorizer.go +++ b/aws/resource_aws_api_gateway_authorizer.go @@ -36,9 +36,8 @@ func resourceAwsApiGatewayAuthorizer() *schema.Resource { Schema: map[string]*schema.Schema{ "authorizer_uri": { - Type: schema.TypeString, - Optional: true, // authorizer_uri is required for authorizer TOKEN/REQUEST - ValidateFunc: validateArn, + Type: schema.TypeString, + Optional: true, // authorizer_uri is required for authorizer TOKEN/REQUEST }, "identity_source": { Type: schema.TypeString, From 0ba729112129adfd0377e3f4c3e54bfa9f6d5723 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Sat, 25 Jul 2020 01:57:31 +0300 Subject: [PATCH 5/6] refactor tests --- ...esource_aws_api_gateway_authorizer_test.go | 259 ++++++++---------- 1 file changed, 120 insertions(+), 139 deletions(-) diff --git a/aws/resource_aws_api_gateway_authorizer_test.go b/aws/resource_aws_api_gateway_authorizer_test.go index 89075a60d7f..d65d749dac6 100644 --- a/aws/resource_aws_api_gateway_authorizer_test.go +++ b/aws/resource_aws_api_gateway_authorizer_test.go @@ -16,13 +16,10 @@ import ( func TestAccAWSAPIGatewayAuthorizer_basic(t *testing.T) { var conf apigateway.Authorizer - apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") - authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") - lambdaName := acctest.RandomWithPrefix("tf-acctest-igw-auth-lambda") - - resourceName := "aws_api_gateway_authorizer.acctest" - lambdaResourceName := "aws_lambda_function.authorizer" - roleResourceName := "aws_iam_role.invocation_role" + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_api_gateway_authorizer.test" + lambdaResourceName := "aws_lambda_function.test" + roleResourceName := "aws_iam_role.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -30,12 +27,12 @@ func TestAccAWSAPIGatewayAuthorizer_basic(t *testing.T) { CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), resource.TestCheckResourceAttrPair(resourceName, "authorizer_uri", lambdaResourceName, "invoke_arn"), resource.TestCheckResourceAttr(resourceName, "identity_source", "method.request.header.Authorization"), - resource.TestCheckResourceAttr(resourceName, "name", authorizerName), + resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "type", "TOKEN"), resource.TestCheckResourceAttrPair(resourceName, "authorizer_credentials", roleResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", strconv.Itoa(defaultAuthorizerTTL)), @@ -49,12 +46,12 @@ func TestAccAWSAPIGatewayAuthorizer_basic(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaUpdate(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaUpdate(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), resource.TestCheckResourceAttrPair(resourceName, "authorizer_uri", lambdaResourceName, "invoke_arn"), resource.TestCheckResourceAttr(resourceName, "identity_source", "method.request.header.Authorization"), - resource.TestCheckResourceAttr(resourceName, "name", authorizerName+"_modified"), + resource.TestCheckResourceAttr(resourceName, "name", rName+"_modified"), resource.TestCheckResourceAttr(resourceName, "type", "TOKEN"), resource.TestCheckResourceAttrPair(resourceName, "authorizer_credentials", roleResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", strconv.Itoa(360)), @@ -66,11 +63,8 @@ func TestAccAWSAPIGatewayAuthorizer_basic(t *testing.T) { } func TestAccAWSAPIGatewayAuthorizer_cognito(t *testing.T) { - apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") - authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") - cognitoName := acctest.RandomWithPrefix("tf-acctest-cognito-user-pool") - - resourceName := "aws_api_gateway_authorizer.acctest" + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_api_gateway_authorizer.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -78,9 +72,9 @@ func TestAccAWSAPIGatewayAuthorizer_cognito(t *testing.T) { CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSAPIGatewayAuthorizerConfig_cognito(apiGatewayName, authorizerName, cognitoName), + Config: testAccAWSAPIGatewayAuthorizerConfig_cognito(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", authorizerName+"-cognito"), + resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "type", "COGNITO_USER_POOLS"), resource.TestCheckResourceAttr(resourceName, "provider_arns.#", "2"), ), @@ -92,9 +86,9 @@ func TestAccAWSAPIGatewayAuthorizer_cognito(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_cognitoUpdate(apiGatewayName, authorizerName, cognitoName), + Config: testAccAWSAPIGatewayAuthorizerConfig_cognitoUpdate(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", authorizerName+"-cognito-update"), + resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "type", "COGNITO_USER_POOLS"), resource.TestCheckResourceAttr(resourceName, "provider_arns.#", "3"), ), @@ -104,14 +98,10 @@ func TestAccAWSAPIGatewayAuthorizer_cognito(t *testing.T) { } func TestAccAWSAPIGatewayAuthorizer_switchAuthType(t *testing.T) { - apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") - authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") - lambdaName := acctest.RandomWithPrefix("tf-acctest-igw-auth-lambda") - cognitoName := acctest.RandomWithPrefix("tf-acctest-cognito-user-pool") - - resourceName := "aws_api_gateway_authorizer.acctest" - lambdaResourceName := "aws_lambda_function.authorizer" - roleResourceName := "aws_iam_role.invocation_role" + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_api_gateway_authorizer.test" + lambdaResourceName := "aws_lambda_function.test" + roleResourceName := "aws_iam_role.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -119,9 +109,9 @@ func TestAccAWSAPIGatewayAuthorizer_switchAuthType(t *testing.T) { CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", authorizerName), + resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "type", "TOKEN"), resource.TestCheckResourceAttrPair(resourceName, "authorizer_uri", lambdaResourceName, "invoke_arn"), resource.TestCheckResourceAttrPair(resourceName, "authorizer_credentials", roleResourceName, "arn"), @@ -134,17 +124,17 @@ func TestAccAWSAPIGatewayAuthorizer_switchAuthType(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_cognito(apiGatewayName, authorizerName, cognitoName), + Config: testAccAWSAPIGatewayAuthorizerConfig_cognito(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", authorizerName+"-cognito"), + resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "type", "COGNITO_USER_POOLS"), resource.TestCheckResourceAttr(resourceName, "provider_arns.#", "2"), ), }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaUpdate(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaUpdate(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", authorizerName+"_modified"), + resource.TestCheckResourceAttr(resourceName, "name", rName+"_modified"), resource.TestCheckResourceAttr(resourceName, "type", "TOKEN"), resource.TestCheckResourceAttrPair(resourceName, "authorizer_uri", lambdaResourceName, "invoke_arn"), resource.TestCheckResourceAttrPair(resourceName, "authorizer_credentials", roleResourceName, "arn"), @@ -156,10 +146,8 @@ func TestAccAWSAPIGatewayAuthorizer_switchAuthType(t *testing.T) { func TestAccAWSAPIGatewayAuthorizer_switchAuthorizerTTL(t *testing.T) { var conf apigateway.Authorizer - apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") - authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") - lambdaName := acctest.RandomWithPrefix("tf-acctest-igw-auth-lambda") - resourceName := "aws_api_gateway_authorizer.acctest" + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_api_gateway_authorizer.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -167,7 +155,7 @@ func TestAccAWSAPIGatewayAuthorizer_switchAuthorizerTTL(t *testing.T) { CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", strconv.Itoa(defaultAuthorizerTTL)), @@ -180,21 +168,21 @@ func TestAccAWSAPIGatewayAuthorizer_switchAuthorizerTTL(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaUpdate(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaUpdate(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", strconv.Itoa(360)), ), }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaNoCache(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaNoCache(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", strconv.Itoa(0)), ), }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", strconv.Itoa(defaultAuthorizerTTL)), @@ -205,10 +193,7 @@ func TestAccAWSAPIGatewayAuthorizer_switchAuthorizerTTL(t *testing.T) { } func TestAccAWSAPIGatewayAuthorizer_authTypeValidation(t *testing.T) { - apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") - authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") - lambdaName := acctest.RandomWithPrefix("tf-acctest-igw-auth-lambda") - cognitoName := acctest.RandomWithPrefix("tf-acctest-cognito-user-pool") + rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -216,15 +201,15 @@ func TestAccAWSAPIGatewayAuthorizer_authTypeValidation(t *testing.T) { CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSAPIGatewayAuthorizerConfig_authTypeValidationDefaultToken(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_authTypeValidationDefaultToken(rName), ExpectError: regexp.MustCompile(`authorizer_uri must be set non-empty when authorizer type is TOKEN`), }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_authTypeValidationRequest(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_authTypeValidationRequest(rName), ExpectError: regexp.MustCompile(`authorizer_uri must be set non-empty when authorizer type is REQUEST`), }, { - Config: testAccAWSAPIGatewayAuthorizerConfig_authTypeValidationCognito(apiGatewayName, authorizerName, cognitoName), + Config: testAccAWSAPIGatewayAuthorizerConfig_authTypeValidationCognito(rName), ExpectError: regexp.MustCompile(`provider_arns must be set non-empty when authorizer type is COGNITO_USER_POOLS`), }, }, @@ -233,10 +218,8 @@ func TestAccAWSAPIGatewayAuthorizer_authTypeValidation(t *testing.T) { func TestAccAWSAPIGatewayAuthorizer_zero_ttl(t *testing.T) { var conf apigateway.Authorizer - apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") - authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") - lambdaName := acctest.RandomWithPrefix("tf-acctest-igw-auth-lambda") - resourceName := "aws_api_gateway_authorizer.acctest" + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_api_gateway_authorizer.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -244,7 +227,7 @@ func TestAccAWSAPIGatewayAuthorizer_zero_ttl(t *testing.T) { CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaNoCache(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambdaNoCache(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", "0"), @@ -262,10 +245,8 @@ func TestAccAWSAPIGatewayAuthorizer_zero_ttl(t *testing.T) { func TestAccAWSAPIGatewayAuthorizer_disappears(t *testing.T) { var conf apigateway.Authorizer - apiGatewayName := acctest.RandomWithPrefix("tf-acctest-apigw") - authorizerName := acctest.RandomWithPrefix("tf-acctest-igw-authorizer") - lambdaName := acctest.RandomWithPrefix("tf-acctest-igw-auth-lambda") - resourceName := "aws_api_gateway_authorizer.acctest" + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_api_gateway_authorizer.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -273,7 +254,7 @@ func TestAccAWSAPIGatewayAuthorizer_disappears(t *testing.T) { CheckDestroy: testAccCheckAWSAPIGatewayAuthorizerDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(apiGatewayName, authorizerName, lambdaName), + Config: testAccAWSAPIGatewayAuthorizerConfig_lambda(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayAuthorizerExists(resourceName, &conf), testAccCheckResourceDisappears(testAccProvider, resourceAwsApiGatewayAuthorizer(), resourceName), @@ -355,14 +336,14 @@ func testAccAWSAPIGatewayAuthorizerImportStateIdFunc(resourceName string) resour } } -func testAccAWSAPIGatewayAuthorizerConfig_baseLambda(apiGatewayName, lambdaName string) string { +func testAccAWSAPIGatewayAuthorizerConfigBase(rName string) string { return fmt.Sprintf(` -resource "aws_api_gateway_rest_api" "acctest" { - name = "%s" +resource "aws_api_gateway_rest_api" "test" { + name = %[1]q } -resource "aws_iam_role" "invocation_role" { - name = "%s_auth_invocation_role" +resource "aws_iam_role" "test" { + name = %[1]q path = "/" assume_role_policy = < Date: Sat, 25 Jul 2020 02:04:14 +0300 Subject: [PATCH 6/6] refactor tests --- aws/resource_aws_api_gateway_authorizer_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_api_gateway_authorizer_test.go b/aws/resource_aws_api_gateway_authorizer_test.go index d65d749dac6..1a0322444f9 100644 --- a/aws/resource_aws_api_gateway_authorizer_test.go +++ b/aws/resource_aws_api_gateway_authorizer_test.go @@ -477,7 +477,7 @@ resource "aws_api_gateway_rest_api" "test" { resource "aws_cognito_user_pool" "test" { count = 3 - name = "%[1]s-${count.index}-update" + name = "%[1]s-${count.index}" } resource "aws_api_gateway_authorizer" "test" {