diff --git a/aws/resource_aws_apigatewayv2_stage.go b/aws/resource_aws_apigatewayv2_stage.go index f6b954b50a0..ffbfaa37f33 100644 --- a/aws/resource_aws_apigatewayv2_stage.go +++ b/aws/resource_aws_apigatewayv2_stage.go @@ -274,6 +274,14 @@ func resourceAwsApiGatewayV2StageRead(d *schema.ResourceData, meta interface{}) } d.Set("deployment_id", resp.DeploymentId) d.Set("description", resp.Description) + executionArn := arn.ARN{ + Partition: meta.(*AWSClient).partition, + Service: "execute-api", + Region: region, + AccountID: meta.(*AWSClient).accountid, + Resource: fmt.Sprintf("%s/%s", apiId, stageName), + }.String() + d.Set("execution_arn", executionArn) d.Set("name", stageName) err = d.Set("route_settings", flattenApiGatewayV2RouteSettings(resp.RouteSettings)) if err != nil { @@ -296,17 +304,8 @@ func resourceAwsApiGatewayV2StageRead(d *schema.ResourceData, meta interface{}) switch aws.StringValue(apiOutput.ProtocolType) { case apigatewayv2.ProtocolTypeWebsocket: - executionArn := arn.ARN{ - Partition: meta.(*AWSClient).partition, - Service: "execute-api", - Region: region, - AccountID: meta.(*AWSClient).accountid, - Resource: fmt.Sprintf("%s/%s", apiId, stageName), - }.String() - d.Set("execution_arn", executionArn) d.Set("invoke_url", fmt.Sprintf("wss://%s.execute-api.%s.amazonaws.com/%s", apiId, region, stageName)) case apigatewayv2.ProtocolTypeHttp: - d.Set("execution_arn", "") if stageName == apigatewayv2DefaultStageName { d.Set("invoke_url", fmt.Sprintf("https://%s.execute-api.%s.amazonaws.com/", apiId, region)) } else { diff --git a/aws/resource_aws_apigatewayv2_stage_test.go b/aws/resource_aws_apigatewayv2_stage_test.go index 1ad52f9e8d7..019a78da619 100644 --- a/aws/resource_aws_apigatewayv2_stage_test.go +++ b/aws/resource_aws_apigatewayv2_stage_test.go @@ -29,7 +29,7 @@ func TestAccAWSAPIGatewayV2Stage_basicWebSocket(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -40,7 +40,7 @@ func TestAccAWSAPIGatewayV2Stage_basicWebSocket(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -74,7 +74,7 @@ func TestAccAWSAPIGatewayV2Stage_basicHttp(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -85,7 +85,7 @@ func TestAccAWSAPIGatewayV2Stage_basicHttp(t *testing.T) { 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", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), 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"), @@ -119,7 +119,7 @@ func TestAccAWSAPIGatewayV2Stage_defaultHttpStage(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayV2StageExists(resourceName, &apiId, &v), resource.TestCheckResourceAttr(resourceName, "access_log_settings.#", "0"), - testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/apis/.+/stages/\$default`)), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -130,7 +130,7 @@ func TestAccAWSAPIGatewayV2Stage_defaultHttpStage(t *testing.T) { 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", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("https://.+\\.execute-api\\.%s.amazonaws\\.com/", testAccGetRegion()))), resource.TestCheckResourceAttr(resourceName, "name", "$default"), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -164,7 +164,7 @@ func TestAccAWSAPIGatewayV2Stage_autoDeployHttp(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -175,7 +175,7 @@ func TestAccAWSAPIGatewayV2Stage_autoDeployHttp(t *testing.T) { 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", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), 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"), @@ -188,7 +188,7 @@ func TestAccAWSAPIGatewayV2Stage_autoDeployHttp(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "true"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -200,7 +200,7 @@ func TestAccAWSAPIGatewayV2Stage_autoDeployHttp(t *testing.T) { // 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", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), 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"), @@ -261,7 +261,7 @@ func TestAccAWSAPIGatewayV2Stage_AccessLogSettings(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "access_log_settings.#", "1"), resource.TestCheckResourceAttrPair(resourceName, "access_log_settings.0.destination_arn", cloudWatchResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "access_log_settings.0.format", "$context.identity.sourceIp $context.requestId"), - testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(fmt.Sprintf("/apis/.+/stages/%s", rName))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -272,7 +272,7 @@ func TestAccAWSAPIGatewayV2Stage_AccessLogSettings(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -330,7 +330,7 @@ func TestAccAWSAPIGatewayV2Stage_ClientCertificateIdAndDescription(t *testing.T) 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttrPair(resourceName, "client_certificate_id", certificateResourceName, "id"), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -341,7 +341,7 @@ func TestAccAWSAPIGatewayV2Stage_ClientCertificateIdAndDescription(t *testing.T) resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", "Test stage"), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -360,7 +360,7 @@ func TestAccAWSAPIGatewayV2Stage_ClientCertificateIdAndDescription(t *testing.T) 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -371,7 +371,7 @@ func TestAccAWSAPIGatewayV2Stage_ClientCertificateIdAndDescription(t *testing.T) resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", "Test stage updated"), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -399,7 +399,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsWebSocket(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -410,7 +410,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsWebSocket(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "8888"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -423,7 +423,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsWebSocket(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -434,7 +434,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsWebSocket(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "9999"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -489,7 +489,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsHttp(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -500,7 +500,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsHttp(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "8888"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "execution_arn", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), 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"), @@ -513,7 +513,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsHttp(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -524,7 +524,7 @@ func TestAccAWSAPIGatewayV2Stage_DefaultRouteSettingsHttp(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "9999"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "execution_arn", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), 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"), @@ -580,7 +580,7 @@ func TestAccAWSAPIGatewayV2Stage_Deployment(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -591,7 +591,7 @@ func TestAccAWSAPIGatewayV2Stage_Deployment(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), resource.TestCheckResourceAttrPair(resourceName, "deployment_id", deploymentResourceName, "id"), resource.TestCheckResourceAttr(resourceName, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -625,7 +625,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsWebSocket(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -636,7 +636,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsWebSocket(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "2"), @@ -664,7 +664,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsWebSocket(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -675,7 +675,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsWebSocket(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "default_route_settings.0.throttling_rate_limit", "0"), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), resource.TestCheckResourceAttr(resourceName, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "3"), @@ -752,7 +752,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsHttp(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -763,7 +763,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsHttp(t *testing.T) { 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", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), 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.#", "1"), @@ -783,7 +783,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsHttp(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "default_route_settings.#", "1"), @@ -794,7 +794,7 @@ func TestAccAWSAPIGatewayV2Stage_RouteSettingsHttp(t *testing.T) { 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", ""), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), 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.#", "1"), @@ -856,7 +856,7 @@ func TestAccAWSAPIGatewayV2Stage_StageVariables(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), @@ -867,7 +867,7 @@ func TestAccAWSAPIGatewayV2Stage_StageVariables(t *testing.T) { 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, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -924,7 +924,7 @@ func TestAccAWSAPIGatewayV2Stage_Tags(t *testing.T) { 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))), + testAccCheckAWSAPIGatewayV2StageARN(resourceName, "arn", &apiId, &v), resource.TestCheckResourceAttr(resourceName, "auto_deploy", "false"), resource.TestCheckResourceAttr(resourceName, "client_certificate_id", ""), resource.TestCheckResourceAttr(resourceName, "deployment_id", ""), @@ -935,7 +935,7 @@ func TestAccAWSAPIGatewayV2Stage_Tags(t *testing.T) { 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, "description", ""), - testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(fmt.Sprintf(".+/%s", rName))), + testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, "execution_arn", &apiId, &v), resource.TestMatchResourceAttr(resourceName, "invoke_url", regexp.MustCompile(fmt.Sprintf("wss://.+\\.execute-api\\.%s.amazonaws\\.com/%s", testAccGetRegion(), rName))), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "route_settings.#", "0"), @@ -1030,6 +1030,18 @@ func testAccCheckAWSAPIGatewayV2StageExists(n string, vApiId *string, v *apigate } } +func testAccCheckAWSAPIGatewayV2StageARN(resourceName, attributeName string, vApiId *string, v *apigatewayv2.GetStageOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + return testAccCheckResourceAttrRegionalARNNoAccount(resourceName, attributeName, "apigateway", fmt.Sprintf("/apis/%s/stages/%s", *vApiId, *v.StageName))(s) + } +} + +func testAccCheckAWSAPIGatewayV2StageExecutionARN(resourceName, attributeName string, vApiId *string, v *apigatewayv2.GetStageOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + return testAccCheckResourceAttrRegionalARN(resourceName, attributeName, "execute-api", fmt.Sprintf("%s/%s", *vApiId, *v.StageName))(s) + } +} + func testAccAWSAPIGatewayV2StageImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { return func(s *terraform.State) (string, error) { rs, ok := s.RootModule().Resources[resourceName] diff --git a/website/docs/r/apigatewayv2_stage.html.markdown b/website/docs/r/apigatewayv2_stage.html.markdown index f251a32685c..b20befb94eb 100644 --- a/website/docs/r/apigatewayv2_stage.html.markdown +++ b/website/docs/r/apigatewayv2_stage.html.markdown @@ -72,10 +72,9 @@ In addition to all arguments above, the following attributes are exported: * `id` - The stage identifier. * `arn` - The ARN of the stage. -* `execution_arn` - The ARN prefix to be used in an [`aws_lambda_permission`](/docs/providers/aws/r/lambda_permission.html)'s `source_arn` attribute -or in an [`aws_iam_policy`](/docs/providers/aws/r/iam_policy.html) to authorize access to the [`@connections` API](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html). +* `execution_arn` - The ARN prefix to be used in an [`aws_lambda_permission`](/docs/providers/aws/r/lambda_permission.html)'s `source_arn` attribute. +For WebSocket APIs this attribute can additionally be used in an [`aws_iam_policy`](/docs/providers/aws/r/iam_policy.html) to authorize access to the [`@connections` API](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html). See the [Amazon API Gateway Developer Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-control-access-iam.html) for details. -Set only for WebSocket APIs. * `invoke_url` - The URL to invoke the API pointing to the stage, e.g. `wss://z4675bid1j.execute-api.eu-west-2.amazonaws.com/example-stage`, or `https://z4675bid1j.execute-api.eu-west-2.amazonaws.com/`