Skip to content

Commit 3894440

Browse files
modular-magicianLuca Prete
and
Luca Prete
authored
Add storage_billing_model for BigQuery datasets (#7615) (#15115)
* [Waiting for the feature to go GA] Add storage_billing_model for BigQuery datasets * updating precheck test function name --------- Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Luca Prete <[email protected]>
1 parent 8e58c0e commit 3894440

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

.changelog/7615.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigquery: add `storage_billing_model` argument to `google_bigquery_dataset`
3+
```

google/resource_big_query_dataset_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ func TestAccBigQueryDataset_cmek(t *testing.T) {
169169
})
170170
}
171171

172+
func TestAccBigQueryDataset_storageBillModel(t *testing.T) {
173+
t.Parallel()
174+
175+
datasetID := fmt.Sprintf("tf_test_%s", RandString(t, 10))
176+
177+
VcrTest(t, resource.TestCase{
178+
PreCheck: func() { acctest.AccTestPreCheck(t) },
179+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
180+
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
181+
Steps: []resource.TestStep{
182+
{
183+
Config: testAccBigQueryDatasetStorageBillingModel(datasetID),
184+
},
185+
{
186+
ResourceName: "google_bigquery_dataset.test",
187+
ImportState: true,
188+
ImportStateVerify: true,
189+
},
190+
},
191+
})
192+
}
193+
172194
func testAccAddTable(t *testing.T, datasetID string, tableID string) resource.TestCheckFunc {
173195
// Not actually a check, but adds a table independently of terraform
174196
return func(s *terraform.State) error {
@@ -391,3 +413,22 @@ resource "google_bigquery_dataset" "test" {
391413
}
392414
`, pid, datasetID, kmsKey)
393415
}
416+
417+
func testAccBigQueryDatasetStorageBillingModel(datasetID string) string {
418+
return fmt.Sprintf(`
419+
resource "google_bigquery_dataset" "test" {
420+
dataset_id = "%s"
421+
friendly_name = "foo"
422+
description = "This is a foo description"
423+
location = "EU"
424+
default_partition_expiration_ms = 3600000
425+
default_table_expiration_ms = 3600000
426+
storage_billing_model = "PHYSICAL"
427+
428+
labels = {
429+
env = "foo"
430+
default_table_expiration_ms = 3600000
431+
}
432+
}
433+
`, datasetID)
434+
}

google/services/bigquery/resource_bigquery_dataset.go

+33
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ Changing this forces a new resource to be created.`,
216216
Optional: true,
217217
Description: `Defines the time travel window in hours. The value can be from 48 to 168 hours (2 to 7 days).`,
218218
},
219+
"storage_billing_model": {
220+
Type: schema.TypeString,
221+
Computed: true,
222+
Optional: true,
223+
Description: `Specifies the storage billing model for the dataset.
224+
Set this flag value to LOGICAL to use logical bytes for storage billing,
225+
or to PHYSICAL to use physical bytes instead.
226+
227+
LOGICAL is the default if this flag isn't specified.`,
228+
},
219229
"creation_time": {
220230
Type: schema.TypeInt,
221231
Computed: true,
@@ -487,6 +497,12 @@ func resourceBigQueryDatasetCreate(d *schema.ResourceData, meta interface{}) err
487497
} else if v, ok := d.GetOkExists("default_collation"); !tpgresource.IsEmptyValue(reflect.ValueOf(defaultCollationProp)) && (ok || !reflect.DeepEqual(v, defaultCollationProp)) {
488498
obj["defaultCollation"] = defaultCollationProp
489499
}
500+
storageBillingModelProp, err := expandBigQueryDatasetStorageBillingModel(d.Get("storage_billing_model"), d, config)
501+
if err != nil {
502+
return err
503+
} else if v, ok := d.GetOkExists("storage_billing_model"); !tpgresource.IsEmptyValue(reflect.ValueOf(storageBillingModelProp)) && (ok || !reflect.DeepEqual(v, storageBillingModelProp)) {
504+
obj["storageBillingModel"] = storageBillingModelProp
505+
}
490506

491507
url, err := tpgresource.ReplaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets")
492508
if err != nil {
@@ -635,6 +651,9 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error
635651
if err := d.Set("default_collation", flattenBigQueryDatasetDefaultCollation(res["defaultCollation"], d, config)); err != nil {
636652
return fmt.Errorf("Error reading Dataset: %s", err)
637653
}
654+
if err := d.Set("storage_billing_model", flattenBigQueryDatasetStorageBillingModel(res["storageBillingModel"], d, config)); err != nil {
655+
return fmt.Errorf("Error reading Dataset: %s", err)
656+
}
638657
if err := d.Set("self_link", tpgresource.ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
639658
return fmt.Errorf("Error reading Dataset: %s", err)
640659
}
@@ -730,6 +749,12 @@ func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) err
730749
} else if v, ok := d.GetOkExists("default_collation"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultCollationProp)) {
731750
obj["defaultCollation"] = defaultCollationProp
732751
}
752+
storageBillingModelProp, err := expandBigQueryDatasetStorageBillingModel(d.Get("storage_billing_model"), d, config)
753+
if err != nil {
754+
return err
755+
} else if v, ok := d.GetOkExists("storage_billing_model"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, storageBillingModelProp)) {
756+
obj["storageBillingModel"] = storageBillingModelProp
757+
}
733758

734759
url, err := tpgresource.ReplaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets/{{dataset_id}}")
735760
if err != nil {
@@ -1117,6 +1142,10 @@ func flattenBigQueryDatasetDefaultCollation(v interface{}, d *schema.ResourceDat
11171142
return v
11181143
}
11191144

1145+
func flattenBigQueryDatasetStorageBillingModel(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1146+
return v
1147+
}
1148+
11201149
func expandBigQueryDatasetMaxTimeTravelHours(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
11211150
return v, nil
11221151
}
@@ -1444,3 +1473,7 @@ func expandBigQueryDatasetIsCaseInsensitive(v interface{}, d tpgresource.Terrafo
14441473
func expandBigQueryDatasetDefaultCollation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
14451474
return v, nil
14461475
}
1476+
1477+
func expandBigQueryDatasetStorageBillingModel(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1478+
return v, nil
1479+
}

website/docs/r/bigquery_dataset.html.markdown

+7
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ The following arguments are supported:
311311
- 'und:ci': undetermined locale, case insensitive.
312312
- '': empty string. Default to case-sensitive behavior.
313313

314+
* `storage_billing_model` -
315+
(Optional)
316+
Specifies the storage billing model for the dataset.
317+
Set this flag value to LOGICAL to use logical bytes for storage billing,
318+
or to PHYSICAL to use physical bytes instead.
319+
LOGICAL is the default if this flag isn't specified.
320+
314321
* `project` - (Optional) The ID of the project in which the resource belongs.
315322
If it is not provided, the provider project is used.
316323

0 commit comments

Comments
 (0)