Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_api_gateway_method_response: Remove deprecated response_parameters_in_json argument #7704

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 19 additions & 51 deletions aws/resource_aws_api_gateway_method_response.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package aws

import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
"sync"
"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 @@ -75,17 +72,15 @@ func resourceAwsApiGatewayMethodResponse() *schema.Resource {
},

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

"response_parameters_in_json": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"response_parameters"},
Deprecated: "Use field response_parameters instead",
Type: schema.TypeString,
Optional: true,
Removed: "Use `response_parameters` argument instead",
},
},
}
Expand All @@ -109,11 +104,6 @@ func resourceAwsApiGatewayMethodResponseCreate(d *schema.ResourceData, meta inte
}
}
}
if v, ok := d.GetOk("response_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)
}
}

resourceAwsApiGatewayMethodResponseMutex.Lock()
defer resourceAwsApiGatewayMethodResponseMutex.Unlock()
Expand Down Expand Up @@ -168,14 +158,6 @@ func resourceAwsApiGatewayMethodResponseRead(d *schema.ResourceData, meta interf
return fmt.Errorf("error setting response_parameters: %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("response_parameters_in_json"); ok {
d.Set("response_parameters_in_json", aws.BoolValueMap(methodResponse.ResponseParameters))
}

return nil
}

Expand All @@ -189,14 +171,6 @@ func resourceAwsApiGatewayMethodResponseUpdate(d *schema.ResourceData, meta inte
operations = append(operations, expandApiGatewayRequestResponseModelOperations(d, "response_models", "responseModels")...)
}

if d.HasChange("response_parameters_in_json") {
ops, err := deprecatedExpandApiGatewayMethodParametersJSONOperations(d, "response_parameters_in_json", "responseParameters")
if err != nil {
return err
}
operations = append(operations, ops...)
}

if d.HasChange("response_parameters") {
ops, err := expandApiGatewayMethodParametersOperations(d, "response_parameters", "responseParameters")
if err != nil {
Expand Down Expand Up @@ -226,26 +200,20 @@ func resourceAwsApiGatewayMethodResponseDelete(d *schema.ResourceData, meta inte
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Method Response: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteMethodResponse(&apigateway.DeleteMethodResponseInput{
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)),
StatusCode: aws.String(d.Get("status_code").(string)),
})
if err == nil {
return nil
}
_, err := conn.DeleteMethodResponse(&apigateway.DeleteMethodResponseInput{
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)),
StatusCode: aws.String(d.Get("status_code").(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 Response (%s): %s", d.Id(), err)
}

return resource.NonRetryableError(err)
})
return nil
}
1 change: 0 additions & 1 deletion website/docs/r/api_gateway_method_response.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ The following arguments are supported:
* `response_parameters` - (Optional) A map of response parameters that can be sent to the caller.
For example: `response_parameters = { "method.response.header.X-Some-Header" = true }`
would define that the header `X-Some-Header` can be provided on the response.
* `response_parameters_in_json` - **Deprecated**, use `response_parameters` instead.

## Import

Expand Down