@@ -56,9 +56,32 @@ func ResourceBigqueryAnalyticsHubListing() *schema.Resource {
56
56
),
57
57
58
58
Schema : map [string ]* schema.Schema {
59
+ "data_exchange_id" : {
60
+ Type : schema .TypeString ,
61
+ Required : true ,
62
+ ForceNew : true ,
63
+ Description : `The ID of the data exchange. Must contain only Unicode letters, numbers (0-9), underscores (_). Should not use characters that require URL-escaping, or characters outside of ASCII, spaces.` ,
64
+ },
65
+ "display_name" : {
66
+ Type : schema .TypeString ,
67
+ Required : true ,
68
+ Description : `Human-readable display name of the listing. The display name must contain only Unicode letters, numbers (0-9), underscores (_), dashes (-), spaces ( ), ampersands (&) and can't start or end with spaces.` ,
69
+ },
70
+ "listing_id" : {
71
+ Type : schema .TypeString ,
72
+ Required : true ,
73
+ ForceNew : true ,
74
+ Description : `The ID of the listing. Must contain only Unicode letters, numbers (0-9), underscores (_). Should not use characters that require URL-escaping, or characters outside of ASCII, spaces.` ,
75
+ },
76
+ "location" : {
77
+ Type : schema .TypeString ,
78
+ Required : true ,
79
+ ForceNew : true ,
80
+ Description : `The name of the location this data exchange listing.` ,
81
+ },
59
82
"bigquery_dataset" : {
60
83
Type : schema .TypeList ,
61
- Required : true ,
84
+ Optional : true ,
62
85
ForceNew : true ,
63
86
Description : `Shared dataset i.e. BigQuery dataset source.` ,
64
87
MaxItems : 1 ,
@@ -90,29 +113,7 @@ func ResourceBigqueryAnalyticsHubListing() *schema.Resource {
90
113
},
91
114
},
92
115
},
93
- },
94
- "data_exchange_id" : {
95
- Type : schema .TypeString ,
96
- Required : true ,
97
- ForceNew : true ,
98
- Description : `The ID of the data exchange. Must contain only Unicode letters, numbers (0-9), underscores (_). Should not use characters that require URL-escaping, or characters outside of ASCII, spaces.` ,
99
- },
100
- "display_name" : {
101
- Type : schema .TypeString ,
102
- Required : true ,
103
- Description : `Human-readable display name of the listing. The display name must contain only Unicode letters, numbers (0-9), underscores (_), dashes (-), spaces ( ), ampersands (&) and can't start or end with spaces.` ,
104
- },
105
- "listing_id" : {
106
- Type : schema .TypeString ,
107
- Required : true ,
108
- ForceNew : true ,
109
- Description : `The ID of the listing. Must contain only Unicode letters, numbers (0-9), underscores (_). Should not use characters that require URL-escaping, or characters outside of ASCII, spaces.` ,
110
- },
111
- "location" : {
112
- Type : schema .TypeString ,
113
- Required : true ,
114
- ForceNew : true ,
115
- Description : `The name of the location this data exchange listing.` ,
116
+ ExactlyOneOf : []string {"pubsub_topic" , "bigquery_dataset" },
116
117
},
117
118
"categories" : {
118
119
Type : schema .TypeList ,
@@ -188,6 +189,34 @@ func ResourceBigqueryAnalyticsHubListing() *schema.Resource {
188
189
},
189
190
},
190
191
},
192
+ "pubsub_topic" : {
193
+ Type : schema .TypeList ,
194
+ Optional : true ,
195
+ Description : `Pub/Sub topic source.` ,
196
+ MaxItems : 1 ,
197
+ Elem : & schema.Resource {
198
+ Schema : map [string ]* schema.Schema {
199
+ "topic" : {
200
+ Type : schema .TypeString ,
201
+ Required : true ,
202
+ ForceNew : true ,
203
+ DiffSuppressFunc : tpgresource .ProjectNumberDiffSuppress ,
204
+ Description : `Resource name of the Pub/Sub topic source for this listing. e.g. projects/myproject/topics/topicId` ,
205
+ },
206
+ "data_affinity_regions" : {
207
+ Type : schema .TypeSet ,
208
+ Optional : true ,
209
+ Description : `Region hint on where the data might be published. Data affinity regions are modifiable.
210
+ See https://cloud.google.com/about/locations for full listing of possible Cloud regions.` ,
211
+ Elem : & schema.Schema {
212
+ Type : schema .TypeString ,
213
+ },
214
+ Set : schema .HashString ,
215
+ },
216
+ },
217
+ },
218
+ ExactlyOneOf : []string {"pubsub_topic" , "bigquery_dataset" },
219
+ },
191
220
"request_access" : {
192
221
Type : schema .TypeString ,
193
222
Optional : true ,
@@ -302,6 +331,12 @@ func resourceBigqueryAnalyticsHubListingCreate(d *schema.ResourceData, meta inte
302
331
} else if v , ok := d .GetOkExists ("bigquery_dataset" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (bigqueryDatasetProp )) && (ok || ! reflect .DeepEqual (v , bigqueryDatasetProp )) {
303
332
obj ["bigqueryDataset" ] = bigqueryDatasetProp
304
333
}
334
+ pubsubTopicProp , err := expandBigqueryAnalyticsHubListingPubsubTopic (d .Get ("pubsub_topic" ), d , config )
335
+ if err != nil {
336
+ return err
337
+ } else if v , ok := d .GetOkExists ("pubsub_topic" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (pubsubTopicProp )) && (ok || ! reflect .DeepEqual (v , pubsubTopicProp )) {
338
+ obj ["pubsubTopic" ] = pubsubTopicProp
339
+ }
305
340
restrictedExportConfigProp , err := expandBigqueryAnalyticsHubListingRestrictedExportConfig (d .Get ("restricted_export_config" ), d , config )
306
341
if err != nil {
307
342
return err
@@ -436,6 +471,9 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf
436
471
if err := d .Set ("bigquery_dataset" , flattenBigqueryAnalyticsHubListingBigqueryDataset (res ["bigqueryDataset" ], d , config )); err != nil {
437
472
return fmt .Errorf ("Error reading Listing: %s" , err )
438
473
}
474
+ if err := d .Set ("pubsub_topic" , flattenBigqueryAnalyticsHubListingPubsubTopic (res ["pubsubTopic" ], d , config )); err != nil {
475
+ return fmt .Errorf ("Error reading Listing: %s" , err )
476
+ }
439
477
if err := d .Set ("restricted_export_config" , flattenBigqueryAnalyticsHubListingRestrictedExportConfig (res ["restrictedExportConfig" ], d , config )); err != nil {
440
478
return fmt .Errorf ("Error reading Listing: %s" , err )
441
479
}
@@ -516,6 +554,12 @@ func resourceBigqueryAnalyticsHubListingUpdate(d *schema.ResourceData, meta inte
516
554
} else if v , ok := d .GetOkExists ("categories" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , categoriesProp )) {
517
555
obj ["categories" ] = categoriesProp
518
556
}
557
+ pubsubTopicProp , err := expandBigqueryAnalyticsHubListingPubsubTopic (d .Get ("pubsub_topic" ), d , config )
558
+ if err != nil {
559
+ return err
560
+ } else if v , ok := d .GetOkExists ("pubsub_topic" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , pubsubTopicProp )) {
561
+ obj ["pubsubTopic" ] = pubsubTopicProp
562
+ }
519
563
restrictedExportConfigProp , err := expandBigqueryAnalyticsHubListingRestrictedExportConfig (d .Get ("restricted_export_config" ), d , config )
520
564
if err != nil {
521
565
return err
@@ -568,6 +612,10 @@ func resourceBigqueryAnalyticsHubListingUpdate(d *schema.ResourceData, meta inte
568
612
updateMask = append (updateMask , "categories" )
569
613
}
570
614
615
+ if d .HasChange ("pubsub_topic" ) {
616
+ updateMask = append (updateMask , "pubsubTopic" )
617
+ }
618
+
571
619
if d .HasChange ("restricted_export_config" ) {
572
620
updateMask = append (updateMask , "restrictedExportConfig" )
573
621
}
@@ -577,6 +625,25 @@ func resourceBigqueryAnalyticsHubListingUpdate(d *schema.ResourceData, meta inte
577
625
if err != nil {
578
626
return err
579
627
}
628
+ if d .HasChange ("pubsub_topic.0.data_affinity_regions" ) {
629
+ // Split URL into base and query parts
630
+ parts := strings .SplitN (url , "?" , 2 )
631
+ if len (parts ) == 2 {
632
+ base := parts [0 ]
633
+ query := parts [1 ]
634
+
635
+ query = strings .ReplaceAll (query , "%2C" , "," )
636
+ query = strings .ReplaceAll (query , "%2c" , "," )
637
+
638
+ // Replace "pubsubTopic" with "pubsubTopic.dataAffinityRegions"
639
+ query = strings .ReplaceAll (query , "pubsubTopic" , "pubsubTopic.dataAffinityRegions" )
640
+
641
+ // Re-encode commas back
642
+ query = strings .ReplaceAll (query , "," , "%2C" )
643
+
644
+ url = base + "?" + query
645
+ }
646
+ }
580
647
581
648
// err == nil indicates that the billing_project value was found
582
649
if bp , err := tpgresource .GetBillingProject (d , config ); err == nil {
@@ -794,6 +861,32 @@ func flattenBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesTable(v i
794
861
return v
795
862
}
796
863
864
+ func flattenBigqueryAnalyticsHubListingPubsubTopic (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
865
+ if v == nil {
866
+ return nil
867
+ }
868
+ original := v .(map [string ]interface {})
869
+ if len (original ) == 0 {
870
+ return nil
871
+ }
872
+ transformed := make (map [string ]interface {})
873
+ transformed ["topic" ] =
874
+ flattenBigqueryAnalyticsHubListingPubsubTopicTopic (original ["topic" ], d , config )
875
+ transformed ["data_affinity_regions" ] =
876
+ flattenBigqueryAnalyticsHubListingPubsubTopicDataAffinityRegions (original ["dataAffinityRegions" ], d , config )
877
+ return []interface {}{transformed }
878
+ }
879
+ func flattenBigqueryAnalyticsHubListingPubsubTopicTopic (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
880
+ return v
881
+ }
882
+
883
+ func flattenBigqueryAnalyticsHubListingPubsubTopicDataAffinityRegions (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
884
+ if v == nil {
885
+ return v
886
+ }
887
+ return schema .NewSet (schema .HashString , v .([]interface {}))
888
+ }
889
+
797
890
func flattenBigqueryAnalyticsHubListingRestrictedExportConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
798
891
if v == nil {
799
892
return nil
@@ -979,6 +1072,41 @@ func expandBigqueryAnalyticsHubListingBigqueryDatasetSelectedResourcesTable(v in
979
1072
return v , nil
980
1073
}
981
1074
1075
+ func expandBigqueryAnalyticsHubListingPubsubTopic (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1076
+ l := v .([]interface {})
1077
+ if len (l ) == 0 || l [0 ] == nil {
1078
+ return nil , nil
1079
+ }
1080
+ raw := l [0 ]
1081
+ original := raw .(map [string ]interface {})
1082
+ transformed := make (map [string ]interface {})
1083
+
1084
+ transformedTopic , err := expandBigqueryAnalyticsHubListingPubsubTopicTopic (original ["topic" ], d , config )
1085
+ if err != nil {
1086
+ return nil , err
1087
+ } else if val := reflect .ValueOf (transformedTopic ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1088
+ transformed ["topic" ] = transformedTopic
1089
+ }
1090
+
1091
+ transformedDataAffinityRegions , err := expandBigqueryAnalyticsHubListingPubsubTopicDataAffinityRegions (original ["data_affinity_regions" ], d , config )
1092
+ if err != nil {
1093
+ return nil , err
1094
+ } else if val := reflect .ValueOf (transformedDataAffinityRegions ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1095
+ transformed ["dataAffinityRegions" ] = transformedDataAffinityRegions
1096
+ }
1097
+
1098
+ return transformed , nil
1099
+ }
1100
+
1101
+ func expandBigqueryAnalyticsHubListingPubsubTopicTopic (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1102
+ return v , nil
1103
+ }
1104
+
1105
+ func expandBigqueryAnalyticsHubListingPubsubTopicDataAffinityRegions (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1106
+ v = v .(* schema.Set ).List ()
1107
+ return v , nil
1108
+ }
1109
+
982
1110
func expandBigqueryAnalyticsHubListingRestrictedExportConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
983
1111
l := v .([]interface {})
984
1112
if len (l ) == 0 || l [0 ] == nil {
0 commit comments