Skip to content

Commit 2dc9511

Browse files
Adding support for Routines in Listings (#14472) (#10327)
[upstream:487b6c8093e6da5b2658a82ee59ac2f544d0224e] Signed-off-by: Modular Magician <[email protected]>
1 parent 0d06c22 commit 2dc9511

File tree

5 files changed

+190
-1
lines changed

5 files changed

+190
-1
lines changed

.changelog/14472.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigqueryanalyticshub: added `routine` field to `google_bigquery_analytics_hub_listing` resource (beta)
3+
```

google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ func ResourceBigqueryAnalyticsHubListing() *schema.Resource {
101101
Description: `Resource in this dataset that is selectively shared. This field is required for data clean room exchanges.`,
102102
Elem: &schema.Resource{
103103
Schema: map[string]*schema.Schema{
104+
"routine": {
105+
Type: schema.TypeString,
106+
Optional: true,
107+
ForceNew: true,
108+
DiffSuppressFunc: tpgresource.ProjectNumberDiffSuppress,
109+
Description: `Format: For routine: projects/{projectId}/datasets/{datasetId}/routines/{routineId} Example:"projects/test_project/datasets/test_dataset/routines/test_routine"`,
110+
ExactlyOneOf: []string{},
111+
},
104112
"table": {
105113
Type: schema.TypeString,
106114
Optional: true,
107115
ForceNew: true,
108116
DiffSuppressFunc: tpgresource.ProjectNumberDiffSuppress,
109117
Description: `Format: For table: projects/{projectId}/datasets/{datasetId}/tables/{tableId} Example:"projects/test_project/datasets/test_dataset/tables/test_table"`,
118+
ExactlyOneOf: []string{},
110119
},
111120
},
112121
},
@@ -861,7 +870,8 @@ func flattenBigqueryAnalyticsHubListingBigqueryDatasetSelectedResources(v interf
861870
continue
862871
}
863872
transformed = append(transformed, map[string]interface{}{
864-
"table": flattenBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesTable(original["table"], d, config),
873+
"table": flattenBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesTable(original["table"], d, config),
874+
"routine": flattenBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesRoutine(original["routine"], d, config),
865875
})
866876
}
867877
return transformed
@@ -870,6 +880,10 @@ func flattenBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesTable(v i
870880
return v
871881
}
872882

883+
func flattenBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesRoutine(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
884+
return v
885+
}
886+
873887
func flattenBigqueryAnalyticsHubListingPubsubTopic(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
874888
if v == nil {
875889
return nil
@@ -1072,6 +1086,13 @@ func expandBigqueryAnalyticsHubListingBigqueryDatasetSelectedResources(v interfa
10721086
transformed["table"] = transformedTable
10731087
}
10741088

1089+
transformedRoutine, err := expandBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesRoutine(original["routine"], d, config)
1090+
if err != nil {
1091+
return nil, err
1092+
} else if val := reflect.ValueOf(transformedRoutine); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1093+
transformed["routine"] = transformedRoutine
1094+
}
1095+
10751096
req = append(req, transformed)
10761097
}
10771098
return req, nil
@@ -1081,6 +1102,10 @@ func expandBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesTable(v in
10811102
return v, nil
10821103
}
10831104

1105+
func expandBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesRoutine(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1106+
return v, nil
1107+
}
1108+
10841109
func expandBigqueryAnalyticsHubListingPubsubTopic(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10851110
l := v.([]interface{})
10861111
if len(l) == 0 || l[0] == nil {

google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ api_version: 'v1'
66
api_resource_type_kind: 'Listing'
77
fields:
88
- field: 'bigquery_dataset.dataset'
9+
- field: 'bigquery_dataset.selected_resources.routine'
910
- field: 'bigquery_dataset.selected_resources.table'
1011
- field: 'categories'
1112
- field: 'data_exchange_id'

google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,94 @@ resource "google_bigquery_analytics_hub_listing" "listing" {
347347
`, context)
348348
}
349349

