Skip to content

Commit 801cd36

Browse files
authored
resource/aws_api_gateway_rest_api: Add disable_execute_api_endpoint argument (#16198)
Output from acceptance testing: ``` --- PASS: TestAccAWSAPIGatewayRestApi_api_key_source (49.76s) --- PASS: TestAccAWSAPIGatewayRestApi_basic (733.13s) --- PASS: TestAccAWSAPIGatewayRestApi_disable_execute_api_endpoint (29.79s) --- PASS: TestAccAWSAPIGatewayRestApi_disappears (30.64s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration (237.77s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_Private (9.10s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_VPCEndpoint (222.18s) --- PASS: TestAccAWSAPIGatewayRestApi_openapi (17.50s) --- PASS: TestAccAWSAPIGatewayRestApi_Parameters (38.95s) --- PASS: TestAccAWSAPIGatewayRestApi_policy (437.20s) --- PASS: TestAccAWSAPIGatewayRestApi_tags (20.53s) ```
1 parent 9b338a5 commit 801cd36

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

aws/resource_aws_api_gateway_rest_api.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ func resourceAwsApiGatewayRestApi() *schema.Resource {
6565
Optional: true,
6666
},
6767

68+
"disable_execute_api_endpoint": {
69+
Type: schema.TypeBool,
70+
Optional: true,
71+
Default: false,
72+
},
73+
6874
"parameters": {
6975
Type: schema.TypeMap,
7076
Optional: true,
@@ -156,6 +162,10 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{}
156162
params.ApiKeySource = aws.String(v.(string))
157163
}
158164

165+
if v, ok := d.GetOk("disable_execute_api_endpoint"); ok {
166+
params.DisableExecuteApiEndpoint = aws.Bool(v.(bool))
167+
}
168+
159169
if v, ok := d.GetOk("policy"); ok {
160170
params.Policy = aws.String(v.(string))
161171
}
@@ -241,6 +251,7 @@ func resourceAwsApiGatewayRestApiRead(d *schema.ResourceData, meta interface{})
241251
d.Set("name", api.Name)
242252
d.Set("description", api.Description)
243253
d.Set("api_key_source", api.ApiKeySource)
254+
d.Set("disable_execute_api_endpoint", api.DisableExecuteApiEndpoint)
244255

245256
// The API returns policy as an escaped JSON string
246257
// {\\\"Version\\\":\\\"2012-10-17\\\",...}
@@ -324,6 +335,15 @@ func resourceAwsApiGatewayRestApiUpdateOperations(d *schema.ResourceData) []*api
324335
})
325336
}
326337

