|
4 | 4 | "testing" |
5 | 5 |
|
6 | 6 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 7 | +{{ if ne $.TargetVersionName "ga" }} |
| 8 | + "github.com/hashicorp/terraform-plugin-testing/plancheck" |
| 9 | +{{ end }} |
7 | 10 | "github.com/hashicorp/terraform-provider-google/google/acctest" |
8 | 11 | "github.com/hashicorp/terraform-provider-google/google/envvar" |
9 | 12 | ) |
@@ -642,3 +645,152 @@ output "binary_authorization_policy_eq" { |
642 | 645 | } |
643 | 646 | `, context) |
644 | 647 | } |
| 648 | + |
| 649 | +{{ if ne $.TargetVersionName "ga" }} |
| 650 | + |
| 651 | +func TestAccCloudfunctions2function_cloudfunctions2DirectvpcExample_update(t *testing.T) { |
| 652 | + t.Parallel() |
| 653 | + |
| 654 | + context := map[string]interface{}{ |
| 655 | + "project": envvar.GetTestProjectFromEnv(), |
| 656 | + "location": "us-central1", |
| 657 | + "zip_path": "./test-fixtures/function-source.zip", |
| 658 | + "random_suffix": acctest.RandString(t, 10), |
| 659 | + } |
| 660 | + |
| 661 | + acctest.VcrTest(t, resource.TestCase{ |
| 662 | + PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| 663 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), |
| 664 | + CheckDestroy: testAccCheckCloudfunctions2functionDestroyProducer(t), |
| 665 | + Steps: []resource.TestStep{ |
| 666 | + { |
| 667 | + Config: testAccCloudfunctions2function_cloudfunctions2DirectvpcExample_basic(context), |
| 668 | + }, |
| 669 | + { |
| 670 | + ResourceName: "google_cloudfunctions2_function.function", |
| 671 | + ImportState: true, |
| 672 | + ImportStateVerify: true, |
| 673 | + ImportStateVerifyIgnore: []string{"build_config.0.source.0.storage_source.0.bucket", "build_config.0.source.0.storage_source.0.object", "labels", "location", "terraform_labels"}, |
| 674 | + }, |
| 675 | + { |
| 676 | + Config: testAccCloudfunctions2function_cloudfunctions2DirectvpcExample_update(context), |
| 677 | + ConfigPlanChecks: resource.ConfigPlanChecks{ |
| 678 | + PreApply: []plancheck.PlanCheck{ |
| 679 | + plancheck.ExpectResourceAction("google_cloudfunctions2_function.function", plancheck.ResourceActionUpdate), |
| 680 | + }, |
| 681 | + }, |
| 682 | + }, |
| 683 | + { |
| 684 | + ResourceName: "google_cloudfunctions2_function.function", |
| 685 | + ImportState: true, |
| 686 | + ImportStateVerify: true, |
| 687 | + ImportStateVerifyIgnore: []string{"build_config.0.source.0.storage_source.0.bucket", "build_config.0.source.0.storage_source.0.object", "build_config.0.source.0.storage_source.0.generation", "labels", "location", "terraform_labels"}, |
| 688 | + }, |
| 689 | + }, |
| 690 | + }) |
| 691 | +} |
| 692 | + |
| 693 | +func testAccCloudfunctions2function_cloudfunctions2DirectvpcExample_basic(context map[string]interface{}) string { |
| 694 | + return acctest.Nprintf(` |
| 695 | +locals { |
| 696 | + project = "%{project}" # Google Cloud Platform Project ID |
| 697 | +} |
| 698 | + |
| 699 | +resource "google_storage_bucket" "bucket" { |
| 700 | + provider = google-beta |
| 701 | + name = "${local.project}-tf-test-gcf-source%{random_suffix}" # Every bucket name must be globally unique |
| 702 | + location = "US" |
| 703 | + uniform_bucket_level_access = true |
| 704 | +} |
| 705 | + |
| 706 | +resource "google_storage_bucket_object" "object" { |
| 707 | + provider = google-beta |
| 708 | + name = "function-source.zip" |
| 709 | + bucket = google_storage_bucket.bucket.name |
| 710 | + source = "%{zip_path}" # Add path to the zipped function source code |
| 711 | +} |
| 712 | + |
| 713 | +resource "google_cloudfunctions2_function" "function" { |
| 714 | + provider = google-beta |
| 715 | + name = "tf-test-function-v2%{random_suffix}" |
| 716 | + location = "us-central1" |
| 717 | + description = "a new function" |
| 718 | + |
| 719 | + build_config { |
| 720 | + runtime = "nodejs20" |
| 721 | + entry_point = "helloHttp" # Set the entry point |
| 722 | + source { |
| 723 | + storage_source { |
| 724 | + bucket = google_storage_bucket.bucket.name |
| 725 | + object = google_storage_bucket_object.object.name |
| 726 | + } |
| 727 | + } |
| 728 | + } |
| 729 | + |
| 730 | + service_config { |
| 731 | + max_instance_count = 1 |
| 732 | + available_memory = "256M" |
| 733 | + timeout_seconds = 60 |
| 734 | + direct_vpc_network_interface { |
| 735 | + network = "default" |
| 736 | + subnetwork = "default" |
| 737 | + tags = ["tag1", "tag2"] |
| 738 | + } |
| 739 | + direct_vpc_egress = "VPC_EGRESS_ALL_TRAFFIC" |
| 740 | + } |
| 741 | +} |
| 742 | +`, context) |
| 743 | +} |
| 744 | + |
| 745 | +func testAccCloudfunctions2function_cloudfunctions2DirectvpcExample_update(context map[string]interface{}) string { |
| 746 | + return acctest.Nprintf(` |
| 747 | +locals { |
| 748 | + project = "%{project}" # Google Cloud Platform Project ID |
| 749 | +} |
| 750 | + |
| 751 | +resource "google_storage_bucket" "bucket" { |
| 752 | + provider = google-beta |
| 753 | + name = "${local.project}-tf-test-gcf-source%{random_suffix}" # Every bucket name must be globally unique |
| 754 | + location = "US" |
| 755 | + uniform_bucket_level_access = true |
| 756 | +} |
| 757 | + |
| 758 | +resource "google_storage_bucket_object" "object" { |
| 759 | + provider = google-beta |
| 760 | + name = "function-source.zip" |
| 761 | + bucket = google_storage_bucket.bucket.name |
| 762 | + source = "%{zip_path}" # Add path to the zipped function source code |
| 763 | +} |
| 764 | + |
| 765 | +resource "google_cloudfunctions2_function" "function" { |
| 766 | + provider = google-beta |
| 767 | + name = "tf-test-function-v2%{random_suffix}" |
| 768 | + location = "us-central1" |
| 769 | + description = "a new function" |
| 770 | + |
| 771 | + build_config { |
| 772 | + runtime = "nodejs20" |
| 773 | + entry_point = "helloHttp" # Set the entry point |
| 774 | + source { |
| 775 | + storage_source { |
| 776 | + bucket = google_storage_bucket.bucket.name |
| 777 | + object = google_storage_bucket_object.object.name |
| 778 | + } |
| 779 | + } |
| 780 | + } |
| 781 | + |
| 782 | + service_config { |
| 783 | + max_instance_count = 1 |
| 784 | + available_memory = "256M" |
| 785 | + timeout_seconds = 60 |
| 786 | + direct_vpc_network_interface { |
| 787 | + network = "default" |
| 788 | + subnetwork = "default" |
| 789 | + tags = ["tag3", "tag4"] |
| 790 | + } |
| 791 | + direct_vpc_egress = "VPC_EGRESS_PRIVATE_RANGES_ONLY" |
| 792 | + } |
| 793 | +} |
| 794 | +`, context) |
| 795 | +} |
| 796 | +{{ end }} |
0 commit comments