Skip to content

Commit 224fcf7

Browse files
add export psc support to Network Connectivity Center hub (#11241) (#18866)
[upstream:1250c4a58730915e62d391539e2e7e8b86bf09fa] Signed-off-by: Modular Magician <[email protected]>
1 parent ea778ee commit 224fcf7

5 files changed

+91
-0
lines changed

.changelog/11241.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
networkconnectivity: added `export_psc` field to `google_network_connectivity_hub` resource
3+
```

google/services/networkconnectivity/resource_network_connectivity_hub.go

+33
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ func ResourceNetworkConnectivityHub() *schema.Resource {
6868
Optional: true,
6969
Description: `An optional description of the hub.`,
7070
},
71+
"export_psc": {
72+
Type: schema.TypeBool,
73+
Computed: true,
74+
Optional: true,
75+
Description: `Whether Private Service Connect transitivity is enabled for the hub. If true, Private Service Connect endpoints in VPC spokes attached to the hub are made accessible to other VPC spokes attached to the hub. The default value is false.`,
76+
},
7177
"labels": {
7278
Type: schema.TypeMap,
7379
Optional: true,
@@ -156,6 +162,12 @@ func resourceNetworkConnectivityHubCreate(d *schema.ResourceData, meta interface
156162
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
157163
obj["description"] = descriptionProp
158164
}
165+
exportPscProp, err := expandNetworkConnectivityHubExportPsc(d.Get("export_psc"), d, config)
166+
if err != nil {
167+
return err
168+
} else if v, ok := d.GetOkExists("export_psc"); !tpgresource.IsEmptyValue(reflect.ValueOf(exportPscProp)) && (ok || !reflect.DeepEqual(v, exportPscProp)) {
169+
obj["exportPsc"] = exportPscProp
170+
}
159171
labelsProp, err := expandNetworkConnectivityHubEffectiveLabels(d.Get("effective_labels"), d, config)
160172
if err != nil {
161173
return err
@@ -285,6 +297,9 @@ func resourceNetworkConnectivityHubRead(d *schema.ResourceData, meta interface{}
285297
if err := d.Set("routing_vpcs", flattenNetworkConnectivityHubRoutingVpcs(res["routingVpcs"], d, config)); err != nil {
286298
return fmt.Errorf("Error reading Hub: %s", err)
287299
}
300+
if err := d.Set("export_psc", flattenNetworkConnectivityHubExportPsc(res["exportPsc"], d, config)); err != nil {
301+
return fmt.Errorf("Error reading Hub: %s", err)
302+
}
288303
if err := d.Set("terraform_labels", flattenNetworkConnectivityHubTerraformLabels(res["labels"], d, config)); err != nil {
289304
return fmt.Errorf("Error reading Hub: %s", err)
290305
}
@@ -317,6 +332,12 @@ func resourceNetworkConnectivityHubUpdate(d *schema.ResourceData, meta interface
317332
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
318333
obj["description"] = descriptionProp
319334
}
335+
exportPscProp, err := expandNetworkConnectivityHubExportPsc(d.Get("export_psc"), d, config)
336+
if err != nil {
337+
return err
338+
} else if v, ok := d.GetOkExists("export_psc"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, exportPscProp)) {
339+
obj["exportPsc"] = exportPscProp
340+
}
320341
labelsProp, err := expandNetworkConnectivityHubEffectiveLabels(d.Get("effective_labels"), d, config)
321342
if err != nil {
322343
return err
@@ -337,6 +358,10 @@ func resourceNetworkConnectivityHubUpdate(d *schema.ResourceData, meta interface
337358
updateMask = append(updateMask, "description")
338359
}
339360

361+
if d.HasChange("export_psc") {
362+
updateMask = append(updateMask, "exportPsc")
363+
}
364+
340365
if d.HasChange("effective_labels") {
341366
updateMask = append(updateMask, "labels")
342367
}
@@ -520,6 +545,10 @@ func flattenNetworkConnectivityHubRoutingVpcsUri(v interface{}, d *schema.Resour
520545
return v
521546
}
522547

548+
func flattenNetworkConnectivityHubExportPsc(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
549+
return v
550+
}
551+
523552
func flattenNetworkConnectivityHubTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
524553
if v == nil {
525554
return v
@@ -547,6 +576,10 @@ func expandNetworkConnectivityHubDescription(v interface{}, d tpgresource.Terraf
547576
return v, nil
548577
}
549578

579+
func expandNetworkConnectivityHubExportPsc(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
580+
return v, nil
581+
}
582+
550583
func expandNetworkConnectivityHubEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
551584
if v == nil {
552585
return map[string]string{}, nil

google/services/networkconnectivity/resource_network_connectivity_hub_generated_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,41 @@ resource "google_network_connectivity_hub" "primary" {
6767
`, context)
6868
}
6969

