diff --git a/aws/resource_aws_api_gateway2_integration.go b/aws/resource_aws_api_gateway2_integration.go index 8912589f7881..88e17b0ec38c 100644 --- a/aws/resource_aws_api_gateway2_integration.go +++ b/aws/resource_aws_api_gateway2_integration.go @@ -20,6 +20,7 @@ func resourceAwsApiGateway2Integration() *schema.Resource { Importer: &schema.ResourceImporter{ State: resourceAwsApiGateway2IntegrationImport, }, + CustomizeDiff: resourceAwsApiGateway2IntegrationCustomizeDiff, Schema: map[string]*schema.Schema{ "api_id": { @@ -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 +} diff --git a/website/docs/r/api_gateway_v2_integration.html.markdown b/website/docs/r/api_gateway_v2_integration.html.markdown index 837833f5f86e..6a7157655cf8 100644 --- a/website/docs/r/api_gateway_v2_integration.html.markdown +++ b/website/docs/r/api_gateway_v2_integration.html.markdown @@ -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.