mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-18 20:52:58 -06:00
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:
commit
7642fa05a8
@ -66,7 +66,7 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta
|
|||||||
templates[k] = v.(string)
|
templates[k] = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.PutIntegrationResponse(&apigateway.PutIntegrationResponseInput{
|
input := apigateway.PutIntegrationResponseInput{
|
||||||
HttpMethod: aws.String(d.Get("http_method").(string)),
|
HttpMethod: aws.String(d.Get("http_method").(string)),
|
||||||
ResourceId: aws.String(d.Get("resource_id").(string)),
|
ResourceId: aws.String(d.Get("resource_id").(string)),
|
||||||
RestApiId: aws.String(d.Get("rest_api_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),
|
ResponseTemplates: aws.StringMap(templates),
|
||||||
// TODO implement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented
|
// TODO implement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented
|
||||||
ResponseParameters: nil,
|
ResponseParameters: nil,
|
||||||
})
|
}
|
||||||
|
if v, ok := d.GetOk("selection_pattern"); ok {
|
||||||
|
input.SelectionPattern = aws.String(v.(string))
|
||||||
|
}
|
||||||
|
_, err := conn.PutIntegrationResponse(&input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating API Gateway Integration Response: %s", err)
|
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)))
|
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())
|
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 {
|
func resourceAwsApiGatewayIntegrationResponseRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
@ -103,7 +107,10 @@ func resourceAwsApiGatewayIntegrationResponseRead(d *schema.ResourceData, meta i
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] Received API Gateway Integration Response: %s", integrationResponse)
|
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.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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,9 @@ func testAccCheckAWSAPIGatewayIntegrationResponseAttributes(conf *apigateway.Int
|
|||||||
if *conf.ResponseTemplates["application/xml"] != "#set($inputRoot = $input.path('$'))\n{ }" {
|
if *conf.ResponseTemplates["application/xml"] != "#set($inputRoot = $input.path('$'))\n{ }" {
|
||||||
return fmt.Errorf("wrong ResponseTemplate for application/xml")
|
return fmt.Errorf("wrong ResponseTemplate for application/xml")
|
||||||
}
|
}
|
||||||
|
if conf.SelectionPattern == nil || *conf.SelectionPattern != ".*" {
|
||||||
|
return fmt.Errorf("wrong SelectionPattern (expected .*)")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,6 +167,7 @@ resource "aws_api_gateway_integration_response" "test" {
|
|||||||
resource_id = "${aws_api_gateway_resource.test.id}"
|
resource_id = "${aws_api_gateway_resource.test.id}"
|
||||||
http_method = "${aws_api_gateway_method.test.http_method}"
|
http_method = "${aws_api_gateway_method.test.http_method}"
|
||||||
status_code = "${aws_api_gateway_method_response.error.status_code}"
|
status_code = "${aws_api_gateway_method_response.error.status_code}"
|
||||||
|
selection_pattern = ".*"
|
||||||
|
|
||||||
response_templates = {
|
response_templates = {
|
||||||
"application/json" = ""
|
"application/json" = ""
|
||||||
|
@ -61,5 +61,8 @@ The following arguments are supported:
|
|||||||
* `resource_id` - (Required) The API resource ID
|
* `resource_id` - (Required) The API resource ID
|
||||||
* `http_method` - (Required) The HTTP method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`)
|
* `http_method` - (Required) The HTTP method (`GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTION`)
|
||||||
* `status_code` - (Required) The HTTP status code
|
* `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
|
* `response_templates` - (Optional) A map specifying the templates used to transform the integration response body
|
||||||
|
Loading…
Reference in New Issue
Block a user