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: Suppress integration_method diff for AWS Lambda integrations #13266

Merged
merged 4 commits into from Jul 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions aws/resource_aws_apigatewayv2_integration.go
Expand Up @@ -62,6 +62,14 @@ func resourceAwsApiGatewayV2Integration() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateHTTPMethod(),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// Default HTTP method for Lambda integration is POST.
if v := d.Get("integration_type").(string); (v == apigatewayv2.IntegrationTypeAws || v == apigatewayv2.IntegrationTypeAwsProxy) && old == "POST" && new == "" {
return true
}

return false
},
},
"integration_response_selection_expression": {
Type: schema.TypeString,
Expand Down
99 changes: 87 additions & 12 deletions aws/resource_aws_apigatewayv2_integration_test.go
Expand Up @@ -189,7 +189,7 @@ func TestAccAWSAPIGatewayV2Integration_IntegrationTypeHttp(t *testing.T) {
})
}

func TestAccAWSAPIGatewayV2Integration_Lambda(t *testing.T) {
func TestAccAWSAPIGatewayV2Integration_LambdaWebSocket(t *testing.T) {
var apiId string
var v apigatewayv2.GetIntegrationOutput
resourceName := "aws_apigatewayv2_integration.test"
Expand All @@ -203,7 +203,7 @@ func TestAccAWSAPIGatewayV2Integration_Lambda(t *testing.T) {
CheckDestroy: testAccCheckAWSAPIGatewayV2IntegrationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGatewayV2IntegrationConfig_lambda(rName),
Config: testAccAWSAPIGatewayV2IntegrationConfig_lambdaWebSocket(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayV2IntegrationExists(resourceName, &apiId, &v),
resource.TestCheckResourceAttr(resourceName, "connection_type", "INTERNET"),
Expand Down Expand Up @@ -233,6 +233,50 @@ func TestAccAWSAPIGatewayV2Integration_Lambda(t *testing.T) {
})
}

func TestAccAWSAPIGatewayV2Integration_LambdaHttp(t *testing.T) {
var apiId string
var v apigatewayv2.GetIntegrationOutput
resourceName := "aws_apigatewayv2_integration.test"
callerIdentityDatasourceName := "data.aws_caller_identity.current"
lambdaResourceName := "aws_lambda_function.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayV2IntegrationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGatewayV2IntegrationConfig_lambdaHttp(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayV2IntegrationExists(resourceName, &apiId, &v),
resource.TestCheckResourceAttr(resourceName, "connection_type", "INTERNET"),
resource.TestCheckResourceAttr(resourceName, "content_handling_strategy", ""),
resource.TestCheckResourceAttrPair(resourceName, "credentials_arn", callerIdentityDatasourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "description", "Test Lambda"),
resource.TestCheckResourceAttr(resourceName, "integration_method", "POST"),
resource.TestCheckResourceAttr(resourceName, "integration_response_selection_expression", ""),
resource.TestCheckResourceAttr(resourceName, "integration_type", "AWS_PROXY"),
resource.TestCheckResourceAttrPair(resourceName, "integration_uri", lambdaResourceName, "invoke_arn"),
resource.TestCheckResourceAttr(resourceName, "passthrough_behavior", ""),
resource.TestCheckResourceAttr(resourceName, "payload_format_version", "2.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"),
resource.TestCheckResourceAttr(resourceName, "tls_config.#", "0"),
),
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccAWSAPIGatewayV2IntegrationImportStateIdFunc(resourceName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSAPIGatewayV2Integration_VpcLinkWebSocket(t *testing.T) {
var apiId string
var v apigatewayv2.GetIntegrationOutput
Expand Down Expand Up @@ -556,8 +600,11 @@ resource "aws_apigatewayv2_integration" "test" {
`
}

func testAccAWSAPIGatewayV2IntegrationConfig_lambda(rName string) string {
return testAccAWSAPIGatewayV2IntegrationConfig_apiWebSocket(rName) + baseAccAWSLambdaConfig(rName, rName, rName) + fmt.Sprintf(`
func testAccAWSAPIGatewayV2IntegrationConfig_lambdaWebSocket(rName string) string {
return composeConfig(
testAccAWSAPIGatewayV2IntegrationConfig_apiWebSocket(rName),
baseAccAWSLambdaConfig(rName, rName, rName),
fmt.Sprintf(`
data "aws_caller_identity" "current" {}

resource "aws_lambda_function" "test" {
Expand All @@ -572,15 +619,43 @@ resource "aws_apigatewayv2_integration" "test" {
api_id = "${aws_apigatewayv2_api.test.id}"
integration_type = "AWS"

connection_type = "INTERNET"
content_handling_strategy = "CONVERT_TO_TEXT"
credentials_arn = "${data.aws_caller_identity.current.arn}"
description = "Test Lambda"
integration_method = "POST"
integration_uri = "${aws_lambda_function.test.invoke_arn}"
passthrough_behavior = "WHEN_NO_MATCH"
connection_type = "INTERNET"
content_handling_strategy = "CONVERT_TO_TEXT"
credentials_arn = "${data.aws_caller_identity.current.arn}"
description = "Test Lambda"
integration_uri = "${aws_lambda_function.test.invoke_arn}"
passthrough_behavior = "WHEN_NO_MATCH"
}
`, rName)
`, rName))
}

func testAccAWSAPIGatewayV2IntegrationConfig_lambdaHttp(rName string) string {
return composeConfig(
testAccAWSAPIGatewayV2IntegrationConfig_apiHttp(rName),
baseAccAWSLambdaConfig(rName, rName, rName),
fmt.Sprintf(`
data "aws_caller_identity" "current" {}

resource "aws_lambda_function" "test" {
filename = "test-fixtures/lambdatest.zip"
function_name = %[1]q
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "index.handler"
runtime = "nodejs10.x"
}

resource "aws_apigatewayv2_integration" "test" {
api_id = "${aws_apigatewayv2_api.test.id}"
integration_type = "AWS_PROXY"

connection_type = "INTERNET"
credentials_arn = "${data.aws_caller_identity.current.arn}"
description = "Test Lambda"
integration_uri = "${aws_lambda_function.test.invoke_arn}"

payload_format_version = "2.0"
}
`, rName))
}

func testAccAWSAPIGatewayV2IntegrationConfig_httpProxy(rName string) string {
Expand Down