Skip to content

Commit

Permalink
r/aws_api_gateway_v2_integration: 'integration_method' must be set on…
Browse files Browse the repository at this point in the history
…ly if 'integration_method' is not 'MOCK'.
  • Loading branch information
ewbankkit committed Aug 16, 2019
1 parent edc72d8 commit 1dac073
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions aws/resource_aws_api_gateway2_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func resourceAwsApiGateway2Integration() *schema.Resource {
Importer: &schema.ResourceImporter{
State: resourceAwsApiGateway2IntegrationImport,
},
CustomizeDiff: resourceAwsApiGateway2IntegrationCustomizeDiff,

Schema: map[string]*schema.Schema{
"api_id": {
Expand Down Expand Up @@ -279,3 +280,20 @@ func resourceAwsApiGateway2IntegrationImport(d *schema.ResourceData, meta interf

return []*schema.ResourceData{d}, nil
}

func resourceAwsApiGateway2IntegrationCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error {
if diff.Id() == "" {
// New resource.
integrationMethod := diff.Get("integration_method").(string)
integrationType := diff.Get("integration_type").(string)
if integrationType == apigatewayv2.IntegrationTypeMock {
if integrationMethod != "" {
return fmt.Errorf("'integration_method' must not be set when 'integration_type' is '%s'", integrationType)
}
} else if integrationMethod == "" {
return fmt.Errorf("'integration_method' must be set when 'integration_type' is '%s'", integrationType)
}
}

return nil
}
2 changes: 1 addition & 1 deletion website/docs/r/api_gateway_v2_integration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Valid values: `AWS`, `AWS_PROXY`, `HTTP`, `HTTP_PROXY`, `MOCK`.
* `content_handling_strategy` - (Optional) How to handle response payload content type conversions. Valid values: `CONVERT_TO_BINARY`, `CONVERT_TO_TEXT`.
* `credentials_arn` - (Optional) The credentials required for the integration, if any.
* `description` - (Optional) The description of the integration.
* `integration_method` - (Optional) The integration's HTTP method.
* `integration_method` - (Optional) The integration's HTTP method. Must be specified if `integration_type` is not `MOCK`.
* `integration_uri` - (Optional) The URI of the Lambda function for a Lambda proxy integration, where `integration_type` is `AWS_PROXY`.
* `passthrough_behavior` - (Optional) The pass-through behavior for incoming requests based on the Content-Type header in the request, and the available mapping templates specified as the `request_templates` attribute. Valid values: `WHEN_NO_MATCH`, `WHEN_NO_TEMPLATES`, `NEVER`. Default is `WHEN_NO_MATCH`.
* `request_templates` - (Optional) A map of Velocity templates that are applied on the request payload based on the value of the Content-Type header sent by the client.
Expand Down

0 comments on commit 1dac073

Please sign in to comment.