Skip to content

Commit 36d3be2

Browse files
AnalyticsHub Marketplace Changes (#14556) (#23731)
[upstream:4dd5624b9bd5d9fb7d39acf94deb53127832f1d1] Signed-off-by: Modular Magician <[email protected]>
1 parent 46261ea commit 36d3be2

9 files changed

+349
-0
lines changed

.changelog/14556.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 'commercial_info' and 'delete_commercial' fields in 'google_bigquery_analytics_hub_listing' resource
3+
```

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,45 @@ See https://cloud.google.com/about/locations for full listing of possible Cloud
247247
},
248248
},
249249
},
250+
"commercial_info": {
251+
Type: schema.TypeList,
252+
Computed: true,
253+
Description: `Commercial info contains the information about the commercial data products associated with the listing.`,
254+
Elem: &schema.Resource{
255+
Schema: map[string]*schema.Schema{
256+
"cloud_marketplace": {
257+
Type: schema.TypeList,
258+
Computed: true,
259+
Description: `Details of the Marketplace Data Product associated with the Listing.`,
260+
Elem: &schema.Resource{
261+
Schema: map[string]*schema.Schema{
262+
"commercial_state": {
263+
Type: schema.TypeString,
264+
Computed: true,
265+
Description: `Commercial state of the Marketplace Data Product.
266+
Possible values: COMMERCIAL_STATE_UNSPECIFIED, ONBOARDING, ACTIVE`,
267+
},
268+
"service": {
269+
Type: schema.TypeString,
270+
Computed: true,
271+
Description: `Resource name of the commercial service associated with the Marketplace Data Product. e.g. example.com`,
272+
},
273+
},
274+
},
275+
},
276+
},
277+
},
278+
},
250279
"name": {
251280
Type: schema.TypeString,
252281
Computed: true,
253282
Description: `The resource name of the listing. e.g. "projects/myproject/locations/US/dataExchanges/123/listings/456"`,
254283
},
284+
"delete_commercial": {
285+
Type: schema.TypeBool,
286+
Optional: true,
287+
Description: `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.`,
288+
},
255289
"project": {
256290
Type: schema.TypeString,
257291
Optional: true,
@@ -434,6 +468,7 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf
434468
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("BigqueryAnalyticsHubListing %q", d.Id()))
435469
}
436470

471+
// Explicitly set virtual fields to default values if unset
437472
if err := d.Set("project", project); err != nil {
438473
return fmt.Errorf("Error reading Listing: %s", err)
439474
}
@@ -480,6 +515,9 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf
480515
if err := d.Set("log_linked_dataset_query_user_email", flattenBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(res["logLinkedDatasetQueryUserEmail"], d, config)); err != nil {
481516
return fmt.Errorf("Error reading Listing: %s", err)
482517
}
518+
if err := d.Set("commercial_info", flattenBigqueryAnalyticsHubListingCommercialInfo(res["commercialInfo"], d, config)); err != nil {
519+
return fmt.Errorf("Error reading Listing: %s", err)
520+
}
483521

484522
return nil
485523
}
@@ -712,6 +750,10 @@ func resourceBigqueryAnalyticsHubListingDelete(d *schema.ResourceData, meta inte
712750
}
713751

714752
headers := make(http.Header)
753+
deleteCommercial := d.Get("delete_commercial")
754+
if deleteCommercial != nil {
755+
url = url + "?deleteCommercial=" + fmt.Sprintf("%v", deleteCommercial)
756+
}
715757

716758
log.Printf("[DEBUG] Deleting Listing %q", d.Id())
717759
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
@@ -749,6 +791,8 @@ func resourceBigqueryAnalyticsHubListingImport(d *schema.ResourceData, meta inte
749791
}
750792
d.SetId(id)
751793

794+
// Explicitly set virtual fields to default values on import
795+
752796
return []*schema.ResourceData{d}, nil
753797
}
754798

@@ -930,6 +974,42 @@ func flattenBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(v interfac
930974
return v
931975
}
932976

977+
func flattenBigqueryAnalyticsHubListingCommercialInfo(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
978+
if v == nil {
979+
return nil
980+
}
981+
original := v.(map[string]interface{})
982+
if len(original) == 0 {
983+
return nil
984+
}
985+
transformed := make(map[string]interface{})
986+
transformed["cloud_marketplace"] =
987+
flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplace(original["cloudMarketplace"], d, config)
988+
return []interface{}{transformed}
989+
}
990+
func flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplace(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
991+
if v == nil {
992+
return nil
993+
}
994+
original := v.(map[string]interface{})
995+
if len(original) == 0 {
996+
return nil
997+
}
998+
transformed := make(map[string]interface{})
999+
transformed["service"] =
1000+
flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceService(original["service"], d, config)
1001+
transformed["commercial_state"] =
1002+
flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceCommercialState(original["commercialState"], d, config)
1003+
return []interface{}{transformed}
1004+
}
1005+
func flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceService(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1006+
return v
1007+
}
1008+
1009+
func flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceCommercialState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1010+
return v
1011+
}
1012+
9331013
func expandBigqueryAnalyticsHubListingDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
9341014
return v, nil
9351015
}

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_meta.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ fields:
88
- field: 'bigquery_dataset.dataset'
99
- field: 'bigquery_dataset.selected_resources.table'
1010
- field: 'categories'
11+
- field: 'commercial_info.cloud_marketplace.commercial_state'
12+
- field: 'commercial_info.cloud_marketplace.service'
1113
- field: 'data_exchange_id'
1214
provider_only: true
1315
- field: 'data_provider.name'
1416
- field: 'data_provider.primary_contact'
17+
- field: 'delete_commercial'
18+
provider_only: true
1519
- field: 'description'
1620
- field: 'display_name'
1721
- field: 'documentation'

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_test.go

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

350+
func TestAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceExample(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.ProtoV5ProviderFactories(t),
360+
CheckDestroy: testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t),
361+
Steps: []resource.TestStep{
362+
{
363+
Config: testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceExample(context),
364+
},
365+
{
366+
ResourceName: "google_bigquery_analytics_hub_listing.listing",
367+
ImportState: true,
368+
ImportStateVerify: true,
369+
ImportStateVerifyIgnore: []string{"data_exchange_id", "delete_commercial", "listing_id", "location"},
370+
},
371+
},
372+
})
373+
}
374+
375+
func testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceExample(context map[string]interface{}) string {
376+
return acctest.Nprintf(`
377+
resource "google_bigquery_analytics_hub_data_exchange" "listing" {
378+
location = "US"
379+
data_exchange_id = "tf_test_my_data_exchange%{random_suffix}"
380+
display_name = "tf_test_my_data_exchange%{random_suffix}"
381+
description = "example data exchange%{random_suffix}"
382+
}
383+
384+
resource "google_bigquery_analytics_hub_listing" "listing" {
385+
location = "US"
386+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.listing.data_exchange_id
387+
listing_id = "tf_test_my_listing%{random_suffix}"
388+
display_name = "tf_test_my_listing%{random_suffix}"
389+
description = "example data exchange%{random_suffix}"
390+
delete_commercial = true
391+
392+
bigquery_dataset {
393+
dataset = google_bigquery_dataset.listing.id
394+
}
395+
396+
}
397+
398+
resource "google_bigquery_dataset" "listing" {
399+
dataset_id = "tf_test_my_listing%{random_suffix}"
400+
friendly_name = "tf_test_my_listing%{random_suffix}"
401+
description = "example data exchange%{random_suffix}"
402+
location = "US"
403+
}
404+
`, context)
405+
}
406+
350407
func testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t *testing.T) func(s *terraform.State) error {
351408
return func(s *terraform.State) error {
352409
for name, rs := range s.RootModule().Resources {

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ organize and group your datasets.`,
136136
DiffSuppressFunc: tpgresource.CaseDiffSuppress,
137137
Description: `The name of the location of the data exchange. Distinct from the location of the destination data set.`,
138138
},
139+
"commercial_info": {
140+
Type: schema.TypeList,
141+
Computed: true,
142+
Description: `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.`,
143+
Elem: &schema.Resource{
144+
Schema: map[string]*schema.Schema{
145+
"cloud_marketplace": {
146+
Type: schema.TypeList,
147+
Computed: true,
148+
Description: `Cloud Marketplace commercial metadata for this subscription.`,
149+
Elem: &schema.Resource{
150+
Schema: map[string]*schema.Schema{
151+
"order": {
152+
Type: schema.TypeString,
153+
Computed: true,
154+
Description: `Resource name of the Marketplace Order.`,
155+
},
156+
},
157+
},
158+
},
159+
},
160+
},
161+
},
139162
"creation_time": {
140163
Type: schema.TypeString,
141164
Computed: true,
@@ -412,6 +435,9 @@ func resourceBigqueryAnalyticsHubListingSubscriptionRead(d *schema.ResourceData,
412435
if err := d.Set("log_linked_dataset_query_user_email", flattenBigqueryAnalyticsHubListingSubscriptionLogLinkedDatasetQueryUserEmail(res["logLinkedDatasetQueryUserEmail"], d, config)); err != nil {
413436
return fmt.Errorf("Error reading ListingSubscription: %s", err)
414437
}
438+
if err := d.Set("commercial_info", flattenBigqueryAnalyticsHubListingSubscriptionCommercialInfo(res["commercialInfo"], d, config)); err != nil {
439+
return fmt.Errorf("Error reading ListingSubscription: %s", err)
440+
}
415441

416442
return nil
417443
}
@@ -613,6 +639,36 @@ func flattenBigqueryAnalyticsHubListingSubscriptionLogLinkedDatasetQueryUserEmai
613639
return v
614640
}
615641

