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_stage: 'deployment_id` is Computed for auto-deployments #13644

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
1 change: 1 addition & 0 deletions aws/resource_aws_apigatewayv2_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func resourceAwsApiGatewayV2Stage() *schema.Resource {
"deployment_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"description": {
Type: schema.TypeString,
Expand Down
91 changes: 89 additions & 2 deletions aws/resource_aws_apigatewayv2_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -872,7 +960,6 @@ resource "aws_apigatewayv2_stage" "test" {
name = %[1]q

description = "Test stage updated"
auto_deploy = true
}
`, rName)
}
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/apigatewayv2_stage.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down