Skip to content

Commit

Permalink
'aws_api_gateway2_integration_response' -> 'aws_apigatewayv2_integrat…
Browse files Browse the repository at this point in the history
…ion_response'.
  • Loading branch information
ewbankkit committed Apr 9, 2020
1 parent 8bb4f49 commit d4e10d7
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func resourceAwsApiGateway2IntegrationResponse() *schema.Resource {
func resourceAwsApiGatewayV2IntegrationResponse() *schema.Resource {
return &schema.Resource{
Create: resourceAwsApiGateway2IntegrationResponseCreate,
Read: resourceAwsApiGateway2IntegrationResponseRead,
Update: resourceAwsApiGateway2IntegrationResponseUpdate,
Delete: resourceAwsApiGateway2IntegrationResponseDelete,
Create: resourceAwsApiGatewayV2IntegrationResponseCreate,
Read: resourceAwsApiGatewayV2IntegrationResponseRead,
Update: resourceAwsApiGatewayV2IntegrationResponseUpdate,
Delete: resourceAwsApiGatewayV2IntegrationResponseDelete,
Importer: &schema.ResourceImporter{
State: resourceAwsApiGateway2IntegrationResponseImport,
State: resourceAwsApiGatewayV2IntegrationResponseImport,
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -57,7 +57,7 @@ func resourceAwsApiGateway2IntegrationResponse() *schema.Resource {
}
}

func resourceAwsApiGateway2IntegrationResponseCreate(d *schema.ResourceData, meta interface{}) error {
func resourceAwsApiGatewayV2IntegrationResponseCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigatewayv2conn

req := &apigatewayv2.CreateIntegrationResponseInput{
Expand All @@ -83,10 +83,10 @@ func resourceAwsApiGateway2IntegrationResponseCreate(d *schema.ResourceData, met

d.SetId(aws.StringValue(resp.IntegrationResponseId))

return resourceAwsApiGateway2IntegrationResponseRead(d, meta)
return resourceAwsApiGatewayV2IntegrationResponseRead(d, meta)
}

func resourceAwsApiGateway2IntegrationResponseRead(d *schema.ResourceData, meta interface{}) error {
func resourceAwsApiGatewayV2IntegrationResponseRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigatewayv2conn

resp, err := conn.GetIntegrationResponse(&apigatewayv2.GetIntegrationResponseInput{
Expand Down Expand Up @@ -114,7 +114,7 @@ func resourceAwsApiGateway2IntegrationResponseRead(d *schema.ResourceData, meta
return nil
}

func resourceAwsApiGateway2IntegrationResponseUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceAwsApiGatewayV2IntegrationResponseUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigatewayv2conn

req := &apigatewayv2.UpdateIntegrationResponseInput{
Expand All @@ -141,10 +141,10 @@ func resourceAwsApiGateway2IntegrationResponseUpdate(d *schema.ResourceData, met
return fmt.Errorf("error updating API Gateway v2 integration response: %s", err)
}

return resourceAwsApiGateway2IntegrationResponseRead(d, meta)
return resourceAwsApiGatewayV2IntegrationResponseRead(d, meta)
}

func resourceAwsApiGateway2IntegrationResponseDelete(d *schema.ResourceData, meta interface{}) error {
func resourceAwsApiGatewayV2IntegrationResponseDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigatewayv2conn

log.Printf("[DEBUG] Deleting API Gateway v2 integration response (%s)", d.Id())
Expand All @@ -163,7 +163,7 @@ func resourceAwsApiGateway2IntegrationResponseDelete(d *schema.ResourceData, met
return nil
}

func resourceAwsApiGateway2IntegrationResponseImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
func resourceAwsApiGatewayV2IntegrationResponseImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
if len(parts) != 3 {
return []*schema.ResourceData{}, fmt.Errorf("Wrong format of resource: %s. Please follow 'api-id/integration-id/integration-response-id'", d.Id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccAWSAPIGateway2IntegrationResponse_basic(t *testing.T) {
resourceName := "aws_api_gateway_v2_integration_response.test"
integrationResourceName := "aws_api_gateway_v2_integration.test"
rName := fmt.Sprintf("tf-testacc-apigwv2-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
func TestAccAWSAPIGatewayV2IntegrationResponse_basic(t *testing.T) {
var apiId, integrationId string
var v apigatewayv2.GetIntegrationResponseOutput
resourceName := "aws_apigatewayv2_integration_response.test"
integrationResourceName := "aws_apigatewayv2_integration.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGateway2IntegrationResponseDestroy,
CheckDestroy: testAccCheckAWSAPIGatewayV2IntegrationResponseDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGateway2IntegrationResponseConfig_basic(rName),
Config: testAccAWSAPIGatewayV2IntegrationResponseConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGateway2IntegrationResponseExists(resourceName),
testAccCheckAWSAPIGatewayV2IntegrationResponseExists(resourceName, &apiId, &integrationId, &v),
resource.TestCheckResourceAttr(resourceName, "content_handling_strategy", ""),
resource.TestCheckResourceAttrPair(resourceName, "integration_id", integrationResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "integration_response_key", "/200/"),
Expand All @@ -34,28 +36,53 @@ func TestAccAWSAPIGateway2IntegrationResponse_basic(t *testing.T) {
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccAWSAPIGateway2IntegrationResponseImportStateIdFunc(resourceName),
ImportStateIdFunc: testAccAWSAPIGatewayV2IntegrationResponseImportStateIdFunc(resourceName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSAPIGateway2IntegrationResponse_AllAttributes(t *testing.T) {
resourceName := "aws_api_gateway_v2_integration_response.test"
integrationResourceName := "aws_api_gateway_v2_integration.test"
rName := fmt.Sprintf("tf-testacc-apigwv2-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
func TestAccAWSAPIGatewayV2IntegrationResponse_disappears(t *testing.T) {
var apiId, integrationId string
var v apigatewayv2.GetIntegrationResponseOutput
resourceName := "aws_apigatewayv2_integration_response.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGateway2IntegrationResponseDestroy,
CheckDestroy: testAccCheckAWSAPIGatewayV2IntegrationResponseDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGateway2IntegrationResponseConfig_allAttributes(rName),
Config: testAccAWSAPIGatewayV2IntegrationResponseConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGateway2IntegrationResponseExists(resourceName),
testAccCheckAWSAPIGatewayV2IntegrationResponseExists(resourceName, &apiId, &integrationId, &v),
testAccCheckAWSAPIGatewayV2IntegrationResponseDisappears(&apiId, &integrationId, &v),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func TestAccAWSAPIGatewayV2IntegrationResponse_AllAttributes(t *testing.T) {
var apiId, integrationId string
var v apigatewayv2.GetIntegrationResponseOutput
resourceName := "aws_apigatewayv2_integration_response.test"
integrationResourceName := "aws_apigatewayv2_integration.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayV2IntegrationResponseDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGatewayV2IntegrationResponseConfig_allAttributes(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayV2IntegrationResponseExists(resourceName, &apiId, &integrationId, &v),
resource.TestCheckResourceAttr(resourceName, "content_handling_strategy", "CONVERT_TO_TEXT"),
resource.TestCheckResourceAttrPair(resourceName, "integration_id", integrationResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "integration_response_key", "$default"),
Expand All @@ -65,9 +92,9 @@ func TestAccAWSAPIGateway2IntegrationResponse_AllAttributes(t *testing.T) {
),
},
{
Config: testAccAWSAPIGateway2IntegrationResponseConfig_allAttributesUpdated(rName),
Config: testAccAWSAPIGatewayV2IntegrationResponseConfig_allAttributesUpdated(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGateway2IntegrationResponseExists(resourceName),
testAccCheckAWSAPIGatewayV2IntegrationResponseExists(resourceName, &apiId, &integrationId, &v),
resource.TestCheckResourceAttr(resourceName, "content_handling_strategy", "CONVERT_TO_BINARY"),
resource.TestCheckResourceAttrPair(resourceName, "integration_id", integrationResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "integration_response_key", "/404/"),
Expand All @@ -79,19 +106,19 @@ func TestAccAWSAPIGateway2IntegrationResponse_AllAttributes(t *testing.T) {
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccAWSAPIGateway2IntegrationResponseImportStateIdFunc(resourceName),
ImportStateIdFunc: testAccAWSAPIGatewayV2IntegrationResponseImportStateIdFunc(resourceName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckAWSAPIGateway2IntegrationResponseDestroy(s *terraform.State) error {
func testAccCheckAWSAPIGatewayV2IntegrationResponseDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_api_gateway_v2_integration_response" {
if rs.Type != "aws_apigatewayv2_integration_response" {
continue
}

Expand All @@ -113,7 +140,21 @@ func testAccCheckAWSAPIGateway2IntegrationResponseDestroy(s *terraform.State) er
return nil
}

func testAccCheckAWSAPIGateway2IntegrationResponseExists(n string) resource.TestCheckFunc {
func testAccCheckAWSAPIGatewayV2IntegrationResponseDisappears(apiId, integrationId *string, v *apigatewayv2.GetIntegrationResponseOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn

_, err := conn.DeleteIntegrationResponse(&apigatewayv2.DeleteIntegrationResponseInput{
ApiId: apiId,
IntegrationId: integrationId,
IntegrationResponseId: v.IntegrationResponseId,
})

return err
}
}

func testAccCheckAWSAPIGatewayV2IntegrationResponseExists(n string, vApiId, vIntegrationId *string, v *apigatewayv2.GetIntegrationResponseOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand All @@ -126,20 +167,26 @@ func testAccCheckAWSAPIGateway2IntegrationResponseExists(n string) resource.Test

conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn

_, err := conn.GetIntegrationResponse(&apigatewayv2.GetIntegrationResponseInput{
ApiId: aws.String(rs.Primary.Attributes["api_id"]),
IntegrationId: aws.String(rs.Primary.Attributes["integration_id"]),
apiId := aws.String(rs.Primary.Attributes["api_id"])
integrationId := aws.String(rs.Primary.Attributes["integration_id"])
resp, err := conn.GetIntegrationResponse(&apigatewayv2.GetIntegrationResponseInput{
ApiId: apiId,
IntegrationId: integrationId,
IntegrationResponseId: aws.String(rs.Primary.ID),
})
if err != nil {
return err
}

*vApiId = *apiId
*vIntegrationId = *integrationId
*v = *resp

return nil
}
}

func testAccAWSAPIGateway2IntegrationResponseImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
func testAccAWSAPIGatewayV2IntegrationResponseImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
Expand All @@ -150,21 +197,21 @@ func testAccAWSAPIGateway2IntegrationResponseImportStateIdFunc(resourceName stri
}
}

func testAccAWSAPIGateway2IntegrationResponseConfig_basic(rName string) string {
func testAccAWSAPIGatewayV2IntegrationResponseConfig_basic(rName string) string {
return testAccAWSAPIGatewayV2IntegrationConfig_basic(rName) + fmt.Sprintf(`
resource "aws_api_gateway_v2_integration_response" "test" {
api_id = "${aws_api_gateway_v2_api.test.id}"
integration_id = "${aws_api_gateway_v2_integration.test.id}"
resource "aws_apigatewayv2_integration_response" "test" {
api_id = "${aws_apigatewayv2_api.test.id}"
integration_id = "${aws_apigatewayv2_integration.test.id}"
integration_response_key = "/200/"
}
`)
}

func testAccAWSAPIGateway2IntegrationResponseConfig_allAttributes(rName string) string {
func testAccAWSAPIGatewayV2IntegrationResponseConfig_allAttributes(rName string) string {
return testAccAWSAPIGatewayV2IntegrationConfig_basic(rName) + fmt.Sprintf(`
resource "aws_api_gateway_v2_integration_response" "test" {
api_id = "${aws_api_gateway_v2_api.test.id}"
integration_id = "${aws_api_gateway_v2_integration.test.id}"
resource "aws_apigatewayv2_integration_response" "test" {
api_id = "${aws_apigatewayv2_api.test.id}"
integration_id = "${aws_apigatewayv2_integration.test.id}"
integration_response_key = "$default"
content_handling_strategy = "CONVERT_TO_TEXT"
Expand All @@ -177,11 +224,11 @@ resource "aws_api_gateway_v2_integration_response" "test" {
`)
}

func testAccAWSAPIGateway2IntegrationResponseConfig_allAttributesUpdated(rName string) string {
func testAccAWSAPIGatewayV2IntegrationResponseConfig_allAttributesUpdated(rName string) string {
return testAccAWSAPIGatewayV2IntegrationConfig_basic(rName) + fmt.Sprintf(`
resource "aws_api_gateway_v2_integration_response" "test" {
api_id = "${aws_api_gateway_v2_api.test.id}"
integration_id = "${aws_api_gateway_v2_integration.test.id}"
resource "aws_apigatewayv2_integration_response" "test" {
api_id = "${aws_apigatewayv2_api.test.id}"
integration_id = "${aws_apigatewayv2_integration.test.id}"
integration_response_key = "/404/"
content_handling_strategy = "CONVERT_TO_BINARY"
Expand Down
2 changes: 1 addition & 1 deletion aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func Provider() terraform.ResourceProvider {
"aws_apigatewayv2_api": resourceAwsApiGatewayV2Api(),
"aws_apigatewayv2_authorizer": resourceAwsApiGatewayV2Authorizer(),
"aws_apigatewayv2_integration": resourceAwsApiGatewayV2Integration(),
"aws_api_gateway_v2_integration_response": resourceAwsApiGateway2IntegrationResponse(),
"aws_apigatewayv2_integration_response": resourceAwsApiGatewayV2IntegrationResponse(),
"aws_apigatewayv2_model": resourceAwsApiGatewayV2Model(),
"aws_app_cookie_stickiness_policy": resourceAwsAppCookieStickinessPolicy(),
"aws_appautoscaling_target": resourceAwsAppautoscalingTarget(),
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-version v1.2.0
github.com/hashicorp/terraform v0.12.24
github.com/hashicorp/terraform-plugin-sdk v1.9.0
github.com/hashicorp/vault v0.10.4
github.com/jen20/awspolicyequivalence v1.1.0
Expand Down
Loading

0 comments on commit d4e10d7

Please sign in to comment.