|
| 1 | +package google |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 8 | +) |
| 9 | + |
| 10 | +func TestAccDataSourceGoogleCloudFunctions2Function_basic(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + |
| 13 | + funcDataNameHttp := "data.google_cloudfunctions2_function.function_http_v2" |
| 14 | + functionName := fmt.Sprintf("tf-test-%s", randString(t, 10)) |
| 15 | + bucketName := fmt.Sprintf("tf-test-bucket-%d", randInt(t)) |
| 16 | + zipFilePath := "./test-fixtures/cloudfunctions2/function-source.zip" |
| 17 | + |
| 18 | + vcrTest(t, resource.TestCase{ |
| 19 | + PreCheck: func() { testAccPreCheck(t) }, |
| 20 | + Providers: testAccProviders, |
| 21 | + CheckDestroy: testAccCheckCloudfunctions2functionDestroyProducer(t), |
| 22 | + Steps: []resource.TestStep{ |
| 23 | + { |
| 24 | + Config: testAccDataSourceGoogleCloudFunctions2FunctionConfig(functionName, |
| 25 | + bucketName, zipFilePath), |
| 26 | + Check: resource.ComposeTestCheckFunc( |
| 27 | + checkDataSourceStateMatchesResourceStateWithIgnores(funcDataNameHttp, |
| 28 | + "google_cloudfunctions2_function.function_http_v2", map[string]struct{}{"build_config.0.source.0.storage_source.0.bucket": {}, "build_config.0.source.0.storage_source.0.object": {}}), |
| 29 | + ), |
| 30 | + }, |
| 31 | + }, |
| 32 | + }) |
| 33 | +} |
| 34 | + |
| 35 | +func testAccDataSourceGoogleCloudFunctions2FunctionConfig(functionName, bucketName, zipFilePath string) string { |
| 36 | + return fmt.Sprintf(` |
| 37 | +resource "google_storage_bucket" "bucket" { |
| 38 | + name = "%s" |
| 39 | + location = "US" |
| 40 | +} |
| 41 | + |
| 42 | +resource "google_storage_bucket_object" "object" { |
| 43 | + name = "function-source.zip" |
| 44 | + bucket = google_storage_bucket.bucket.name |
| 45 | + source = "%s" |
| 46 | +} |
| 47 | +
|
| 48 | +resource "google_cloudfunctions2_function" "function_http_v2" { |
| 49 | + name = "%s" |
| 50 | + location = "us-central1" |
| 51 | + description = "a new function" |
| 52 | +
|
| 53 | + build_config { |
| 54 | + runtime = "nodejs12" |
| 55 | + entry_point = "helloHttp" |
| 56 | + source { |
| 57 | + storage_source { |
| 58 | + bucket = google_storage_bucket.bucket.name |
| 59 | + object = google_storage_bucket_object.object.name |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | +
|
| 64 | + service_config { |
| 65 | + max_instance_count = 1 |
| 66 | + available_memory = "256Mi" |
| 67 | + timeout_seconds = 60 |
| 68 | + } |
| 69 | +} |
| 70 | +data "google_cloudfunctions2_function" "function_http_v2" { |
| 71 | + name = google_cloudfunctions2_function.function_http_v2.name |
| 72 | + location = "us-central1" |
| 73 | +} |
| 74 | +`, bucketName, zipFilePath, functionName) |
| 75 | +} |
0 commit comments