Skip to content

Commit

Permalink
provider/aws: Add support for content_handling to
Browse files Browse the repository at this point in the history
aws_api_gateway_integration_response

This continues the work carried out in #10696

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSAPIGatewayIntegrationResponse_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/01/03 14:18:46 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v
-run=TestAccAWSAPIGatewayIntegrationResponse_ -timeout 120m
=== RUN   TestAccAWSAPIGatewayIntegrationResponse_basic
--- PASS: TestAccAWSAPIGatewayIntegrationResponse_basic (57.33s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws57.352s
```
  • Loading branch information
stack72 committed Jan 3, 2017
1 parent c7f6b37 commit 610e152
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceAwsApiGatewayIntegration() *schema.Resource {
return &schema.Resource{
Create: resourceAwsApiGatewayIntegrationCreate,
Read: resourceAwsApiGatewayIntegrationRead,
Update: resourceAwsApiGatewayIntegrationUpdate,
Update: resourceAwsApiGatewayIntegrationCreate,
Delete: resourceAwsApiGatewayIntegrationDelete,

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -202,10 +202,6 @@ func resourceAwsApiGatewayIntegrationRead(d *schema.ResourceData, meta interface
return nil
}

func resourceAwsApiGatewayIntegrationUpdate(d *schema.ResourceData, meta interface{}) error {
return resourceAwsApiGatewayIntegrationCreate(d, meta)
}

func resourceAwsApiGatewayIntegrationDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Integration: %s", d.Id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,64 @@ func resourceAwsApiGatewayIntegrationResponse() *schema.Resource {
return &schema.Resource{
Create: resourceAwsApiGatewayIntegrationResponseCreate,
Read: resourceAwsApiGatewayIntegrationResponseRead,
Update: resourceAwsApiGatewayIntegrationResponseUpdate,
Update: resourceAwsApiGatewayIntegrationResponseCreate,
Delete: resourceAwsApiGatewayIntegrationResponseDelete,

Schema: map[string]*schema.Schema{
"rest_api_id": &schema.Schema{
"rest_api_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"resource_id": &schema.Schema{
"resource_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"http_method": &schema.Schema{
"http_method": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateHTTPMethod,
},

"status_code": &schema.Schema{
"status_code": {
Type: schema.TypeString,
Required: true,
},

"selection_pattern": &schema.Schema{
"selection_pattern": {
Type: schema.TypeString,
Optional: true,
},

"response_templates": &schema.Schema{
"response_templates": {
Type: schema.TypeMap,
Optional: true,
Elem: schema.TypeString,
},

"response_parameters": &schema.Schema{
"response_parameters": {
Type: schema.TypeMap,
Elem: schema.TypeString,
Optional: true,
ConflictsWith: []string{"response_parameters_in_json"},
},

"response_parameters_in_json": &schema.Schema{
"response_parameters_in_json": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"response_parameters"},
Deprecated: "Use field response_parameters instead",
},

"content_handling": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateApiGatewayIntegrationContentHandling,
},
},
}
}
Expand All @@ -92,6 +98,10 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta
return fmt.Errorf("Error unmarshaling response_parameters_in_json: %s", err)
}
}
var contentHandling *string
if val, ok := d.GetOk("content_handling"); ok {
contentHandling = aws.String(val.(string))
}

input := apigateway.PutIntegrationResponseInput{
HttpMethod: aws.String(d.Get("http_method").(string)),
Expand All @@ -100,10 +110,12 @@ func resourceAwsApiGatewayIntegrationResponseCreate(d *schema.ResourceData, meta
StatusCode: aws.String(d.Get("status_code").(string)),
ResponseTemplates: aws.StringMap(templates),
ResponseParameters: aws.StringMap(parameters),
ContentHandling: contentHandling,
}
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)
Expand Down Expand Up @@ -143,10 +155,6 @@ func resourceAwsApiGatewayIntegrationResponseRead(d *schema.ResourceData, meta i
return nil
}

func resourceAwsApiGatewayIntegrationResponseUpdate(d *schema.ResourceData, meta interface{}) error {
return resourceAwsApiGatewayIntegrationResponseCreate(d, meta)
}

func resourceAwsApiGatewayIntegrationResponseDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Integration Response: %s", d.Id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestAccAWSAPIGatewayIntegrationResponse_basic(t *testing.T) {
"aws_api_gateway_integration_response.test", "response_templates.application/json", ""),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration_response.test", "response_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration_response.test", "content_handling", ""),
),
},

Expand All @@ -40,6 +42,8 @@ func TestAccAWSAPIGatewayIntegrationResponse_basic(t *testing.T) {
"aws_api_gateway_integration_response.test", "response_templates.application/json", "$input.path('$')"),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration_response.test", "response_templates.application/xml", ""),
resource.TestCheckResourceAttr(
"aws_api_gateway_integration_response.test", "content_handling", "CONVERT_TO_BINARY"),
),
},
},
Expand Down Expand Up @@ -282,5 +286,7 @@ resource "aws_api_gateway_integration_response" "test" {
"application/xml" = ""
}
content_handling = "CONVERT_TO_BINARY"
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ The following arguments are supported:
* `response_parameters` - (Optional) A map of response parameters that can be read from the backend response.
For example: `response_parameters = { "method.response.header.X-Some-Header" = "integration.response.header.X-Some-Other-Header" }`,
* `response_parameters_in_json` - **Deprecated**, use `response_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 response payload will be passed through from the integration response to the method response without modification.

0 comments on commit 610e152

Please sign in to comment.