Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/api_gateway_authorizer - fix to allow zero value for authorizer_result_ttl_in_seconds #12643

Merged
merged 6 commits into from
Jul 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add validation for authorizer_uri, authorizer_credentials
changes for %w
remove deprecated func
  • Loading branch information
DrFaust92 committed Jul 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7f1ff9529590ce93b42b4da43ee6ee91f1e701a0
35 changes: 18 additions & 17 deletions aws/resource_aws_api_gateway_authorizer.go
Original file line number Diff line number Diff line change
@@ -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)
}
}