Skip to content

Commit 6015b1a

Browse files
Added support for google_datastream_connection_profile.bigquery_profile field (#6616) (#12693)
* Added support for google_datastream_connection_profile.bigquery_profile field Related to #10810 This required making some changes to compilation & templates to truly support completely empty "nested objects". I removed .nested_properties? in favor of more explicitly checking whether the nested properties are not specified or are present but empty. * Fixed ruby errors * Added bigquery test * Made logic for 'Structure is documented below' match the logic for generating the related docs block Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 23b7bce commit 6015b1a

5 files changed

+117
-5
lines changed

.changelog/6616.txt

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

google/resource_datastream_connection_profile.go

+56-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ func resourceDatastreamConnectionProfile() *schema.Resource {
5959
ForceNew: true,
6060
Description: `The name of the location this repository is located in.`,
6161
},
62+
"bigquery_profile": {
63+
Type: schema.TypeList,
64+
Optional: true,
65+
Description: `BigQuery warehouse profile.`,
66+
MaxItems: 1,
67+
Elem: &schema.Resource{
68+
Schema: map[string]*schema.Schema{},
69+
},
70+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
71+
},
6272
"forward_ssh_connectivity": {
6373
Type: schema.TypeList,
6474
Optional: true,
@@ -120,7 +130,7 @@ func resourceDatastreamConnectionProfile() *schema.Resource {
120130
},
121131
},
122132
},
123-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"},
133+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
124134
},
125135
"labels": {
126136
Type: schema.TypeMap,
@@ -212,7 +222,7 @@ If this field is used then the 'client_certificate' and the
212222
},
213223
},
214224
},
215-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"},
225+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
216226
},
217227
"oracle_profile": {
218228
Type: schema.TypeList,
@@ -256,7 +266,7 @@ If this field is used then the 'client_certificate' and the
256266
},
257267
},
258268
},
259-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"},
269+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
260270
},
261271
"postgresql_profile": {
262272
Type: schema.TypeList,
@@ -294,7 +304,7 @@ If this field is used then the 'client_certificate' and the
294304
},
295305
},
296306
},
297-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"},
307+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
298308
},
299309
"name": {
300310
Type: schema.TypeString,
@@ -350,6 +360,12 @@ func resourceDatastreamConnectionProfileCreate(d *schema.ResourceData, meta inte
350360
} else if v, ok := d.GetOkExists("mysql_profile"); !isEmptyValue(reflect.ValueOf(mysqlProfileProp)) && (ok || !reflect.DeepEqual(v, mysqlProfileProp)) {
351361
obj["mysqlProfile"] = mysqlProfileProp
352362
}
363+
bigqueryProfileProp, err := expandDatastreamConnectionProfileBigqueryProfile(d.Get("bigquery_profile"), d, config)
364+
if err != nil {
365+
return err
366+
} else if v, ok := d.GetOkExists("bigquery_profile"); ok || !reflect.DeepEqual(v, bigqueryProfileProp) {
367+
obj["bigqueryProfile"] = bigqueryProfileProp
368+
}
353369
postgresqlProfileProp, err := expandDatastreamConnectionProfilePostgresqlProfile(d.Get("postgresql_profile"), d, config)
354370
if err != nil {
355371
return err
@@ -474,6 +490,9 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf
474490
if err := d.Set("mysql_profile", flattenDatastreamConnectionProfileMysqlProfile(res["mysqlProfile"], d, config)); err != nil {
475491
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
476492
}
493+
if err := d.Set("bigquery_profile", flattenDatastreamConnectionProfileBigqueryProfile(res["bigqueryProfile"], d, config)); err != nil {
494+
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
495+
}
477496
if err := d.Set("postgresql_profile", flattenDatastreamConnectionProfilePostgresqlProfile(res["postgresqlProfile"], d, config)); err != nil {
478497
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
479498
}
@@ -530,6 +549,12 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
530549
} else if v, ok := d.GetOkExists("mysql_profile"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, mysqlProfileProp)) {
531550
obj["mysqlProfile"] = mysqlProfileProp
532551
}
552+
bigqueryProfileProp, err := expandDatastreamConnectionProfileBigqueryProfile(d.Get("bigquery_profile"), d, config)
553+
if err != nil {
554+
return err
555+
} else if v, ok := d.GetOkExists("bigquery_profile"); ok || !reflect.DeepEqual(v, bigqueryProfileProp) {
556+
obj["bigqueryProfile"] = bigqueryProfileProp
557+
}
533558
postgresqlProfileProp, err := expandDatastreamConnectionProfilePostgresqlProfile(d.Get("postgresql_profile"), d, config)
534559
if err != nil {
535560
return err
@@ -571,6 +596,10 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
571596
updateMask = append(updateMask, "mysqlProfile")
572597
}
573598

