Merge pull request #5893 from TimeIncOSS/b-aws-api-gateway-fields

provider/aws: Respect 'selection_pattern' in api_gateway_integration_response
This commit is contained in:
Radek Simko 2016-04-27 20:46:29 +02:00
commit 7642fa05a8
3 changed files with 18 additions and 4 deletions

View File

@ -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
}

View File

@ -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" = ""

View File

@ -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