Skip to content

Commit 9dd01b4

Browse files
Added is_case_insensitive and default_collation fields for google_bigquery_dataset resource (#7457) (#14031)
Signed-off-by: Modular Magician <[email protected]>
1 parent 6b70d76 commit 9dd01b4

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed

.changelog/7457.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigquery: added `is_case_insensitive` and `default_collation` fields to `google_bigquery_dataset` resource
3+
```

google/resource_bigquery_dataset.go

+69
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ underscores (_). The maximum length is 1,024 characters.`,
8787
Elem: bigqueryDatasetAccessSchema(),
8888
// Default schema.HashSchema is used.
8989
},
90+
"default_collation": {
91+
Type: schema.TypeString,
92+
Computed: true,
93+
Optional: true,
94+
Description: `Defines the default collation specification of future tables created
95+
in the dataset. If a table is created in this dataset without table-level
96+
default collation, then the table inherits the dataset default collation,
97+
which is applied to the string fields that do not have explicit collation
98+
specified. A change to this field affects only tables created afterwards,
99+
and does not alter the existing tables.
100+
101+
The following values are supported:
102+
- 'und:ci': undetermined locale, case insensitive.
103+
- '': empty string. Default to case-sensitive behavior.`,
104+
},
90105
"default_encryption_configuration": {
91106
Type: schema.TypeList,
92107
Optional: true,
@@ -153,6 +168,14 @@ expiration time indicated by this property.`,
153168
Optional: true,
154169
Description: `A descriptive name for the dataset`,
155170
},
171+
"is_case_insensitive": {
172+
Type: schema.TypeBool,
173+
Computed: true,
174+
Optional: true,
175+
Description: `TRUE if the dataset and its table names are case-insensitive, otherwise FALSE.
176+
By default, this is FALSE, which means the dataset and its table names are
177+
case-sensitive. This field does not affect routine references.`,
178+
},
156179
"labels": {
157180
Type: schema.TypeMap,
158181
Computed: true,
@@ -445,6 +468,18 @@ func resourceBigQueryDatasetCreate(d *schema.ResourceData, meta interface{}) err
445468
} else if v, ok := d.GetOkExists("default_encryption_configuration"); !isEmptyValue(reflect.ValueOf(defaultEncryptionConfigurationProp)) && (ok || !reflect.DeepEqual(v, defaultEncryptionConfigurationProp)) {
446469
obj["defaultEncryptionConfiguration"] = defaultEncryptionConfigurationProp
447470
}
471+
isCaseInsensitiveProp, err := expandBigQueryDatasetIsCaseInsensitive(d.Get("is_case_insensitive"), d, config)
472+
if err != nil {
473+
return err
474+
} else if v, ok := d.GetOkExists("is_case_insensitive"); !isEmptyValue(reflect.ValueOf(isCaseInsensitiveProp)) && (ok || !reflect.DeepEqual(v, isCaseInsensitiveProp)) {
475+
obj["isCaseInsensitive"] = isCaseInsensitiveProp
476+
}
477+
defaultCollationProp, err := expandBigQueryDatasetDefaultCollation(d.Get("default_collation"), d, config)
478+
if err != nil {
479+
return err
480+
} else if v, ok := d.GetOkExists("default_collation"); !isEmptyValue(reflect.ValueOf(defaultCollationProp)) && (ok || !reflect.DeepEqual(v, defaultCollationProp)) {
481+
obj["defaultCollation"] = defaultCollationProp
482+
}
448483

449484
url, err := replaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets")
450485
if err != nil {
@@ -573,6 +608,12 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error
573608
if err := d.Set("default_encryption_configuration", flattenBigQueryDatasetDefaultEncryptionConfiguration(res["defaultEncryptionConfiguration"], d, config)); err != nil {
574609
return fmt.Errorf("Error reading Dataset: %s", err)
575610
}
611+
if err := d.Set("is_case_insensitive", flattenBigQueryDatasetIsCaseInsensitive(res["isCaseInsensitive"], d, config)); err != nil {
612+
return fmt.Errorf("Error reading Dataset: %s", err)
613+
}
614+
if err := d.Set("default_collation", flattenBigQueryDatasetDefaultCollation(res["defaultCollation"], d, config)); err != nil {
615+
return fmt.Errorf("Error reading Dataset: %s", err)
616+
}
576617
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
577618
return fmt.Errorf("Error reading Dataset: %s", err)
578619
}
@@ -656,6 +697,18 @@ func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) err
656697
} else if v, ok := d.GetOkExists("default_encryption_configuration"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultEncryptionConfigurationProp)) {
657698
obj["defaultEncryptionConfiguration"] = defaultEncryptionConfigurationProp
658699
}
700+
isCaseInsensitiveProp, err := expandBigQueryDatasetIsCaseInsensitive(d.Get("is_case_insensitive"), d, config)
701+
if err != nil {
702+
return err
703+
} else if v, ok := d.GetOkExists("is_case_insensitive"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, isCaseInsensitiveProp)) {
704+
obj["isCaseInsensitive"] = isCaseInsensitiveProp
705+
}
706+
defaultCollationProp, err := expandBigQueryDatasetDefaultCollation(d.Get("default_collation"), d, config)
707+
if err != nil {
708+
return err
709+
} else if v, ok := d.GetOkExists("default_collation"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultCollationProp)) {
710+
obj["defaultCollation"] = defaultCollationProp
711+
}
659712

660713
url, err := replaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets/{{dataset_id}}")
661714
if err != nil {
@@ -1019,6 +1072,14 @@ func flattenBigQueryDatasetDefaultEncryptionConfigurationKmsKeyName(v interface{
10191072
return v
10201073
}
10211074

1075+
func flattenBigQueryDatasetIsCaseInsensitive(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1076+
return v
1077+
}
1078+
1079+
func flattenBigQueryDatasetDefaultCollation(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1080+
return v
1081+
}
1082+
10221083
func expandBigQueryDatasetMaxTimeTravelHours(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
10231084
return v, nil
10241085
}
@@ -1338,3 +1399,11 @@ func expandBigQueryDatasetDefaultEncryptionConfiguration(v interface{}, d Terraf
13381399
func expandBigQueryDatasetDefaultEncryptionConfigurationKmsKeyName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
13391400
return v, nil
13401401
}
1402+
1403+
func expandBigQueryDatasetIsCaseInsensitive(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1404+
return v, nil
1405+
}
1406+
1407+
func expandBigQueryDatasetDefaultCollation(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1408+
return v, nil
1409+
}

google/resource_bigquery_dataset_generated_test.go

+110
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,116 @@ resource "google_bigquery_dataset" "private" {
286286
`, context)
287287
}
288288

