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_api: Add 'disable_execute_api_endpoint' attribute #15250

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
24 changes: 16 additions & 8 deletions aws/resource_aws_apigatewayv2_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func resourceAwsApiGatewayV2Api() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 1024),
},
"disable_execute_api_endpoint": {
Type: schema.TypeBool,
Optional: true,
},
"execution_arn": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -109,13 +113,10 @@ func resourceAwsApiGatewayV2Api() *schema.Resource {
ValidateFunc: validateStringIsJsonOrYaml,
},
"protocol_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
apigatewayv2.ProtocolTypeHttp,
apigatewayv2.ProtocolTypeWebsocket,
}, false),
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(apigatewayv2.ProtocolType_Values(), false),
},
"route_key": {
Type: schema.TypeString,
Expand Down Expand Up @@ -221,6 +222,9 @@ func resourceAwsApiGatewayV2ApiCreate(d *schema.ResourceData, meta interface{})
if v, ok := d.GetOk("description"); ok {
req.Description = aws.String(v.(string))
}
if v, ok := d.GetOk("disable_execute_api_endpoint"); ok {
req.DisableExecuteApiEndpoint = aws.Bool(v.(bool))
}
if v, ok := d.GetOk("route_key"); ok {
req.RouteKey = aws.String(v.(string))
}
Expand Down Expand Up @@ -279,6 +283,7 @@ func resourceAwsApiGatewayV2ApiRead(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("error setting cors_configuration: %s", err)
}
d.Set("description", resp.Description)
d.Set("disable_execute_api_endpoint", resp.DisableExecuteApiEndpoint)
executionArn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "execute-api",
Expand Down Expand Up @@ -317,7 +322,7 @@ func resourceAwsApiGatewayV2ApiUpdate(d *schema.ResourceData, meta interface{})
}
}

