diff --git a/aws/resource_aws_apigatewayv2_stage.go b/aws/resource_aws_apigatewayv2_stage.go index 3c5dc95f572..d2276c5fce1 100644 --- a/aws/resource_aws_apigatewayv2_stage.go +++ b/aws/resource_aws_apigatewayv2_stage.go @@ -119,6 +119,7 @@ func resourceAwsApiGatewayV2Stage() *schema.Resource { "deployment_id": { Type: schema.TypeString, Optional: true, + Computed: true, }, "description": { Type: schema.TypeString, diff --git a/aws/resource_aws_apigatewayv2_stage_test.go b/aws/resource_aws_apigatewayv2_stage_test.go index a6f8a7f0edc..8b2cb0aaf11 100644 --- a/aws/resource_aws_apigatewayv2_stage_test.go +++ b/aws/resource_aws_apigatewayv2_stage_test.go @@ -149,6 +149,77 @@ func TestAccAWSAPIGatewayV2Stage_defaultHttpStage(t *testing.T) { }) } +func TestAccAWSAPIGatewayV2Stage_autoDeployHttp(t *testing.T) { + var apiId string + var v apigatewayv2.GetStageOutput + resourceName := "aws_apigatewayv2_stage.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAPIGatewayV2StageDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAPIGatewayV2StageConfig_autoDeployHttp(rName, false), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayV2StageExists(resourceName, &apiId, &v), + resource.TestCheckResourceAttr(resourceName, "access_log_settings.#", "0"), + testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(fmt.Sprintf("/apis/.+/stages/%s", rName))), + resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), + resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.data_trace_enabled", "false"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.detailed_metrics_enabled", "false"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.logging_level", ""), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_burst_limit", "0"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), + resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "execution_arn", ""), + resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("https://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), + resource.TestCheckResourceAttr(resourceName, "stage_variables.%", "0"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + { + Config: testAccAWSAPIGatewayV2StageConfig_autoDeployHttp(rName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAPIGatewayV2StageExists(resourceName, &apiId, &v), + resource.TestCheckResourceAttr(resourceName, "access_log_settings.#", "0"), + testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(fmt.Sprintf("/apis/.+/stages/%s", rName))), + resource.TestCheckResourceAttr(resourceName, "auto_deploy", "true"), + resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.data_trace_enabled", "false"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.detailed_metrics_enabled", "false"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.logging_level", ""), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_burst_limit", "0"), + resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), + // The stage's DeploymentId attribute will be set asynchronously as deployments are done automatically. + // resource.TestCheckResourceAttrSet(resourceName, "deployment_id"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "execution_arn", ""), + resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("https://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), + resource.TestCheckResourceAttr(resourceName, "stage_variables.%", "0"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + { + ResourceName: resourceName, + ImportStateIdFunc: testAccAWSAPIGatewayV2StageImportStateIdFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deployment_id"}, + }, + }, + }) +} + func TestAccAWSAPIGatewayV2Stage_disappears(t *testing.T) { var apiId string var v apigatewayv2.GetStageOutput @@ -291,7 +362,7 @@ func TestAccAWSAPIGatewayV2Stage_ClientCertificateIdAndDescription(t *testing.T) testAccCheckAWSAPIGatewayV2StageExists(resourceName, &apiId, &v), resource.TestCheckResourceAttr(resourceName, "access_log_settings.#", "0"), testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(fmt.Sprintf("/apis/.+/stages/%s", rName))), - resource.TestCheckResourceAttr(resourceName, "auto_deploy", "true"), + resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.data_trace_enabled", "false"), @@ -782,6 +853,23 @@ resource "aws_apigatewayv2_stage" "test" { ` } +func testAccAWSAPIGatewayV2StageConfig_autoDeployHttp(rName string, autoDeploy bool) string { + return testAccAWSAPIGatewayV2IntegrationConfig_httpProxy(rName) + fmt.Sprintf(` +resource "aws_apigatewayv2_route" "test" { + api_id = "${aws_apigatewayv2_api.test.id}" + route_key = "GET /test" + target = "integrations/${aws_apigatewayv2_integration.test.id}" +} + +resource "aws_apigatewayv2_stage" "test" { + api_id = "${aws_apigatewayv2_api.test.id}" + name = %[1]q + + auto_deploy = %[2]t +} +`, rName, autoDeploy) +} + func testAccAWSAPIGatewayV2StageConfig_accessLogSettings(rName, format string) string { return testAccAWSAPIGatewayV2StageConfig_apiWebSocket(rName) + fmt.Sprintf(` resource "aws_iam_role" "test" { @@ -872,7 +960,6 @@ resource "aws_apigatewayv2_stage" "test" { name = %[1]q description = "Test stage updated" - auto_deploy = true } `, rName) } diff --git a/website/docs/r/apigatewayv2_stage.html.markdown b/website/docs/r/apigatewayv2_stage.html.markdown index 79e76e9091d..0cedcebc7c3 100644 --- a/website/docs/r/apigatewayv2_stage.html.markdown +++ b/website/docs/r/apigatewayv2_stage.html.markdown @@ -30,11 +30,11 @@ The following arguments are supported: * `name` - (Required) The name of the stage. * `access_log_settings` - (Optional) Settings for logging access in this stage. Use the [`aws_api_gateway_account`](/docs/providers/aws/r/api_gateway_account.html) resource to configure [permissions for CloudWatch Logging](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html#set-up-access-logging-permissions). -* `auto_deploy` - (Optional) Whether updates to an API automatically trigger a new deployment. Defaults to `false`. +* `auto_deploy` - (Optional) Whether updates to an API automatically trigger a new deployment. Defaults to `false`. Applicable for HTTP APIs. * `client_certificate_id` - (Optional) The identifier of a client certificate for the stage. Use the [`aws_api_gateway_client_certificate`](/docs/providers/aws/r/api_gateway_client_certificate.html) resource to configure a client certificate. Supported only for WebSocket APIs. * `default_route_settings` - (Optional) The default route settings for the stage. -* `deployment_id` - (Optional) The deployment identifier of the stage. Use the `aws_apigatewayv2_deployment` resource to configure a deployment. +* `deployment_id` - (Optional) The deployment identifier of the stage. Use the [`aws_apigatewayv2_deployment`](/docs/providers/aws/r/apigatewayv2_deployment.html) resource to configure a deployment. * `description` - (Optional) The description for the stage. * `route_settings` - (Optional) Route settings for the stage. * `stage_variables` - (Optional) A map that defines the stage variables for the stage.