289+
func TestAccBigQueryDataset_bigqueryDatasetCaseInsensitiveNamesExample(t *testing.T) {
290+
t.Parallel()
291+
292+
context := map[string]interface{}{
293+
"random_suffix": RandString(t, 10),
294+
}
295+
296+
VcrTest(t, resource.TestCase{
297+
PreCheck: func() { testAccPreCheck(t) },
298+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
299+
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
300+
Steps: []resource.TestStep{
301+
{
302+
Config: testAccBigQueryDataset_bigqueryDatasetCaseInsensitiveNamesExample(context),
303+
},
304+
{
305+
ResourceName: "google_bigquery_dataset.dataset",
306+
ImportState: true,
307+
ImportStateVerify: true,
308+
},
309+
},
310+
})
311+
}
312+
313+
func testAccBigQueryDataset_bigqueryDatasetCaseInsensitiveNamesExample(context map[string]interface{}) string {
314+
return Nprintf(`
315+
resource "google_bigquery_dataset" "dataset" {
316+
dataset_id = "tf_test_example_dataset%{random_suffix}"
317+
friendly_name = "test"
318+
description = "This is a test description"
319+
location = "EU"
320+
default_table_expiration_ms = 3600000
321+
is_case_insensitive = true
322+
323+
labels = {
324+
env = "default"
325+
}
326+
327+
access {
328+
role = "OWNER"
329+
user_by_email = google_service_account.bqowner.email
330+
}
331+
332+
access {
333+
role = "READER"
334+
domain = "hashicorp.com"
335+
}
336+
}
337+
338+
resource "google_service_account" "bqowner" {
339+
account_id = "bqowner%{random_suffix}"
340+
}
341+
`, context)
342+
}
343+
344+
func TestAccBigQueryDataset_bigqueryDatasetDefaultCollationSetExample(t *testing.T) {
345+
t.Parallel()
346+
347+
context := map[string]interface{}{
348+
"random_suffix": RandString(t, 10),
349+
}
350+
351+
VcrTest(t, resource.TestCase{
352+
PreCheck: func() { testAccPreCheck(t) },
353+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
354+
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
355+
Steps: []resource.TestStep{
356+
{
357+
Config: testAccBigQueryDataset_bigqueryDatasetDefaultCollationSetExample(context),
358+
},
359+
{
360+
ResourceName: "google_bigquery_dataset.dataset",
361+
ImportState: true,
362+
ImportStateVerify: true,
363+
},
364+
},
365+
})
366+
}
367+
368+
func testAccBigQueryDataset_bigqueryDatasetDefaultCollationSetExample(context map[string]interface{}) string {
369+
return Nprintf(`
370+
resource "google_bigquery_dataset" "dataset" {
371+
dataset_id = "tf_test_example_dataset%{random_suffix}"
372+
friendly_name = "test"
373+
description = "This is a test description"
374+
location = "EU"
375+
default_table_expiration_ms = 3600000
376+
default_collation = "und:ci"
377+
378+
labels = {
379+
env = "default"
380+
}
381+
382+
access {
383+
role = "OWNER"
384+
user_by_email = google_service_account.bqowner.email
385+
}
386+
387+
access {
388+
role = "READER"
389+
domain = "hashicorp.com"
390+
}
391+
}
392+
393+
resource "google_service_account" "bqowner" {
394+
account_id = "bqowner%{random_suffix}"
395+
}
396+
`, context)
397+
}
398+
289399
func testAccCheckBigQueryDatasetDestroyProducer(t *testing.T) func(s *terraform.State) error {
290400
return func(s *terraform.State) error {
291401
for name, rs := range s.RootModule().Resources {

website/docs/r/bigquery_dataset.html.markdown

+18
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,24 @@ The following arguments are supported:
293293
this value, unless table creation request (or query) overrides the key.
294294
Structure is [documented below](#nested_default_encryption_configuration).
295295

296+
* `is_case_insensitive` -
297+
(Optional)
298+
TRUE if the dataset and its table names are case-insensitive, otherwise FALSE.
299+
By default, this is FALSE, which means the dataset and its table names are
300+
case-sensitive. This field does not affect routine references.
301+
302+
* `default_collation` -
303+
(Optional)
304+
Defines the default collation specification of future tables created
305+
in the dataset. If a table is created in this dataset without table-level
306+
default collation, then the table inherits the dataset default collation,
307+
which is applied to the string fields that do not have explicit collation
308+
specified. A change to this field affects only tables created afterwards,
309+
and does not alter the existing tables.
310+
The following values are supported:
311+
- 'und:ci': undetermined locale, case insensitive.
312+
- '': empty string. Default to case-sensitive behavior.
313+
296314
* `project` - (Optional) The ID of the project in which the resource belongs.
297315
If it is not provided, the provider project is used.
298316

0 commit comments

Comments
 (0)