diff --git a/builtin/providers/aws/resource_aws_api_gateway_integration_response.go b/builtin/providers/aws/resource_aws_api_gateway_integration_response.go index 0f2a9af005..b394291e99 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_response.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_response.go @@ -66,7 +66,7 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta templates[k] = v.(string) } - _, err := conn.PutIntegrationResponse(&apigateway.PutIntegrationResponseInput{ + input := apigateway.PutIntegrationResponseInput{ HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), @@ -74,7 +74,11 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta ResponseTemplates: aws.StringMap(templates), // TODO implement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented ResponseParameters: nil, - }) + } + if v, ok := d.GetOk("selection_pattern"); ok { + input.SelectionPattern = aws.String(v.(string)) + } + _, err := conn.PutIntegrationResponse(&input) if err != nil { return fmt.Errorf("Error creating API Gateway Integration Response: %s", err) } @@ -82,7 +86,7 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta d.SetId(fmt.Sprintf("agir-%s-%s-%s-%s", d.Get("rest_api_id").(string), d.Get("resource_id").(string), d.Get("http_method").(string), d.Get("status_code").(string))) log.Printf("[DEBUG] API Gateway Integration Response ID: %s", d.Id()) - return nil + return resourceAwsApiGatewayIntegrationResponseRead(d, meta) } func resourceAwsApiGatewayIntegrationResponseRead(d *schema.ResourceData, meta interface{}) error { @@ -103,7 +107,10 @@ func resourceAwsApiGatewayIntegrationResponseRead(d *schema.ResourceData, meta i return err } log.Printf("[DEBUG] Received API Gateway Integration Response: %s", integrationResponse) + d.SetId(fmt.Sprintf("agir-%s-%s-%s-%s", d.Get("rest_api_id").(string), d.Get("resource_id").(string), d.Get("http_method").(string), d.Get("status_code").(string))) + d.Set("response_templates", integrationResponse.ResponseTemplates) + d.Set("selection_pattern", integrationResponse.SelectionPattern) return nil } diff --git a/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go b/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go index 7809507b3e..3809408dba 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_response_test.go @@ -45,6 +45,9 @@ func testAccCheckAWSAPIGatewayIntegrationResponseAttributes(conf *apigateway.Int if *conf.ResponseTemplates["application/xml"] != "#set($inputRoot = $input.path('$'))\n{ }" { return fmt.Errorf("wrong ResponseTemplate for application/xml") } + if conf.SelectionPattern == nil || *conf.SelectionPattern != ".*" { + return fmt.Errorf("wrong SelectionPattern (expected .*)") + } return nil } } @@ -164,6 +167,7 @@ resource "aws_api_gateway_integration_response" "test" { resource_id = "${aws_api_gateway_resource.test.id}" http_method = "${aws_api_gateway_method.test.http_method}" status_code = "${aws_api_gateway_method_response.error.status_code}" + selection_pattern = ".*" response_templates = { "application/json" = "" diff --git a/website/source/docs/providers/aws/r/api_gateway_integration_response.html.markdown b/website/source/docs/providers/aws/r/api_gateway_integration_response.html.markdown index 454d19bf4d..4f4cedcda8 100644 --- a/website/source/docs/providers/aws/r/api_gateway_integration_response.html.markdown +++ b/website/source/docs/providers/aws/r/api_gateway_integration_response.html.markdown @@ -61,5 +61,8 @@ The following arguments are supported: * `resource_id` - (Required) The API resource ID * `http_method` - (Required) The HTTP method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`) * `status_code` - (Required) The HTTP status code -* `selection_pattern` - (Optional) Specifies the regular expression pattern used to choose an integration response based on the response from the backend +* `selection_pattern` - (Optional) Specifies the regular expression pattern used to choose + an integration response based on the response from the backend. + If the backend is an `AWS` Lambda function, the AWS Lambda function error header is matched. + For all other `HTTP` and `AWS` backends, the HTTP status code is matched. * `response_templates` - (Optional) A map specifying the templates used to transform the integration response body