599+
if d.HasChange("bigquery_profile") {
600+
updateMask = append(updateMask, "bigqueryProfile")
601+
}
602+
574603
if d.HasChange("postgresql_profile") {
575604
updateMask = append(updateMask, "postgresqlProfile")
576605
}
@@ -867,6 +896,14 @@ func flattenDatastreamConnectionProfileMysqlProfileSslConfigCaCertificateSet(v i
867896
return v
868897
}
869898

899+
func flattenDatastreamConnectionProfileBigqueryProfile(v interface{}, d *schema.ResourceData, config *Config) interface{} {
900+
if v == nil {
901+
return nil
902+
}
903+
transformed := make(map[string]interface{})
904+
return []interface{}{transformed}
905+
}
906+
870907
func flattenDatastreamConnectionProfilePostgresqlProfile(v interface{}, d *schema.ResourceData, config *Config) interface{} {
871908
if v == nil {
872909
return nil
@@ -1250,6 +1287,21 @@ func expandDatastreamConnectionProfileMysqlProfileSslConfigCaCertificateSet(v in
12501287
return v, nil
12511288
}
12521289

1290+
func expandDatastreamConnectionProfileBigqueryProfile(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1291+
l := v.([]interface{})
1292+
if len(l) == 0 {
1293+
return nil, nil
1294+
}
1295+
1296+
if l[0] == nil {
1297+
transformed := make(map[string]interface{})
1298+
return transformed, nil
1299+
}
1300+
transformed := make(map[string]interface{})
1301+
1302+
return transformed, nil
1303+
}
1304+
12531305
func expandDatastreamConnectionProfilePostgresqlProfile(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
12541306
l := v.([]interface{})
12551307
if len(l) == 0 || l[0] == nil {

google/resource_datastream_connection_profile_generated_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,43 @@ resource "google_datastream_connection_profile" "default" {
6363
`, context)
6464
}
6565

66+
func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(t *testing.T) {
67+
t.Parallel()
68+
69+
context := map[string]interface{}{
70+
"random_suffix": randString(t, 10),
71+
}
72+
73+
vcrTest(t, resource.TestCase{
74+
PreCheck: func() { testAccPreCheck(t) },
75+
Providers: testAccProviders,
76+
CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t),
77+
Steps: []resource.TestStep{
78+
{
79+
Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context),
80+
},
81+
{
82+
ResourceName: "google_datastream_connection_profile.default",
83+
ImportState: true,
84+
ImportStateVerify: true,
85+
ImportStateVerifyIgnore: []string{"connection_profile_id", "location"},
86+
},
87+
},
88+
})
89+
}
90+
91+
func testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context map[string]interface{}) string {
92+
return Nprintf(`
93+
resource "google_datastream_connection_profile" "default" {
94+
display_name = "Connection profile"
95+
location = "us-central1"
96+
connection_profile_id = "tf-test-my-profile%{random_suffix}"
97+
98+
bigquery_profile {}
99+
}
100+
`, context)
101+
}
102+
66103
func TestAccDatastreamConnectionProfile_datastreamConnectionProfileFullExample(t *testing.T) {
67104
t.Parallel()
68105

website/docs/r/data_catalog_tag.html.markdown

-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ The following arguments are supported:
379379
* `enum_value` -
380380
(Optional)
381381
Holds the value for a tag field with enum type. This value must be one of the allowed values in the definition of this enum.
382-
Structure is [documented below](#nested_enum_value).
383382

384383
- - -
385384

website/docs/r/datastream_connection_profile.html.markdown

+21
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ resource "google_datastream_connection_profile" "default" {
5252
}
5353
}
5454
```
55+
<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">
57+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
58+
</a>
59+
</div>
60+
## Example Usage - Datastream Connection Profile Bigquery
61+
62+
63+
```hcl
64+
resource "google_datastream_connection_profile" "default" {
65+
display_name = "Connection profile"
66+
location = "us-central1"
67+
connection_profile_id = "my-profile"
68+
69+
bigquery_profile {}
70+
}
71+
```
5572
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
5673
<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_full&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
5774
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
@@ -188,6 +205,10 @@ The following arguments are supported:
188205
MySQL database profile.
189206
Structure is [documented below](#nested_mysql_profile).
190207

208+
* `bigquery_profile` -
209+
(Optional)
210+
BigQuery warehouse profile.
211+
191212
* `postgresql_profile` -
192213
(Optional)
193214
PostgreSQL database profile.

0 commit comments

Comments
 (0)