mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-16 18:35:03 -06:00
Merge branch 'jmettes-api_gateway_binary_media_types'
This commit is contained in:
commit
3d29d8212e
@ -82,6 +82,12 @@ func resourceAwsApiGatewayIntegration() *schema.Resource {
|
||||
Deprecated: "Use field request_parameters instead",
|
||||
},
|
||||
|
||||
"content_handling": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validateApiGatewayIntegrationContentHandling,
|
||||
},
|
||||
|
||||
"passthrough_behavior": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
@ -131,6 +137,11 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa
|
||||
credentials = aws.String(val.(string))
|
||||
}
|
||||
|
||||
var contentHandling *string
|
||||
if val, ok := d.GetOk("content_handling"); ok {
|
||||
contentHandling = aws.String(val.(string))
|
||||
}
|
||||
|
||||
_, err := conn.PutIntegration(&apigateway.PutIntegrationInput{
|
||||
HttpMethod: aws.String(d.Get("http_method").(string)),
|
||||
ResourceId: aws.String(d.Get("resource_id").(string)),
|
||||
@ -144,6 +155,7 @@ func resourceAwsApiGatewayIntegrationCreate(d *schema.ResourceData, meta interfa
|
||||
CacheNamespace: nil,
|
||||
CacheKeyParameters: nil,
|
||||
PassthroughBehavior: passthroughBehavior,
|
||||
ContentHandling: contentHandling,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating API Gateway Integration: %s", err)
|
||||
@ -185,6 +197,7 @@ func resourceAwsApiGatewayIntegrationRead(d *schema.ResourceData, meta interface
|
||||
d.Set("request_parameters", aws.StringValueMap(integration.RequestParameters))
|
||||
d.Set("request_parameters_in_json", aws.StringValueMap(integration.RequestParameters))
|
||||
d.Set("passthrough_behavior", integration.PassthroughBehavior)
|
||||
d.Set("content_handling", integration.ContentHandling)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ func TestAccAWSAPIGatewayIntegration_basic(t *testing.T) {
|
||||
"aws_api_gateway_integration.test", "request_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_api_gateway_integration.test", "passthrough_behavior", "WHEN_NO_MATCH"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_api_gateway_integration.test", "content_handling", ""),
|
||||
),
|
||||
},
|
||||
|
||||
@ -52,6 +54,8 @@ func TestAccAWSAPIGatewayIntegration_basic(t *testing.T) {
|
||||
"aws_api_gateway_integration.test", "uri", ""),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_api_gateway_integration.test", "passthrough_behavior", "NEVER"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_api_gateway_integration.test", "content_handling", "CONVERT_TO_BINARY"),
|
||||
),
|
||||
},
|
||||
},
|
||||
@ -66,6 +70,9 @@ func testAccCheckAWSAPIGatewayMockIntegrationAttributes(conf *apigateway.Integra
|
||||
if *conf.RequestParameters["integration.request.header.X-Authorization"] != "'updated'" {
|
||||
return fmt.Errorf("wrong updated RequestParameters for header.X-Authorization")
|
||||
}
|
||||
if *conf.ContentHandling != "CONVERT_TO_BINARY" {
|
||||
return fmt.Errorf("wrong ContentHandling: %q", *conf.ContentHandling)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -232,6 +239,7 @@ resource "aws_api_gateway_integration" "test" {
|
||||
|
||||
type = "MOCK"
|
||||
passthrough_behavior = "NEVER"
|
||||
content_handling = "CONVERT_TO_BINARY"
|
||||
|
||||
}
|
||||
`
|
||||
|
@ -30,6 +30,13 @@ func resourceAwsApiGatewayRestApi() *schema.Resource {
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"binary_media_types": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
|
||||
"root_resource_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@ -51,10 +58,18 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{}
|
||||
if d.Get("description").(string) != "" {
|
||||
description = aws.String(d.Get("description").(string))
|
||||
}
|
||||
gateway, err := conn.CreateRestApi(&apigateway.CreateRestApiInput{
|
||||
|
||||
params := &apigateway.CreateRestApiInput{
|
||||
Name: aws.String(d.Get("name").(string)),
|
||||
Description: description,
|
||||
})
|
||||
}
|
||||
|
||||
binaryMediaTypes, binaryMediaTypesOk := d.GetOk("binary_media_types")
|
||||
if binaryMediaTypesOk {
|
||||
params.BinaryMediaTypes = expandStringList(binaryMediaTypes.([]interface{}))
|
||||
}
|
||||
|
||||
gateway, err := conn.CreateRestApi(params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating API Gateway: %s", err)
|
||||
}
|
||||
@ -105,6 +120,7 @@ func resourceAwsApiGatewayRestApiRead(d *schema.ResourceData, meta interface{})
|
||||
|
||||
d.Set("name", api.Name)
|
||||
d.Set("description", api.Description)
|
||||
d.Set("binary_media_types", api.BinaryMediaTypes)
|
||||
|
||||
if err := d.Set("created_date", api.CreatedDate.Format(time.RFC3339)); err != nil {
|
||||
log.Printf("[DEBUG] Error setting created_date: %s", err)
|
||||
|
@ -29,6 +29,8 @@ func TestAccAWSAPIGatewayRestApi_basic(t *testing.T) {
|
||||
"aws_api_gateway_rest_api.test", "description", ""),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"aws_api_gateway_rest_api.test", "created_date"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_api_gateway_rest_api.test", "binary_media_types", ""),
|
||||
),
|
||||
},
|
||||
|
||||
@ -44,6 +46,10 @@ func TestAccAWSAPIGatewayRestApi_basic(t *testing.T) {
|
||||
"aws_api_gateway_rest_api.test", "description", "test"),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"aws_api_gateway_rest_api.test", "created_date"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_api_gateway_rest_api.test", "binary_media_types.#", "1"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_api_gateway_rest_api.test", "binary_media_types.0", "application/octet-stream"),
|
||||
),
|
||||
},
|
||||
},
|
||||
@ -135,5 +141,6 @@ const testAccAWSAPIGatewayRestAPIUpdateConfig = `
|
||||
resource "aws_api_gateway_rest_api" "test" {
|
||||
name = "test"
|
||||
description = "test"
|
||||
binary_media_types = ["application/octet-stream"]
|
||||
}
|
||||
`
|
||||
|
@ -541,6 +541,22 @@ func validateApiGatewayIntegrationType(v interface{}, k string) (ws []string, er
|
||||
return
|
||||
}
|
||||
|
||||
func validateApiGatewayIntegrationContentHandling(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(string)
|
||||
|
||||
validTypes := map[string]bool{
|
||||
"CONVERT_TO_BINARY": true,
|
||||
"CONVERT_TO_TEXT": true,
|
||||
}
|
||||
|
||||
if _, ok := validTypes[value]; !ok {
|
||||
errors = append(errors, fmt.Errorf(
|
||||
"%q contains an invalid integration type %q. Valid types are either %q or %q.",
|
||||
k, value, "CONVERT_TO_BINARY", "CONVERT_TO_TEXT"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateSQSQueueName(v interface{}, k string) (errors []error) {
|
||||
value := v.(string)
|
||||
if len(value) > 80 {
|
||||
|
@ -60,3 +60,4 @@ The following arguments are supported:
|
||||
For example: `request_parameters = { "integration.request.header.X-Some-Other-Header" = "method.request.header.X-Some-Header" }`
|
||||
* `passthrough_behavior` - (Optional) The integration passthrough behavior (`WHEN_NO_MATCH`, `WHEN_NO_TEMPLATES`, `NEVER`). **Required** if `request_templates` is used.
|
||||
* `request_parameters_in_json` - **Deprecated**, use `request_parameters` instead.
|
||||
* `content_handling` - (Optional) Specifies how to handle request payload content type conversions. Supported values are `CONVERT_TO_BINARY` and `CONVERT_TO_TEXT`. If this property is not defined, the request payload will be passed through from the method request to integration request without modification, provided that the passthroughBehaviors is configured to support payload pass-through.
|
||||
|
@ -25,6 +25,7 @@ The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the REST API
|
||||
* `description` - (Optional) The description of the REST API
|
||||
* `binary_media_types` - (Optional) The list of binary media types supported by the RestApi. By default, the RestApi supports only UTF-8-encoded text payloads.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user