Skip to content

Commit

Permalink
Network Connectivity Hub (GoogleCloudPlatform#5574)
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn authored and betsy-lichtenberg committed Apr 25, 2022
1 parent 2c8347d commit 5eabf93
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 3 deletions.
5 changes: 3 additions & 2 deletions mmv1/third_party/terraform/utils/config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ type Config struct {
CloudResourceManagerBasePath string
EventarcBasePath string
GkeHubBasePath string
ContainerAzureBasePath string
ContainerAwsBasePath string
ContainerAzureBasePath string
ContainerAwsBasePath string
NetworkConnectivityBasePath string
OrgPolicyBasePath string
RecaptchaEnterpriseBasePath string
<% if version == 'private' -%>
Expand Down
3 changes: 3 additions & 0 deletions mmv1/third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func Provider() *schema.Provider {
CloudResourceManagerEndpointEntryKey: CloudResourceManagerEndpointEntry,
EventarcEndpointEntryKey: EventarcEndpointEntry,
GkeHubFeatureCustomEndpointEntryKey: GkeHubFeatureCustomEndpointEntry,
NetworkConnectivityEndpointEntryKey: NetworkConnectivityEndpointEntry,
OrgPolicyEndpointEntryKey: OrgPolicyEndpointEntry,
PrivatecaCertificateTemplateEndpointEntryKey: PrivatecaCertificateTemplateCustomEndpointEntry,
RecaptchaEnterpriseEndpointEntryKey: RecaptchaEnterpriseEndpointEntry,
Expand Down Expand Up @@ -472,6 +473,7 @@ end # products.each do
"google_gke_hub_feature_membership": resourceGkeHubFeatureMembership(),
"google_monitoring_monitored_project": resourceMonitoringMonitoredProject(),
<% end -%>
"google_network_connectivity_hub": resourceNetworkConnectivityHub(),
"google_org_policy_policy": resourceOrgPolicyPolicy(),
"google_os_config_os_policy_assignment": resourceOSConfigOSPolicyAssignment(),
<% if version == 'private' -%>
Expand Down Expand Up @@ -662,6 +664,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.CloudResourceManagerBasePath = d.Get(CloudResourceManagerEndpointEntryKey).(string)
config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
config.GkeHubBasePath = d.Get(GkeHubFeatureCustomEndpointEntryKey).(string)
config.NetworkConnectivityBasePath = d.Get(NetworkConnectivityEndpointEntryKey).(string)
config.OrgPolicyBasePath = d.Get(OrgPolicyEndpointEntryKey).(string)
config.PrivatecaBasePath = d.Get(PrivatecaCertificateTemplateEndpointEntryKey).(string)
config.ContainerAwsBasePath = d.Get(ContainerAwsCustomEndpointEntryKey).(string)
Expand Down
8 changes: 8 additions & 0 deletions tpgtools/api/networkconnectivity/samples/basic.hub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "{{hub}}",
"project": "{{project}}",
"labels": {
"label-one": "value-one"
},
"description": "A sample hub"
}
28 changes: 28 additions & 0 deletions tpgtools/api/networkconnectivity/samples/basic_hub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: basic_hub
description: A basic test of a networkconnectivity hub
type: hub
versions:
- ga
- beta
resource: samples/basic.hub.json
updates:
- resource: samples/update.hub.json
dependencies: []
variables:
- name: hub
type: resource_name
- name: project
type: project
8 changes: 8 additions & 0 deletions tpgtools/api/networkconnectivity/samples/update.hub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "{{hub}}",
"project": "{{project}}",
"labels": {
"label-two": "value-one"
},
"description": "An updated sample hub"
}
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions tpgtools/overrides/networkconnectivity/samples/hub/basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
updates:
variables:
- name: "project"
type: "project"
- name: "hub"
type: "resource_name"
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion tpgtools/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func createPropertiesFromSchema(schema *openapi.Schema, typeFetcher *TypeFetcher

if dsfOk {
p.DiffSuppressFunc = &dsf.DiffSuppressFunc
} else {
} else if !(p.Computed && !p.Optional) {
p.DiffSuppressFunc = p.DefaultDiffSuppress()
}

Expand Down
152 changes: 152 additions & 0 deletions tpgtools/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
eventarcBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc/beta"
gkehubBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
monitoringBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/monitoring/beta"
networkconnectivity "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/networkconnectivity"
networkconnectivityBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/networkconnectivity/beta"
orgpolicy "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/orgpolicy"
orgpolicyBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/orgpolicy/beta"
osconfig "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/osconfig"
Expand Down Expand Up @@ -97,6 +99,8 @@ func DCLToTerraformReference(resourceType string, version string) (string, error
return "google_gke_hub_feature_membership", nil
case "MonitoringMonitoredProject":
return "google_monitoring_monitored_project", nil
case "NetworkConnectivityHub":
return "google_network_connectivity_hub", nil
case "OrgPolicyPolicy":
return "google_org_policy_policy", nil
case "OSConfigOSPolicyAssignment":
Expand Down Expand Up @@ -141,6 +145,8 @@ func DCLToTerraformReference(resourceType string, version string) (string, error
return "google_dataproc_workflow_template", nil
case "EventarcTrigger":
return "google_eventarc_trigger", nil
case "NetworkConnectivityHub":
return "google_network_connectivity_hub", nil
case "OrgPolicyPolicy":
return "google_org_policy_policy", nil
case "OSConfigOSPolicyAssignment":
Expand Down Expand Up @@ -184,6 +190,8 @@ func DCLToTerraformReference(resourceType string, version string) (string, error
return "google_dataproc_workflow_template", nil
case "EventarcTrigger":
return "google_eventarc_trigger", nil
case "NetworkConnectivityHub":
return "google_network_connectivity_hub", nil
case "OrgPolicyPolicy":
return "google_org_policy_policy", nil
case "OsConfigOSPolicyAssignment":
Expand Down Expand Up @@ -233,6 +241,8 @@ func DCLToTerraformSampleName(service, resource string) (string, string, error)
return "Dataproc", "WorkflowTemplate", nil
case "eventarctrigger":
return "Eventarc", "Trigger", nil
case "networkconnectivityhub":
return "NetworkConnectivity", "Hub", nil
case "orgpolicypolicy":
return "OrgPolicy", "Policy", nil
case "osconfigospolicyassignment":
Expand Down Expand Up @@ -369,6 +379,12 @@ func ConvertSampleJSONToHCL(resourceType string, version string, hasGAEquivalent
return "", err
}
return MonitoringMonitoredProjectBetaAsHCL(*r, hasGAEquivalent)
case "NetworkConnectivityHub":
r := &networkconnectivityBeta.Hub{}
if err := json.Unmarshal(b, r); err != nil {
return "", err
}
return NetworkConnectivityHubBetaAsHCL(*r, hasGAEquivalent)
case "OrgPolicyPolicy":
r := &orgpolicyBeta.Policy{}
if err := json.Unmarshal(b, r); err != nil {
Expand Down Expand Up @@ -493,6 +509,12 @@ func ConvertSampleJSONToHCL(resourceType string, version string, hasGAEquivalent
return "", err
}
return EventarcTriggerAsHCL(*r, hasGAEquivalent)
case "NetworkConnectivityHub":
r := &networkconnectivity.Hub{}
if err := json.Unmarshal(b, r); err != nil {
return "", err
}
return NetworkConnectivityHubAsHCL(*r, hasGAEquivalent)
case "OrgPolicyPolicy":
r := &orgpolicy.Policy{}
if err := json.Unmarshal(b, r); err != nil {
Expand Down Expand Up @@ -617,6 +639,12 @@ func ConvertSampleJSONToHCL(resourceType string, version string, hasGAEquivalent
return "", err
}
return EventarcTriggerAsHCL(*r, hasGAEquivalent)
case "NetworkConnectivityHub":
r := &networkconnectivity.Hub{}
if err := json.Unmarshal(b, r); err != nil {
return "", err
}
return NetworkConnectivityHubAsHCL(*r, hasGAEquivalent)
case "OrgPolicyPolicy":
r := &orgpolicy.Policy{}
if err := json.Unmarshal(b, r); err != nil {
Expand Down Expand Up @@ -3539,6 +3567,47 @@ func MonitoringMonitoredProjectBetaAsHCL(r monitoringBeta.MonitoredProject, hasG
return formatted, nil
}

// NetworkConnectivityHubBetaAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
// the crucial point is that `terraform import; terraform apply` will not produce
// any changes. We do not validate that the resource specified will pass terraform
// validation unless is an object returned from the API after an Apply.
func NetworkConnectivityHubBetaAsHCL(r networkconnectivityBeta.Hub, hasGAEquivalent bool) (string, error) {
outputConfig := "resource \"google_network_connectivity_hub\" \"output\" {\n"
if r.Name != nil {
outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name)
}
if r.Description != nil {
outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description)
}
outputConfig += "\tlabels = {"
for k, v := range r.Labels {
outputConfig += fmt.Sprintf("%v = %q, ", k, v)
}
outputConfig += "}\n"
if r.Project != nil {
outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project)
}
formatted, err := formatHCL(outputConfig + "}")
if err != nil {
return "", err
}
if !hasGAEquivalent {
// The formatter will not accept the google-beta symbol because it is injected during testing.
return withProviderLine(formatted), nil
}
return formatted, nil
}

func convertNetworkConnectivityHubBetaRoutingVpcsToHCL(r *networkconnectivityBeta.HubRoutingVpcs) string {
if r == nil {
return ""
}
outputConfig := "{\n"
return outputConfig + "}"
}

// OrgPolicyPolicyBetaAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
Expand Down Expand Up @@ -7214,6 +7283,47 @@ func convertEventarcTriggerTransportPubsubToHCL(r *eventarc.TriggerTransportPubs
return outputConfig + "}"
}

// NetworkConnectivityHubAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
// the crucial point is that `terraform import; terraform apply` will not produce
// any changes. We do not validate that the resource specified will pass terraform
// validation unless is an object returned from the API after an Apply.
func NetworkConnectivityHubAsHCL(r networkconnectivity.Hub, hasGAEquivalent bool) (string, error) {
outputConfig := "resource \"google_network_connectivity_hub\" \"output\" {\n"
if r.Name != nil {
outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name)
}
if r.Description != nil {
outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description)
}
outputConfig += "\tlabels = {"
for k, v := range r.Labels {
outputConfig += fmt.Sprintf("%v = %q, ", k, v)
}
outputConfig += "}\n"
if r.Project != nil {
outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project)
}
formatted, err := formatHCL(outputConfig + "}")
if err != nil {
return "", err
}
if !hasGAEquivalent {
// The formatter will not accept the google-beta symbol because it is injected during testing.
return withProviderLine(formatted), nil
}
return formatted, nil
}

func convertNetworkConnectivityHubRoutingVpcsToHCL(r *networkconnectivity.HubRoutingVpcs) string {
if r == nil {
return ""
}
outputConfig := "{\n"
return outputConfig + "}"
}

// OrgPolicyPolicyAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
Expand Down Expand Up @@ -10822,6 +10932,27 @@ func convertGkeHubFeatureMembershipBetaConfigmanagementPolicyControllerList(i in
return out
}

func convertNetworkConnectivityHubBetaRoutingVpcs(i interface{}) map[string]interface{} {
if i == nil {
return nil
}
in := i.(map[string]interface{})
return map[string]interface{}{
"uri": in["uri"],
}
}

func convertNetworkConnectivityHubBetaRoutingVpcsList(i interface{}) (out []map[string]interface{}) {
if i == nil {
return nil
}

for _, v := range i.([]interface{}) {
out = append(out, convertNetworkConnectivityHubBetaRoutingVpcs(v))
}
return out
}

func convertOrgPolicyPolicyBetaSpec(i interface{}) map[string]interface{} {
if i == nil {
return nil
Expand Down Expand Up @@ -14169,6 +14300,27 @@ func convertEventarcTriggerTransportPubsubList(i interface{}) (out []map[string]
return out
}

func convertNetworkConnectivityHubRoutingVpcs(i interface{}) map[string]interface{} {
if i == nil {
return nil
}
in := i.(map[string]interface{})
return map[string]interface{}{
"uri": in["uri"],
}
}

func convertNetworkConnectivityHubRoutingVpcsList(i interface{}) (out []map[string]interface{}) {
if i == nil {
return nil
}

for _, v := range i.([]interface{}) {
out = append(out, convertNetworkConnectivityHubRoutingVpcs(v))
}
return out
}

func convertOrgPolicyPolicySpec(i interface{}) map[string]interface{} {
if i == nil {
return nil
Expand Down

0 comments on commit 5eabf93

Please sign in to comment.