Skip to content

Commit f6f2167

Browse files
committed
feat(bigqueryanalyticshub): Add multi-region support to listings and subscriptions
1 parent 57e2a04 commit f6f2167

File tree

7 files changed

+618
-177
lines changed

7 files changed

+618
-177
lines changed

mmv1/products/bigqueryanalyticshub/Listing.yaml

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ iam_policy:
3535
method_name_separator: ':'
3636
fetch_iam_policy_verb: 'POST'
3737
parent_resource_attribute: 'listing_id'
38+
example_config_body: 'templates/terraform/iam/iam_attributes.go.tmpl'
3839
import_format:
3940
- 'projects/{{project}}/locations/{{location}}/dataExchanges/{{data_exchange_id}}/listings/{{listing_id}}'
4041
- '{{listing_id}}'
4142
custom_code:
4243
pre_update: 'templates/terraform/pre_update/bigqueryanalyticshub_listing.go.tmpl'
43-
pre_delete: 'templates/terraform/pre_delete/bigquery_analytics_hub_listing.go.tmpl'
4444
# Skipping the sweeper due to the non-standard base_url
4545
exclude_sweeper: true
4646
examples:
@@ -97,29 +97,16 @@ examples:
9797
dataset_id: 'tf_test_dataset'
9898
routine_id: 'tf_test_routine'
9999
desc: 'Example for listing with routine'
100-
- name: 'bigquery_analyticshub_public_listing'
100+
- name: 'bigquery_analyticshub_listing_multiregion'
101101
primary_resource_id: 'listing'
102+
min_version: beta
102103
primary_resource_name: 'fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"]), fmt.Sprintf("tf_test_my_listing%s", context["random_suffix"])'
103104
region_override: 'US'
104105
vars:
105106
data_exchange_id: 'my_data_exchange'
106107
listing_id: 'my_listing'
107-
desc: 'example public listing'
108-
- name: 'bigquery_analyticshub_listing_marketplace'
109-
primary_resource_id: 'listing'
110-
primary_resource_name: 'fmt.Sprintf("tf_test_my_data_exchange%s", context["random_suffix"]), fmt.Sprintf("tf_test_my_listing%s", context["random_suffix"])'
111-
region_override: 'us'
112-
vars:
113-
data_exchange_id: 'my_data_exchange'
114-
listing_id: 'my_listing'
115-
desc: 'example data exchange'
116-
ignore_read_extra:
117-
- 'delete_commercial'
118-
virtual_fields:
119-
- name: 'delete_commercial'
120-
type: Boolean
121-
description: |-
122-
If the listing is commercial then this field must be set to true, otherwise a failure is thrown. This acts as a safety guard to avoid deleting commercial listings accidentally.
108+
description: 'example listing for multiregion'
109+
exclude_test: true #Handwritten Create test as replica has to be created through Go BQ client
123110
parameters:
124111
properties:
125112
- name: 'name'
@@ -148,6 +135,7 @@ properties:
148135
url_param_only: true
149136
required: true
150137
immutable: true
138+
diff_suppress_func: 'tpgresource.CaseDiffSuppress'
151139
- name: 'displayName'
152140
type: String
153141
description: |-
@@ -206,7 +194,6 @@ properties:
206194
- name: 'bigqueryDataset'
207195
type: NestedObject
208196
description: Shared dataset i.e. BigQuery dataset source.
209-
immutable: true
210197
exactly_one_of:
211198
- 'pubsubTopic'
212199
- 'bigqueryDataset'
@@ -245,6 +232,43 @@ properties:
245232
exactly_one_of:
246233
- 'table'
247234
- 'routine'
235+
- name: 'replicaLocations'
236+
type: Array
237+
is_set: true
238+
min_version: 'beta'
239+
set_hash_func: 'tpgresource.CaseInsensitiveHash' # Add this line
240+
description: |
241+
A list of regions where the publisher has created shared dataset replicas.
242+
item_type:
243+
type: String
244+
diff_suppress_func: 'tpgresource.CaseDiffSuppress'
245+
- name: 'effectiveReplicas'
246+
type: Array
247+
description: |
248+
Server owned effective state of replicas. Contains both primary and secondary replicas.
249+
Each replica includes a system-computed (output-only) state and primary designation.
250+
output: true
251+
min_version: 'beta'
252+
item_type:
253+
type: NestedObject
254+
properties:
255+
- name: 'location'
256+
type: String
257+
description: |
258+
The geographic location where the replica resides.
259+
output: true
260+
- name: 'replicaState'
261+
type: String
262+
description: |
263+
Output-only. Assigned by Analytics Hub based on real BigQuery replication state.
264+
Possible values: REPLICA_STATE_UNSPECIFIED, READY_TO_USE, UNAVAILABLE
265+
output: true
266+
- name: 'primaryState'
267+
type: String
268+
description: |
269+
Output-only. Indicates that this replica is the primary replica.
270+
Possible values: PRIMARY_STATE_UNSPECIFIED, PRIMARY_REPLICA
271+
output: true
248272
- name: 'pubsubTopic'
249273
type: NestedObject
250274
description: Pub/Sub topic source.
@@ -288,41 +312,3 @@ properties:
288312
type: Boolean
289313
description:
290314
If true, subscriber email logging is enabled and all queries on the linked dataset will log the email address of the querying user. Once enabled, this setting cannot be turned off.
291-
- name: 'state'
292-
type: String
293-
description: |-
294-
Current state of the listing.
295-
output: true
296-
- name: 'discoveryType'
297-
type: Enum
298-
enum_values:
299-
- 'DISCOVERY_TYPE_PRIVATE'
300-
- 'DISCOVERY_TYPE_PUBLIC'
301-
default_from_api: true
302-
description: Specifies the type of discovery on the discovery page. Cannot be set for a restricted listing. Note that this does not control the visibility of the exchange/listing which is defined by IAM permission.
303-
- name: 'allowOnlyMetadataSharing'
304-
type: Boolean
305-
immutable: true
306-
description: If true, the listing is only available to get the resource metadata. Listing is non subscribable.
307-
- name: 'commercialInfo'
308-
type: NestedObject
309-
description: |
310-
Commercial info contains the information about the commercial data products associated with the listing.
311-
output: true
312-
properties:
313-
- name: 'cloudMarketplace'
314-
type: NestedObject
315-
description: Details of the Marketplace Data Product associated with the Listing.
316-
output: true
317-
properties:
318-
- name: 'service'
319-
type: String
320-
description: |
321-
Resource name of the commercial service associated with the Marketplace Data Product. e.g. example.com
322-
output: true
323-
- name: 'commercialState'
324-
type: String
325-
description: |
326-
Commercial state of the Marketplace Data Product.
327-
Possible values: COMMERCIAL_STATE_UNSPECIFIED, ONBOARDING, ACTIVE
328-
output: true