if d.HasChanges("api_key_selection_expression", "description", "name", "route_selection_expression", "version") ||
if d.HasChanges("api_key_selection_expression", "description", "disable_execute_api_endpoint", "name", "route_selection_expression", "version") ||
(d.HasChange("cors_configuration") && !deleteCorsConfiguration) {
req := &apigatewayv2.UpdateApiInput{
ApiId: aws.String(d.Id()),
Expand All @@ -332,6 +337,9 @@ func resourceAwsApiGatewayV2ApiUpdate(d *schema.ResourceData, meta interface{})
if d.HasChange("description") {
req.Description = aws.String(d.Get("description").(string))
}
if d.HasChange("disable_execute_api_endpoint") {
req.DisableExecuteApiEndpoint = aws.Bool(d.Get("disable_execute_api_endpoint").(bool))
}
if d.HasChange("name") {
req.Name = aws.String(d.Get("name").(string))
}
Expand Down
40 changes: 22 additions & 18 deletions aws/resource_aws_apigatewayv2_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func TestAccAWSAPIGatewayV2Api_basicWebSocket(t *testing.T) {
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/apis/.+`)),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(`.+`)),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "protocol_type", apigatewayv2.ProtocolTypeWebsocket),
Expand Down Expand Up @@ -124,6 +125,7 @@ func TestAccAWSAPIGatewayV2Api_basicHttp(t *testing.T) {
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/apis/.+`)),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(`.+`)),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "protocol_type", apigatewayv2.ProtocolTypeHttp),
Expand Down Expand Up @@ -155,7 +157,7 @@ func TestAccAWSAPIGatewayV2Api_disappears(t *testing.T) {
Config: testAccAWSAPIGatewayV2ApiConfig_basicWebSocket(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayV2ApiExists(resourceName, &v),
testAccCheckAWSAPIGatewayV2ApiDisappears(&v),
testAccCheckResourceDisappears(testAccProvider, resourceAwsApiGatewayV2Api(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -183,6 +185,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesWebSocket(t *testing.T) {
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/apis/.+`)),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", "test description"),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "true"),
testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(`.+`)),
resource.TestCheckResourceAttr(resourceName, "name", rName1),
resource.TestCheckResourceAttr(resourceName, "protocol_type", apigatewayv2.ProtocolTypeWebsocket),
Expand All @@ -198,6 +201,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesWebSocket(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_selection_expression", "$request.header.x-api-key"),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "name", rName1),
resource.TestCheckResourceAttr(resourceName, "protocol_type", apigatewayv2.ProtocolTypeWebsocket),
resource.TestCheckResourceAttr(resourceName, "route_selection_expression", "$request.body.action"),
Expand All @@ -212,6 +216,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesWebSocket(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_selection_expression", "$context.authorizer.usageIdentifierKey"),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", "test description"),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "true"),
resource.TestCheckResourceAttr(resourceName, "name", rName2),
resource.TestCheckResourceAttr(resourceName, "route_selection_expression", "$request.body.service"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand All @@ -225,6 +230,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesWebSocket(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_selection_expression", "$context.authorizer.usageIdentifierKey"),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", "test description"),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "true"),
resource.TestCheckResourceAttr(resourceName, "name", rName1),
resource.TestCheckResourceAttr(resourceName, "route_selection_expression", "$request.body.service"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -260,6 +266,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesHttp(t *testing.T) {
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/apis/.+`)),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", "test description"),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "true"),
testAccMatchResourceAttrRegionalARN(resourceName, "execution_arn", "execute-api", regexp.MustCompile(`.+`)),
resource.TestCheckResourceAttr(resourceName, "name", rName1),
resource.TestCheckResourceAttr(resourceName, "protocol_type", apigatewayv2.ProtocolTypeHttp),
Expand All @@ -275,6 +282,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesHttp(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_selection_expression", "$request.header.x-api-key"),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "name", rName1),
resource.TestCheckResourceAttr(resourceName, "protocol_type", apigatewayv2.ProtocolTypeHttp),
resource.TestCheckResourceAttr(resourceName, "route_selection_expression", "$request.method $request.path"),
Expand All @@ -289,6 +297,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesHttp(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_selection_expression", "$request.header.x-api-key"),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", "test description"),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "true"),
resource.TestCheckResourceAttr(resourceName, "name", rName2),
resource.TestCheckResourceAttr(resourceName, "route_selection_expression", "$request.method $request.path"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand All @@ -302,6 +311,7 @@ func TestAccAWSAPIGatewayV2Api_AllAttributesHttp(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_selection_expression", "$request.header.x-api-key"),
resource.TestCheckResourceAttr(resourceName, "cors_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "description", "test description"),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "true"),
resource.TestCheckResourceAttr(resourceName, "name", rName1),
resource.TestCheckResourceAttr(resourceName, "route_selection_expression", "$request.method $request.path"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -333,6 +343,7 @@ func TestAccAWSAPIGatewayV2Api_Openapi(t *testing.T) {
testAccCheckAWSAPIGatewayV2ApiExists(resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, "api_endpoint"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "version", ""),
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/apis/.+`)),
Expand All @@ -350,6 +361,7 @@ func TestAccAWSAPIGatewayV2Api_Openapi(t *testing.T) {
Config: testAccAWSAPIGatewayV2ApiConfig_UpdatedOpenAPIYaml(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "version", ""),
testAccCheckAWSAPIGatewayV2ApiExists(resourceName, &v),
Expand Down Expand Up @@ -477,6 +489,7 @@ func TestAccAWSAPIGatewayV2Api_OpenapiWithMoreFields(t *testing.T) {
testAccCheckAWSAPIGatewayV2ApiExists(resourceName, &v),
resource.TestCheckResourceAttrSet(resourceName, "api_endpoint"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "version", ""),
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "apigateway", regexp.MustCompile(`/apis/.+`)),
Expand All @@ -494,6 +507,7 @@ func TestAccAWSAPIGatewayV2Api_OpenapiWithMoreFields(t *testing.T) {
Config: testAccAWSAPIGatewayV2ApiConfig_UpdatedOpenAPI2(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "description", "description test"),
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "version", "2017-04-21T04:08:08Z"),
testAccCheckAWSAPIGatewayV2ApiExists(resourceName, &v),
Expand Down Expand Up @@ -753,18 +767,6 @@ func testAccCheckAWSAPIGatewayV2ApiDestroy(s *terraform.State) error {
return nil
}

func testAccCheckAWSAPIGatewayV2ApiDisappears(v *apigatewayv2.GetApiOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn

_, err := conn.DeleteApi(&apigatewayv2.DeleteApiInput{
ApiId: v.ApiId,
})

return err
}
}

func testAccCheckAWSAPIGatewayV2ApiExists(n string, v *apigatewayv2.GetApiOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -914,6 +916,7 @@ func testAccAWSAPIGatewayV2ApiConfig_allAttributesWebSocket(rName string) string
resource "aws_apigatewayv2_api" "test" {
api_key_selection_expression = "$context.authorizer.usageIdentifierKey"
description = "test description"
disable_execute_api_endpoint = true
name = %[1]q
protocol_type = "WEBSOCKET"
route_selection_expression = "$request.body.service"
Expand All @@ -925,10 +928,11 @@ resource "aws_apigatewayv2_api" "test" {
func testAccAWSAPIGatewayV2ApiConfig_allAttributesHttp(rName string) string {
return fmt.Sprintf(`
resource "aws_apigatewayv2_api" "test" {
description = "test description"
name = %[1]q
protocol_type = "HTTP"
version = "v1"
description = "test description"
disable_execute_api_endpoint = true
name = %[1]q
protocol_type = "HTTP"
version = "v1"
}
`, rName)
}
Expand Down Expand Up @@ -1241,7 +1245,7 @@ resource "aws_apigatewayv2_api" "test" {
"info": {
"title": "%s_DIFFERENT",
"version": "2.0",
"description": "description different"
"description": "description different"
},
"paths": {
"/update": {
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/apigatewayv2_api.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Applicable for WebSocket APIs.
* `cors_configuration` - (Optional) The cross-origin resource sharing (CORS) [configuration](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html). Applicable for HTTP APIs.
* `credentials_arn` - (Optional) Part of _quick create_. Specifies any credentials required for the integration. Applicable for HTTP APIs.
* `description` - (Optional) The description of the API.
* `disable_execute_api_endpoint` - (Optional) Whether clients can invoke the API by using the default `execute-api` endpoint.
By default, clients can invoke the API with the default `{api_id}.execute-api.{region}.amazonaws.com endpoint`.
To require that clients use a custom domain name to invoke the API, disable the default endpoint.
* `route_key` - (Optional) Part of _quick create_. Specifies any [route key](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html). Applicable for HTTP APIs.
* `route_selection_expression` - (Optional) The [route selection expression](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-selection-expressions.html#apigateway-websocket-api-route-selection-expressions) for the API.
Defaults to `$request.method $request.path`.
Expand Down