From 29d026d99d8042551be933627a0a3360c4f40bb8 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 21 Aug 2020 08:49:01 -0700 Subject: [PATCH] Add `notificationPubsubTopic` to BigQuery Data Transfer (#3881) (#7076) * Add notificationPubsubTopic to BigQuery Data Transfer * Fix test resource names suffix to be random Signed-off-by: Modular Magician --- .changelog/3881.txt | 3 ++ .../resource_bigquery_data_transfer_config.go | 33 +++++++++++++++++++ ...urce_bigquery_data_transfer_config_test.go | 7 +++- ...igquery_data_transfer_config.html.markdown | 5 +++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .changelog/3881.txt diff --git a/.changelog/3881.txt b/.changelog/3881.txt new file mode 100644 index 00000000000..0d97149967c --- /dev/null +++ b/.changelog/3881.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +bigquery: added `notification_pubsub_topic` field to `google_bigquery_data_transfer_config` resource +``` diff --git a/google/resource_bigquery_data_transfer_config.go b/google/resource_bigquery_data_transfer_config.go index df619a2210e..d6b083712b2 100644 --- a/google/resource_bigquery_data_transfer_config.go +++ b/google/resource_bigquery_data_transfer_config.go @@ -88,6 +88,12 @@ Set the value to 0 to use the default value.`, Examples: US, EU, asia-northeast1. The default value is US.`, Default: "US", }, + "notification_pubsub_topic": { + Type: schema.TypeString, + Optional: true, + Description: `Pub/Sub topic where notifications will be sent after transfer runs +associated with this transfer config finish.`, + }, "schedule": { Type: schema.TypeString, Optional: true, @@ -155,6 +161,12 @@ func resourceBigqueryDataTransferConfigCreate(d *schema.ResourceData, meta inter } else if v, ok := d.GetOkExists("schedule"); !isEmptyValue(reflect.ValueOf(scheduleProp)) && (ok || !reflect.DeepEqual(v, scheduleProp)) { obj["schedule"] = scheduleProp } + notificationPubsubTopicProp, err := expandBigqueryDataTransferConfigNotificationPubsubTopic(d.Get("notification_pubsub_topic"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("notification_pubsub_topic"); !isEmptyValue(reflect.ValueOf(notificationPubsubTopicProp)) && (ok || !reflect.DeepEqual(v, notificationPubsubTopicProp)) { + obj["notificationPubsubTopic"] = notificationPubsubTopicProp + } dataRefreshWindowDaysProp, err := expandBigqueryDataTransferConfigDataRefreshWindowDays(d.Get("data_refresh_window_days"), d, config) if err != nil { return err @@ -256,6 +268,9 @@ func resourceBigqueryDataTransferConfigRead(d *schema.ResourceData, meta interfa if err := d.Set("schedule", flattenBigqueryDataTransferConfigSchedule(res["schedule"], 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) + } if err := d.Set("data_refresh_window_days", flattenBigqueryDataTransferConfigDataRefreshWindowDays(res["dataRefreshWindowDays"], d, config)); err != nil { return fmt.Errorf("Error reading Config: %s", err) } @@ -290,6 +305,12 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter } else if v, ok := d.GetOkExists("schedule"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, scheduleProp)) { obj["schedule"] = scheduleProp } + notificationPubsubTopicProp, err := expandBigqueryDataTransferConfigNotificationPubsubTopic(d.Get("notification_pubsub_topic"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("notification_pubsub_topic"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, notificationPubsubTopicProp)) { + obj["notificationPubsubTopic"] = notificationPubsubTopicProp + } dataRefreshWindowDaysProp, err := expandBigqueryDataTransferConfigDataRefreshWindowDays(d.Get("data_refresh_window_days"), d, config) if err != nil { return err @@ -325,6 +346,10 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter updateMask = append(updateMask, "schedule") } + if d.HasChange("notification_pubsub_topic") { + updateMask = append(updateMask, "notificationPubsubTopic") + } + if d.HasChange("data_refresh_window_days") { updateMask = append(updateMask, "dataRefreshWindowDays") } @@ -410,6 +435,10 @@ func flattenBigqueryDataTransferConfigSchedule(v interface{}, d *schema.Resource return v } +func flattenBigqueryDataTransferConfigNotificationPubsubTopic(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + func flattenBigqueryDataTransferConfigDataRefreshWindowDays(v interface{}, d *schema.ResourceData, config *Config) interface{} { // Handles the string fixed64 format if strVal, ok := v.(string); ok { @@ -461,6 +490,10 @@ func expandBigqueryDataTransferConfigSchedule(v interface{}, d TerraformResource return v, nil } +func expandBigqueryDataTransferConfigNotificationPubsubTopic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandBigqueryDataTransferConfigDataRefreshWindowDays(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } diff --git a/google/resource_bigquery_data_transfer_config_test.go b/google/resource_bigquery_data_transfer_config_test.go index 273d1ce25be..f9918077a15 100644 --- a/google/resource_bigquery_data_transfer_config_test.go +++ b/google/resource_bigquery_data_transfer_config_test.go @@ -164,6 +164,10 @@ resource "google_bigquery_dataset" "my_dataset" { location = "asia-northeast1" } +resource "google_pubsub_topic" "my_topic" { + name = "tf-test-my-topic-%s" +} + resource "google_bigquery_data_transfer_config" "query_config" { depends_on = [google_project_iam_member.permissions] @@ -172,13 +176,14 @@ resource "google_bigquery_data_transfer_config" "query_config" { data_source_id = "scheduled_query" schedule = "%s sunday of quarter 00:00" destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id + notification_pubsub_topic = google_pubsub_topic.my_topic.id params = { destination_table_name_template = "my_table" write_disposition = "WRITE_APPEND" query = "SELECT name FROM tabl WHERE x = '%s'" } } -`, random_suffix, random_suffix, schedule, letter) +`, random_suffix, random_suffix, random_suffix, schedule, letter) } func testAccBigqueryDataTransferConfig_scheduledQuery_service_account(random_suffix string) string { diff --git a/website/docs/r/bigquery_data_transfer_config.html.markdown b/website/docs/r/bigquery_data_transfer_config.html.markdown index b36551781d5..2fda6d4e081 100644 --- a/website/docs/r/bigquery_data_transfer_config.html.markdown +++ b/website/docs/r/bigquery_data_transfer_config.html.markdown @@ -105,6 +105,11 @@ The following arguments are supported: https://cloud.google.com/appengine/docs/flexible/python/scheduling-jobs-with-cron-yaml#the_schedule_format NOTE: the granularity should be at least 8 hours, or less frequent. +* `notification_pubsub_topic` - + (Optional) + Pub/Sub topic where notifications will be sent after transfer runs + associated with this transfer config finish. + * `data_refresh_window_days` - (Optional) The number of days to look back to automatically refresh the data.