From 5210e1127eb2614521e56a559b9ecca1a3bd2e64 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 29 Mar 2016 07:56:02 +0100 Subject: [PATCH 1/4] provider/aws: Add regression test for #5891 --- .../aws/resource_aws_api_gateway_integration_response_test.go | 4 ++++ 1 file changed, 4 insertions(+) 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" = "" From 70242c2e6dcc8370ff7ad34b44eb51e68c98275a Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 29 Mar 2016 07:47:06 +0100 Subject: [PATCH 2/4] provider/aws: Respect 'selection_pattern' in api_gateway_integration_response - Fixes https://github.com/hashicorp/terraform/issues/5891 --- .../aws/resource_aws_api_gateway_integration_response.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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..ca85ba0e09 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) } From d9f327c282596a10b09f26e2089344e11a08ab86 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 29 Mar 2016 07:48:49 +0100 Subject: [PATCH 3/4] provider/aws: Read aws_api_gateway_integration_response fields back --- .../aws/resource_aws_api_gateway_integration_response.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 ca85ba0e09..b394291e99 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_integration_response.go +++ b/builtin/providers/aws/resource_aws_api_gateway_integration_response.go @@ -86,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 { @@ -107,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 } From a9dc48158db7e792c78a3b1704b829724aab41b8 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 29 Mar 2016 07:56:41 +0100 Subject: [PATCH 4/4] docs: Improve docs for API Gateway int. response selection_pattern --- .../aws/r/api_gateway_integration_response.html.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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