|
| 1 | +package google |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 7 | +) |
| 8 | + |
| 9 | +func TestAccCloudFunctions2Function_update(t *testing.T) { |
| 10 | + t.Parallel() |
| 11 | + |
| 12 | + context := map[string]interface{}{ |
| 13 | + "zip_path": "./test-fixtures/cloudfunctions2/function-source.zip", |
| 14 | + "random_suffix": randString(t, 10), |
| 15 | + } |
| 16 | + |
| 17 | + vcrTest(t, resource.TestCase{ |
| 18 | + PreCheck: func() { testAccPreCheck(t) }, |
| 19 | + Providers: testAccProvidersOiCS, |
| 20 | + CheckDestroy: testAccCheckCloudfunctions2functionDestroyProducer(t), |
| 21 | + Steps: []resource.TestStep{ |
| 22 | + { |
| 23 | + Config: testAccCloudfunctions2function_basic(context), |
| 24 | + }, |
| 25 | + { |
| 26 | + ResourceName: "google_cloudfunctions2_function.terraform-test2", |
| 27 | + ImportState: true, |
| 28 | + ImportStateVerify: true, |
| 29 | + ImportStateVerifyIgnore: []string{"location", "build_config.0.source.0.storage_source.0.object", "build_config.0.source.0.storage_source.0.bucket"}, |
| 30 | + }, |
| 31 | + { |
| 32 | + Config: testAccCloudFunctions2Function_updated(context), |
| 33 | + }, |
| 34 | + { |
| 35 | + ResourceName: "google_cloudfunctions2_function.terraform-test2", |
| 36 | + ImportState: true, |
| 37 | + ImportStateVerify: true, |
| 38 | + ImportStateVerifyIgnore: []string{"location", "build_config.0.source.0.storage_source.0.object", "build_config.0.source.0.storage_source.0.bucket"}, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }) |
| 42 | +} |
| 43 | + |
| 44 | +func testAccCloudfunctions2function_basic(context map[string]interface{}) string { |
| 45 | + return Nprintf(` |
| 46 | +resource "google_storage_bucket" "bucket" { |
| 47 | + provider = google-beta |
| 48 | + name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" |
| 49 | + location = "US" |
| 50 | + uniform_bucket_level_access = true |
| 51 | +} |
| 52 | + |
| 53 | +resource "google_storage_bucket_object" "object" { |
| 54 | + provider = google-beta |
| 55 | + name = "function-source.zip" |
| 56 | + bucket = google_storage_bucket.bucket.name |
| 57 | + source = "%{zip_path}" |
| 58 | +} |
| 59 | + |
| 60 | +resource "google_cloudfunctions2_function" "terraform-test2" { |
| 61 | + provider = google-beta |
| 62 | + name = "tf-test-test-function%{random_suffix}" |
| 63 | + location = "us-central1" |
| 64 | + description = "a new function" |
| 65 | + |
| 66 | + build_config { |
| 67 | + runtime = "nodejs12" |
| 68 | + entry_point = "helloHttp" |
| 69 | + source { |
| 70 | + storage_source { |
| 71 | + bucket = google_storage_bucket.bucket.name |
| 72 | + object = google_storage_bucket_object.object.name |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + service_config { |
| 78 | + max_instance_count = 1 |
| 79 | + available_memory = "1536Mi" |
| 80 | + timeout_seconds = 30 |
| 81 | + } |
| 82 | +} |
| 83 | +`, context) |
| 84 | +} |
| 85 | + |
| 86 | +func testAccCloudFunctions2Function_updated(context map[string]interface{}) string { |
| 87 | + return Nprintf(` |
| 88 | +resource "google_storage_bucket" "bucket" { |
| 89 | + provider = google-beta |
| 90 | + name = "tf-test-cloudfunctions2-function-bucket%{random_suffix}" |
| 91 | + location = "US" |
| 92 | + uniform_bucket_level_access = true |
| 93 | +} |
| 94 | + |
| 95 | +resource "google_storage_bucket_object" "object" { |
| 96 | + provider = google-beta |
| 97 | + name = "function-source.zip" |
| 98 | + bucket = google_storage_bucket.bucket.name |
| 99 | + source = "%{zip_path}" |
| 100 | +} |
| 101 | + |
| 102 | +resource "google_cloudfunctions2_function" "terraform-test2" { |
| 103 | + provider = google-beta |
| 104 | + name = "tf-test-test-function%{random_suffix}" |
| 105 | + location = "us-west1" |
| 106 | + description = "function test" |
| 107 | + |
| 108 | + build_config { |
| 109 | + runtime = "nodejs16" |
| 110 | + entry_point = "helloHttp" |
| 111 | + environment_variables = { |
| 112 | + BUILD_CONFIG_TEST = "build_test" |
| 113 | + } |
| 114 | + source { |
| 115 | + storage_source { |
| 116 | + bucket = google_storage_bucket.bucket.name |
| 117 | + object = google_storage_bucket_object.object.name |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + service_config { |
| 123 | + max_instance_count = 5 |
| 124 | + min_instance_count = 1 |
| 125 | + available_memory = "256M" |
| 126 | + timeout_seconds = 60 |
| 127 | + environment_variables = { |
| 128 | + SERVICE_CONFIG_TEST = "build_test" |
| 129 | + } |
| 130 | + } |
| 131 | +} |
| 132 | +`, context) |
| 133 | +} |
0 commit comments