Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/wperron/terraform-provider-…
Browse files Browse the repository at this point in the history
…aws into wperron-master
  • Loading branch information
bflad committed Jan 13, 2021
2 parents 9dd1e48 + d283ae5 commit c73c7e2
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
25 changes: 25 additions & 0 deletions aws/resource_aws_api_gateway_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func resourceAwsApiGatewayMethod() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},

"operation_name": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -140,6 +145,10 @@ func resourceAwsApiGatewayMethodCreate(d *schema.ResourceData, meta interface{})
input.RequestValidatorId = aws.String(v.(string))
}

if v, ok := d.GetOk("operation_name"); ok {
input.OperationName = aws.String(v.(string))
}

_, err := conn.PutMethod(&input)
if err != nil {
return fmt.Errorf("Error creating API Gateway Method: %s", err)
Expand Down Expand Up @@ -189,6 +198,8 @@ func resourceAwsApiGatewayMethodRead(d *schema.ResourceData, meta interface{}) e

d.Set("request_validator_id", out.RequestValidatorId)

d.Set("operation_name", out.OperationName)

return nil
}

Expand Down Expand Up @@ -289,6 +300,20 @@ func resourceAwsApiGatewayMethodUpdate(d *schema.ResourceData, meta interface{})
})
}

if d.HasChange("operation_name") {
var operation_name *string
if v, ok := d.GetOk("operation_name"); ok {
if s := v.(string); len(s) > 0 {
operation_name = &s
}
}
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/operationName"),
Value: operation_name,
})
}

method, err := conn.UpdateMethod(&apigateway.UpdateMethodInput{
HttpMethod: aws.String(d.Get("http_method").(string)),
ResourceId: aws.String(d.Get("resource_id").(string)),
Expand Down
107 changes: 107 additions & 0 deletions aws/resource_aws_api_gateway_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,50 @@ func TestAccAWSAPIGatewayMethod_disappears(t *testing.T) {
})
}

func TestAccAWSAPIGatewayMethod_customoperationname(t *testing.T) {
var conf apigateway.Method
rInt := acctest.RandInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayMethodDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGatewayMethodConfigWithCustomOperationName(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayMethodExists("aws_api_gateway_method.test", &conf),
testAccCheckAWSAPIGatewayMethodAttributes(&conf),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "http_method", "GET"),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "authorization", "NONE"),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "request_models.application/json", "Error"),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "operation_name", "getTest"),
),
},
{
ResourceName: "aws_api_gateway_method.test",
ImportState: true,
ImportStateIdFunc: testAccAWSAPIGatewayMethodImportStateIdFunc("aws_api_gateway_method.test"),
ImportStateVerify: true,
},

{
Config: testAccAWSAPIGatewayMethodConfigWithCustomOperationNameUpdate(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayMethodExists("aws_api_gateway_method.test", &conf),
testAccCheckAWSAPIGatewayMethodAttributesUpdate(&conf),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "operation_name", "describeTest"),
),
},
},
})
}

func testAccCheckAWSAPIGatewayMethodAttributes(conf *apigateway.Method) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *conf.HttpMethod != "GET" {
Expand Down Expand Up @@ -725,3 +769,66 @@ resource "aws_api_gateway_method" "test" {
}
`, rInt)
}

func testAccAWSAPIGatewayMethodConfigWithCustomOperationName(rInt int) string {
return fmt.Sprintf(`
resource "aws_api_gateway_rest_api" "test" {
name = "tf-acc-test-apig-method-custom-op-name-%d"
}
resource "aws_api_gateway_resource" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
parent_id = "${aws_api_gateway_rest_api.test.root_resource_id}"
path_part = "test"
}
resource "aws_api_gateway_method" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
resource_id = "${aws_api_gateway_resource.test.id}"
http_method = "GET"
authorization = "NONE"
request_models = {
"application/json" = "Error"
}
request_parameters = {
"method.request.header.Content-Type" = false
"method.request.querystring.page" = true
}
operation_name = "getTest"
}
`, rInt)
}

func testAccAWSAPIGatewayMethodConfigWithCustomOperationNameUpdate(rInt int) string {
return fmt.Sprintf(`
resource "aws_api_gateway_rest_api" "test" {
name = "tf-acc-test-apig-method-custom-op-name-%d"
}
resource "aws_api_gateway_resource" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
parent_id = "${aws_api_gateway_rest_api.test.root_resource_id}"
path_part = "test"
}
resource "aws_api_gateway_method" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
resource_id = "${aws_api_gateway_resource.test.id}"
http_method = "GET"
authorization = "NONE"
request_models = {
"application/json" = "Error"
}
request_parameters = {
"method.request.querystring.page" = false
}
operation_name = "describeTest"
}
`, rInt)
}
1 change: 1 addition & 0 deletions website/docs/r/api_gateway_method.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ 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 parameters (from the path, query string and headers) that should be passed to the integration. The boolean value indicates whether the parameter is required (`true`) or optional (`false`).
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.
* `operation_name` - (Optional) The function name that will be given to the method when generating an SDK through API Gateway. If omitted, API Gateway will generate a function name based on the resource path and HTTP verb.

## Import

Expand Down

0 comments on commit c73c7e2

Please sign in to comment.