Skip to content

Commit

Permalink
remove forceNew on display_name (#6387) (#12311)
Browse files Browse the repository at this point in the history
Co-authored-by: Edward Sun <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
modular-magician and Edward Sun authored Aug 15, 2022
1 parent 26a7743 commit e31ee86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/6387.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigquery: Data Transfer: removed force replacement for `display_name` on `google_bigquery_data_transfer_config`
```
11 changes: 10 additions & 1 deletion google/resource_bigquery_data_transfer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func resourceBigqueryDataTransferConfig() *schema.Resource {
"display_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The user specified display name for the transfer config.`,
},
"params": {
Expand Down Expand Up @@ -460,6 +459,12 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter
billingProject = project

obj := make(map[string]interface{})
displayNameProp, err := expandBigqueryDataTransferConfigDisplayName(d.Get("display_name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) {
obj["displayName"] = displayNameProp
}
destinationDatasetIdProp, err := expandBigqueryDataTransferConfigDestinationDatasetId(d.Get("destination_dataset_id"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -522,6 +527,10 @@ func resourceBigqueryDataTransferConfigUpdate(d *schema.ResourceData, meta inter
log.Printf("[DEBUG] Updating Config %q: %#v", d.Id(), obj)
updateMask := []string{}

if d.HasChange("display_name") {
updateMask = append(updateMask, "displayName")
}

if d.HasChange("destination_dataset_id") {
updateMask = append(updateMask, "destinationDatasetId")
}
Expand Down
20 changes: 15 additions & 5 deletions google/resource_bigquery_data_transfer_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func testAccBigqueryDataTransferConfig_scheduledQuery_basic(t *testing.T) {
CheckDestroy: testAccCheckBigqueryDataTransferConfigDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, "third", start_time, end_time, "y"),
Config: testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, random_suffix, "third", start_time, end_time, "y"),
},
{
ResourceName: "google_bigquery_data_transfer_config.query_config",
Expand All @@ -68,17 +68,27 @@ func testAccBigqueryDataTransferConfig_scheduledQuery_update(t *testing.T) {
first_end_time := now.AddDate(0, 1, 0).Format(time.RFC3339)
second_start_time := now.Add(2 * time.Hour).Format(time.RFC3339)
second_end_time := now.AddDate(0, 2, 0).Format(time.RFC3339)
random_suffix2 := randString(t, 10)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBigqueryDataTransferConfigDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, "first", first_start_time, first_end_time, "y"),
Config: testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, random_suffix, "first", first_start_time, first_end_time, "y"),
},
{
Config: testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, "second", second_start_time, second_end_time, "z"),
Config: testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, random_suffix, "second", second_start_time, second_end_time, "z"),
},
{
ResourceName: "google_bigquery_data_transfer_config.query_config",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
},
{
Config: testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, random_suffix2, "second", second_start_time, second_end_time, "z"),
},
{
ResourceName: "google_bigquery_data_transfer_config.query_config",
Expand Down Expand Up @@ -185,7 +195,7 @@ func testAccCheckBigqueryDataTransferConfigDestroyProducer(t *testing.T) func(s
}
}

func testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, schedule, start_time, end_time, letter string) string {
func testAccBigqueryDataTransferConfig_scheduledQuery(random_suffix, random_suffix2, schedule, start_time, end_time, letter string) string {
return fmt.Sprintf(`
data "google_project" "project" {}
Expand Down Expand Up @@ -233,7 +243,7 @@ resource "google_bigquery_data_transfer_config" "query_config" {
query = "SELECT name FROM tabl WHERE x = '%s'"
}
}
`, random_suffix, random_suffix, random_suffix, schedule, start_time, end_time, letter)
`, random_suffix, random_suffix, random_suffix2, schedule, start_time, end_time, letter)
}

func testAccBigqueryDataTransferConfig_scheduledQuery_service_account(random_suffix string) string {
Expand Down

0 comments on commit e31ee86

Please sign in to comment.