11package filestore_test
22
33import (
4+ " bytes"
45 " context"
56 " fmt"
67 " reflect"
78 " regexp"
89 " testing"
10+ " text/template"
911
1012 " github.com/hashicorp/terraform-plugin-testing/helper/resource"
1113 " github.com/hashicorp/terraform-provider-google/google/acctest"
@@ -592,4 +594,114 @@ resource "google_filestore_instance" "instance" {
592594}
593595` , name, location, tier)
594596}
595- {{- end }}
597+
598+ {{- end }}
599+ {{- if ne $ .TargetVersionName " ga" }}
600+
601+ func TestAccFilestoreInstance_psc(t *testing.T ) {
602+ t.Parallel ()
603+
604+ data := map[string]string{
605+ " Name" : fmt.Sprintf (" tf-test-%d " , acctest.RandInt (t)),
606+ " Location" : " us-central1" ,
607+ " Tier" : " REGIONAL" ,
608+ }
609+ config, err := executeTemplate(pscInstanceConfigTemplate, data)
610+ if err != nil {
611+ t.Fatalf (" Failed to execute config template: %v " , err)
612+ }
613+
614+ acctest.VcrTest (t, resource.TestCase {
615+ PreCheck: func() { acctest.AccTestPreCheck (t) },
616+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories (t),
617+ CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
618+ Steps: []resource.TestStep {
619+ {
620+ Config: config,
621+ Check: resource.ComposeTestCheckFunc (
622+ resource.TestCheckResourceAttr (" google_filestore_instance.instance" , " networks.0.connect_mode" , " PRIVATE_SERVICE_CONNECT" ),
623+ ),
624+ },
625+ {
626+ ResourceName: " google_filestore_instance.instance" ,
627+ ImportState: true,
628+ ImportStateVerify: true,
629+ ImportStateVerifyIgnore: []string{" zone" },
630+ },
631+ },
632+ })
633+ }
634+
635+ func executeTemplate(tmplString string, data any) (string, error) {
636+ tmpl, err := template .New (" tmpl" ).Delims (" [[" , " ]]" ).Parse (tmplString)
637+ if err != nil {
638+ return " " , err
639+ }
640+ var b bytes.Buffer
641+ if err := tmpl.Execute (&b, data); err != nil {
642+ return " " , err
643+ }
644+ return b.String (), nil
645+ }
646+
647+ const pscInstanceConfigTemplate = `
648+ data "google_client_config" "current" {}
649+
650+ resource "google_compute_network" "psc_network" {
651+ provider = google-beta
652+ name = "[[.Name]]"
653+ auto_create_subnetworks = false
654+ }
655+
656+ resource "google_compute_subnetwork" "psc_subnet" {
657+ provider = google-beta
658+ name = "[[.Name]]"
659+ ip_cidr_range = "10.2.0.0/16"
660+ region = "[[.Location]]"
661+ network = google_compute_network.psc_network.id
662+ }
663+
664+ resource "google_network_connectivity_service_connection_policy" "default" {
665+ provider = google-beta
666+ name = "[[.Name]]"
667+ location = "[[.Location]]"
668+ service_class = "google-cloud-filestore"
669+ network = google_compute_network.psc_network.id
670+ psc_config {
671+ subnetworks = [google_compute_subnetwork.psc_subnet.id]
672+ }
673+ }
674+
675+ resource "google_filestore_instance" "instance" {
676+ provider = google-beta
677+ depends_on = [
678+ google_network_connectivity_service_connection_policy.default
679+ ]
680+ name = "[[.Name]]"
681+ location = "[[.Location]]"
682+ tier = "[[.Tier]]"
683+ description = "An instance created during testing."
684+ protocol = "NFS_V4_1"
685+
686+ file_shares {
687+ capacity_gb = 1024
688+ name = "share"
689+
690+ nfs_export_options {
691+ ip_ranges = ["70.0.0.1/24"]
692+ network = google_compute_network.psc_network.name
693+ }
694+ }
695+
696+ networks {
697+ network = google_compute_network.psc_network.name
698+ modes = ["MODE_IPV4"]
699+ connect_mode = "PRIVATE_SERVICE_CONNECT"
700+ psc_config {
701+ endpoint_project = data.google_client_config.current.project
702+ }
703+ }
704+ }
705+ `
706+
707+ {{- end }}
0 commit comments