Skip to content

Commit

Permalink
make ForceNew on newly added required field (#5362) (#10421)
Browse files Browse the repository at this point in the history
* make ForceNew on newly added required field

* Update resource_bigquery_table.go

Fixed a typo

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Oct 27, 2021
1 parent bdbbf91 commit 8e7078f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/5362.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigquery: fixed a bug of cannot add required fields to an existing schema on `google_bigquery_table`
```
11 changes: 11 additions & 0 deletions google/resource_bigquery_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ func resourceBigQueryTableSchemaIsChangeable(old, new interface{}) (bool, error)
return false, err
}
mapNew := bigQueryArrayToMapIndexedByName(arrayNew)
for key := range mapNew {
// making unchangeable if an newly added column is with REQUIRED mode
if _, ok := mapOld[key]; !ok {
items := mapNew[key].(map[string]interface{})
for k := range items {
if k == "mode" && fmt.Sprintf("%v", items[k]) == "REQUIRED" {
return false, nil
}
}
}
}
for key := range mapOld {
// all old keys should be represented in the new config
if _, ok := mapNew[key]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion google/resource_container_node_pool.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package google

import (
"context"
"fmt"
"log"
"regexp"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down

0 comments on commit 8e7078f

Please sign in to comment.