Skip to content

Commit

Permalink
add optional input ParentService to BootstrapSharedServiceNetworkingC… (
Browse files Browse the repository at this point in the history
  • Loading branch information
shuyama1 authored Dec 8, 2023
1 parent 528ec5d commit a691e03
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mmv1/products/looker/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ examples:
test_vars_overrides:
address_name: 'acctest.BootstrapSharedTestGlobalAddress(t, "looker-vpc-network-1", acctest.AddressWithPrefixLength(20))'
kms_key_name: 'acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name'
network_name: 'acctest.BootstrapSharedServiceNetworkingConnection(t, "looker-vpc-network-1", acctest.AddressWithPrefixLength(20))'
network_name: 'acctest.BootstrapSharedServiceNetworkingConnection(t, "looker-vpc-network-1", acctest.ServiceNetworkWithPrefixLength(20))'
skip_docs: true
parameters:
- !ruby/object:Api::Type::String
Expand Down
36 changes: 33 additions & 3 deletions mmv1/third_party/terraform/acctest/bootstrap_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,35 @@ func BootstrapSharedTestGlobalAddress(t *testing.T, testId string, params ...fun
return address.Name
}

type ServiceNetworkSettings struct {
PrefixLength int
ParentService string
}

func ServiceNetworkWithPrefixLength(prefixLength int) func(*ServiceNetworkSettings) {
return func(settings *ServiceNetworkSettings) {
settings.PrefixLength = prefixLength
}
}

func ServiceNetworkWithParentService(parentService string) func(*ServiceNetworkSettings) {
return func(settings *ServiceNetworkSettings) {
settings.ParentService = parentService
}
}

func NewServiceNetworkSettings(options ...func(*ServiceNetworkSettings)) *ServiceNetworkSettings {
settings := &ServiceNetworkSettings{
PrefixLength: 16, // default prefix length
ParentService: "servicenetworking.googleapis.com", // default parent service
}

for _, o := range options {
o(settings)
}
return settings
}

// BootstrapSharedServiceNetworkingConnection will create a shared network
// if it hasn't been created in the test project, a global address
// if it hasn't been created in the test project, and a service networking connection
Expand All @@ -461,8 +490,9 @@ func BootstrapSharedTestGlobalAddress(t *testing.T, testId string, params ...fun
// https://cloud.google.com/vpc/docs/configure-private-services-access#removing-connection
//
// testId specifies the test for which a shared network and a gobal address are used/initialized.
func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string, params ...func(*AddressSettings)) string {
parentService := "services/servicenetworking.googleapis.com"
func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string, params ...func(*ServiceNetworkSettings)) string {
settings := NewServiceNetworkSettings(params...)
parentService := "services/" + settings.ParentService
projectId := envvar.GetTestProjectFromEnv()

config := BootstrapConfig(t)
Expand All @@ -479,7 +509,7 @@ func BootstrapSharedServiceNetworkingConnection(t *testing.T, testId string, par

networkName := SharedTestNetworkPrefix + testId
networkId := fmt.Sprintf("projects/%v/global/networks/%v", project.ProjectNumber, networkName)
globalAddressName := BootstrapSharedTestGlobalAddress(t, testId, params...)
globalAddressName := BootstrapSharedTestGlobalAddress(t, testId, AddressWithPrefixLength(settings.PrefixLength))

readCall := config.NewServiceNetworkingClient(config.UserAgent).Services.Connections.List(parentService).Network(networkId)
if config.UserProjectOverride {
Expand Down

0 comments on commit a691e03

Please sign in to comment.