Skip to content

Commit bdf055f

Browse files
committed
addressed comments
1 parent ce42117 commit bdf055f

File tree

7 files changed

+39
-115
lines changed

7 files changed

+39
-115
lines changed

mmv1/products/storage/AnywhereCache.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ examples:
3232
primary_resource_id: 'cache'
3333
vars:
3434
bucket_name: 'bucket-name'
35-
test_vars_overrides:
36-
bucket_name: '"anywhere-cache-bucket" + acctest.RandString(t, 10)'
3735
external_providers: ["time"]
3836
identity:
3937
- bucket
4038
- anywhereCacheId
4139
custom_code:
42-
custom_create: templates/terraform/custom_create/storage_anywhere_cache_custom_create.go.tmpl
40+
post_create: templates/terraform/post_create/storage_anywhere_cache_post_create.go.tmpl
4341
autogen_async: false
4442
timeouts:
4543
insert_minutes: 240

mmv1/templates/terraform/custom_create/storage_anywhere_cache_custom_create.go.tmpl

-98
This file was deleted.

mmv1/templates/terraform/examples/storage_anywhere_cache_basic.tf.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ resource "google_storage_anywhere_cache" "cache" {
1212
bucket = google_storage_bucket.bucket.name
1313
zone = "us-central1-f"
1414
ttl = "3601s"
15+
depends_on = [time_sleep.destroy_wait_5000_seconds]
1516
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
nameVal, ok := opRes["name"].(string)
2+
if !ok {
3+
return fmt.Errorf("opRes['name'] is not a string: %v", opRes["name"])
4+
}
5+
6+
nameParts := strings.Split(nameVal, "/")
7+
if len(nameParts) != 6 || nameParts[0] != "projects" || nameParts[2] != "buckets" || nameParts[4] != "anywhereCaches" {
8+
return fmt.Errorf("error parsing the anywhereCacheId from %s", nameVal)
9+
}
10+
11+
anywhereCacheID := nameParts[5]
12+
if err := d.Set("anywhere_cache_id", anywhereCacheID); err != nil {
13+
return err
14+
}
15+
16+
// This may have caused the ID to update - update it if so.
17+
id, err = tpgresource.ReplaceVars(d, config, "{{"b/{{bucket}}/anywhereCaches/{{anywhere_cache_id}}"}}")
18+
if err != nil {
19+
return fmt.Errorf("Error constructing id: %s", err)
20+
}
21+
d.SetId(id)

mmv1/third_party/terraform/services/storage/resource_storage_anywhere_cache_test.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
package storage_test
44

55
import (
6-
"testing"
76
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
88
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"testing"
910
)
1011

1112
func TestAccStorageAnywhereCache_basic(t *testing.T) {
1213
t.Parallel()
1314

1415
context := map[string]interface{}{
15-
"bucket_name": "anywhere-cache-bucket" + acctest.RandString(t, 10),
1616
"random_suffix": acctest.RandString(t, 10),
1717
}
1818

@@ -34,6 +34,11 @@ func TestAccStorageAnywhereCache_basic(t *testing.T) {
3434
},
3535
{
3636
Config: testAccStorageAnywhereCache_update(context),
37+
ConfigPlanChecks: resource.ConfigPlanChecks{
38+
PreApply: []plancheck.PlanCheck{
39+
plancheck.ExpectResourceAction("google_storage_anywhere_cache.cache", plancheck.ResourceActionUpdate),
40+
},
41+
},
3742
},
3843
{
3944
ResourceName: "google_storage_anywhere_cache.cache",
@@ -48,7 +53,7 @@ func TestAccStorageAnywhereCache_basic(t *testing.T) {
4853
func testAccStorageAnywhereCache_full(context map[string]interface{}) string {
4954
return acctest.Nprintf(`
5055
resource "google_storage_bucket" "bucket" {
51-
name = "%{bucket_name}"
56+
name = "tf-test-bucket-name%{random_suffix}"
5257
location = "US"
5358
}
5459
@@ -60,16 +65,16 @@ resource "time_sleep" "destroy_wait_5000_seconds" {
6065
resource "google_storage_anywhere_cache" "cache" {
6166
bucket = google_storage_bucket.bucket.name
6267
zone = "us-central1-f"
63-
admission_policy = "admit-on-first-miss"
6468
ttl = "3601s"
69+
depends_on = [time_sleep.destroy_wait_5000_seconds]
6570
}
6671
`, context)
6772
}
6873

6974
func testAccStorageAnywhereCache_update(context map[string]interface{}) string {
7075
return acctest.Nprintf(`
7176
resource "google_storage_bucket" "bucket" {
72-
name = "%{bucket_name}"
77+
name = "tf-test-bucket-name%{random_suffix}"
7378
location = "US"
7479
}
7580
@@ -83,6 +88,7 @@ resource "google_storage_anywhere_cache" "cache" {
8388
zone = "us-central1-f"
8489
admission_policy = "admit-on-second-miss"
8590
ttl = "3620s"
91+
depends_on = [time_sleep.destroy_wait_5000_seconds]
8692
}
8793
`, context)
8894
}

mmv1/third_party/terraform/services/storage/resource_storage_bucket_sweeper.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77
"fmt"
88
"log"
9-
"strings"
109

1110
"github.com/hashicorp/terraform-provider-google/google/sweeper"
1211
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
@@ -131,13 +130,11 @@ func testSweepStorageBucket(region string) error {
131130
continue
132131
}
133132

134-
if strings.HasPrefix(id, "anywhere-cache-bucket") {
135-
readyToDeleteBucket := disableAnywhereCacheIfAny(config, id)
136-
if !readyToDeleteBucket {
137-
log.Printf("[INFO][SWEEPER_LOG] Bucket %s has anywhere caches, requests have been made to backend to disable them, The bucket would be automatically deleted once caches are deleted from bucket", id)
138-
bucketWithCaches++
139-
continue
140-
}
133+
readyToDeleteBucket := disableAnywhereCacheIfAny(config, id)
134+
if !readyToDeleteBucket {
135+
log.Printf("[INFO][SWEEPER_LOG] Bucket %s has anywhere caches, requests have been made to backend to disable them, The bucket would be automatically deleted once caches are deleted from bucket", id)
136+
bucketWithCaches++
137+
continue
141138
}
142139

143140
deleteUrl := fmt.Sprintf("https://storage.googleapis.com/storage/v1/b/%s", id)

mmv1/third_party/terraform/sweeper/gcp_sweeper.go

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var testResourcePrefixes = []string{
2828
"cluster-", // https://github.com/hashicorp/terraform-provider-google/issues/8924
2929
"k8s-fw-", // firewall rules are getting created and not cleaned up by k8 resources using this prefix
3030
"ext-tf-test", // Cloud Tasks Queues created automatically by tests for `google_firebase_extensions_instance`.
31-
"anywhere-cache-bucket", // GCS bucket with anywhere caches on it.
3231
}
3332

3433
// SharedConfigForRegion returns a common config setup needed for the sweeper

0 commit comments

Comments
 (0)