Skip to content

Commit 6215511

Browse files
Added private connectivity field to datastream_connection_profile (#6651) (#12844)
* Added private connectivity field to datastream_connection_profile * Corrected example filename * Added missing example var * Corrected space -> tab inconsistency Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 3b5986b commit 6215511

4 files changed

+141
-5
lines changed

.changelog/6651.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
datastream: added `private_connectivity` field to `google_datastream_connection_profile`
3+
```

google/resource_datastream_connection_profile.go

+76
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func resourceDatastreamConnectionProfile() *schema.Resource {
110110
},
111111
},
112112
},
113+
ConflictsWith: []string{"private_connectivity"},
113114
},
114115
"gcs_profile": {
115116
Type: schema.TypeList,
@@ -306,6 +307,22 @@ If this field is used then the 'client_certificate' and the
306307
},
307308
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
308309
},
310+
"private_connectivity": {
311+
Type: schema.TypeList,
312+
Optional: true,
313+
Description: `Private connectivity.`,
314+
MaxItems: 1,
315+
Elem: &schema.Resource{
316+
Schema: map[string]*schema.Schema{
317+
"private_connection": {
318+
Type: schema.TypeString,
319+
Required: true,
320+
Description: `A reference to a private connection resource. Format: 'projects/{project}/locations/{location}/privateConnections/{name}'`,
321+
},
322+
},
323+
},
324+
ConflictsWith: []string{"forward_ssh_connectivity"},
325+
},
309326
"name": {
310327
Type: schema.TypeString,
311328
Computed: true,
@@ -378,6 +395,12 @@ func resourceDatastreamConnectionProfileCreate(d *schema.ResourceData, meta inte
378395
} else if v, ok := d.GetOkExists("forward_ssh_connectivity"); !isEmptyValue(reflect.ValueOf(forwardSshConnectivityProp)) && (ok || !reflect.DeepEqual(v, forwardSshConnectivityProp)) {
379396
obj["forwardSshConnectivity"] = forwardSshConnectivityProp
380397
}
398+
privateConnectivityProp, err := expandDatastreamConnectionProfilePrivateConnectivity(d.Get("private_connectivity"), d, config)
399+
if err != nil {
400+
return err
401+
} else if v, ok := d.GetOkExists("private_connectivity"); !isEmptyValue(reflect.ValueOf(privateConnectivityProp)) && (ok || !reflect.DeepEqual(v, privateConnectivityProp)) {
402+
obj["privateConnectivity"] = privateConnectivityProp
403+
}
381404

382405
url, err := replaceVars(d, config, "{{DatastreamBasePath}}projects/{{project}}/locations/{{location}}/connectionProfiles?connectionProfileId={{connection_profile_id}}")
383406
if err != nil {
@@ -500,6 +523,9 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf
500523
if err := d.Set("forward_ssh_connectivity", flattenDatastreamConnectionProfileForwardSshConnectivity(res["forwardSshConnectivity"], d, config)); err != nil {
501524
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
502525
}
526+
if err := d.Set("private_connectivity", flattenDatastreamConnectionProfilePrivateConnectivity(res["privateConnectivity"], d, config)); err != nil {
527+
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
528+
}
503529

504530
return nil
505531
}
@@ -568,6 +594,12 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
568594
} else if v, ok := d.GetOkExists("forward_ssh_connectivity"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, forwardSshConnectivityProp)) {
569595
obj["forwardSshConnectivity"] = forwardSshConnectivityProp
570596
}
597+
privateConnectivityProp, err := expandDatastreamConnectionProfilePrivateConnectivity(d.Get("private_connectivity"), d, config)
598+
if err != nil {
599+
return err
600+
} else if v, ok := d.GetOkExists("private_connectivity"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, privateConnectivityProp)) {
601+
obj["privateConnectivity"] = privateConnectivityProp
602+
}
571603

572604
url, err := replaceVars(d, config, "{{DatastreamBasePath}}projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}")
573605
if err != nil {
@@ -608,6 +640,10 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
608640
if d.HasChange("forward_ssh_connectivity") {
609641
updateMask = append(updateMask, "forwardSshConnectivity")
610642
}
643+
644+
if d.HasChange("private_connectivity") {
645+
updateMask = append(updateMask, "privateConnectivity")
646+
}
611647
// updateMask is a URL parameter but not present in the schema, so replaceVars
612648
// won't set it
613649
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -1013,6 +1049,23 @@ func flattenDatastreamConnectionProfileForwardSshConnectivityPrivateKey(v interf
10131049
return d.Get("forward_ssh_connectivity.0.private_key")
10141050
}
10151051

1052+
func flattenDatastreamConnectionProfilePrivateConnectivity(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1053+
if v == nil {
1054+
return nil
1055+
}
1056+
original := v.(map[string]interface{})
1057+
if len(original) == 0 {
1058+
return nil
1059+
}
1060+
transformed := make(map[string]interface{})
1061+
transformed["private_connection"] =
1062+
flattenDatastreamConnectionProfilePrivateConnectivityPrivateConnection(original["privateConnection"], d, config)
1063+
return []interface{}{transformed}
1064+
}
1065+
func flattenDatastreamConnectionProfilePrivateConnectivityPrivateConnection(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1066+
return v
1067+
}
1068+
10161069
func expandDatastreamConnectionProfileLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
10171070
if v == nil {
10181071
return map[string]string{}, nil
@@ -1436,3 +1489,26 @@ func expandDatastreamConnectionProfileForwardSshConnectivityPassword(v interface
14361489
func expandDatastreamConnectionProfileForwardSshConnectivityPrivateKey(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
14371490
return v, nil
14381491
}
1492+
1493+
func expandDatastreamConnectionProfilePrivateConnectivity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1494+
l := v.([]interface{})
1495+
if len(l) == 0 || l[0] == nil {
1496+
return nil, nil
1497+
}
1498+
raw := l[0]
1499+
original := raw.(map[string]interface{})
1500+
transformed := make(map[string]interface{})
1501+
1502+
transformedPrivateConnection, err := expandDatastreamConnectionProfilePrivateConnectivityPrivateConnection(original["private_connection"], d, config)
1503+
if err != nil {
1504+
return nil, err
1505+
} else if val := reflect.ValueOf(transformedPrivateConnection); val.IsValid() && !isEmptyValue(val) {
1506+
transformed["privateConnection"] = transformedPrivateConnection
1507+
}
1508+
1509+
return transformed, nil
1510+
}
1511+
1512+
func expandDatastreamConnectionProfilePrivateConnectivityPrivateConnection(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1513+
return v, nil
1514+
}

google/resource_datastream_connection_profile_generated_test.go

+26-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ resource "google_datastream_connection_profile" "default" {
6363
`, context)
6464
}
6565

