Skip to content

Commit d667572

Browse files
committed
Add PSC fields to Filestore instance in beta
1 parent 8767bf2 commit d667572

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
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: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package filestore_test
22

33
import (
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

Comments
 (0)