Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 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
26 changes: 26 additions & 0 deletions mmv1/products/bigquerydatatransfer/Config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
display_name: 'my-salesforce-config'
dataset_id: 'my_dataset'
exclude_test: true
- name: bigquerydatatransfer_config_pub_sub
primary_resource_id: 'event_driven_config'
vars:
display_name: 'my-event-driven-query'
dataset_id: 'my_dataset'
topic_name: 'my_dataset_topic'
subscription_name: 'my_dataset_topic_subscription'
exclude_test: true # test skipped because this resources uses handwritten tests

Check warning on line 77 in mmv1/products/bigquerydatatransfer/Config.yaml

View workflow job for this annotation

GitHub Actions / lint-yaml

77:24 [comments] too few spaces before comment
parameters:
- name: 'location'
type: String
Expand Down Expand Up @@ -139,6 +147,7 @@
- 'schedule_options.0.disable_auto_scheduling'
- 'schedule_options.0.start_time'
- 'schedule_options.0.end_time'
- 'schedule_options.0.event_driven_schedule'
- name: 'startTime'
type: Time
description: |
Expand All @@ -151,6 +160,7 @@
- 'schedule_options.0.disable_auto_scheduling'
- 'schedule_options.0.start_time'
- 'schedule_options.0.end_time'
- 'schedule_options.0.event_driven_schedule'
- name: 'endTime'
type: Time
description: |
Expand All @@ -162,6 +172,22 @@
- 'schedule_options.0.disable_auto_scheduling'
- 'schedule_options.0.start_time'
- 'schedule_options.0.end_time'
- 'schedule_options.0.event_driven_schedule'
- name: 'eventDrivenSchedule'
type: NestedObject
description: |
Event driven transfer schedule options. If set, the transfer will be scheduled upon events arrial.
at_least_one_of:
- 'schedule_options.0.disable_auto_scheduling'
- 'schedule_options.0.start_time'
- 'schedule_options.0.end_time'
- 'schedule_options.0.event_driven_schedule'
properties:
- name: 'pubsubSubscription'
type: string
description: |
Pub/Sub subscription name used to receive events. Only Google Cloud Storage data source support this option. Format: projects/{project}/subscriptions/{subscription}.

- name: 'emailPreferences'
type: NestedObject
description: |
Expand Down Expand Up @@ -239,7 +265,7 @@
- 'sensitive_params.0.secretAccessKeyWo'
conflicts:
- 'sensitive_params.0.secretAccessKeyWo'
- name: 'secretAccessKeyWo' # Wo is convention for write-only properties

Check warning on line 268 in mmv1/products/bigquerydatatransfer/Config.yaml

View workflow job for this annotation

GitHub Actions / lint-yaml

268:35 [comments] too few spaces before comment
type: String
description: |
The Secret Access Key of the AWS account transferring data from.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
data "google_project" "project" {
}

resource "google_project_iam_member" "permissions" {
project = data.google_project.project.project_id
role = "roles/iam.serviceAccountTokenCreator"
member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-bigquerydatatransfer.iam.gserviceaccount.com"
}

resource "google_bigquery_data_transfer_config" "{{$.PrimaryResourceId}}" {
depends_on = [google_project_iam_member.permissions]

display_name = "{{index $.Vars "display_name"}}"
location = "asia-northeast1"
data_source_id = "scheduled_query"
schedule = "first sunday of quarter 00:00"
schedule_options {
event_driven_schedule {
pubsub_subscription = google_pubsub_subscription.{{$.PrimaryResourceId}}.id
}
}
destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
params = {
destination_table_name_template = "my_table"
write_disposition = "WRITE_APPEND"
query = "SELECT name FROM tabl WHERE x = 'y'"
}
}

resource "google_bigquery_dataset" "my_dataset" {
depends_on = [google_project_iam_member.permissions]

dataset_id = "{{index $.Vars "dataset_id"}}"
friendly_name = "foo"
description = "bar"
location = "asia-northeast1"
}

resource "google_pubsub_topic" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "topic_name"}}"
}

resource "google_pubsub_subscription" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "subscription_name"}}"
topic = google_pubsub_topic.{{$.PrimaryResourceId}}.id
}
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,27 @@ func testAccBigqueryDataTransferConfig_salesforce_basic(t *testing.T) {
})
}

func TestAccBigqueryDataTransferConfig_pub_sub_basic(t *testing.T) {
randomSuffix := acctest.RandString(t, 10)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigqueryDataTransferConfigDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigqueryDataTransferConfig_pub_sub(randomSuffix),
},
{
ResourceName: "google_bigquery_data_transfer_config.event_driven_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
},
},
})
}

func testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, random_suffix2, schedule, start_time, end_time, letter string) string {
return fmt.Sprintf(`
data "google_project" "project" {}
Expand Down Expand Up @@ -949,3 +970,46 @@ resource "google_bigquery_data_transfer_config" "salesforce_config" {
}
`, randomSuffix, randomSuffix)
}

func testAccBigqueryDataTransferConfig_pub_sub(randomSuffix string) string {
return fmt.Sprintf(`

resource "google_bigquery_data_transfer_config" "event_driven_config" {
depends_on = [google_project_iam_member.permissions]

display_name = "my-event-driven-query-%s"
location = "asia-northeast1"
data_source_id = "scheduled_query"
schedule = "first sunday of quarter 00:00"
schedule_options {
event_driven_schedule {
pubsub_subscription = google_pubsub_subscription.my_dataset_topic_subscription.id
}
}
destination_dataset_id = google_bigquery_dataset.my_dataset.dataset_id
params = {
destination_table_name_template = "my_table"
write_disposition = "WRITE_APPEND"
query = "SELECT name FROM tabl WHERE x = 'y'"
}
}

resource "google_bigquery_dataset" "my_dataset" {
depends_on = [google_project_iam_member.permissions]

dataset_id = "my_dataset-%s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dataset_id = "my_dataset-%s"
dataset_id = "my_dataset_%s"

- is not allowed in this resource's id.

friendly_name = "foo"
description = "bar"
location = "asia-northeast1"
}

resource "google_pubsub_topic" "my_dataset_topic" {
name = "my_dataset_topic"
}

resource "google_pubsub_subscription" "my_dataset_topic_subscription" {
name = "my_dataset_topic_subscription"
topic = google_pubsub_topic.my_dataset_topic.id
}
`, randomSuffix, randomSuffix)
}
Loading