Skip to content

Commit 7d4c100

Browse files
AnalyticsHub Marketplace Changes (#14556) (#10415)
[upstream:4dd5624b9bd5d9fb7d39acf94deb53127832f1d1] Signed-off-by: Modular Magician <[email protected]>
1 parent 7e16689 commit 7d4c100

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-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,45 @@ See https://cloud.google.com/about/locations for full listing of possible Cloud
255255
},
256256
},
257257
},
258+
"commercial_info": {
259+
Type: schema.TypeList,
260+
Computed: true,
261+
Description: `Commercial info contains the information about the commercial data products associated with the listing.`,
262+
Elem: &schema.Resource{
263+
Schema: map[string]*schema.Schema{
264+
"cloud_marketplace": {
265+
Type: schema.TypeList,
266+
Computed: true,
267+
Description: `Details of the Marketplace Data Product associated with the Listing.`,
268+
Elem: &schema.Resource{
269+
Schema: map[string]*schema.Schema{
270+
"commercial_state": {
271+
Type: schema.TypeString,
272+
Computed: true,
273+
Description: `Commercial state of the Marketplace Data Product.
274+
Possible values: COMMERCIAL_STATE_UNSPECIFIED, ONBOARDING, ACTIVE`,
275+
},
276+
"service": {
277+
Type: schema.TypeString,
278+
Computed: true,
279+
Description: `Resource name of the commercial service associated with the Marketplace Data Product. e.g. example.com`,
280+
},
281+
},
282+
},
283+
},
284+
},
285+
},
286+
},
258287
"name": {
259288
Type: schema.TypeString,
260289
Computed: true,
261290
Description: `The resource name of the listing. e.g. "projects/myproject/locations/US/dataExchanges/123/listings/456"`,
262291
},
292+
"delete_commercial": {
293+
Type: schema.TypeBool,
294+
Optional: true,
295+
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.`,
296+
},
263297
"project": {
264298
Type: schema.TypeString,
265299
Optional: true,
@@ -442,6 +476,7 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf
442476
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("BigqueryAnalyticsHubListing %q", d.Id()))
443477
}
444478

479+
// Explicitly set virtual fields to default values if unset
445480
if err := d.Set("project", project); err != nil {
446481
return fmt.Errorf("Error reading Listing: %s", err)
447482
}
@@ -488,6 +523,9 @@ func resourceBigqueryAnalyticsHubListingRead(d *schema.ResourceData, meta interf
488523
if err := d.Set("log_linked_dataset_query_user_email", flattenBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(res["logLinkedDatasetQueryUserEmail"], d, config)); err != nil {
489524
return fmt.Errorf("Error reading Listing: %s", err)
490525
}
526+
if err := d.Set("commercial_info", flattenBigqueryAnalyticsHubListingCommercialInfo(res["commercialInfo"], d, config)); err != nil {
527+
return fmt.Errorf("Error reading Listing: %s", err)
528+
}
491529

492530
return nil
493531
}
@@ -720,6 +758,10 @@ func resourceBigqueryAnalyticsHubListingDelete(d *schema.ResourceData, meta inte
720758
}
721759

722760
headers := make(http.Header)
761+
deleteCommercial := d.Get("delete_commercial")
762+
if deleteCommercial != nil {
763+
url = url + "?deleteCommercial=" + fmt.Sprintf("%v", deleteCommercial)
764+
}
723765

724766
log.Printf("[DEBUG] Deleting Listing %q", d.Id())
725767
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
@@ -757,6 +799,8 @@ func resourceBigqueryAnalyticsHubListingImport(d *schema.ResourceData, meta inte
757799
}
758800
d.SetId(id)
759801

802+
// Explicitly set virtual fields to default values on import
803+
760804
return []*schema.ResourceData{d}, nil
761805
}
762806

@@ -943,6 +987,42 @@ func flattenBigqueryAnalyticsHubListingLogLinkedDatasetQueryUserEmail(v interfac
943987
return v
944988
}
945989

990+
func flattenBigqueryAnalyticsHubListingCommercialInfo(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["cloud_marketplace"] =
1000+
flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplace(original["cloudMarketplace"], d, config)
1001+
return []interface{}{transformed}
1002+
}
1003+
func flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplace(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1004+
if v == nil {
1005+
return nil
1006+
}
1007+
original := v.(map[string]interface{})
1008+
if len(original) == 0 {
1009+
return nil
1010+
}
1011+
transformed := make(map[string]interface{})
1012+
transformed["service"] =
1013+
flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceService(original["service"], d, config)
1014+
transformed["commercial_state"] =
1015+
flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceCommercialState(original["commercialState"], d, config)
1016+
return []interface{}{transformed}
1017+
}
1018+
func flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceService(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1019+
return v
1020+
}
1021+
1022+
func flattenBigqueryAnalyticsHubListingCommercialInfoCloudMarketplaceCommercialState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1023+
return v
1024+
}
1025+
9461026
func expandBigqueryAnalyticsHubListingDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
9471027
return v, nil
9481028
}

google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_meta.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ fields:
99
- field: 'bigquery_dataset.selected_resources.routine'
1010
- field: 'bigquery_dataset.selected_resources.table'
1111
- field: 'categories'
12+
- field: 'commercial_info.cloud_marketplace.commercial_state'
13+
- field: 'commercial_info.cloud_marketplace.service'
1214
- field: 'data_exchange_id'
1315
provider_only: true
1416
- field: 'data_provider.name'
1517
- field: 'data_provider.primary_contact'
18+
- field: 'delete_commercial'
19+
provider_only: true
1620
- field: 'description'
1721
- field: 'display_name'
1822
- field: 'documentation'

google-beta/services/bigqueryanalyticshub/resource_bigquery_analytics_hub_listing_generated_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,63 @@ resource "google_bigquery_analytics_hub_listing" "listing" {
435435
`, context)
436436
}
437437