642+
func flattenBigqueryAnalyticsHubListingSubscriptionCommercialInfo(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
643+
if v == nil {
644+
return nil
645+
}
646+
original := v.(map[string]interface{})
647+
if len(original) == 0 {
648+
return nil
649+
}
650+
transformed := make(map[string]interface{})
651+
transformed["cloud_marketplace"] =
652+
flattenBigqueryAnalyticsHubListingSubscriptionCommercialInfoCloudMarketplace(original["cloudMarketplace"], d, config)
653+
return []interface{}{transformed}
654+
}
655+
func flattenBigqueryAnalyticsHubListingSubscriptionCommercialInfoCloudMarketplace(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
656+
if v == nil {
657+
return nil
658+
}
659+
original := v.(map[string]interface{})
660+
if len(original) == 0 {
661+
return nil
662+
}
663+
transformed := make(map[string]interface{})
664+
transformed["order"] =
665+
flattenBigqueryAnalyticsHubListingSubscriptionCommercialInfoCloudMarketplaceOrder(original["order"], d, config)
666+
return []interface{}{transformed}
667+
}
668+
func flattenBigqueryAnalyticsHubListingSubscriptionCommercialInfoCloudMarketplaceOrder(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
669+
return v
670+
}
671+
616672
func expandBigqueryAnalyticsHubListingSubscriptionDestinationDataset(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
617673
l := v.([]interface{})
618674
if len(l) == 0 || l[0] == nil {

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_subscription_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ api_service_name: 'analyticshub.googleapis.com'
55
api_version: 'v1'
66
api_resource_type_kind: 'Subscription'
77
fields:
8+
- field: 'commercial_info.cloud_marketplace.order'
89
- field: 'creation_time'
910
- field: 'data_exchange_id'
1011
provider_only: true

google/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,72 @@ resource "google_bigquery_analytics_hub_listing" "listing_pubsub" {
146146
}
147147
`, updatedContext)
148148
}
149+
150+
func TestAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceUpdate(t *testing.T) {
151+
t.Parallel()
152+
153+
context := map[string]interface{}{
154+
"random_suffix": acctest.RandString(t, 10),
155+
}
156+
157+
acctest.VcrTest(t, resource.TestCase{
158+
PreCheck: func() { acctest.AccTestPreCheck(t) },
159+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
160+
CheckDestroy: testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t),
161+
Steps: []resource.TestStep{
162+
{
163+
Config: testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceExample(context),
164+
},
165+
{
166+
ResourceName: "google_bigquery_analytics_hub_listing.listing",
167+
ImportState: true,
168+
ImportStateVerify: true,
169+
ImportStateVerifyIgnore: []string{"data_exchange_id", "listing_id", "location", "delete_commercial"},
170+
},
171+
{
172+
Config: testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceUpdate(context),
173+
Check: resource.ComposeTestCheckFunc(
174+
resource.TestCheckResourceAttr("google_bigquery_analytics_hub_listing.listing", "delete_commercial", "false"),
175+
),
176+
},
177+
{
178+
ResourceName: "google_bigquery_analytics_hub_listing.listing",
179+
ImportState: true,
180+
ImportStateVerify: true,
181+
ImportStateVerifyIgnore: []string{"data_exchange_id", "listing_id", "location", "delete_commercial"},
182+
},
183+
},
184+
})
185+
}
186+
187+
func testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceUpdate(context map[string]interface{}) string {
188+
return acctest.Nprintf(`
189+
resource "google_bigquery_analytics_hub_data_exchange" "listing" {
190+
location = "US"
191+
data_exchange_id = "tf_test_my_data_exchange%{random_suffix}"
192+
display_name = "tf_test_my_data_exchange%{random_suffix}"
193+
description = "example data exchange%{random_suffix}"
194+
}
195+
196+
resource "google_bigquery_analytics_hub_listing" "listing" {
197+
location = "US"
198+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.listing.data_exchange_id
199+
listing_id = "tf_test_my_listing%{random_suffix}"
200+
display_name = "tf_test_my_listing%{random_suffix}"
201+
description = "example data exchange%{random_suffix}"
202+
delete_commercial = false
203+
204+
bigquery_dataset {
205+
dataset = google_bigquery_dataset.listing.id
206+
}
207+
208+
}
209+
210+
resource "google_bigquery_dataset" "listing" {
211+
dataset_id = "tf_test_my_listing%{random_suffix}"
212+
friendly_name = "tf_test_my_listing%{random_suffix}"
213+
description = "example data exchange%{random_suffix}"
214+
location = "US"
215+
}
216+
`, context)
217+
}

0 commit comments

Comments
 (0)