Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added is_case_insensitive and default_collation fields for google_bigquery_dataset resource #14031

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/7457.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigquery: added `is_case_insensitive` and `default_collation` fields to `google_bigquery_dataset` resource
```
69 changes: 69 additions & 0 deletions google/resource_bigquery_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ underscores (_). The maximum length is 1,024 characters.`,
Elem: bigqueryDatasetAccessSchema(),
// Default schema.HashSchema is used.
},
"default_collation": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `Defines the default collation specification of future tables created
in the dataset. If a table is created in this dataset without table-level
default collation, then the table inherits the dataset default collation,
which is applied to the string fields that do not have explicit collation
specified. A change to this field affects only tables created afterwards,
and does not alter the existing tables.

The following values are supported:
- 'und:ci': undetermined locale, case insensitive.
- '': empty string. Default to case-sensitive behavior.`,
},
"default_encryption_configuration": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -153,6 +168,14 @@ expiration time indicated by this property.`,
Optional: true,
Description: `A descriptive name for the dataset`,
},
"is_case_insensitive": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
Description: `TRUE if the dataset and its table names are case-insensitive, otherwise FALSE.
By default, this is FALSE, which means the dataset and its table names are
case-sensitive. This field does not affect routine references.`,
},
"labels": {
Type: schema.TypeMap,
Computed: true,
Expand Down Expand Up @@ -445,6 +468,18 @@ func resourceBigQueryDatasetCreate(d *schema.ResourceData, meta interface{}) err
} else if v, ok := d.GetOkExists("default_encryption_configuration"); !isEmptyValue(reflect.ValueOf(defaultEncryptionConfigurationProp)) && (ok || !reflect.DeepEqual(v, defaultEncryptionConfigurationProp)) {
obj["defaultEncryptionConfiguration"] = defaultEncryptionConfigurationProp
}
isCaseInsensitiveProp, err := expandBigQueryDatasetIsCaseInsensitive(d.Get("is_case_insensitive"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("is_case_insensitive"); !isEmptyValue(reflect.ValueOf(isCaseInsensitiveProp)) && (ok || !reflect.DeepEqual(v, isCaseInsensitiveProp)) {
obj["isCaseInsensitive"] = isCaseInsensitiveProp
}
defaultCollationProp, err := expandBigQueryDatasetDefaultCollation(d.Get("default_collation"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("default_collation"); !isEmptyValue(reflect.ValueOf(defaultCollationProp)) && (ok || !reflect.DeepEqual(v, defaultCollationProp)) {
obj["defaultCollation"] = defaultCollationProp
}

url, err := replaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets")
if err != nil {
Expand Down Expand Up @@ -573,6 +608,12 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("default_encryption_configuration", flattenBigQueryDatasetDefaultEncryptionConfiguration(res["defaultEncryptionConfiguration"], d, config)); err != nil {
return fmt.Errorf("Error reading Dataset: %s", err)
}
if err := d.Set("is_case_insensitive", flattenBigQueryDatasetIsCaseInsensitive(res["isCaseInsensitive"], d, config)); err != nil {
return fmt.Errorf("Error reading Dataset: %s", err)
}
if err := d.Set("default_collation", flattenBigQueryDatasetDefaultCollation(res["defaultCollation"], d, config)); err != nil {
return fmt.Errorf("Error reading Dataset: %s", err)
}
if err := d.Set("self_link", ConvertSelfLinkToV1(res["selfLink"].(string))); err != nil {
return fmt.Errorf("Error reading Dataset: %s", err)
}
Expand Down Expand Up @@ -656,6 +697,18 @@ func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) err
} else if v, ok := d.GetOkExists("default_encryption_configuration"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultEncryptionConfigurationProp)) {
obj["defaultEncryptionConfiguration"] = defaultEncryptionConfigurationProp
}
isCaseInsensitiveProp, err := expandBigQueryDatasetIsCaseInsensitive(d.Get("is_case_insensitive"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("is_case_insensitive"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, isCaseInsensitiveProp)) {
obj["isCaseInsensitive"] = isCaseInsensitiveProp
}
defaultCollationProp, err := expandBigQueryDatasetDefaultCollation(d.Get("default_collation"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("default_collation"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultCollationProp)) {
obj["defaultCollation"] = defaultCollationProp
}

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

func flattenBigQueryDatasetIsCaseInsensitive(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenBigQueryDatasetDefaultCollation(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func expandBigQueryDatasetMaxTimeTravelHours(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -1338,3 +1399,11 @@ func expandBigQueryDatasetDefaultEncryptionConfiguration(v interface{}, d Terraf
func expandBigQueryDatasetDefaultEncryptionConfigurationKmsKeyName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandBigQueryDatasetIsCaseInsensitive(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandBigQueryDatasetDefaultCollation(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
110 changes: 110 additions & 0 deletions google/resource_bigquery_dataset_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,116 @@ resource "google_bigquery_dataset" "private" {
`, context)
}

func TestAccBigQueryDataset_bigqueryDatasetCaseInsensitiveNamesExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigQueryDataset_bigqueryDatasetCaseInsensitiveNamesExample(context),
},
{
ResourceName: "google_bigquery_dataset.dataset",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccBigQueryDataset_bigqueryDatasetCaseInsensitiveNamesExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_bigquery_dataset" "dataset" {
dataset_id = "tf_test_example_dataset%{random_suffix}"
friendly_name = "test"
description = "This is a test description"
location = "EU"
default_table_expiration_ms = 3600000
is_case_insensitive = true

labels = {
env = "default"
}

access {
role = "OWNER"
user_by_email = google_service_account.bqowner.email
}

access {
role = "READER"
domain = "hashicorp.com"
}
}

resource "google_service_account" "bqowner" {
account_id = "bqowner%{random_suffix}"
}
`, context)
}

func TestAccBigQueryDataset_bigqueryDatasetDefaultCollationSetExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigQueryDataset_bigqueryDatasetDefaultCollationSetExample(context),
},
{
ResourceName: "google_bigquery_dataset.dataset",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccBigQueryDataset_bigqueryDatasetDefaultCollationSetExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_bigquery_dataset" "dataset" {
dataset_id = "tf_test_example_dataset%{random_suffix}"
friendly_name = "test"
description = "This is a test description"
location = "EU"
default_table_expiration_ms = 3600000
default_collation = "und:ci"

labels = {
env = "default"
}

access {
role = "OWNER"
user_by_email = google_service_account.bqowner.email
}

access {
role = "READER"
domain = "hashicorp.com"
}
}

resource "google_service_account" "bqowner" {
account_id = "bqowner%{random_suffix}"
}
`, context)
}

func testAccCheckBigQueryDatasetDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
18 changes: 18 additions & 0 deletions website/docs/r/bigquery_dataset.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ The following arguments are supported:
this value, unless table creation request (or query) overrides the key.
Structure is [documented below](#nested_default_encryption_configuration).

* `is_case_insensitive` -
(Optional)
TRUE if the dataset and its table names are case-insensitive, otherwise FALSE.
By default, this is FALSE, which means the dataset and its table names are
case-sensitive. This field does not affect routine references.

* `default_collation` -
(Optional)
Defines the default collation specification of future tables created
in the dataset. If a table is created in this dataset without table-level
default collation, then the table inherits the dataset default collation,
which is applied to the string fields that do not have explicit collation
specified. A change to this field affects only tables created afterwards,
and does not alter the existing tables.
The following values are supported:
- 'und:ci': undetermined locale, case insensitive.
- '': empty string. Default to case-sensitive behavior.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down