mmv1/products/bigqueryanalyticshub/ListingSubscription.yaml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import_format:
3232
custom_code:
3333
decoder: 'templates/terraform/decoders/bigqueryanalyticshub_listing_subscription.go.tmpl'
3434
pre_read: 'templates/terraform/pre_read/bigqueryanalyticshub_listing_subscription.tmpl'
35-
post_read: 'templates/terraform/post_read/bigqueryanalyticshub_listing_subscription.go.tmpl'
3635
pre_delete: 'templates/terraform/pre_read/bigqueryanalyticshub_listing_subscription.tmpl'
3736
post_import: templates/terraform/post_import/analytics_hub_subscription.go.tmpl
3837
sweeper:
@@ -52,6 +51,21 @@ examples:
5251
listing_id: 'my_listing'
5352
destination_dataset_id: 'destination_dataset'
5453
description: 'example data exchange'
54+
- name: 'bigquery_analyticshub_listing_subscription_multiregion'
55+
primary_resource_id: 'subscription'
56+
min_version: beta
57+
primary_resource_name: 'fmt.Sprintf(\"tf_test_my_data_exchange%s\",
58+
context[\"\
59+
random_suffix\"]), fmt.Sprintf(\"tf_test_my_listing%s\",
60+
context[\"random_suffix\"\
61+
])'
62+
region_override: 'US'
63+
vars:
64+
data_exchange_id: 'my_data_exchange'
65+
listing_id: 'my_listing'
66+
destination_dataset_id: 'destination_dataset'
67+
description: 'example listing multiregion subscription'
68+
exclude_test: true #Handwritten Create test as replica has to be created through Go BQ client
5569
parameters:
5670
- name: 'dataExchangeId'
5771
type: String
@@ -77,6 +91,7 @@ properties:
7791
- name: 'destinationDataset'
7892
type: NestedObject
7993
required: true
94+
ignore_read: true
8095
description:
8196
The destination dataset for this subscription.
8297
properties:
@@ -112,6 +127,16 @@ properties:
112127
description: |
113128
The labels associated with this dataset. You can use these to
114129
organize and group your datasets.
130+
- name: 'replicaLocations'
131+
is_set: true
132+
type: Array
133+
min_version: 'beta'
134+
set_hash_func: 'tpgresource.CaseInsensitiveHash' # Add this line
135+
description: |
136+
List of regions where the subscriber wants dataset replicas.
137+
item_type:
138+
type: String
139+
diff_suppress_func: 'tpgresource.CaseDiffSuppress' # Apply here for array elements
115140
- name: 'name'
116141
type: String
117142
description: |-
@@ -198,19 +223,3 @@ properties:
198223
type: Boolean
199224
description: 'Output only. By default, false. If true, the Subscriber agreed to the email sharing mandate that is enabled for Listing.'
200225
output: true
201-
- name: 'commercialInfo'
202-
type: NestedObject
203-
description: |
204-
Commercial info metadata for this subscription. This is set if this is a commercial subscription i.e. if this subscription was created from subscribing to a commercial listing.
205-
output: true
206-
properties:
207-
- name: 'cloudMarketplace'
208-
type: NestedObject
209-
description: Cloud Marketplace commercial metadata for this subscription.
210-
output: true
211-
properties:
212-
- name: 'order'
213-
type: String
214-
description: |
215-
Resource name of the Marketplace Order.
216-
output: true

mmv1/templates/terraform/pre_update/bigqueryanalyticshub_listing.go.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,23 @@ if d.HasChange("pubsub_topic.0.data_affinity_regions"){
1818
}
1919
}
2020

21+
if d.HasChange("bigquery_dataset.0.replica_locations"){
22+
// Split URL into base and query parts
23+
parts := strings.SplitN(url, "?", 2)
24+
if len(parts) == 2 {
25+
base := parts[0]
26+
query := parts[1]
27+
28+
query = strings.ReplaceAll(query, "%2C", ",")
29+
query = strings.ReplaceAll(query, "%2c", ",")
30+
31+
// Replace "bigqueryDataset" with "bigqueryDataset.replicaLocations"
32+
query = strings.ReplaceAll(query, "bigqueryDataset", "bigqueryDataset.replicaLocations")
33+
34+
// Re-encode commas back
35+
query = strings.ReplaceAll(query, ",", "%2C")
36+
37+
url = base + "?" + query
38+
}
39+
}
40+

0 commit comments

Comments
 (0)