Skip to content

Commit e1f62d7

Browse files
oselaBBBmau
authored andcommitted
Add PSC fields to Filestore instance in beta (GoogleCloudPlatform#13883)
1 parent bc215e5 commit e1f62d7

File tree

2 files changed

+184
-0
lines changed

2 files changed

+184
-0
lines changed

mmv1/products/filestore/Instance.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ properties:
209209
An integer representing the anonymous group id with a default value of 65534.
210210
Anon_gid may only be set with squashMode of ROOT_SQUASH. An error will be returned
211211
if this field is specified for other squashMode settings.
212+
- name: 'network'
213+
type: String
214+
min_version: beta
215+
description: |
216+
The source VPC network for `ip_ranges`.
217+
Required for instances using Private Service Connect, optional otherwise.
212218
max_size: 10
213219
max_size: 1
214220
- name: 'networks'
@@ -273,6 +279,22 @@ properties:
273279
enum_values:
274280
- 'DIRECT_PEERING'
275281
- 'PRIVATE_SERVICE_ACCESS'
282+
- 'PRIVATE_SERVICE_CONNECT'
283+
- name: 'pscConfig'
284+
type: NestedObject
285+
min_version: beta
286+
description: |
287+
Private Service Connect configuration.
288+
Should only be set when connect_mode is PRIVATE_SERVICE_CONNECT.
289+
properties:
290+
- name: endpointProject
291+
type: String
292+
description: |
293+
Consumer service project in which the Private Service Connect endpoint
294+
would be set up. This is optional, and only relevant in case the network
295+
is a shared VPC. If this is not specified, the endpoint would be set up
296+
in the VPC host project.
297+
immutable: true
276298
min_size: 1
277299
- name: 'etag'
278300
type: String

mmv1/third_party/terraform/services/filestore/resource_filestore_instance_test.go.tmpl

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)