@@ -592,4 +592,166 @@ resource "google_filestore_instance" "instance" {
592592}
593593` , name, location, tier)
594594}
595+
596+ {{- end }}
597+ {{- if ne $ .TargetVersionName " ga" }}
598+
599+ func TestAccFilestoreInstance_psc(t *testing.T ) {
600+ t.Parallel ()
601+
602+ context := map[string]interface{}{
603+ " name" : fmt.Sprintf (" tf-test-%d " , acctest.RandInt (t)),
604+ " location" : " us-central1" ,
605+ " tier" : " REGIONAL" ,
606+ }
607+
608+ acctest.VcrTest (t, resource.TestCase {
609+ PreCheck: func() { acctest.AccTestPreCheck (t) },
610+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories (t),
611+ CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
612+ Steps: []resource.TestStep {
613+ {
614+ Config: testAccFilestoreInstance_psc(context),
615+ Check: resource.ComposeTestCheckFunc (
616+ resource.TestCheckResourceAttr (" google_filestore_instance.instance" , " networks.0.connect_mode" , " PRIVATE_SERVICE_CONNECT" ),
617+ ),
618+ },
619+ {
620+ ResourceName: " google_filestore_instance.instance" ,
621+ ImportState: true,
622+ ImportStateVerify: true,
623+ ImportStateVerifyIgnore: []string{" zone" },
624+ },
625+ },
626+ })
627+ }
628+
629+ func testAccFilestoreInstance_psc(context map[string]interface{}) string {
630+ return acctest.Nprintf (`
631+ data "google_client_config" "current" {
632+ provider = google-beta
633+ }
634+
635+ resource "google_compute_network" "psc_network" {
636+ provider = google-beta
637+ name = "%{name}"
638+ auto_create_subnetworks = false
639+ }
640+
641+ resource "google_compute_subnetwork" "psc_subnet" {
642+ provider = google-beta
643+ name = "%{name}"
644+ ip_cidr_range = "10.2.0.0/16"
645+ region = "%{location}"
646+ network = google_compute_network.psc_network.id
647+ }
648+
649+ resource "google_network_connectivity_service_connection_policy" "default" {
650+ provider = google-beta
651+ name = "%{name}"
652+ location = "%{location}"
653+ service_class = "google-cloud-filestore"
654+ network = google_compute_network.psc_network.id
655+ psc_config {
656+ subnetworks = [google_compute_subnetwork.psc_subnet.id]
657+ }
658+ }
659+
660+ resource "google_filestore_instance" "instance" {
661+ provider = google-beta
662+ depends_on = [
663+ google_network_connectivity_service_connection_policy.default
664+ ]
665+ name = "%{name}"
666+ location = "%{location}"
667+ tier = "%{tier}"
668+ description = "An instance created during testing."
669+ protocol = "NFS_V4_1"
670+
671+ file_shares {
672+ capacity_gb = 1024
673+ name = "share"
674+
675+ nfs_export_options {
676+ ip_ranges = ["70.0.0.1/24"]
677+ network = google_compute_network.psc_network.name
678+ }
679+ }
680+
681+ networks {
682+ network = google_compute_network.psc_network.name
683+ modes = ["MODE_IPV4"]
684+ connect_mode = "PRIVATE_SERVICE_CONNECT"
685+ psc_config {
686+ endpoint_project = data.google_client_config.current.project
687+ }
688+ }
689+ }
690+ ` , context)
691+ }
692+
693+ func TestAccFilestoreInstance_nfsExportOptionsNetwork_update(t *testing.T ) {
694+ t.Parallel ()
695+
696+ name := fmt.Sprintf (" tf-test-%d " , acctest.RandInt (t))
697+ location := " us-central1-a"
698+ tier := " ZONAL"
699+
700+ // Currently, we can only alternate between an empty network and the instance network of non-PSC instances.
701+ acctest.VcrTest (t, resource.TestCase {
702+ PreCheck: func() { acctest.AccTestPreCheck (t) },
703+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories (t),
704+ CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
705+ Steps: []resource.TestStep {
706+ {
707+ Config: testAccFilestoreInstance_nfsExportOptionsNetwork_update(name, location, tier, " " ),
708+ Check: resource.TestCheckResourceAttr (" google_filestore_instance.instance" , " file_shares.0.nfs_export_options.0.network" , " " ),
709+ },
710+ {
711+ ResourceName: " google_filestore_instance.instance" ,
712+ ImportState: true,
713+ ImportStateVerify: true,
714+ ImportStateVerifyIgnore: []string{" zone" },
715+ },
716+ {
717+ Config: testAccFilestoreInstance_nfsExportOptionsNetwork_update(name, location, tier, " default" ),
718+ Check: resource.TestCheckResourceAttr (" google_filestore_instance.instance" , " file_shares.0.nfs_export_options.0.network" , " default" ),
719+ },
720+ {
721+ ResourceName: " google_filestore_instance.instance" ,
722+ ImportState: true,
723+ ImportStateVerify: true,
724+ ImportStateVerifyIgnore: []string{" zone" },
725+ },
726+ },
727+ })
728+ }
729+
730+ func testAccFilestoreInstance_nfsExportOptionsNetwork_update(name, location, tier, network string) string {
731+ return fmt.Sprintf (`
732+ resource "google_filestore_instance" "instance" {
733+ provider = google-beta
734+ name = "%s "
735+ zone = "%s "
736+ tier = "%s "
737+ description = "An instance created during testing."
738+
739+ file_shares {
740+ capacity_gb = 1024
741+ name = "share"
742+
743+ nfs_export_options {
744+ ip_ranges = ["70.0.0.1/24"]
745+ network = "%s "
746+ }
747+ }
748+
749+ networks {
750+ network = "default"
751+ modes = ["MODE_IPV4"]
752+ }
753+ }
754+ ` , name, location, tier, network)
755+ }
756+
595757{{- end }}
0 commit comments