Skip to content

Commit

Permalink
Added max_time_travel_hours field in google_bigquery_dataset resource (
Browse files Browse the repository at this point in the history
…#6709) (#12830)

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Oct 19, 2022
1 parent c92e898 commit 4c715f1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
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

0 comments on commit 4c715f1

Please sign in to comment.