Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for google_datastream_connection_profile.bigquery_profile field #12693

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6616.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
datastream: Added field `bigquery_profile` to `google_datastream_connection_profile`
```
60 changes: 56 additions & 4 deletions google/resource_datastream_connection_profile.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions google/resource_datastream_connection_profile_generated_test.go
Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion website/docs/r/data_catalog_tag.html.markdown
Expand Up @@ -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).

- - -

Expand Down
21 changes: 21 additions & 0 deletions website/docs/r/datastream_connection_profile.html.markdown
Expand Up @@ -52,6 +52,23 @@ resource "google_datastream_connection_profile" "default" {
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%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">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## 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 {}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%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">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
Expand Down Expand Up @@ -188,6 +205,10 @@ The following arguments are supported:
MySQL database profile.
Structure is [documented below](#nested_mysql_profile).

* `bigquery_profile` -
(Optional)
BigQuery warehouse profile.

* `postgresql_profile` -
(Optional)
PostgreSQL database profile.
Expand Down