Add support for binary media type to AWS API Gateway
This commit is contained in:
parent
79958752a8
commit
0e6b2a4f9f
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue