Skip to content

Commit 0ea9b62

Browse files
Adding support for log_linked_dataset_query_user_email attribute for BigQuery Analytics Hub listings. (#14225) (#10177)
[upstream:cf25ab930f3bb6688ee4210ab137142b69c4da70] Signed-off-by: Modular Magician <[email protected]>
1 parent e191810 commit 0ea9b62

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

.changelog/14225.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 `log_linked_dataset_query_user_email` field to `google_bigquery_analytics_hub_listing` resource
3+
```

google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ func ResourceBigqueryAnalyticsHubListing() *schema.Resource {
157157
Optional: true,
158158
Description: `Base64 encoded image representing the listing.`,
159159
},
160+
"log_linked_dataset_query_user_email": {
161+
Type: schema.TypeBool,
162+
Optional: true,
163+
ForceNew: true,
164+
Description: `If true, subscriber email logging is enabled and all queries on the linked dataset will log the email address of the querying user.`,
165+
},
160166
"primary_contact": {
161167
Type: schema.TypeString,
162168
Optional: true,
@@ -302,6 +308,12 @@ func resourceBigqueryAnalyticsHubListingCreate(d *schema.ResourceData, meta inte
302308
} else if v, ok := d.GetOkExists("restricted_export_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(restrictedExportConfigProp)) && (ok || !reflect.DeepEqual(v, restrictedExportConfigProp)) {
303309
obj["restrictedExportConfig"] = restrictedExportConfigProp
304310
}
311+
logLinkedDatasetQueryUserEmailProp, err := expandBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(d.Get("log_linked_dataset_query_user_email"), d, config)
312+
if err != nil {
313+
return err
314+
} else if v, ok := d.GetOkExists("log_linked_dataset_query_user_email"); !tpgresource.IsEmptyValue(reflect.ValueOf(logLinkedDatasetQueryUserEmailProp)) && (ok || !reflect.DeepEqual(v, logLinkedDatasetQueryUserEmailProp)) {
315+
obj["logLinkedDatasetQueryUserEmail"] = logLinkedDatasetQueryUserEmailProp
316+
}
305317

306318
url, err := tpgresource.ReplaceVars(d, config, "{{BigqueryAnalyticsHubBasePath}}projects/{{project}}/locations/{{location}}/dataExchanges/{{data_exchange_id}}/listings?listing_id={{listing_id}}")
307319
if err != nil {
@@ -427,6 +439,9 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf
427439
if err := d.Set("restricted_export_config", flattenBigqueryAnalyticsHubListingRestrictedExportConfig(res["restrictedExportConfig"], d, config)); err != nil {
428440
return fmt.Errorf("Error reading Listing: %s", err)
429441
}
442+
if err := d.Set("log_linked_dataset_query_user_email", flattenBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(res["logLinkedDatasetQueryUserEmail"], d, config)); err != nil {
443+
return fmt.Errorf("Error reading Listing: %s", err)
444+
}
430445

431446
return nil
432447
}
@@ -808,6 +823,10 @@ func flattenBigqueryAnalyticsHubListingRestrictedExportConfigRestrictQueryResult
808823
return v
809824
}
810825

826+
func flattenBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
827+
return v
828+
}
829+
811830
func expandBigqueryAnalyticsHubListingDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
812831
return v, nil
813832
}
@@ -1004,3 +1023,7 @@ func expandBigqueryAnalyticsHubListingRestrictedExportConfigRestrictDirectTableA
10041023
func expandBigqueryAnalyticsHubListingRestrictedExportConfigRestrictQueryResult(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10051024
return v, nil
10061025
}
1026+
1027+
func expandBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1028+
return v, nil
1029+
}

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
@@ -20,6 +20,7 @@ fields:
2020
provider_only: true
2121
- field: 'location'
2222
provider_only: true
23+
- field: 'log_linked_dataset_query_user_email'
2324
- field: 'name'
2425
- field: 'primary_contact'
2526
- field: 'publisher.name'

google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,62 @@ EOF
235235
`, context)
236236
}
237237

