Skip to content

Commit 9981d0b

Browse files
bq analyticshub listing - add support for restrictedExportConfig (#9661) (#16850)
* bq analyticshub listing - add support for restrictedExportConfig * lint * Update mmv1/products/bigqueryanalyticshub/Listing.yaml --------- [upstream:9baa61fae74633eaa57e63c532a0bef70c12aaa6] Signed-off-by: Modular Magician <[email protected]>
1 parent b9fffd4 commit 9981d0b

File tree

4 files changed

+214
-0
lines changed

4 files changed

+214
-0
lines changed

.changelog/9661.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigqueryanalyticshub: added `restricted_export_config` field to `google_bigquery_analytics_hub_listing ` resource
3+
```

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go

+96
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ func ResourceBigqueryAnalyticsHubListing() *schema.Resource {
165165
Optional: true,
166166
Description: `Email or URL of the request access of the listing. Subscribers can use this reference to request access.`,
167167
},
168+
"restricted_export_config": {
169+
Type: schema.TypeList,
170+
Optional: true,
171+
Description: `If set, restricted export configuration will be propagated and enforced on the linked dataset.`,
172+
MaxItems: 1,
173+
Elem: &schema.Resource{
174+
Schema: map[string]*schema.Schema{
175+
"enabled": {
176+
Type: schema.TypeBool,
177+
Optional: true,
178+
Description: `If true, enable restricted export.`,
179+
},
180+
"restrict_query_result": {
181+
Type: schema.TypeBool,
182+
Optional: true,
183+
Description: `If true, restrict export of query result derived from restricted linked dataset table.`,
184+
},
185+
},
186+
},
187+
},
168188
"name": {
169189
Type: schema.TypeString,
170190
Computed: true,
@@ -249,6 +269,12 @@ func resourceBigqueryAnalyticsHubListingCreate(d *schema.ResourceData, meta inte
249269
} else if v, ok := d.GetOkExists("bigquery_dataset"); !tpgresource.IsEmptyValue(reflect.ValueOf(bigqueryDatasetProp)) && (ok || !reflect.DeepEqual(v, bigqueryDatasetProp)) {
250270
obj["bigqueryDataset"] = bigqueryDatasetProp
251271
}
272+
restrictedExportConfigProp, err := expandBigqueryAnalyticsHubListingRestrictedExportConfig(d.Get("restricted_export_config"), d, config)
273+
if err != nil {
274+
return err
275+
} else if v, ok := d.GetOkExists("restricted_export_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(restrictedExportConfigProp)) && (ok || !reflect.DeepEqual(v, restrictedExportConfigProp)) {
276+
obj["restrictedExportConfig"] = restrictedExportConfigProp
277+
}
252278

253279
url, err := tpgresource.ReplaceVars(d, config, "{{BigqueryAnalyticsHubBasePath}}projects/{{project}}/locations/{{location}}/dataExchanges/{{data_exchange_id}}/listings?listing_id={{listing_id}}")
254280
if err != nil {
@@ -370,6 +396,9 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf
370396
if err := d.Set("bigquery_dataset", flattenBigqueryAnalyticsHubListingBigqueryDataset(res["bigqueryDataset"], d, config)); err != nil {
371397
return fmt.Errorf("Error reading Listing: %s", err)
372398
}
399+
if err := d.Set("restricted_export_config", flattenBigqueryAnalyticsHubListingRestrictedExportConfig(res["restrictedExportConfig"], d, config)); err != nil {
400+
return fmt.Errorf("Error reading Listing: %s", err)
401+
}
373402

374403
return nil
375404
}
@@ -450,6 +479,12 @@ func resourceBigqueryAnalyticsHubListingUpdate(d *schema.ResourceData, meta inte
450479
} else if v, ok := d.GetOkExists("bigquery_dataset"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, bigqueryDatasetProp)) {
451480
obj["bigqueryDataset"] = bigqueryDatasetProp
452481
}
482+
restrictedExportConfigProp, err := expandBigqueryAnalyticsHubListingRestrictedExportConfig(d.Get("restricted_export_config"), d, config)
483+
if err != nil {
484+
return err
485+
} else if v, ok := d.GetOkExists("restricted_export_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, restrictedExportConfigProp)) {
486+
obj["restrictedExportConfig"] = restrictedExportConfigProp
487+
}
453488

454489
url, err := tpgresource.ReplaceVars(d, config, "{{BigqueryAnalyticsHubBasePath}}projects/{{project}}/locations/{{location}}/dataExchanges/{{data_exchange_id}}/listings/{{listing_id}}")
455490
if err != nil {
@@ -498,6 +533,10 @@ func resourceBigqueryAnalyticsHubListingUpdate(d *schema.ResourceData, meta inte
498533
if d.HasChange("bigquery_dataset") {
499534
updateMask = append(updateMask, "bigqueryDataset")
500535
}
536+
537+
if d.HasChange("restricted_export_config") {
538+
updateMask = append(updateMask, "restrictedExportConfig")
539+
}
501540
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
502541
// won't set it
503542
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -693,6 +732,29 @@ func flattenBigqueryAnalyticsHubListingBigqueryDatasetDataset(v interface{}, d *
693732
return v
694733
}
695734

735+
func flattenBigqueryAnalyticsHubListingRestrictedExportConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
736+
if v == nil {
737+
return nil
738+
}
739+
original := v.(map[string]interface{})
740+
if len(original) == 0 {
741+
return nil
742+
}
743+
transformed := make(map[string]interface{})
744+
transformed["enabled"] =
745+
flattenBigqueryAnalyticsHubListingRestrictedExportConfigEnabled(original["enabled"], d, config)
746+
transformed["restrict_query_result"] =
747+
flattenBigqueryAnalyticsHubListingRestrictedExportConfigRestrictQueryResult(original["restrictQueryResult"], d, config)
748+
return []interface{}{transformed}
749+
}
750+
func flattenBigqueryAnalyticsHubListingRestrictedExportConfigEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
751+
return v
752+
}
753+
754+
func flattenBigqueryAnalyticsHubListingRestrictedExportConfigRestrictQueryResult(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
755+
return v
756+
}
757+
696758
func expandBigqueryAnalyticsHubListingDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
697759
return v, nil
698760
}
@@ -811,3 +873,37 @@ func expandBigqueryAnalyticsHubListingBigqueryDataset(v interface{}, d tpgresour
811873
func expandBigqueryAnalyticsHubListingBigqueryDatasetDataset(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
812874
return v, nil
813875
}
876+
877+
func expandBigqueryAnalyticsHubListingRestrictedExportConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
878+
l := v.([]interface{})
879+
if len(l) == 0 || l[0] == nil {
880+
return nil, nil
881+
}
882+
raw := l[0]
883+
original := raw.(map[string]interface{})
884+
transformed := make(map[string]interface{})
885+
886+
transformedEnabled, err := expandBigqueryAnalyticsHubListingRestrictedExportConfigEnabled(original["enabled"], d, config)
887+
if err != nil {
888+
return nil, err
889+
} else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) {
890+
transformed["enabled"] = transformedEnabled
891+
}
892+
893+
transformedRestrictQueryResult, err := expandBigqueryAnalyticsHubListingRestrictedExportConfigRestrictQueryResult(original["restrict_query_result"], d, config)
894+
if err != nil {
895+
return nil, err
896+
} else if val := reflect.ValueOf(transformedRestrictQueryResult); val.IsValid() && !tpgresource.IsEmptyValue(val) {
897+
transformed["restrictQueryResult"] = transformedRestrictQueryResult
898+
}
899+
900+
return transformed, nil
901+
}
902+
903+
func expandBigqueryAnalyticsHubListingRestrictedExportConfigEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
904+
return v, nil
905+
}
906+
907+
func expandBigqueryAnalyticsHubListingRestrictedExportConfigRestrictQueryResult(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
908+
return v, nil
909+
}

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,66 @@ resource "google_bigquery_dataset" "listing" {
8585
`, context)
8686
}
8787

