|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +package storage_test |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/terraform" |
| 12 | + |
| 13 | + "github.com/hashicorp/terraform-provider-google/google/acctest" |
| 14 | + "github.com/hashicorp/terraform-provider-google/google/tpgresource" |
| 15 | + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" |
| 16 | +) |
| 17 | + |
| 18 | +func TestAccStorageAnywhereCache_update(t *testing.T) { |
| 19 | + t.Parallel() |
| 20 | + |
| 21 | + context := map[string]interface{}{ |
| 22 | + "random_suffix": acctest.RandString(t, 10), |
| 23 | + } |
| 24 | + |
| 25 | + acctest.VcrTest(t, resource.TestCase{ |
| 26 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 27 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| 28 | + CheckDestroy: testAccCheckStorageAnywhereCacheDestroyProducer(t), |
| 29 | + Steps: []resource.TestStep{ |
| 30 | + { |
| 31 | + Config: testAccStorageAnywhereCache_full(context), |
| 32 | + }, |
| 33 | + { |
| 34 | + ResourceName: "google_storage_anywhere_cache.cache", |
| 35 | + ImportState: true, |
| 36 | + ImportStateVerify: true, |
| 37 | + ImportStateVerifyIgnore: []string{"bucket"}, |
| 38 | + }, |
| 39 | + { |
| 40 | + Config: testAccStorageAnywhereCache_update(context), |
| 41 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 42 | + PreApply: []plancheck.PlanCheck{ |
| 43 | + plancheck.ExpectResourceAction("google_storage_anywhere_cache.cache", plancheck.ResourceActionUpdate), |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + { |
| 48 | + ResourceName: "google_storage_anywhere_cache.cache", |
| 49 | + ImportState: true, |
| 50 | + ImportStateVerify: true, |
| 51 | + ImportStateVerifyIgnore: []string{"bucket"}, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }) |
| 55 | +} |
| 56 | + |
| 57 | +func testAccStorageAnywhereCache_full(context map[string]interface{}) string { |
| 58 | + return acctest.Nprintf(` |
| 59 | +resource "google_storage_bucket" "bucket" { |
| 60 | + name = "tf-test-my-bucket%{random_suffix}" |
| 61 | + location = "US" |
| 62 | +} |
| 63 | +
|
| 64 | +resource "google_storage_bucket_iam_binding" "binding" { |
| 65 | + bucket = google_storage_bucket.bucket.name |
| 66 | + role = "roles/storage.admin" |
| 67 | + members = [ |
| 68 | + "allUsers", |
| 69 | + ] |
| 70 | + depends_on = [ google_storage_bucket.bucket ] |
| 71 | +} |
| 72 | +
|
| 73 | +resource "time_sleep" "wait_4000_seconds" { |
| 74 | + depends_on = [google_storage_bucket.bucket] |
| 75 | + destroy_duration = "4000s" |
| 76 | +} |
| 77 | +
|
| 78 | +resource "google_storage_anywhere_cache" "cache" { |
| 79 | + bucket = google_storage_bucket.bucket.name |
| 80 | + zone = "us-central1-f" |
| 81 | + admission_policy = "admit-on-first-miss" |
| 82 | + ttl = "90000s" |
| 83 | + depends_on = [ google_storage_bucket_iam_binding.binding ] |
| 84 | +} |
| 85 | +`, context) |
| 86 | +} |
| 87 | + |
| 88 | +func testAccStorageAnywhereCache_update(context map[string]interface{}) string { |
| 89 | + return acctest.Nprintf(` |
| 90 | +resource "google_storage_bucket" "bucket" { |
| 91 | + name = "tf-test-my-bucket%{random_suffix}" |
| 92 | + location = "US" |
| 93 | +} |
| 94 | +
|
| 95 | +resource "google_storage_bucket_iam_binding" "binding" { |
| 96 | + bucket = google_storage_bucket.bucket.name |
| 97 | + role = "roles/storage.admin" |
| 98 | + members = [ |
| 99 | + "allUsers", |
| 100 | + ] |
| 101 | + depends_on = [ google_storage_bucket.bucket ] |
| 102 | +} |
| 103 | +
|
| 104 | +resource "time_sleep" "wait_4000_seconds" { |
| 105 | + depends_on = [google_storage_bucket.bucket] |
| 106 | + destroy_duration = "4000s" |
| 107 | +} |
| 108 | +
|
| 109 | +resource "google_storage_anywhere_cache" "cache" { |
| 110 | + bucket = google_storage_bucket.bucket.name |
| 111 | + zone = "us-central1-f" |
| 112 | + admission_policy = "admit-on-second-miss" |
| 113 | + ttl = "100000s" |
| 114 | + depends_on = [ google_storage_bucket_iam_binding.binding ] |
| 115 | +} |
| 116 | +`, context) |
| 117 | +} |
| 118 | + |
0 commit comments