338+
if d.HasChange("disable_execute_api_endpoint") {
339+
value := strconv.FormatBool(d.Get("disable_execute_api_endpoint").(bool))
340+
operations = append(operations, &apigateway.PatchOperation{
341+
Op: aws.String(apigateway.OpReplace),
342+
Path: aws.String("/disableExecuteApiEndpoint"),
343+
Value: aws.String(value),
344+
})
345+
}
346+
327347
if d.HasChange("policy") {
328348
operations = append(operations, &apigateway.PatchOperation{
329349
Op: aws.String(apigateway.OpReplace),

aws/resource_aws_api_gateway_rest_api_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func TestAccAWSAPIGatewayRestApi_basic(t *testing.T) {
8484
resource.TestCheckResourceAttr(resourceName, "name", rName),
8585
resource.TestCheckResourceAttr(resourceName, "description", ""),
8686
resource.TestCheckResourceAttr(resourceName, "api_key_source", "HEADER"),
87+
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", `false`),
8788
resource.TestCheckResourceAttr(resourceName, "minimum_compression_size", "0"),
8889
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
8990
resource.TestCheckResourceAttrSet(resourceName, "execution_arn"),
@@ -106,6 +107,7 @@ func TestAccAWSAPIGatewayRestApi_basic(t *testing.T) {
106107
testAccCheckAWSAPIGatewayRestAPIMinimumCompressionSizeAttribute(&conf, 10485760),
107108
resource.TestCheckResourceAttr(resourceName, "name", rName),
108109
resource.TestCheckResourceAttr(resourceName, "description", "test"),
110+
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", `false`),
109111
resource.TestCheckResourceAttr(resourceName, "minimum_compression_size", "10485760"),
110112
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
111113
resource.TestCheckResourceAttrSet(resourceName, "execution_arn"),
@@ -437,6 +439,42 @@ func TestAccAWSAPIGatewayRestApi_api_key_source(t *testing.T) {
437439
})
438440
}
439441

442+
func TestAccAWSAPIGatewayRestApi_disable_execute_api_endpoint(t *testing.T) {
443+
rName := acctest.RandomWithPrefix("tf-acc-test")
444+
resourceName := "aws_api_gateway_rest_api.test"
445+
446+
resource.ParallelTest(t, resource.TestCase{
447+
PreCheck: func() { testAccPreCheck(t); testAccAPIGatewayTypeEDGEPreCheck(t) },
448+
Providers: testAccProviders,
449+
CheckDestroy: testAccCheckAWSAPIGatewayRestAPIDestroy,
450+
Steps: []resource.TestStep{
451+
{
452+
Config: testAccAWSAPIGatewayRestAPIConfig_DisableExecuteApiEndpoint(rName, false),
453+
Check: resource.ComposeTestCheckFunc(
454+
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", `false`),
455+
),
456+
},
457+
{
458+
ResourceName: resourceName,
459+
ImportState: true,
460+
ImportStateVerify: true,
461+
},
462+
{
463+
Config: testAccAWSAPIGatewayRestAPIConfig_DisableExecuteApiEndpoint(rName, true),
464+
Check: resource.ComposeTestCheckFunc(
465+
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", `true`),
466+
),
467+
},
468+
{
469+
Config: testAccAWSAPIGatewayRestAPIConfig_DisableExecuteApiEndpoint(rName, false),
470+
Check: resource.ComposeTestCheckFunc(
471+
resource.TestCheckResourceAttr(resourceName, "disable_execute_api_endpoint", `false`),
472+
),
473+
},
474+
},
475+
})
476+
}
477+
440478
func TestAccAWSAPIGatewayRestApi_policy(t *testing.T) {
441479
resourceName := "aws_api_gateway_rest_api.test"
442480
expectedPolicyText := `{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"*"},"Action":"execute-api:Invoke","Resource":"*","Condition":{"IpAddress":{"aws:SourceIp":"123.123.123.123/32"}}}]}`
@@ -704,6 +742,15 @@ resource "aws_api_gateway_rest_api" "test" {
704742
`, rName, endpointType)
705743
}
706744

745+
func testAccAWSAPIGatewayRestAPIConfig_DisableExecuteApiEndpoint(rName string, disabled bool) string {
746+
return fmt.Sprintf(`
747+
resource "aws_api_gateway_rest_api" "test" {
748+
name = "%s"
749+
disable_execute_api_endpoint = %t
750+
}
751+
`, rName, disabled)
752+
}
753+
707754
func testAccAWSAPIGatewayRestAPIConfig_Name(rName string) string {
708755
return fmt.Sprintf(`
709756
resource "aws_api_gateway_rest_api" "test" {

website/docs/r/api_gateway_rest_api.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The following arguments are supported:
4848
* `parameters` - (Optional) Map of customizations for importing the specification in the `body` argument. For example, to exclude DocumentationParts from an imported API, set `ignore` equal to `documentation`. Additional documentation, including other parameters such as `basepath`, can be found in the [API Gateway Developer Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html).
4949
* `policy` - (Optional) JSON formatted policy document that controls access to the API Gateway. For more information about building AWS IAM policy documents with Terraform, see the [AWS IAM Policy Document Guide](https://learn.hashicorp.com/terraform/aws/iam-policy). Terraform will only perform drift detection of its value when present in a configuration. It is recommended to use the [`aws_api_gateway_rest_api_policy` resource](/docs/providers/aws/r/api_gateway_rest_api_policy.html) instead.
5050
* `api_key_source` - (Optional) The source of the API key for requests. Valid values are HEADER (default) and AUTHORIZER.
51+
* `disable_execute_api_endpoint` - (Optional) Specifies whether clients can invoke your API by using the default execute-api endpoint. By default, clients can invoke your API with the default https://{api_id}.execute-api.{region}.amazonaws.com endpoint. To require that clients use a custom domain name to invoke your API, disable the default endpoint. Defaults to `false`.
5152
* `tags` - (Optional) Key-value map of resource tags
5253

5354
__Note__: If the `body` argument is provided, the OpenAPI specification will be used to configure the resources, methods and integrations for the Rest API. If this argument is provided, the following resources should not be managed as separate ones, as updates may cause manual resource updates to be overwritten:

0 commit comments

Comments
 (0)