From 6015b1a4bbb37e0dc9d77581e2327d5ac225ff33 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 30 Sep 2022 14:14:33 -0700 Subject: [PATCH] Added support for google_datastream_connection_profile.bigquery_profile field (#6616) (#12693) * Added support for google_datastream_connection_profile.bigquery_profile field Related to https://github.com/hashicorp/terraform-provider-google/issues/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 Signed-off-by: Modular Magician --- .changelog/6616.txt | 3 + .../resource_datastream_connection_profile.go | 60 +++++++++++++++++-- ...tream_connection_profile_generated_test.go | 37 ++++++++++++ website/docs/r/data_catalog_tag.html.markdown | 1 - ...atastream_connection_profile.html.markdown | 21 +++++++ 5 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 .changelog/6616.txt diff --git a/.changelog/6616.txt b/.changelog/6616.txt new file mode 100644 index 00000000000..b7c0b7edf21 --- /dev/null +++ b/.changelog/6616.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +datastream: Added field `bigquery_profile` to `google_datastream_connection_profile` +``` diff --git a/google/resource_datastream_connection_profile.go b/google/resource_datastream_connection_profile.go index f388759cc6c..80089806867 100644 --- a/google/resource_datastream_connection_profile.go +++ b/google/resource_datastream_connection_profile.go @@ -59,6 +59,16 @@ func resourceDatastreamConnectionProfile() *schema.Resource { ForceNew: true, Description: `The name of the location this repository is located in.`, }, + "bigquery_profile": { + Type: schema.TypeList, + Optional: true, + Description: `BigQuery warehouse profile.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{}, + }, + ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"}, + }, "forward_ssh_connectivity": { Type: schema.TypeList, Optional: true, @@ -120,7 +130,7 @@ func resourceDatastreamConnectionProfile() *schema.Resource { }, }, }, - ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"}, + ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"}, }, "labels": { Type: schema.TypeMap, @@ -212,7 +222,7 @@ If this field is used then the 'client_certificate' and the }, }, }, - ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"}, + ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"}, }, "oracle_profile": { Type: schema.TypeList, @@ -256,7 +266,7 @@ If this field is used then the 'client_certificate' and the }, }, }, - ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"}, + ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"}, }, "postgresql_profile": { Type: schema.TypeList, @@ -294,7 +304,7 @@ If this field is used then the 'client_certificate' and the }, }, }, - ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "postgresql_profile"}, + ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"}, }, "name": { Type: schema.TypeString, @@ -350,6 +360,12 @@ func resourceDatastreamConnectionProfileCreate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("mysql_profile"); !isEmptyValue(reflect.ValueOf(mysqlProfileProp)) && (ok || !reflect.DeepEqual(v, mysqlProfileProp)) { obj["mysqlProfile"] = mysqlProfileProp } + bigqueryProfileProp, err := expandDatastreamConnectionProfileBigqueryProfile(d.Get("bigquery_profile"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("bigquery_profile"); ok || !reflect.DeepEqual(v, bigqueryProfileProp) { + obj["bigqueryProfile"] = bigqueryProfileProp + } postgresqlProfileProp, err := expandDatastreamConnectionProfilePostgresqlProfile(d.Get("postgresql_profile"), d, config) if err != nil { return err @@ -474,6 +490,9 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf if err := d.Set("mysql_profile", flattenDatastreamConnectionProfileMysqlProfile(res["mysqlProfile"], d, config)); err != nil { return fmt.Errorf("Error reading ConnectionProfile: %s", err) } + if err := d.Set("bigquery_profile", flattenDatastreamConnectionProfileBigqueryProfile(res["bigqueryProfile"], d, config)); err != nil { + return fmt.Errorf("Error reading ConnectionProfile: %s", err) + } if err := d.Set("postgresql_profile", flattenDatastreamConnectionProfilePostgresqlProfile(res["postgresqlProfile"], d, config)); err != nil { return fmt.Errorf("Error reading ConnectionProfile: %s", err) } @@ -530,6 +549,12 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("mysql_profile"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, mysqlProfileProp)) { obj["mysqlProfile"] = mysqlProfileProp } + bigqueryProfileProp, err := expandDatastreamConnectionProfileBigqueryProfile(d.Get("bigquery_profile"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("bigquery_profile"); ok || !reflect.DeepEqual(v, bigqueryProfileProp) { + obj["bigqueryProfile"] = bigqueryProfileProp + } postgresqlProfileProp, err := expandDatastreamConnectionProfilePostgresqlProfile(d.Get("postgresql_profile"), d, config) if err != nil { return err @@ -571,6 +596,10 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte updateMask = append(updateMask, "mysqlProfile") } + if d.HasChange("bigquery_profile") { + updateMask = append(updateMask, "bigqueryProfile") + } + if d.HasChange("postgresql_profile") { updateMask = append(updateMask, "postgresqlProfile") } @@ -867,6 +896,14 @@ func flattenDatastreamConnectionProfileMysqlProfileSslConfigCaCertificateSet(v i return v } +func flattenDatastreamConnectionProfileBigqueryProfile(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + transformed := make(map[string]interface{}) + return []interface{}{transformed} +} + func flattenDatastreamConnectionProfilePostgresqlProfile(v interface{}, d *schema.ResourceData, config *Config) interface{} { if v == nil { return nil @@ -1250,6 +1287,21 @@ func expandDatastreamConnectionProfileMysqlProfileSslConfigCaCertificateSet(v in return v, nil } +func expandDatastreamConnectionProfileBigqueryProfile(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 { + return nil, nil + } + + if l[0] == nil { + transformed := make(map[string]interface{}) + return transformed, nil + } + transformed := make(map[string]interface{}) + + return transformed, nil +} + func expandDatastreamConnectionProfilePostgresqlProfile(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google/resource_datastream_connection_profile_generated_test.go b/google/resource_datastream_connection_profile_generated_test.go index 5c05e443a84..65cf3ae021d 100644 --- a/google/resource_datastream_connection_profile_generated_test.go +++ b/google/resource_datastream_connection_profile_generated_test.go @@ -63,6 +63,43 @@ resource "google_datastream_connection_profile" "default" { `, context) } +func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context), + }, + { + ResourceName: "google_datastream_connection_profile.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location"}, + }, + }, + }) +} + +func testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_datastream_connection_profile" "default" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "tf-test-my-profile%{random_suffix}" + + bigquery_profile {} +} +`, context) +} + func TestAccDatastreamConnectionProfile_datastreamConnectionProfileFullExample(t *testing.T) { t.Parallel() diff --git a/website/docs/r/data_catalog_tag.html.markdown b/website/docs/r/data_catalog_tag.html.markdown index 18f5ea26edd..5c07bce3ca6 100644 --- a/website/docs/r/data_catalog_tag.html.markdown +++ b/website/docs/r/data_catalog_tag.html.markdown @@ -379,7 +379,6 @@ The following arguments are supported: * `enum_value` - (Optional) 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. - Structure is [documented below](#nested_enum_value). - - - diff --git a/website/docs/r/datastream_connection_profile.html.markdown b/website/docs/r/datastream_connection_profile.html.markdown index 059f9dfcd47..fb0385ec8f2 100644 --- a/website/docs/r/datastream_connection_profile.html.markdown +++ b/website/docs/r/datastream_connection_profile.html.markdown @@ -52,6 +52,23 @@ resource "google_datastream_connection_profile" "default" { } } ``` + +## Example Usage - Datastream Connection Profile Bigquery + + +```hcl +resource "google_datastream_connection_profile" "default" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "my-profile" + + bigquery_profile {} +} +```