Skip to content

Commit

Permalink
Add notificationPubsubTopic to BigQuery Data Transfer (#3881) (#7076)
Browse files Browse the repository at this point in the history
* Add notificationPubsubTopic to BigQuery Data Transfer

* Fix test resource names suffix to be random

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 21, 2020
1 parent 09801c6 commit 29d026d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/3881.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigquery: added `notification_pubsub_topic` field to `google_bigquery_data_transfer_config` resource
```
33 changes: 33 additions & 0 deletions google/resource_bigquery_data_transfer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion google/resource_bigquery_data_transfer_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/bigquery_data_transfer_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 29d026d

Please sign in to comment.