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 max_time_travel_hours field in google_bigquery_dataset resource #12830

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6709.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
bigquery: added `max_time_travel_hours` field in `google_bigquery_dataset` resource
```
28 changes: 28 additions & 0 deletions google/resource_bigquery_dataset.go
Expand Up @@ -179,6 +179,11 @@ The default value is multi-regional location 'US'.
Changing this forces a new resource to be created.`,
Default: "US",
},
"max_time_travel_hours": {
Type: schema.TypeString,
Optional: true,
Description: `Defines the time travel window in hours. The value can be from 48 to 168 hours (2 to 7 days).`,
},
"creation_time": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -344,6 +349,12 @@ func resourceBigQueryDatasetCreate(d *schema.ResourceData, meta interface{}) err
}

obj := make(map[string]interface{})
maxTimeTravelHoursProp, err := expandBigQueryDatasetMaxTimeTravelHours(d.Get("max_time_travel_hours"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("max_time_travel_hours"); !isEmptyValue(reflect.ValueOf(maxTimeTravelHoursProp)) && (ok || !reflect.DeepEqual(v, maxTimeTravelHoursProp)) {
obj["maxTimeTravelHours"] = maxTimeTravelHoursProp
}
accessProp, err := expandBigQueryDatasetAccess(d.Get("access"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -475,6 +486,9 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error reading Dataset: %s", err)
}

if err := d.Set("max_time_travel_hours", flattenBigQueryDatasetMaxTimeTravelHours(res["maxTimeTravelHours"], d, config)); err != nil {
return fmt.Errorf("Error reading Dataset: %s", err)
}
if err := d.Set("access", flattenBigQueryDatasetAccess(res["access"], d, config)); err != nil {
return fmt.Errorf("Error reading Dataset: %s", err)
}
Expand Down Expand Up @@ -546,6 +560,12 @@ func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) err
billingProject = project

obj := make(map[string]interface{})
maxTimeTravelHoursProp, err := expandBigQueryDatasetMaxTimeTravelHours(d.Get("max_time_travel_hours"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("max_time_travel_hours"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, maxTimeTravelHoursProp)) {
obj["maxTimeTravelHours"] = maxTimeTravelHoursProp
}
accessProp, err := expandBigQueryDatasetAccess(d.Get("access"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -686,6 +706,10 @@ func resourceBigQueryDatasetImport(d *schema.ResourceData, meta interface{}) ([]
return []*schema.ResourceData{d}, nil
}

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

func flattenBigQueryDatasetAccess(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -929,6 +953,10 @@ func flattenBigQueryDatasetDefaultEncryptionConfigurationKmsKeyName(v interface{
return v
}

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

func expandBigQueryDatasetAccess(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
v = v.(*schema.Set).List()
l := v.([]interface{})
Expand Down
55 changes: 55 additions & 0 deletions google/resource_bigquery_dataset_generated_test.go
Expand Up @@ -77,6 +77,61 @@ resource "google_service_account" "bqowner" {
`, context)
}

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

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

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

func testAccBigQueryDataset_bigqueryDatasetWithMaxTimeTravelHoursExample(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
max_time_travel_hours = "72"

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_bigqueryDatasetAuthorizedDatasetExample(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/bigquery_dataset.html.markdown
Expand Up @@ -177,6 +177,10 @@ The following arguments are supported:
- - -


* `max_time_travel_hours` -
(Optional)
Defines the time travel window in hours. The value can be from 48 to 168 hours (2 to 7 days).

* `access` -
(Optional)
An array of objects that define dataset access for one or more entities.
Expand Down