438+
func TestAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceExample(t *testing.T) {
439+
t.Parallel()
440+
441+
context := map[string]interface{}{
442+
"random_suffix": acctest.RandString(t, 10),
443+
}
444+
445+
acctest.VcrTest(t, resource.TestCase{
446+
PreCheck: func() { acctest.AccTestPreCheck(t) },
447+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
448+
CheckDestroy: testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t),
449+
Steps: []resource.TestStep{
450+
{
451+
Config: testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceExample(context),
452+
},
453+
{
454+
ResourceName: "google_bigquery_analytics_hub_listing.listing",
455+
ImportState: true,
456+
ImportStateVerify: true,
457+
ImportStateVerifyIgnore: []string{"data_exchange_id", "delete_commercial", "listing_id", "location"},
458+
},
459+
},
460+
})
461+
}
462+
463+
func testAccBigqueryAnalyticsHubListing_bigqueryAnalyticshubListingMarketplaceExample(context map[string]interface{}) string {
464+
return acctest.Nprintf(`
465+
resource "google_bigquery_analytics_hub_data_exchange" "listing" {
466+
location = "US"
467+
data_exchange_id = "tf_test_my_data_exchange%{random_suffix}"
468+
display_name = "tf_test_my_data_exchange%{random_suffix}"
469+
description = "example data exchange%{random_suffix}"
470+
}
471+
472+
resource "google_bigquery_analytics_hub_listing" "listing" {
473+
location = "US"
474+
data_exchange_id = google_bigquery_analytics_hub_data_exchange.listing.data_exchange_id
475+
listing_id = "tf_test_my_listing%{random_suffix}"
476+
display_name = "tf_test_my_listing%{random_suffix}"
477+
description = "example data exchange%{random_suffix}"
478+
delete_commercial = true
479+
480+
bigquery_dataset {
481+
dataset = google_bigquery_dataset.listing.id
482+
}
483+
484+
}
485+
486+
resource "google_bigquery_dataset" "listing" {
487+
dataset_id = "tf_test_my_listing%{random_suffix}"
488+
friendly_name = "tf_test_my_listing%{random_suffix}"
489+
description = "example data exchange%{random_suffix}"
490+
location = "US"
491+
}
492+
`, context)
493+
}
494+
438495
func testAccCheckBigqueryAnalyticsHubListingDestroyProducer(t *testing.T) func(s *terraform.State) error {
439496
return func(s *terraform.State) error {
440497
for name, rs := range s.RootModule().Resources {

google-beta/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-beta/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-beta/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)