Skip to content

Commit

Permalink
modifying cache waiting logic to not wait when cache cluster isnt ena…
Browse files Browse the repository at this point in the history
…bled and setting cache size
  • Loading branch information
alpacamybags118 committed Feb 10, 2022
1 parent 09a2c9c commit f76a539
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/23091.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_api_gateway_stage: Fixed issue with providing `cache_cluster_size` without `cache_cluster_enabled` resulted in waiter error
```
10 changes: 5 additions & 5 deletions internal/service/apigateway/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ func resourceStageCreate(d *schema.ResourceData, meta interface{}) error {
input.CacheClusterEnabled = aws.Bool(v.(bool))
waitForCache = true
}
if v, ok := d.GetOk("cache_cluster_size"); ok {
input.CacheClusterSize = aws.String(v.(string))
waitForCache = true
}
if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
Expand Down Expand Up @@ -303,7 +299,11 @@ func resourceStageUpdate(d *schema.ResourceData, meta interface{}) error {
Path: aws.String("/cacheClusterSize"),
Value: aws.String(d.Get("cache_cluster_size").(string)),
})
waitForCache = true
cache_enabled := d.Get("cache_cluster_enabled").(bool)

if cache_enabled {
waitForCache = true
}
}
if d.HasChange("client_certificate_id") {
operations = append(operations, &apigateway.PatchOperation{
Expand Down
56 changes: 56 additions & 0 deletions internal/service/apigateway/stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,51 @@ func TestAccAPIGatewayStage_cache(t *testing.T) {
})
}

// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/22866
func TestAccAPIGatewayStage_cache_size_cache_disabled(t *testing.T) {
var conf apigateway.Stage
rName := sdkacctest.RandString(5)
resourceName := "aws_api_gateway_stage.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckAPIGatewayTypeEDGE(t) },
ErrorCheck: acctest.ErrorCheck(t, apigateway.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckStageDestroy,
Steps: []resource.TestStep{
{
Config: testAccStageConfigBasic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckStageExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "cache_cluster_enabled", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccStageImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
{
Config: testAccStageConfigCacheSizeCacheDisabled(rName, "0.5"),
Check: resource.ComposeTestCheckFunc(
testAccCheckStageExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "cache_cluster_size", "0.5"),
resource.TestCheckResourceAttr(resourceName, "cache_cluster_enabled", "false"),
),
},
{
Config: testAccStageConfigCacheConfig(rName, "0.5"),
Check: resource.ComposeTestCheckFunc(
testAccCheckStageExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "cache_cluster_size", "0.5"),
resource.TestCheckResourceAttr(resourceName, "cache_cluster_enabled", "true"),
),
},
},
})
}

// Reference: https://github.com/hashicorp/terraform-provider-aws/issues/12756
func TestAccAPIGatewayStage_Disappears_referencingDeployment(t *testing.T) {
var stage apigateway.Stage
Expand Down Expand Up @@ -644,6 +689,17 @@ resource "aws_api_gateway_stage" "test" {
`
}

func testAccStageConfigCacheSizeCacheDisabled(rName, size string) string {
return testAccStageConfig_base(rName) + fmt.Sprintf(`
resource "aws_api_gateway_stage" "test" {
rest_api_id = aws_api_gateway_rest_api.test.id
stage_name = "prod"
deployment_id = aws_api_gateway_deployment.dev.id
cache_cluster_size = %[1]q
}
`, size)
}

func testAccStageConfigCacheConfig(rName, size string) string {
return testAccStageConfig_base(rName) + fmt.Sprintf(`
resource "aws_api_gateway_stage" "test" {
Expand Down

0 comments on commit f76a539

Please sign in to comment.