70+
func TestAccNetworkConnectivityHub_networkConnectivityHubWithExportPscExample(t *testing.T) {
71+
t.Parallel()
72+
73+
context := map[string]interface{}{
74+
"random_suffix": acctest.RandString(t, 10),
75+
}
76+
77+
acctest.VcrTest(t, resource.TestCase{
78+
PreCheck: func() { acctest.AccTestPreCheck(t) },
79+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
80+
CheckDestroy: testAccCheckNetworkConnectivityHubDestroyProducer(t),
81+
Steps: []resource.TestStep{
82+
{
83+
Config: testAccNetworkConnectivityHub_networkConnectivityHubWithExportPscExample(context),
84+
},
85+
{
86+
ResourceName: "google_network_connectivity_hub.primary",
87+
ImportState: true,
88+
ImportStateVerify: true,
89+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
90+
},
91+
},
92+
})
93+
}
94+
95+
func testAccNetworkConnectivityHub_networkConnectivityHubWithExportPscExample(context map[string]interface{}) string {
96+
return acctest.Nprintf(`
97+
resource "google_network_connectivity_hub" "primary" {
98+
name = "basic%{random_suffix}"
99+
description = "A sample hub with Private Service Connect transitivity is enabled"
100+
export_psc = true
101+
}
102+
`, context)
103+
}
104+
70105
func testAccCheckNetworkConnectivityHubDestroyProducer(t *testing.T) func(s *terraform.State) error {
71106
return func(s *terraform.State) error {
72107
for name, rs := range s.RootModule().Resources {

google/services/networkconnectivity/resource_network_connectivity_hub_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ resource "google_network_connectivity_hub" "primary" {
141141
labels = {
142142
label-two = "value-one"
143143
}
144+
export_psc = true
144145
}
145146
146147

website/docs/r/network_connectivity_hub.html.markdown

+19
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ resource "google_network_connectivity_hub" "primary" {
4545
}
4646
}
4747
```
48+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
49+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=network_connectivity_hub_with_export_psc&open_in_editor=main.tf" target="_blank">
50+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
51+
</a>
52+
</div>
53+
## Example Usage - Network Connectivity Hub With Export Psc
54+
55+
56+
```hcl
57+
resource "google_network_connectivity_hub" "primary" {
58+
name = "basic"
59+
description = "A sample hub with Private Service Connect transitivity is enabled"
60+
export_psc = true
61+
}
62+
```
4863

4964
## Argument Reference
5065

@@ -69,6 +84,10 @@ The following arguments are supported:
6984
(Optional)
7085
An optional description of the hub.
7186

87+
* `export_psc` -
88+
(Optional)
89+
Whether Private Service Connect transitivity is enabled for the hub. If true, Private Service Connect endpoints in VPC spokes attached to the hub are made accessible to other VPC spokes attached to the hub. The default value is false.
90+
7291
* `project` - (Optional) The ID of the project in which the resource belongs.
7392
If it is not provided, the provider project is used.
7493

0 commit comments

Comments
 (0)