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/aws_apigatewayv2_authorizer: Support Lambda authorization options for HTTP APIs #15232

Merged
Show file tree
Hide file tree
Changes from 2 commits
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
47 changes: 39 additions & 8 deletions aws/resource_aws_apigatewayv2_authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,33 @@ func resourceAwsApiGatewayV2Authorizer() *schema.Resource {
Optional: true,
ValidateFunc: validateArn,
},
"authorizer_payload_format_version": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"1.0", "2.0"}, false),
},
"authorizer_result_ttl_in_seconds": {
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 3600),
},
"authorizer_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
apigatewayv2.AuthorizerTypeJwt,
apigatewayv2.AuthorizerTypeRequest,
}, false),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(apigatewayv2.AuthorizerType_Values(), false),
},
"authorizer_uri": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(1, 2048),
},
"enable_simple_responses": {
Type: schema.TypeBool,
Optional: true,
},
"identity_sources": {
Type: schema.TypeSet,
Required: true,
MinItems: 1,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"jwt_configuration": {
Expand Down Expand Up @@ -91,9 +101,18 @@ func resourceAwsApiGatewayV2AuthorizerCreate(d *schema.ResourceData, meta interf
if v, ok := d.GetOk("authorizer_credentials_arn"); ok {
req.AuthorizerCredentialsArn = aws.String(v.(string))
}
if v, ok := d.GetOk("authorizer_payload_format_version"); ok {
req.AuthorizerPayloadFormatVersion = aws.String(v.(string))
}
if v, ok := d.GetOk("authorizer_result_ttl_in_seconds"); ok {
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
req.AuthorizerResultTtlInSeconds = aws.Int64(int64(v.(int)))
}
if v, ok := d.GetOk("authorizer_uri"); ok {
req.AuthorizerUri = aws.String(v.(string))
}
if v, ok := d.GetOk("enable_simple_responses"); ok {
req.EnableSimpleResponses = aws.Bool(v.(bool))
}
if v, ok := d.GetOk("jwt_configuration"); ok {
req.JwtConfiguration = expandApiGateway2JwtConfiguration(v.([]interface{}))
}
Expand Down Expand Up @@ -126,8 +145,11 @@ func resourceAwsApiGatewayV2AuthorizerRead(d *schema.ResourceData, meta interfac
}

d.Set("authorizer_credentials_arn", resp.AuthorizerCredentialsArn)
d.Set("authorizer_payload_format_version", resp.AuthorizerPayloadFormatVersion)
d.Set("authorizer_result_ttl_in_seconds", resp.AuthorizerResultTtlInSeconds)
d.Set("authorizer_type", resp.AuthorizerType)
d.Set("authorizer_uri", resp.AuthorizerUri)
d.Set("enable_simple_responses", resp.EnableSimpleResponses)
if err := d.Set("identity_sources", flattenStringSet(resp.IdentitySource)); err != nil {
return fmt.Errorf("error setting identity_sources: %s", err)
}
Expand All @@ -149,12 +171,21 @@ func resourceAwsApiGatewayV2AuthorizerUpdate(d *schema.ResourceData, meta interf
if d.HasChange("authorizer_credentials_arn") {
req.AuthorizerCredentialsArn = aws.String(d.Get("authorizer_credentials_arn").(string))
}
if d.HasChange("authorizer_payload_format_version") {
req.AuthorizerPayloadFormatVersion = aws.String(d.Get("authorizer_payload_format_version").(string))
}
if d.HasChange("authorizer_result_ttl_in_seconds") {
req.AuthorizerResultTtlInSeconds = aws.Int64(int64(d.Get("authorizer_result_ttl_in_seconds").(int)))
}
if d.HasChange("authorizer_type") {
req.AuthorizerType = aws.String(d.Get("authorizer_type").(string))
}
if d.HasChange("authorizer_uri") {
req.AuthorizerUri = aws.String(d.Get("authorizer_uri").(string))
}
if d.HasChange("enable_simple_responses") {
req.EnableSimpleResponses = aws.Bool(d.Get("enable_simple_responses").(bool))
}
if d.HasChange("identity_sources") {
req.IdentitySource = expandStringSet(d.Get("identity_sources").(*schema.Set))
}
Expand Down
Loading