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

r/aws_apigatewayv2_integration: Add 'request_parameters' attribute #14080

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
29 changes: 28 additions & 1 deletion aws/resource_aws_apigatewayv2_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ func resourceAwsApiGatewayV2Integration() *schema.Resource {
"2.0",
}, false),
},
"request_parameters": {
Type: schema.TypeMap,
Optional: true,
// Length between [1-512].
Elem: &schema.Schema{Type: schema.TypeString},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the validation rule here? or is there an issue with type map and validations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once Plugin SDK v2 support is merged we can use hashicorp/terraform-plugin-sdk#304.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

},
"request_templates": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
// Length between [0-32768].
Elem: &schema.Schema{Type: schema.TypeString},
},
"template_selection_expression": {
Type: schema.TypeString,
Expand Down Expand Up @@ -155,6 +162,9 @@ func resourceAwsApiGatewayV2IntegrationCreate(d *schema.ResourceData, meta inter
if v, ok := d.GetOk("payload_format_version"); ok {
req.PayloadFormatVersion = aws.String(v.(string))
}
if v, ok := d.GetOk("request_parameters"); ok {
req.RequestParameters = stringMapToPointers(v.(map[string]interface{}))
}
if v, ok := d.GetOk("request_templates"); ok {
req.RequestTemplates = stringMapToPointers(v.(map[string]interface{}))
}
Expand Down Expand Up @@ -203,6 +213,10 @@ func resourceAwsApiGatewayV2IntegrationRead(d *schema.ResourceData, meta interfa
d.Set("integration_uri", resp.IntegrationUri)
d.Set("passthrough_behavior", resp.PassthroughBehavior)
d.Set("payload_format_version", resp.PayloadFormatVersion)
err = d.Set("request_parameters", pointersMapToStringList(resp.RequestParameters))
if err != nil {
return fmt.Errorf("error setting request_parameters: %s", err)
}
err = d.Set("request_templates", pointersMapToStringList(resp.RequestTemplates))
if err != nil {
return fmt.Errorf("error setting request_templates: %s", err)
Expand Down Expand Up @@ -247,6 +261,19 @@ func resourceAwsApiGatewayV2IntegrationUpdate(d *schema.ResourceData, meta inter
if d.HasChange("payload_format_version") {
req.PayloadFormatVersion = aws.String(d.Get("payload_format_version").(string))
}
if d.HasChange("request_parameters") {
o, n := d.GetChange("request_parameters")
add, del := diffStringMaps(o.(map[string]interface{}), n.(map[string]interface{}))
// Parameters are removed by setting the associated value to "".
for k := range del {
del[k] = aws.String("")
}
variables := del
for k, v := range add {
variables[k] = v
}
req.RequestParameters = variables
}
if d.HasChange("request_templates") {
req.RequestTemplates = stringMapToPointers(d.Get("request_templates").(map[string]interface{}))
}
Expand Down
17 changes: 17 additions & 0 deletions aws/resource_aws_apigatewayv2_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestAccAWSAPIGatewayV2Integration_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "integration_uri", ""),
resource.TestCheckResourceAttr(resourceName, "passthrough_behavior", "WHEN_NO_MATCH"),
resource.TestCheckResourceAttr(resourceName, "payload_format_version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "request_templates.%", "0"),
resource.TestCheckResourceAttr(resourceName, "template_selection_expression", ""),
resource.TestCheckResourceAttr(resourceName, "timeout_milliseconds", "29000"),
Expand Down Expand Up @@ -101,6 +102,8 @@ func TestAccAWSAPIGatewayV2Integration_IntegrationTypeHttp(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "integration_uri", "http://www.example.com"),
resource.TestCheckResourceAttr(resourceName, "passthrough_behavior", "WHEN_NO_MATCH"),
resource.TestCheckResourceAttr(resourceName, "payload_format_version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.%", "1"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.integration.request.querystring.stage", "'value1'"),
resource.TestCheckResourceAttr(resourceName, "request_templates.%", "1"),
resource.TestCheckResourceAttr(resourceName, "request_templates.application/json", ""),
resource.TestCheckResourceAttr(resourceName, "template_selection_expression", "$request.body.name"),
Expand All @@ -122,6 +125,9 @@ func TestAccAWSAPIGatewayV2Integration_IntegrationTypeHttp(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "integration_uri", "http://www.example.org"),
resource.TestCheckResourceAttr(resourceName, "passthrough_behavior", "WHEN_NO_TEMPLATES"),
resource.TestCheckResourceAttr(resourceName, "payload_format_version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.%", "2"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.integration.request.header.x-userid", "'value2'"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.integration.request.path.op", "'value3'"),
resource.TestCheckResourceAttr(resourceName, "request_templates.%", "2"),
resource.TestCheckResourceAttr(resourceName, "request_templates.application/json", "#set($number=42)"),
resource.TestCheckResourceAttr(resourceName, "request_templates.application/xml", "#set($percent=$number/100)"),
Expand Down Expand Up @@ -166,6 +172,7 @@ func TestAccAWSAPIGatewayV2Integration_Lambda(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "integration_uri", lambdaResourceName, "invoke_arn"),
resource.TestCheckResourceAttr(resourceName, "passthrough_behavior", "WHEN_NO_MATCH"),
resource.TestCheckResourceAttr(resourceName, "payload_format_version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "request_templates.%", "0"),
resource.TestCheckResourceAttr(resourceName, "template_selection_expression", ""),
resource.TestCheckResourceAttr(resourceName, "timeout_milliseconds", "29000"),
Expand Down Expand Up @@ -208,6 +215,7 @@ func TestAccAWSAPIGatewayV2Integration_VpcLink(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "integration_uri", "http://www.example.net"),
resource.TestCheckResourceAttr(resourceName, "passthrough_behavior", "NEVER"),
resource.TestCheckResourceAttr(resourceName, "payload_format_version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "request_parameters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "request_templates.%", "0"),
resource.TestCheckResourceAttr(resourceName, "template_selection_expression", ""),
resource.TestCheckResourceAttr(resourceName, "timeout_milliseconds", "12345"),
Expand Down Expand Up @@ -335,6 +343,10 @@ resource "aws_apigatewayv2_integration" "test" {
template_selection_expression = "$request.body.name"
timeout_milliseconds = 28999

request_parameters = {
"integration.request.querystring.stage" = "'value1'"
}

request_templates = {
"application/json" = ""
}
Expand All @@ -357,6 +369,11 @@ resource "aws_apigatewayv2_integration" "test" {
template_selection_expression = "$request.body.id"
timeout_milliseconds = 51

request_parameters = {
"integration.request.header.x-userid" = "'value2'"
"integration.request.path.op" = "'value3'"
}

request_templates = {
"application/json" = "#set($number=42)"
"application/xml" = "#set($percent=$number/100)"
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/apigatewayv2_integration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ For an `HTTP` integration, specify a fully-qualified URL. For an HTTP API privat
* `passthrough_behavior` - (Optional) The pass-through behavior for incoming requests based on the Content-Type header in the request, and the available mapping templates specified as the `request_templates` attribute.
Valid values: `WHEN_NO_MATCH`, `WHEN_NO_TEMPLATES`, `NEVER`. Default is `WHEN_NO_MATCH`. Supported only for WebSocket APIs.
* `payload_format_version` - (Optional) The [format of the payload](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#http-api-develop-integrations-lambda.proxy-format) sent to an integration. Valid values: `1.0`, `2.0`. Default is `1.0`.
* `request_parameters` - (Optional) A key-value map specifying request parameters that are passed from the method request to the backend.
Supported only for WebSocket APIs.
* `request_templates` - (Optional) A map of Velocity templates that are applied on the request payload based on the value of the Content-Type header sent by the client. Supported only for WebSocket APIs.
* `template_selection_expression` - (Optional) The [template selection expression](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-selection-expressions.html#apigateway-websocket-api-template-selection-expressions) for the integration.
* `timeout_milliseconds` - (Optional) Custom timeout between 50 and 29,000 milliseconds. The default value is 29,000 milliseconds or 29 seconds.
Expand Down