diff --git a/mmv1/third_party/terraform/utils/config.go.erb b/mmv1/third_party/terraform/utils/config.go.erb index 0d19b19eb869..b2be965482a3 100644 --- a/mmv1/third_party/terraform/utils/config.go.erb +++ b/mmv1/third_party/terraform/utils/config.go.erb @@ -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' -%> diff --git a/mmv1/third_party/terraform/utils/provider.go.erb b/mmv1/third_party/terraform/utils/provider.go.erb index c17b2d97394d..47d1c63d3920 100644 --- a/mmv1/third_party/terraform/utils/provider.go.erb +++ b/mmv1/third_party/terraform/utils/provider.go.erb @@ -182,6 +182,7 @@ func Provider() *schema.Provider { CloudResourceManagerEndpointEntryKey: CloudResourceManagerEndpointEntry, EventarcEndpointEntryKey: EventarcEndpointEntry, GkeHubFeatureCustomEndpointEntryKey: GkeHubFeatureCustomEndpointEntry, + NetworkConnectivityEndpointEntryKey: NetworkConnectivityEndpointEntry, OrgPolicyEndpointEntryKey: OrgPolicyEndpointEntry, PrivatecaCertificateTemplateEndpointEntryKey: PrivatecaCertificateTemplateCustomEndpointEntry, RecaptchaEnterpriseEndpointEntryKey: RecaptchaEnterpriseEndpointEntry, @@ -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' -%> @@ -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) diff --git a/tpgtools/api/networkconnectivity/samples/basic.hub.json b/tpgtools/api/networkconnectivity/samples/basic.hub.json new file mode 100644 index 000000000000..4e513a26d92c --- /dev/null +++ b/tpgtools/api/networkconnectivity/samples/basic.hub.json @@ -0,0 +1,8 @@ +{ + "name": "{{hub}}", + "project": "{{project}}", + "labels": { + "label-one": "value-one" + }, + "description": "A sample hub" +} \ No newline at end of file diff --git a/tpgtools/api/networkconnectivity/samples/basic_hub.yaml b/tpgtools/api/networkconnectivity/samples/basic_hub.yaml new file mode 100644 index 000000000000..88114cdc4753 --- /dev/null +++ b/tpgtools/api/networkconnectivity/samples/basic_hub.yaml @@ -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 \ No newline at end of file diff --git a/tpgtools/api/networkconnectivity/samples/update.hub.json b/tpgtools/api/networkconnectivity/samples/update.hub.json new file mode 100644 index 000000000000..d984f8351b6f --- /dev/null +++ b/tpgtools/api/networkconnectivity/samples/update.hub.json @@ -0,0 +1,8 @@ +{ + "name": "{{hub}}", + "project": "{{project}}", + "labels": { + "label-two": "value-one" + }, + "description": "An updated sample hub" +} \ No newline at end of file diff --git a/tpgtools/overrides/networkconnectivity/beta/hub.yaml b/tpgtools/overrides/networkconnectivity/beta/hub.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tpgtools/overrides/networkconnectivity/hub.yaml b/tpgtools/overrides/networkconnectivity/hub.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tpgtools/overrides/networkconnectivity/samples/hub/basic.yaml b/tpgtools/overrides/networkconnectivity/samples/hub/basic.yaml new file mode 100644 index 000000000000..9428774c187c --- /dev/null +++ b/tpgtools/overrides/networkconnectivity/samples/hub/basic.yaml @@ -0,0 +1,6 @@ +updates: +variables: + - name: "project" + type: "project" + - name: "hub" + type: "resource_name" diff --git a/tpgtools/overrides/networkconnectivity/samples/hub/basic_update_hub.tf.tmpl b/tpgtools/overrides/networkconnectivity/samples/hub/basic_update_hub.tf.tmpl new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tpgtools/overrides/networkconnectivity/samples/hub/meta.yaml b/tpgtools/overrides/networkconnectivity/samples/hub/meta.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tpgtools/property.go b/tpgtools/property.go index bbec2814be14..5852d42347ba 100644 --- a/tpgtools/property.go +++ b/tpgtools/property.go @@ -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() } diff --git a/tpgtools/serialization.go b/tpgtools/serialization.go index e733179fe7fa..96d64aaac3de 100644 --- a/tpgtools/serialization.go +++ b/tpgtools/serialization.go @@ -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" @@ -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": @@ -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": @@ -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": @@ -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": @@ -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 { @@ -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 { @@ -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 { @@ -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 @@ -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 @@ -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 @@ -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