66-
func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(t *testing.T) {
66+
func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryPrivateConnectionExample(t *testing.T) {
6767
t.Parallel()
6868

6969
context := map[string]interface{}{
@@ -76,7 +76,7 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExamp
7676
CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t),
7777
Steps: []resource.TestStep{
7878
{
79-
Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context),
79+
Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryPrivateConnectionExample(context),
8080
},
8181
{
8282
ResourceName: "google_datastream_connection_profile.default",
@@ -88,14 +88,37 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExamp
8888
})
8989
}
9090

91-
func testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context map[string]interface{}) string {
91+
func testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryPrivateConnectionExample(context map[string]interface{}) string {
9292
return Nprintf(`
93+
resource "google_datastream_private_connection" "private_connection" {
94+
display_name = "Connection profile"
95+
location = "us-central1"
96+
private_connection_id = "tf-test-my-connection%{random_suffix}"
97+
98+
labels = {
99+
key = "value"
100+
}
101+
102+
vpc_peering_config {
103+
vpc = google_compute_network.default.id
104+
subnet = "10.0.0.0/29"
105+
}
106+
}
107+
108+
resource "google_compute_network" "default" {
109+
name = "tf-test-my-network%{random_suffix}"
110+
}
111+
93112
resource "google_datastream_connection_profile" "default" {
94113
display_name = "Connection profile"
95114
location = "us-central1"
96115
connection_profile_id = "tf-test-my-profile%{random_suffix}"
97116
98117
bigquery_profile {}
118+
119+
private_connectivity {
120+
private_connection = google_datastream_private_connection.private_connection.id
121+
}
99122
}
100123
`, context)
101124
}

website/docs/r/datastream_connection_profile.html.markdown

+36-2
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,43 @@ resource "google_datastream_connection_profile" "default" {
5353
}
5454
```
5555
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
56-
<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_working_dir=datastream_connection_profile_bigquery&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
56+
<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_working_dir=datastream_connection_profile_bigquery_private_connection&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
5757
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
5858
</a>
5959
</div>
60-
## Example Usage - Datastream Connection Profile Bigquery
60+
## Example Usage - Datastream Connection Profile Bigquery Private Connection
6161

6262

6363
```hcl
64+
resource "google_datastream_private_connection" "private_connection" {
65+
display_name = "Connection profile"
66+
location = "us-central1"
67+
private_connection_id = "my-connection"
68+
69+
labels = {
70+
key = "value"
71+
}
72+
73+
vpc_peering_config {
74+
vpc = google_compute_network.default.id
75+
subnet = "10.0.0.0/29"
76+
}
77+
}
78+
79+
resource "google_compute_network" "default" {
80+
name = "my-network"
81+
}
82+
6483
resource "google_datastream_connection_profile" "default" {
6584
display_name = "Connection profile"
6685
location = "us-central1"
6786
connection_profile_id = "my-profile"
6887
6988
bigquery_profile {}
89+
90+
private_connectivity {
91+
private_connection = google_datastream_private_connection.private_connection.id
92+
}
7093
}
7194
```
7295
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
@@ -219,6 +242,11 @@ The following arguments are supported:
219242
Forward SSH tunnel connectivity.
220243
Structure is [documented below](#nested_forward_ssh_connectivity).
221244

245+
* `private_connectivity` -
246+
(Optional)
247+
Private connectivity.
248+
Structure is [documented below](#nested_private_connectivity).
249+
222250
* `project` - (Optional) The ID of the project in which the resource belongs.
223251
If it is not provided, the provider project is used.
224252

@@ -364,6 +392,12 @@ The following arguments are supported:
364392
SSH private key.
365393
**Note**: This property is sensitive and will not be displayed in the plan.
366394

395+
<a name="nested_private_connectivity"></a>The `private_connectivity` block supports:
396+
397+
* `private_connection` -
398+
(Required)
399+
A reference to a private connection resource. Format: `projects/{project}/locations/{location}/privateConnections/{name}`
400+
367401
## Attributes Reference
368402

369403
In addition to the arguments listed above, the following computed attributes are exported:

0 commit comments

Comments
 (0)