diff --git a/aws/provider.go b/aws/provider.go index bf905a628f1..8cdc8336818 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -372,7 +372,7 @@ func Provider() terraform.ResourceProvider { "aws_apigatewayv2_integration_response": resourceAwsApiGatewayV2IntegrationResponse(), "aws_apigatewayv2_model": resourceAwsApiGatewayV2Model(), "aws_apigatewayv2_route": resourceAwsApiGatewayV2Route(), - "aws_api_gateway_v2_route_response": resourceAwsApiGateway2RouteResponse(), + "aws_apigatewayv2_route_response": resourceAwsApiGatewayV2RouteResponse(), "aws_app_cookie_stickiness_policy": resourceAwsAppCookieStickinessPolicy(), "aws_appautoscaling_target": resourceAwsAppautoscalingTarget(), "aws_appautoscaling_policy": resourceAwsAppautoscalingPolicy(), diff --git a/aws/resource_aws_api_gateway2_route_response_test.go b/aws/resource_aws_api_gateway2_route_response_test.go deleted file mode 100644 index ef5fb8a6e32..00000000000 --- a/aws/resource_aws_api_gateway2_route_response_test.go +++ /dev/null @@ -1,163 +0,0 @@ -package aws - -import ( - "fmt" - "testing" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigatewayv2" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" -) - -func TestAccAWSAPIGateway2RouteResponse_basic(t *testing.T) { - resourceName := "aws_api_gateway_v2_route_response.test" - routeResourceName := "aws_api_gateway_v2_route.test" - rName := fmt.Sprintf("tf-testacc-apigwv2-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum)) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSAPIGateway2RouteResponseDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSAPIGateway2RouteResponseConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSAPIGateway2RouteResponseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "model_selection_expression", ""), - resource.TestCheckResourceAttr(resourceName, "response_models.%", "0"), - resource.TestCheckResourceAttrPair(resourceName, "route_id", routeResourceName, "id"), - resource.TestCheckResourceAttr(resourceName, "route_response_key", "$default"), - ), - }, - { - ResourceName: resourceName, - ImportStateIdFunc: testAccAWSAPIGateway2RouteResponseImportStateIdFunc(resourceName), - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAWSAPIGateway2RouteResponse_Model(t *testing.T) { - resourceName := "aws_api_gateway_v2_route_response.test" - modelResourceName := "aws_api_gateway_v2_model.test" - routeResourceName := "aws_api_gateway_v2_route.test" - rName := fmt.Sprintf("tftestaccapigwv2%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum)) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSAPIGateway2RouteResponseDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSAPIGateway2RouteResponseConfig_model(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSAPIGateway2RouteResponseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "model_selection_expression", "action"), - resource.TestCheckResourceAttr(resourceName, "response_models.%", "1"), - resource.TestCheckResourceAttrPair(resourceName, "response_models.test", modelResourceName, "name"), - resource.TestCheckResourceAttrPair(resourceName, "route_id", routeResourceName, "id"), - resource.TestCheckResourceAttr(resourceName, "route_response_key", "$default"), - ), - }, - { - ResourceName: resourceName, - ImportStateIdFunc: testAccAWSAPIGateway2RouteResponseImportStateIdFunc(resourceName), - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccCheckAWSAPIGateway2RouteResponseDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn - - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_api_gateway_v2_route_response" { - continue - } - - _, err := conn.GetRouteResponse(&apigatewayv2.GetRouteResponseInput{ - ApiId: aws.String(rs.Primary.Attributes["api_id"]), - RouteId: aws.String(rs.Primary.Attributes["route_id"]), - RouteResponseId: aws.String(rs.Primary.ID), - }) - if isAWSErr(err, apigatewayv2.ErrCodeNotFoundException, "") { - continue - } - if err != nil { - return err - } - - return fmt.Errorf("API Gateway v2 route response %s still exists", rs.Primary.ID) - } - - return nil -} - -func testAccCheckAWSAPIGateway2RouteResponseExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No API Gateway v2 route response ID is set") - } - - conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn - - _, err := conn.GetRouteResponse(&apigatewayv2.GetRouteResponseInput{ - ApiId: aws.String(rs.Primary.Attributes["api_id"]), - RouteId: aws.String(rs.Primary.Attributes["route_id"]), - RouteResponseId: aws.String(rs.Primary.ID), - }) - if err != nil { - return err - } - - return nil - } -} - -func testAccAWSAPIGateway2RouteResponseImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { - return func(s *terraform.State) (string, error) { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return "", fmt.Errorf("Not Found: %s", resourceName) - } - - return fmt.Sprintf("%s/%s/%s", rs.Primary.Attributes["api_id"], rs.Primary.Attributes["route_id"], rs.Primary.ID), nil - } -} - -func testAccAWSAPIGateway2RouteResponseConfig_basic(rName string) string { - return testAccAWSAPIGatewayV2RouteConfig_basic(rName) + fmt.Sprintf(` -resource "aws_api_gateway_v2_route_response" "test" { - api_id = "${aws_api_gateway_v2_api.test.id}" - route_id = "${aws_api_gateway_v2_route.test.id}" - route_response_key = "$default" -} -`) -} - -func testAccAWSAPIGateway2RouteResponseConfig_model(rName string) string { - return testAccAWSAPIGatewayV2RouteConfig_model(rName) + fmt.Sprintf(` -resource "aws_api_gateway_v2_route_response" "test" { - api_id = "${aws_api_gateway_v2_api.test.id}" - route_id = "${aws_api_gateway_v2_route.test.id}" - route_response_key = "$default" - - model_selection_expression = "action" - - response_models = { - "test" = "${aws_api_gateway_v2_model.test.name}" - } -} -`) -} diff --git a/aws/resource_aws_api_gateway2_route_response.go b/aws/resource_aws_apigatewayv2_route_response.go similarity index 81% rename from aws/resource_aws_api_gateway2_route_response.go rename to aws/resource_aws_apigatewayv2_route_response.go index 105b99e45dc..ed8f895aad3 100644 --- a/aws/resource_aws_api_gateway2_route_response.go +++ b/aws/resource_aws_apigatewayv2_route_response.go @@ -10,14 +10,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func resourceAwsApiGateway2RouteResponse() *schema.Resource { +func resourceAwsApiGatewayV2RouteResponse() *schema.Resource { return &schema.Resource{ - Create: resourceAwsApiGateway2RouteResponseCreate, - Read: resourceAwsApiGateway2RouteResponseRead, - Update: resourceAwsApiGateway2RouteResponseUpdate, - Delete: resourceAwsApiGateway2RouteResponseDelete, + Create: resourceAwsApiGatewayV2RouteResponseCreate, + Read: resourceAwsApiGatewayV2RouteResponseRead, + Update: resourceAwsApiGatewayV2RouteResponseUpdate, + Delete: resourceAwsApiGatewayV2RouteResponseDelete, Importer: &schema.ResourceImporter{ - State: resourceAwsApiGateway2RouteResponseImport, + State: resourceAwsApiGatewayV2RouteResponseImport, }, Schema: map[string]*schema.Schema{ @@ -48,7 +48,7 @@ func resourceAwsApiGateway2RouteResponse() *schema.Resource { } } -func resourceAwsApiGateway2RouteResponseCreate(d *schema.ResourceData, meta interface{}) error { +func resourceAwsApiGatewayV2RouteResponseCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).apigatewayv2conn req := &apigatewayv2.CreateRouteResponseInput{ @@ -71,10 +71,10 @@ func resourceAwsApiGateway2RouteResponseCreate(d *schema.ResourceData, meta inte d.SetId(aws.StringValue(resp.RouteResponseId)) - return resourceAwsApiGateway2RouteResponseRead(d, meta) + return resourceAwsApiGatewayV2RouteResponseRead(d, meta) } -func resourceAwsApiGateway2RouteResponseRead(d *schema.ResourceData, meta interface{}) error { +func resourceAwsApiGatewayV2RouteResponseRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).apigatewayv2conn resp, err := conn.GetRouteResponse(&apigatewayv2.GetRouteResponseInput{ @@ -100,7 +100,7 @@ func resourceAwsApiGateway2RouteResponseRead(d *schema.ResourceData, meta interf return nil } -func resourceAwsApiGateway2RouteResponseUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceAwsApiGatewayV2RouteResponseUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).apigatewayv2conn req := &apigatewayv2.UpdateRouteResponseInput{ @@ -124,10 +124,10 @@ func resourceAwsApiGateway2RouteResponseUpdate(d *schema.ResourceData, meta inte return fmt.Errorf("error updating API Gateway v2 route response: %s", err) } - return resourceAwsApiGateway2RouteResponseRead(d, meta) + return resourceAwsApiGatewayV2RouteResponseRead(d, meta) } -func resourceAwsApiGateway2RouteResponseDelete(d *schema.ResourceData, meta interface{}) error { +func resourceAwsApiGatewayV2RouteResponseDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).apigatewayv2conn log.Printf("[DEBUG] Deleting API Gateway v2 route response (%s)", d.Id()) @@ -146,7 +146,7 @@ func resourceAwsApiGateway2RouteResponseDelete(d *schema.ResourceData, meta inte return nil } -func resourceAwsApiGateway2RouteResponseImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceAwsApiGatewayV2RouteResponseImport(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/route-id/route-response-id'", d.Id()) diff --git a/aws/resource_aws_apigatewayv2_route_response_test.go b/aws/resource_aws_apigatewayv2_route_response_test.go new file mode 100644 index 00000000000..d38970eaede --- /dev/null +++ b/aws/resource_aws_apigatewayv2_route_response_test.go @@ -0,0 +1,212 @@ +package aws + +import ( + "fmt" + "strings" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/apigatewayv2" + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccAWSAPIGatewayV2RouteResponse_basic(t *testing.T) { + var apiId, routeId string + var v apigatewayv2.GetRouteResponseOutput + resourceName := "aws_apigatewayv2_route_response.test" + routeResourceName := "aws_apigatewayv2_route.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayV2RouteResponseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayV2RouteResponseConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayV2RouteResponseExists(resourceName, &apiId, &routeId, &v), + resource.TestCheckResourceAttr(resourceName, "model_selection_expression", ""), + resource.TestCheckResourceAttr(resourceName, "response_models.%", "0"), + resource.TestCheckResourceAttrPair(resourceName, "route_id", routeResourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "route_response_key", "$default"), + ), + }, + { + ResourceName: resourceName, + ImportStateIdFunc: testAccAWSAPIGatewayV2RouteResponseImportStateIdFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSAPIGatewayV2RouteResponse_disappears(t *testing.T) { + var apiId, routeId string + var v apigatewayv2.GetRouteResponseOutput + resourceName := "aws_apigatewayv2_route_response.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayV2RouteResponseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayV2RouteResponseConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayV2RouteResponseExists(resourceName, &apiId, &routeId, &v), + testAccCheckAWSAPIGatewayV2RouteResponseDisappears(&apiId, &routeId, &v), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccAWSAPIGatewayV2RouteResponse_Model(t *testing.T) { + var apiId, routeId string + var v apigatewayv2.GetRouteResponseOutput + resourceName := "aws_apigatewayv2_route_response.test" + modelResourceName := "aws_apigatewayv2_model.test" + routeResourceName := "aws_apigatewayv2_route.test" + // Model name must be alphanumeric. + rName := strings.ReplaceAll(acctest.RandomWithPrefix("tf-acc-test"), "-", "") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayV2RouteResponseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayV2RouteResponseConfig_model(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayV2RouteResponseExists(resourceName, &apiId, &routeId, &v), + resource.TestCheckResourceAttr(resourceName, "model_selection_expression", "action"), + resource.TestCheckResourceAttr(resourceName, "response_models.%", "1"), + resource.TestCheckResourceAttrPair(resourceName, "response_models.test", modelResourceName, "name"), + resource.TestCheckResourceAttrPair(resourceName, "route_id", routeResourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "route_response_key", "$default"), + ), + }, + { + ResourceName: resourceName, + ImportStateIdFunc: testAccAWSAPIGatewayV2RouteResponseImportStateIdFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckAWSAPIGatewayV2RouteResponseDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_apigatewayv2_route_response" { + continue + } + + _, err := conn.GetRouteResponse(&apigatewayv2.GetRouteResponseInput{ + ApiId: aws.String(rs.Primary.Attributes["api_id"]), + RouteId: aws.String(rs.Primary.Attributes["route_id"]), + RouteResponseId: aws.String(rs.Primary.ID), + }) + if isAWSErr(err, apigatewayv2.ErrCodeNotFoundException, "") { + continue + } + if err != nil { + return err + } + + return fmt.Errorf("API Gateway v2 route response %s still exists", rs.Primary.ID) + } + + return nil +} + +func testAccCheckAWSAPIGatewayV2RouteResponseDisappears(apiId, routeId *string, v *apigatewayv2.GetRouteResponseOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn + + _, err := conn.DeleteRouteResponse(&apigatewayv2.DeleteRouteResponseInput{ + ApiId: apiId, + RouteId: routeId, + RouteResponseId: v.RouteResponseId, + }) + + return err + } +} + +func testAccCheckAWSAPIGatewayV2RouteResponseExists(n string, vApiId, vRouteId *string, v *apigatewayv2.GetRouteResponseOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No API Gateway v2 route response ID is set") + } + + conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn + + apiId := aws.String(rs.Primary.Attributes["api_id"]) + routeId := aws.String(rs.Primary.Attributes["route_id"]) + resp, err := conn.GetRouteResponse(&apigatewayv2.GetRouteResponseInput{ + ApiId: apiId, + RouteId: routeId, + RouteResponseId: aws.String(rs.Primary.ID), + }) + if err != nil { + return err + } + + *vApiId = *apiId + *vRouteId = *routeId + *v = *resp + + return nil + } +} + +func testAccAWSAPIGatewayV2RouteResponseImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not Found: %s", resourceName) + } + + return fmt.Sprintf("%s/%s/%s", rs.Primary.Attributes["api_id"], rs.Primary.Attributes["route_id"], rs.Primary.ID), nil + } +} + +func testAccAWSAPIGatewayV2RouteResponseConfig_basic(rName string) string { + return testAccAWSAPIGatewayV2RouteConfig_basic(rName) + fmt.Sprintf(` +resource "aws_apigatewayv2_route_response" "test" { + api_id = "${aws_apigatewayv2_api.test.id}" + route_id = "${aws_apigatewayv2_route.test.id}" + route_response_key = "$default" +} +`) +} + +func testAccAWSAPIGatewayV2RouteResponseConfig_model(rName string) string { + return testAccAWSAPIGatewayV2RouteConfig_model(rName) + fmt.Sprintf(` +resource "aws_apigatewayv2_route_response" "test" { + api_id = "${aws_apigatewayv2_api.test.id}" + route_id = "${aws_apigatewayv2_route.test.id}" + route_response_key = "$default" + + model_selection_expression = "action" + + response_models = { + "test" = "${aws_apigatewayv2_model.test.name}" + } +} +`) +} diff --git a/website/aws.erb b/website/aws.erb index 97d2d5d5f60..42d2ba89cfc 100644 --- a/website/aws.erb +++ b/website/aws.erb @@ -237,7 +237,7 @@ aws_apigatewayv2_route
  • - aws_api_gateway_v2_route_response + aws_apigatewayv2_route_response
  • diff --git a/website/docs/r/api_gateway_v2_route_response.html.markdown b/website/docs/r/apigatewayv2_route_response.html.markdown similarity index 60% rename from website/docs/r/api_gateway_v2_route_response.html.markdown rename to website/docs/r/apigatewayv2_route_response.html.markdown index abdc8464a32..09d9c05f3b8 100644 --- a/website/docs/r/api_gateway_v2_route_response.html.markdown +++ b/website/docs/r/apigatewayv2_route_response.html.markdown @@ -1,12 +1,12 @@ --- +subcategory: "API Gateway v2 (WebSocket and HTTP APIs)" layout: "aws" -page_title: "AWS: aws_api_gateway_v2_route_response" -sidebar_current: "docs-aws-resource-api-gateway-v2-route-response" +page_title: "AWS: aws_apigatewayv2_route_response" description: |- Manages an Amazon API Gateway Version 2 route response. --- -# Resource: aws_api_gateway_v2_route_response +# Resource: aws_apigatewayv2_route_response Manages an Amazon API Gateway Version 2 route response. More information can be found in the [Amazon API Gateway Developer Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html). @@ -16,9 +16,9 @@ More information can be found in the [Amazon API Gateway Developer Guide](https: ### Basic ```hcl -resource "aws_api_gateway_v2_route_response" "example" { - api_id = "${aws_api_gateway_v2_api.example.id}" - route_id = "${aws_api_gateway_v2_route.example.id}" +resource "aws_apigatewayv2_route_response" "example" { + api_id = "${aws_apigatewayv2_api.example.id}" + route_id = "${aws_apigatewayv2_route.example.id}" route_response_key = "$default" } ``` @@ -28,7 +28,7 @@ resource "aws_api_gateway_v2_route_response" "example" { The following arguments are supported: * `api_id` - (Required) The API identifier. -* `route_id` - (Required) The identifier of the [`aws_api_gateway_v2_route`](/docs/providers/aws/r/api_gateway_v2_route.html). +* `route_id` - (Required) The identifier of the [`aws_apigatewayv2_route`](/docs/providers/aws/r/apigatewayv2_route.html). * `route_response_key` - (Required) The route response key. * `model_selection_expression` - (Optional) The [model selection expression](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-selection-expressions.html#apigateway-websocket-api-model-selection-expressions) for the route response. * `response_models` - (Optional) The response models for the route response. @@ -41,8 +41,8 @@ In addition to all arguments above, the following attributes are exported: ## Import -`aws_api_gateway_v2_route_response` can be imported by using the API identifier, route identifier and route response identifier, e.g. +`aws_apigatewayv2_route_response` can be imported by using the API identifier, route identifier and route response identifier, e.g. ``` -$ terraform import aws_api_gateway_v2_route.example aabbccddee/1122334/998877 +$ terraform import aws_apigatewayv2_route_response.example aabbccddee/1122334/998877 ```