238+
func TestAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingLogLinkedDatasetQueryUserExample(t *testing.T) {
239+
t.Parallel()
240+
241+
context := map[string]interface{}{
242+
"random_suffix": acctest.RandString(t, 10),
243+
}
244+
245+
acctest.VcrTest(t, resource.TestCase{
246+
PreCheck: func() { acctest.AccTestPreCheck(t) },
247+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
248+
CheckDestroy: testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t),
249+
Steps: []resource.TestStep{
250+
{
251+
Config: testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingLogLinkedDatasetQueryUserExample(context),
252+
},
253+
{
254+
ResourceName: "google_bigquery_analytics_hub_listing.listing",
255+
ImportState: true,
256+
ImportStateVerify: true,
257+
ImportStateVerifyIgnore: []string{"data_exchange_id", "listing_id", "location"},
258+
},
259+
},
260+
})
261+
}
262+
263+
func testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingLogLinkedDatasetQueryUserExample(context map[string]interface{}) string {
264+
return acctest.Nprintf(`
265+
resource "google_bigquery_analytics_hub_data_exchange" "listing_log_email" {
266+
location = "US"
267+
data_exchange_id = "tf_test_tf_test_log_email_de%{random_suffix}"
268+
display_name = "tf_test_tf_test_log_email_de%{random_suffix}"
269+
description = "Example for log email test%{random_suffix}"
270+
}
271+
272+
resource "google_bigquery_analytics_hub_listing" "listing" {
273+
location = "US"
274+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.listing_log_email.data_exchange_id
275+
listing_id = "tf_test_tf_test_log_email_listing%{random_suffix}"
276+
display_name = "tf_test_tf_test_log_email_listing%{random_suffix}"
277+
description = "Example for log email test%{random_suffix}"
278+
log_linked_dataset_query_user_email = true
279+
280+
bigquery_dataset {
281+
dataset = google_bigquery_dataset.listing_log_email.id
282+
}
283+
}
284+
285+
resource "google_bigquery_dataset" "listing_log_email" {
286+
dataset_id = "tf_test_tf_test_log_email_ds%{random_suffix}"
287+
friendly_name = "tf_test_tf_test_log_email_ds%{random_suffix}"
288+
description = "Example for log email test%{random_suffix}"
289+
location = "US"
290+
}
291+
`, context)
292+
}
293+
238294
func testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t *testing.T) func(s *terraform.State) error {
239295
return func(s *terraform.State) error {
240296
for name, rs := range s.RootModule().Resources {

website/docs/r/bigquery_analytics_hub_listing.html.markdown

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,42 @@ resource "google_bigquery_table" "listing" {
175175
EOF
176176
}
177177
```
178+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
179+
<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_log_linked_dataset_query_user&open_in_editor=main.tf" target="_blank">
180+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
181+
</a>
182+
</div>
183+
## Example Usage - Bigquery Analyticshub Listing Log Linked Dataset Query User
184+
185+
186+
```hcl
187+
resource "google_bigquery_analytics_hub_data_exchange" "listing_log_email" {
188+
location = "US"
189+
data_exchange_id = "tf_test_log_email_de"
190+
display_name = "tf_test_log_email_de"
191+
description = "Example for log email test"
192+
}
193+
194+
resource "google_bigquery_analytics_hub_listing" "listing" {
195+
location = "US"
196+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.listing_log_email.data_exchange_id
197+
listing_id = "tf_test_log_email_listing"
198+
display_name = "tf_test_log_email_listing"
199+
description = "Example for log email test"
200+
log_linked_dataset_query_user_email = true
201+
202+
bigquery_dataset {
203+
dataset = google_bigquery_dataset.listing_log_email.id
204+
}
205+
}
206+
207+
resource "google_bigquery_dataset" "listing_log_email" {
208+
dataset_id = "tf_test_log_email_ds"
209+
friendly_name = "tf_test_log_email_ds"
210+
description = "Example for log email test"
211+
location = "US"
212+
}
213+
```
178214

179215
## Argument Reference
180216

@@ -263,6 +299,10 @@ The following arguments are supported:
263299
If set, restricted export configuration will be propagated and enforced on the linked dataset.
264300
Structure is [documented below](#nested_restricted_export_config).
265301

302+
* `log_linked_dataset_query_user_email` -
303+
(Optional)
304+
If true, subscriber email logging is enabled and all queries on the linked dataset will log the email address of the querying user.
305+
266306
* `project` - (Optional) The ID of the project in which the resource belongs.
267307
If it is not provided, the provider project is used.
268308

0 commit comments

Comments
 (0)