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

feat(bigquery-data-transfer): add email preferences #7665

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4156.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigquery: added `email_preferences ` field to `google_bigquery_data_transfer_config` resource
```
75 changes: 75 additions & 0 deletions google/resource_bigquery_data_transfer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ Set the value to 0 to use the default value.`,
Optional: true,
Description: `When set to true, no runs are scheduled for a given transfer.`,
},
"email_preferences": {
Type: schema.TypeList,
Optional: true,
Description: `Email notifications will be sent according to these preferences to the
email address of the user who owns this transfer config.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enable_failure_email": {
Type: schema.TypeBool,
Required: true,
Description: `If true, email notifications will be sent on transfer run failures.`,
},
},
},
},
"location": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -248,6 +264,12 @@ func resourceBigqueryDataTransferConfigCreate(d *schema.ResourceData, meta inter
} else if v, ok := d.GetOkExists("schedule_options"); !isEmptyValue(reflect.ValueOf(scheduleOptionsProp)) && (ok || !reflect.DeepEqual(v, scheduleOptionsProp)) {
obj["scheduleOptions"] = scheduleOptionsProp
}
emailPreferencesProp, err := expandBigqueryDataTransferConfigEmailPreferences(d.Get("email_preferences"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("email_preferences"); !isEmptyValue(reflect.ValueOf(emailPreferencesProp)) && (ok || !reflect.DeepEqual(v, emailPreferencesProp)) {
obj["emailPreferences"] = emailPreferencesProp
}
notificationPubsubTopicProp, err := expandBigqueryDataTransferConfigNotificationPubsubTopic(d.Get("notification_pubsub_topic"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -399,6 +421,9 @@ func resourceBigqueryDataTransferConfigRead(d *schema.ResourceData, meta interfa
if err := d.Set("schedule_options", flattenBigqueryDataTransferConfigScheduleOptions(res["scheduleOptions"], d, config)); err != nil {
return fmt.Errorf("Error reading Config: %s", err)
}
if err := d.Set("email_preferences", flattenBigqueryDataTransferConfigEmailPreferences(res["emailPreferences"], d, config)); err != nil {
return fmt.Errorf("Error reading Config: %s", err)
}
if err := d.Set("notification_pubsub_topic", flattenBigqueryDataTransferConfigNotificationPubsubTopic(res["notificationPubsubTopic"], d, config)); err != nil {
return fmt.Errorf("Error reading Config: %s", err)
}
Expand Down Expand Up @@ -449,6 +474,12 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter
} else if v, ok := d.GetOkExists("schedule_options"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, scheduleOptionsProp)) {
obj["scheduleOptions"] = scheduleOptionsProp
}
emailPreferencesProp, err := expandBigqueryDataTransferConfigEmailPreferences(d.Get("email_preferences"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("email_preferences"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, emailPreferencesProp)) {
obj["emailPreferences"] = emailPreferencesProp
}
notificationPubsubTopicProp, err := expandBigqueryDataTransferConfigNotificationPubsubTopic(d.Get("notification_pubsub_topic"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -499,6 +530,10 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter
updateMask = append(updateMask, "scheduleOptions")
}

if d.HasChange("email_preferences") {
updateMask = append(updateMask, "emailPreferences")
}

if d.HasChange("notification_pubsub_topic") {
updateMask = append(updateMask, "notificationPubsubTopic")
}
Expand Down Expand Up @@ -635,6 +670,23 @@ func flattenBigqueryDataTransferConfigScheduleOptionsEndTime(v interface{}, d *s
return v
}

func flattenBigqueryDataTransferConfigEmailPreferences(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["enable_failure_email"] =
flattenBigqueryDataTransferConfigEmailPreferencesEnableFailureEmail(original["enableFailureEmail"], d, config)
return []interface{}{transformed}
}
func flattenBigqueryDataTransferConfigEmailPreferencesEnableFailureEmail(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenBigqueryDataTransferConfigNotificationPubsubTopic(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -735,6 +787,29 @@ func expandBigqueryDataTransferConfigScheduleOptionsEndTime(v interface{}, d Ter
return v, nil
}

func expandBigqueryDataTransferConfigEmailPreferences(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedEnableFailureEmail, err := expandBigqueryDataTransferConfigEmailPreferencesEnableFailureEmail(original["enable_failure_email"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEnableFailureEmail); val.IsValid() && !isEmptyValue(val) {
transformed["enableFailureEmail"] = transformedEnableFailureEmail
}

return transformed, nil
}

func expandBigqueryDataTransferConfigEmailPreferencesEnableFailureEmail(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandBigqueryDataTransferConfigNotificationPubsubTopic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
3 changes: 3 additions & 0 deletions google/resource_bigquery_data_transfer_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ resource "google_bigquery_data_transfer_config" "query_config" {
}
destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
notification_pubsub_topic = google_pubsub_topic.my_topic.id
email_preferences = {
enable_failure_email = true
}
params = {
destination_table_name_template = "my_table"
write_disposition = "WRITE_APPEND"
Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/bigquery_data_transfer_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ The following arguments are supported:
Options customizing the data transfer schedule.
Structure is documented below.

* `email_preferences` -
(Optional)
Email notifications will be sent according to these preferences to the
email address of the user who owns this transfer config.
Structure is documented below.

* `notification_pubsub_topic` -
(Optional)
Pub/Sub topic where notifications will be sent after transfer runs
Expand Down Expand Up @@ -180,6 +186,12 @@ The `schedule_options` block supports:
moment. The time when a data transfer can be triggered manually is not
limited by this option.

The `email_preferences` block supports:

* `enable_failure_email` -
(Required)
If true, email notifications will be sent on transfer run failures.

The `sensitive_params` block supports:

* `secret_access_key` -
Expand Down