@@ -28,6 +28,8 @@ import (
2828 "strconv"
2929 "strings"
3030
31+ "golang.org/x/exp/slices"
32+
3133 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
3234 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
3335 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
@@ -66,7 +68,7 @@ func bigQueryTablecheckNameExists(jsonList []interface{}) error {
6668// Compares two json's while optionally taking in a compareMapKeyVal function.
6769// This function will override any comparison of a given map[string]interface{}
6870// on a specific key value allowing for a separate equality in specific scenarios
69- func jsonCompareWithMapKeyOverride (key string , a , b interface {}, compareMapKeyVal func (key string , val1 , val2 map [string ]interface {}) bool ) (bool , error ) {
71+ func jsonCompareWithMapKeyOverride (key string , a , b interface {}, compareMapKeyVal func (key string , val1 , val2 map [string ]interface {}, d * schema. ResourceData ) bool , d * schema. ResourceData ) (bool , error ) {
7072 switch a .(type ) {
7173 case []interface {}:
7274 arrayA := a .([]interface {})
@@ -89,7 +91,7 @@ func jsonCompareWithMapKeyOverride(key string, a, b interface{}, compareMapKeyVa
8991 bigQueryTableSortArrayByName (arrayB )
9092 }
9193 for i := range arrayA {
92- eq , err := jsonCompareWithMapKeyOverride (strconv .Itoa (i ), arrayA [i ], arrayB [i ], compareMapKeyVal )
94+ eq , err := jsonCompareWithMapKeyOverride (strconv .Itoa (i ), arrayA [i ], arrayB [i ], compareMapKeyVal , d )
9395 if err != nil {
9496 return false , err
9597 } else if ! eq {
@@ -119,14 +121,14 @@ func jsonCompareWithMapKeyOverride(key string, a, b interface{}, compareMapKeyVa
119121 }
120122
121123 for subKey := range unionOfKeys {
122- eq := compareMapKeyVal (subKey , objectA , objectB )
124+ eq := compareMapKeyVal (subKey , objectA , objectB , d )
123125 if ! eq {
124126 valA , ok1 := objectA [subKey ]
125127 valB , ok2 := objectB [subKey ]
126128 if ! ok1 || ! ok2 {
127129 return false , nil
128130 }
129- eq , err := jsonCompareWithMapKeyOverride (subKey , valA , valB , compareMapKeyVal )
131+ eq , err := jsonCompareWithMapKeyOverride (subKey , valA , valB , compareMapKeyVal , d )
130132 if err != nil || ! eq {
131133 return false , err
132134 }
@@ -152,7 +154,7 @@ func valueIsInArray(value interface{}, array []interface{}) bool {
152154 return false
153155}
154156
155- func bigQueryTableMapKeyOverride (key string , objectA , objectB map [string ]interface {}) bool {
157+ func bigQueryTableMapKeyOverride (key string , objectA , objectB map [string ]interface {}, d * schema. ResourceData ) bool {
156158 // we rely on the fallback to nil if the object does not have the key
157159 valA := objectA [key ]
158160 valB := objectB [key ]
@@ -172,14 +174,22 @@ func bigQueryTableMapKeyOverride(key string, objectA, objectB map[string]interfa
172174 case "policyTags" :
173175 eq := bigQueryTableNormalizePolicyTags (valA ) == nil && bigQueryTableNormalizePolicyTags (valB ) == nil
174176 return eq
177+ case "dataPolicies" :
178+ if d == nil {
179+ return false
180+ }
181+ // Access the ignore_schema_changes list from the Terraform configuration
182+ ignoreSchemaChanges := d .Get ("ignore_schema_changes" ).([]interface {})
183+ // Suppress diffs for the "dataPolicies" field if it was present in "ignore_schema_changes"
184+ return slices .Contains (ignoreSchemaChanges , "dataPolicies" )
175185 }
176186
177187 // otherwise rely on default behavior
178188 return false
179189}
180190
181191// Compare the JSON strings are equal
182- func bigQueryTableSchemaDiffSuppress (name , old , new string , _ * schema.ResourceData ) bool {
192+ func bigQueryTableSchemaDiffSuppress (name , old , new string , d * schema.ResourceData ) bool {
183193 // The API can return an empty schema which gets encoded to "null" during read.
184194 if old == "null" {
185195 old = "[]"
@@ -192,7 +202,7 @@ func bigQueryTableSchemaDiffSuppress(name, old, new string, _ *schema.ResourceDa
192202 log .Printf ("[DEBUG] unable to unmarshal new json - %v" , err )
193203 }
194204
195- eq , err := jsonCompareWithMapKeyOverride (name , a , b , bigQueryTableMapKeyOverride )
205+ eq , err := jsonCompareWithMapKeyOverride (name , a , b , bigQueryTableMapKeyOverride , d )
196206 if err != nil {
197207 log .Printf ("[DEBUG] %v" , err )
198208 log .Printf ("[DEBUG] Error comparing JSON: %v, %v" , old , new )
@@ -1278,7 +1288,13 @@ func ResourceBigQueryTable() *schema.Resource {
12781288 Computed : true ,
12791289 Description : `A hash of the resource.` ,
12801290 },
1281-
1291+ "ignore_schema_changes" : {
1292+ Type : schema .TypeList ,
1293+ Optional : true ,
1294+ MaxItems : 10 ,
1295+ Description : `Mention which fields in schema are to be ignored` ,
1296+ Elem : & schema.Schema {Type : schema .TypeString },
1297+ },
12821298 // LastModifiedTime: [Output-only] The time when this table was last
12831299 // modified, in milliseconds since the epoch.
12841300 "last_modified_time" : {
@@ -2070,7 +2086,7 @@ type TableReference struct {
20702086
20712087func resourceBigQueryTableUpdate (d * schema.ResourceData , meta interface {}) error {
20722088 // If only client-side fields were modified, short-circuit the Update function to avoid sending an update API request.
2073- clientSideFields := map [string ]bool {"deletion_protection" : true , "table_metadata_view" : true }
2089+ clientSideFields := map [string ]bool {"deletion_protection" : true , "ignore_schema_changes" : true , " table_metadata_view" : true }
20742090 clientSideOnly := true
20752091 for field := range ResourceBigQueryTable ().Schema {
20762092 if d .HasChange (field ) && ! clientSideFields [field ] {
0 commit comments