350+
func TestAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingDcrRoutineExample(t *testing.T) {
351+
t.Parallel()
352+
353+
context := map[string]interface{}{
354+
"random_suffix": acctest.RandString(t, 10),
355+
}
356+
357+
acctest.VcrTest(t, resource.TestCase{
358+
PreCheck: func() { acctest.AccTestPreCheck(t) },
359+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
360+
CheckDestroy: testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t),
361+
Steps: []resource.TestStep{
362+
{
363+
Config: testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingDcrRoutineExample(context),
364+
},
365+
{
366+
ResourceName: "google_bigquery_analytics_hub_listing.listing",
367+
ImportState: true,
368+
ImportStateVerify: true,
369+
ImportStateVerifyIgnore: []string{"data_exchange_id", "listing_id", "location"},
370+
},
371+
},
372+
})
373+
}
374+
375+
func testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingDcrRoutineExample(context map[string]interface{}) string {
376+
return acctest.Nprintf(`
377+
resource "google_bigquery_analytics_hub_data_exchange" "dcr_data_exchange_example" {
378+
provider = google-beta
379+
location = "us"
380+
data_exchange_id = "tf_test_tf_test_data_exchange%{random_suffix}"
381+
display_name = "tf_test_tf_test_data_exchange%{random_suffix}"
382+
description = "Example for listing with routine%{random_suffix}"
383+
sharing_environment_config {
384+
dcr_exchange_config {}
385+
}
386+
}
387+
388+
resource "google_bigquery_dataset" "listing" {
389+
provider = google-beta
390+
dataset_id = "tf_test_tf_test_dataset%{random_suffix}"
391+
friendly_name = "tf_test_tf_test_dataset%{random_suffix}"
392+
description = "Example for listing with routine%{random_suffix}"
393+
location = "us"
394+
}
395+
396+
resource "google_bigquery_routine" "listing" {
397+
provider = google-beta
398+
dataset_id = google_bigquery_dataset.listing.dataset_id
399+
routine_id = "tf_test_tf_test_routine%{random_suffix}"
400+
routine_type = "TABLE_VALUED_FUNCTION"
401+
language = "SQL"
402+
description = "A DCR routine example."
403+
definition_body = <<-EOS
404+
SELECT 1 + value AS value
405+
EOS
406+
arguments {
407+
name = "value"
408+
argument_kind = "FIXED_TYPE"
409+
data_type = jsonencode({ "typeKind" : "INT64" })
410+
}
411+
return_table_type = jsonencode({
412+
"columns" : [
413+
{ "name" : "value", "type" : { "typeKind" : "INT64" } },
414+
]
415+
})
416+
}
417+
418+
resource "google_bigquery_analytics_hub_listing" "listing" {
419+
provider = google-beta
420+
location = "US"
421+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.dcr_data_exchange_example.data_exchange_id
422+
listing_id = "tf_test_tf_test_listing_routine%{random_suffix}"
423+
display_name = "tf_test_tf_test_listing_routine%{random_suffix}"
424+
description = "Example for listing with routine%{random_suffix}"
425+
bigquery_dataset {
426+
dataset = google_bigquery_dataset.listing.id
427+
selected_resources {
428+
routine = google_bigquery_routine.listing.id
429+
}
430+
}
431+
restricted_export_config {
432+
enabled = true
433+
}
434+
}
435+
`, context)
436+
}
437+
350438
func testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t *testing.T) func(s *terraform.State) error {
351439
return func(s *terraform.State) error {
352440
for name, rs := range s.RootModule().Resources {

website/docs/r/bigquery_analytics_hub_listing.html.markdown

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,74 @@ resource "google_bigquery_analytics_hub_listing" "listing" {
247247
}
248248
}
249249
```
250+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
251+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=bigquery_analyticshub_listing_dcr_routine&open_in_editor=main.tf" target="_blank">
252+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
253+
</a>
254+
</div>
255+
## Example Usage - Bigquery Analyticshub Listing Dcr Routine
256+
257+
258+
```hcl
259+
resource "google_bigquery_analytics_hub_data_exchange" "dcr_data_exchange_example" {
260+
provider = google-beta
261+
location = "us"
262+
data_exchange_id = "tf_test_data_exchange"
263+
display_name = "tf_test_data_exchange"
264+
description = "Example for listing with routine"
265+
sharing_environment_config {
266+
dcr_exchange_config {}
267+
}
268+
}
269+
270+
resource "google_bigquery_dataset" "listing" {
271+
provider = google-beta
272+
dataset_id = "tf_test_dataset"
273+
friendly_name = "tf_test_dataset"
274+
description = "Example for listing with routine"
275+
location = "us"
276+
}
277+
278+
resource "google_bigquery_routine" "listing" {
279+
provider = google-beta
280+
dataset_id = google_bigquery_dataset.listing.dataset_id
281+
routine_id = "tf_test_routine"
282+
routine_type = "TABLE_VALUED_FUNCTION"
283+
language = "SQL"
284+
description = "A DCR routine example."
285+
definition_body = <<-EOS
286+
SELECT 1 + value AS value
287+
EOS
288+
arguments {
289+
name = "value"
290+
argument_kind = "FIXED_TYPE"
291+
data_type = jsonencode({ "typeKind" : "INT64" })
292+
}
293+
return_table_type = jsonencode({
294+
"columns" : [
295+
{ "name" : "value", "type" : { "typeKind" : "INT64" } },
296+
]
297+
})
298+
}
299+
300+
resource "google_bigquery_analytics_hub_listing" "listing" {
301+
provider = google-beta
302+
location = "US"
303+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.dcr_data_exchange_example.data_exchange_id
304+
listing_id = "tf_test_listing_routine"
305+
display_name = "tf_test_listing_routine"
306+
description = "Example for listing with routine"
307+
bigquery_dataset {
308+
dataset = google_bigquery_dataset.listing.id
309+
selected_resources {
310+
routine = google_bigquery_routine.listing.id
311+
}
312+
}
313+
restricted_export_config {
314+
enabled = true
315+
}
316+
}
317+
```
250318

251319
## Argument Reference
252320

@@ -366,6 +434,10 @@ The following arguments are supported:
366434
(Optional)
367435
Format: For table: projects/{projectId}/datasets/{datasetId}/tables/{tableId} Example:"projects/test_project/datasets/test_dataset/tables/test_table"
368436

437+
* `routine` -
438+
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
439+
Format: For routine: projects/{projectId}/datasets/{datasetId}/routines/{routineId} Example:"projects/test_project/datasets/test_dataset/routines/test_routine"
440+
369441
<a name="nested_pubsub_topic"></a>The `pubsub_topic` block supports:
370442

371443
* `topic` -

0 commit comments

Comments
 (0)