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,109 @@ 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+ resource "google_compute_network" "psc_network" {
649+ provider = google-beta
650+ name = "[[.Name]]"
651+ auto_create_subnetworks = false
652+ }
653+
654+ resource "google_compute_subnetwork" "psc_subnet" {
655+ provider = google-beta
656+ name = "[[.Name]]"
657+ ip_cidr_range = "10.2.0.0/16"
658+ region = "[[.Location]]"
659+ network = google_compute_network.psc_network.id
660+ }
661+
662+ resource "google_network_connectivity_service_connection_policy" "default" {
663+ provider = google-beta
664+ name = "[[.Name]]"
665+ location = "[[.Location]]"
666+ service_class = "google-cloud-filestore"
667+ network = google_compute_network.psc_network.id
668+ psc_config {
669+ subnetworks = [google_compute_subnetwork.psc_subnet.id]
670+ }
671+ }
672+
673+ resource "google_filestore_instance" "instance" {
674+ provider = google-beta
675+ depends_on = [
676+ google_network_connectivity_service_connection_policy.default
677+ ]
678+ name = "[[.Name]]"
679+ location = "[[.Location]]"
680+ tier = "[[.Tier]]"
681+ description = "An instance created during testing."
682+ protocol = "NFS_V4_1"
683+
684+ file_shares {
685+ capacity_gb = 1024
686+ name = "share"
687+
688+ nfs_export_options {
689+ ip_ranges = ["70.0.0.1/24"]
690+ network = google_compute_network.psc_network.name
691+ }
692+ }
693+
694+ networks {
695+ network = google_compute_network.psc_network.name
696+ modes = ["MODE_IPV4"]
697+ connect_mode = "PRIVATE_SERVICE_CONNECT"
698+ }
699+ }
700+ `
701+
702+ {{- end }}
0 commit comments