Skip to content

Commit

Permalink
Merge pull request #7701 from terraform-providers/td-aws_api_gateway_…
Browse files Browse the repository at this point in the history
…method-remove-deprecated

resource/aws_api_gateway_method: Remove deprecated request_parameters_in_json argument
  • Loading branch information
bflad authored Feb 27, 2019
2 parents 3ab8be6 + a4cd4de commit a48095f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 45 deletions.
63 changes: 19 additions & 44 deletions aws/resource_aws_api_gateway_method.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package aws

import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -88,17 +85,15 @@ func resourceAwsApiGatewayMethod() *schema.Resource {
},

"request_parameters": {
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeBool},
Optional: true,
ConflictsWith: []string{"request_parameters_in_json"},
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeBool},
Optional: true,
},

"request_parameters_in_json": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"request_parameters"},
Deprecated: "Use field request_parameters instead",
Type: schema.TypeString,
Optional: true,
Removed: "Use `request_parameters` argument instead",
},

"request_validator_id": {
Expand Down Expand Up @@ -139,12 +134,6 @@ func resourceAwsApiGatewayMethodCreate(d *schema.ResourceData, meta interface{})
}
input.RequestParameters = aws.BoolMap(parameters)
}
if v, ok := d.GetOk("request_parameters_in_json"); ok {
if err := json.Unmarshal([]byte(v.(string)), &parameters); err != nil {
return fmt.Errorf("Error unmarshaling request_parameters_in_json: %s", err)
}
input.RequestParameters = aws.BoolMap(parameters)
}

if v, ok := d.GetOk("authorizer_id"); ok {
input.AuthorizerId = aws.String(v.(string))
Expand Down Expand Up @@ -201,16 +190,8 @@ func resourceAwsApiGatewayMethodRead(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("error setting request_models: %s", err)
}

// KNOWN ISSUE: This next d.Set() is broken as it should be a JSON string of the map,
// however leaving as-is since this attribute has been deprecated
// for a very long time and will be removed soon in the next major release.
// Not worth the effort of fixing, acceptance testing, and potential JSON equivalence bugs.
if _, ok := d.GetOk("request_parameters_in_json"); ok {
d.Set("request_parameters_in_json", aws.BoolValueMap(out.RequestParameters))
}

if err := d.Set("request_parameters", aws.BoolValueMap(out.RequestParameters)); err != nil {
return fmt.Errorf("error setting request_models: %s", err)
return fmt.Errorf("error setting request_parameters: %s", err)
}

d.Set("request_validator_id", out.RequestValidatorId)
Expand Down Expand Up @@ -346,25 +327,19 @@ func resourceAwsApiGatewayMethodDelete(d *schema.ResourceData, meta interface{})
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Method: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteMethod(&apigateway.DeleteMethodInput{
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)),
})
if err == nil {
return nil
}
_, err := conn.DeleteMethod(&apigateway.DeleteMethodInput{
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)),
})

apigatewayErr, ok := err.(awserr.Error)
if apigatewayErr.Code() == "NotFoundException" {
return nil
}
if isAWSErr(err, apigateway.ErrCodeNotFoundException, "") {
return nil
}

if !ok {
return resource.NonRetryableError(err)
}
if err != nil {
return fmt.Errorf("error deleting API Gateway Method (%s): %s", d.Id(), err)
}

return resource.NonRetryableError(err)
})
return nil
}
1 change: 0 additions & 1 deletion website/docs/r/api_gateway_method.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ The following arguments are supported:
* `request_validator_id` - (Optional) The ID of a `aws_api_gateway_request_validator`
* `request_parameters` - (Optional) A map of request query string parameters and headers that should be passed to the integration.
For example: `request_parameters = {"method.request.header.X-Some-Header" = true "method.request.querystring.some-query-param" = true}` would define that the header `X-Some-Header` and the query string `some-query-param` must be provided in the request
* `request_parameters_in_json` - **Deprecated**, use `request_parameters` instead.

## Import

Expand Down

0 comments on commit a48095f

Please sign in to comment.