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

Adding passthrough behavior for API Gateway integration #7801

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 18 additions & 5 deletions builtin/providers/aws/resource_aws_api_gateway_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func resourceAwsApiGatewayIntegration() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},

"passthrough_behavior": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateApiGatewayIntegrationPassthroughBehavior,
},
},
}
}
Expand Down Expand Up @@ -106,6 +112,11 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa
}
}

var passthroughBehavior *string
if v, ok := d.GetOk("passthrough_behavior"); ok {
passthroughBehavior = aws.String(v.(string))
}

var credentials *string
if val, ok := d.GetOk("credentials"); ok {
credentials = aws.String(val.(string))
Expand All @@ -119,11 +130,12 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa
IntegrationHttpMethod: integrationHttpMethod,
Uri: uri,
// TODO reimplement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented
RequestParameters: aws.StringMap(parameters),
RequestTemplates: aws.StringMap(templates),
Credentials: credentials,
CacheNamespace: nil,
CacheKeyParameters: nil,
RequestParameters: aws.StringMap(parameters),
RequestTemplates: aws.StringMap(templates),
Credentials: credentials,
CacheNamespace: nil,
CacheKeyParameters: nil,
PassthroughBehavior: passthroughBehavior,
})
if err != nil {
return fmt.Errorf("Error creating API Gateway Integration: %s", err)
Expand Down Expand Up @@ -163,6 +175,7 @@ func resourceAwsApiGatewayIntegrationRead(d *schema.ResourceData, meta interface
d.Set("type", integration.Type)
d.Set("uri", integration.Uri)
d.Set("request_parameters_in_json", aws.StringValueMap(integration.RequestParameters))
d.Set("passthrough_behavior", integration.PassthroughBehavior)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestAccAWSAPIGatewayIntegration_basic(t *testing.T) {
"aws_api_gateway_integration.test", "request_templates.application/json", ""),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration.test", "request_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration.test", "passthrough_behavior", "WHEN_NO_MATCH"),
),
},

Expand All @@ -48,6 +50,8 @@ func TestAccAWSAPIGatewayIntegration_basic(t *testing.T) {
"aws_api_gateway_integration.test", "integration_http_method", ""),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration.test", "uri", ""),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration.test", "passthrough_behavior", "NEVER"),
),
},
},
Expand Down Expand Up @@ -193,6 +197,7 @@ resource "aws_api_gateway_integration" "test" {
type = "HTTP"
uri = "https://www.google.de"
integration_http_method = "GET"
passthrough_behavior = "WHEN_NO_MATCH"
}
`

Expand Down Expand Up @@ -230,5 +235,7 @@ resource "aws_api_gateway_integration" "test" {
PARAMS

type = "MOCK"
passthrough_behavior = "NEVER"

}
`
9 changes: 9 additions & 0 deletions builtin/providers/aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,12 @@ func validateDbEventSubscriptionName(v interface{}, k string) (ws []string, erro
}
return
}

func validateApiGatewayIntegrationPassthroughBehavior(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if value != "WHEN_NO_MATCH" && value != "WHEN_NO_TEMPLATES" && value != "NEVER" {
errors = append(errors, fmt.Errorf(
"%q must be one of 'WHEN_NO_MATCH', 'WHEN_NO_TEMPLATES', 'NEVER'", k))
}
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The following arguments are supported:
Not all methods are compatible with all `AWS` integrations.
e.g. Lambda function [can only be invoked](https://github.com/awslabs/aws-apigateway-importer/issues/9#issuecomment-129651005) via `POST`.
* `request_templates` - (Optional) A map of the integration's request templates.
* `passthrough_behavior` - (Optional) The integration passthrough behavior (`WHEN_NO_MATCH`, `WHEN_NO_TEMPLATES`, `NEVER`). **Required** if `request_templates` is used.
* `request_parameters_in_json` - (Optional) A map written as a JSON string specifying
the request query string parameters and headers that should be passed to the
backend responder.
Expand Down