88+
func TestAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingRestrictedExample(t *testing.T) {
89+
t.Parallel()
90+
91+
context := map[string]interface{}{
92+
"random_suffix": acctest.RandString(t, 10),
93+
}
94+
95+
acctest.VcrTest(t, resource.TestCase{
96+
PreCheck: func() { acctest.AccTestPreCheck(t) },
97+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
98+
CheckDestroy: testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t),
99+
Steps: []resource.TestStep{
100+
{
101+
Config: testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingRestrictedExample(context),
102+
},
103+
{
104+
ResourceName: "google_bigquery_analytics_hub_listing.listing",
105+
ImportState: true,
106+
ImportStateVerify: true,
107+
ImportStateVerifyIgnore: []string{"data_exchange_id", "listing_id", "location"},
108+
},
109+
},
110+
})
111+
}
112+
113+
func testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingRestrictedExample(context map[string]interface{}) string {
114+
return acctest.Nprintf(`
115+
resource "google_bigquery_analytics_hub_data_exchange" "listing" {
116+
location = "US"
117+
data_exchange_id = "tf_test_my_data_exchange%{random_suffix}"
118+
display_name = "tf_test_my_data_exchange%{random_suffix}"
119+
description = "example data exchange%{random_suffix}"
120+
}
121+
122+
resource "google_bigquery_analytics_hub_listing" "listing" {
123+
location = "US"
124+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.listing.data_exchange_id
125+
listing_id = "tf_test_my_listing%{random_suffix}"
126+
display_name = "tf_test_my_listing%{random_suffix}"
127+
description = "example data exchange%{random_suffix}"
128+
129+
bigquery_dataset {
130+
dataset = google_bigquery_dataset.listing.id
131+
}
132+
133+
restricted_export_config {
134+
enabled = true
135+
restrict_query_result = true
136+
}
137+
}
138+
139+
resource "google_bigquery_dataset" "listing" {
140+
dataset_id = "tf_test_my_listing%{random_suffix}"
141+
friendly_name = "tf_test_my_listing%{random_suffix}"
142+
description = "example data exchange%{random_suffix}"
143+
location = "US"
144+
}
145+
`, context)
146+
}
147+
88148
func testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t *testing.T) func(s *terraform.State) error {
89149
return func(s *terraform.State) error {
90150
for name, rs := range s.RootModule().Resources {

website/docs/r/bigquery_analytics_hub_listing.html.markdown

+55
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,46 @@ resource "google_bigquery_analytics_hub_listing" "listing" {
5656
}
5757
}
5858
59+
resource "google_bigquery_dataset" "listing" {
60+
dataset_id = "my_listing"
61+
friendly_name = "my_listing"
62+
description = "example data exchange"
63+
location = "US"
64+
}
65+
```
66+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
67+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=bigquery_analyticshub_listing_restricted&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
68+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
69+
</a>
70+
</div>
71+
## Example Usage - Bigquery Analyticshub Listing Restricted
72+
73+
74+
```hcl
75+
resource "google_bigquery_analytics_hub_data_exchange" "listing" {
76+
location = "US"
77+
data_exchange_id = "my_data_exchange"
78+
display_name = "my_data_exchange"
79+
description = "example data exchange"
80+
}
81+
82+
resource "google_bigquery_analytics_hub_listing" "listing" {
83+
location = "US"
84+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.listing.data_exchange_id
85+
listing_id = "my_listing"
86+
display_name = "my_listing"
87+
description = "example data exchange"
88+
89+
bigquery_dataset {
90+
dataset = google_bigquery_dataset.listing.id
91+
}
92+
93+
restricted_export_config {
94+
enabled = true
95+
restrict_query_result = true
96+
}
97+
}
98+
5999
resource "google_bigquery_dataset" "listing" {
60100
dataset_id = "my_listing"
61101
friendly_name = "my_listing"
@@ -134,6 +174,11 @@ The following arguments are supported:
134174
(Optional)
135175
Categories of the listing. Up to two categories are allowed.
136176

177+
* `restricted_export_config` -
178+
(Optional)
179+
If set, restricted export configuration will be propagated and enforced on the linked dataset.
180+
Structure is [documented below](#nested_restricted_export_config).
181+
137182
* `project` - (Optional) The ID of the project in which the resource belongs.
138183
If it is not provided, the provider project is used.
139184

@@ -158,6 +203,16 @@ The following arguments are supported:
158203
(Optional)
159204
Email or URL of the listing publisher.
160205

206+
<a name="nested_restricted_export_config"></a>The `restricted_export_config` block supports:
207+
208+
* `enabled` -
209+
(Optional)
210+
If true, enable restricted export.
211+
212+
* `restrict_query_result` -
213+
(Optional)
214+
If true, restrict export of query result derived from restricted linked dataset table.
215+
161216
## Attributes Reference
162217

163218
In addition to the arguments listed above, the following computed attributes are exported:

0 commit comments

Comments
 (0)