|
5 | 5 | "testing" |
6 | 6 |
|
7 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 8 | + {{- if ne $.TargetVersionName "ga" }} |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/plancheck" |
| 10 | + {{- end }} |
8 | 11 | "github.com/hashicorp/terraform-provider-google/google/acctest" |
9 | 12 | ) |
10 | 13 |
|
@@ -343,3 +346,128 @@ resource "google_bigquery_routine" "remote_function_routine" { |
343 | 346 | } |
344 | 347 | `, context) |
345 | 348 | } |
| 349 | + |
| 350 | +{{if ne $.TargetVersionName "ga" }} |
| 351 | +func TestAccBigQueryRoutine_bigqueryRoutinePythonFunction_update(t *testing.T) { |
| 352 | + t.Parallel() |
| 353 | + |
| 354 | + context := map[string]interface{}{ |
| 355 | + "random_suffix": acctest.RandString(t, 10), |
| 356 | + } |
| 357 | + |
| 358 | + acctest.VcrTest(t, resource.TestCase{ |
| 359 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 360 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), |
| 361 | + CheckDestroy: testAccCheckBigQueryRoutineDestroyProducer(t), |
| 362 | + Steps: []resource.TestStep{ |
| 363 | + { |
| 364 | + Config: testAccBigQueryRoutine_bigqueryRoutinePythonFunction_basic(context), |
| 365 | + }, |
| 366 | + { |
| 367 | + ResourceName: "google_bigquery_routine.python_function", |
| 368 | + ImportState: true, |
| 369 | + ImportStateVerify: true, |
| 370 | + }, |
| 371 | + { |
| 372 | + Config: testAccBigQueryRoutine_bigqueryRoutinePythonFunction_update(context), |
| 373 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 374 | + PreApply: []plancheck.PlanCheck{ |
| 375 | + plancheck.ExpectResourceAction("google_bigquery_routine.python_function", plancheck.ResourceActionUpdate), |
| 376 | + }, |
| 377 | + }, |
| 378 | + }, |
| 379 | + { |
| 380 | + ResourceName: "google_bigquery_routine.python_function", |
| 381 | + ImportState: true, |
| 382 | + ImportStateVerify: true, |
| 383 | + }, |
| 384 | + }, |
| 385 | + }) |
| 386 | +} |
| 387 | + |
| 388 | +func testAccBigQueryRoutine_bigqueryRoutinePythonFunction_basic(context map[string]interface{}) string { |
| 389 | + return acctest.Nprintf(` |
| 390 | +resource "google_bigquery_dataset" "test" { |
| 391 | + provider = google-beta |
| 392 | + dataset_id = "tf_test_dataset_id%{random_suffix}" |
| 393 | +} |
| 394 | + |
| 395 | +resource "google_bigquery_routine" "python_function" { |
| 396 | + provider = google-beta |
| 397 | + dataset_id = google_bigquery_dataset.test.dataset_id |
| 398 | + routine_id = "tf_test_routine_id%{random_suffix}" |
| 399 | + routine_type = "SCALAR_FUNCTION" |
| 400 | + language = "PYTHON" |
| 401 | + arguments { |
| 402 | + name = "x" |
| 403 | + data_type = "{\"typeKind\" : \"FLOAT64\"}" |
| 404 | + } |
| 405 | + arguments { |
| 406 | + name = "y" |
| 407 | + data_type = "{\"typeKind\" : \"FLOAT64\"}" |
| 408 | + } |
| 409 | + definition_body = <<-EOS |
| 410 | + def multiply(x, y): |
| 411 | + return x * y |
| 412 | + EOS |
| 413 | + return_type = "{\"typeKind\" : \"FLOAT64\"}" |
| 414 | + python_options { |
| 415 | + entry_point = "multiply" |
| 416 | + } |
| 417 | + external_runtime_options { |
| 418 | + runtime_version = "python-3.11" |
| 419 | + } |
| 420 | + |
| 421 | +} |
| 422 | +`, context) |
| 423 | +} |
| 424 | + |
| 425 | +func testAccBigQueryRoutine_bigqueryRoutinePythonFunction_update(context map[string]interface{}) string { |
| 426 | + return acctest.Nprintf(` |
| 427 | +resource "google_bigquery_dataset" "test" { |
| 428 | + provider = google-beta |
| 429 | + dataset_id = "tf_test_dataset_id%{random_suffix}" |
| 430 | +} |
| 431 | + |
| 432 | +resource "google_bigquery_connection" "test" { |
| 433 | + provider = google-beta |
| 434 | + connection_id = "tf_test_connection_id%{random_suffix}" |
| 435 | + location = "US" |
| 436 | + cloud_resource {} |
| 437 | +} |
| 438 | + |
| 439 | +resource "google_bigquery_routine" "python_function" { |
| 440 | + provider = google-beta |
| 441 | + dataset_id = google_bigquery_dataset.test.dataset_id |
| 442 | + routine_id = "tf_test_routine_id%{random_suffix}" |
| 443 | + routine_type = "SCALAR_FUNCTION" |
| 444 | + language = "PYTHON" |
| 445 | + arguments { |
| 446 | + name = "x" |
| 447 | + data_type = "{\"typeKind\" : \"FLOAT64\"}" |
| 448 | + } |
| 449 | + arguments { |
| 450 | + name = "y" |
| 451 | + data_type = "{\"typeKind\" : \"FLOAT64\"}" |
| 452 | + } |
| 453 | + definition_body = <<-EOS |
| 454 | + def multiply(x, y): |
| 455 | + return x * y |
| 456 | + EOS |
| 457 | + return_type = "{\"typeKind\" : \"FLOAT64\"}" |
| 458 | + python_options { |
| 459 | + entry_point = "multiply" |
| 460 | + packages = ["requests"] |
| 461 | + } |
| 462 | + external_runtime_options { |
| 463 | + container_memory = "512Mi" |
| 464 | + container_cpu = 0.5 |
| 465 | + runtime_connection = "${google_bigquery_connection.test.name}" |
| 466 | + runtime_version = "python-3.11" |
| 467 | + max_batching_rows = "10" |
| 468 | + } |
| 469 | + |
| 470 | +} |
| 471 | +`, context) |
| 472 | +} |
| 473 | +{{- end }} |
0 commit comments