@@ -28,6 +28,8 @@ import (
28
28
"strconv"
29
29
"strings"
30
30
31
+ "golang.org/x/exp/slices"
32
+
31
33
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
32
34
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
33
35
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
@@ -66,7 +68,7 @@ func bigQueryTablecheckNameExists(jsonList []interface{}) error {
66
68
// Compares two json's while optionally taking in a compareMapKeyVal function.
67
69
// This function will override any comparison of a given map[string]interface{}
68
70
// 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 ) {
70
72
switch a .(type ) {
71
73
case []interface {}:
72
74
arrayA := a .([]interface {})
@@ -89,7 +91,7 @@ func jsonCompareWithMapKeyOverride(key string, a, b interface{}, compareMapKeyVa
89
91
bigQueryTableSortArrayByName (arrayB )
90
92
}
91
93
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 )
93
95
if err != nil {
94
96
return false , err
95
97
} else if ! eq {
@@ -119,14 +121,14 @@ func jsonCompareWithMapKeyOverride(key string, a, b interface{}, compareMapKeyVa
119
121
}
120
122
121
123
for subKey := range unionOfKeys {
122
- eq := compareMapKeyVal (subKey , objectA , objectB )
124
+ eq := compareMapKeyVal (subKey , objectA , objectB , d )
123
125
if ! eq {
124
126
valA , ok1 := objectA [subKey ]
125
127
valB , ok2 := objectB [subKey ]
126
128
if ! ok1 || ! ok2 {
127
129
return false , nil
128
130
}
129
- eq , err := jsonCompareWithMapKeyOverride (subKey , valA , valB , compareMapKeyVal )
131
+ eq , err := jsonCompareWithMapKeyOverride (subKey , valA , valB , compareMapKeyVal , d )
130
132
if err != nil || ! eq {
131
133
return false , err
132
134
}
@@ -152,7 +154,7 @@ func valueIsInArray(value interface{}, array []interface{}) bool {
152
154
return false
153
155
}
154
156
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 {
156
158
// we rely on the fallback to nil if the object does not have the key
157
159
valA := objectA [key ]
158
160
valB := objectB [key ]
@@ -172,14 +174,22 @@ func bigQueryTableMapKeyOverride(key string, objectA, objectB map[string]interfa
172
174
case "policyTags" :
173
175
eq := bigQueryTableNormalizePolicyTags (valA ) == nil && bigQueryTableNormalizePolicyTags (valB ) == nil
174
176
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" )
175
185
}
176
186
177
187
// otherwise rely on default behavior
178
188
return false
179
189
}
180
190
181
191
// 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 {
183
193
// The API can return an empty schema which gets encoded to "null" during read.
184
194
if old == "null" {
185
195
old = "[]"
@@ -192,7 +202,7 @@ func bigQueryTableSchemaDiffSuppress(name, old, new string, _ *schema.ResourceDa
192
202
log .Printf ("[DEBUG] unable to unmarshal new json - %v" , err )
193
203
}
194
204
195
- eq , err := jsonCompareWithMapKeyOverride (name , a , b , bigQueryTableMapKeyOverride )
205
+ eq , err := jsonCompareWithMapKeyOverride (name , a , b , bigQueryTableMapKeyOverride , d )
196
206
if err != nil {
197
207
log .Printf ("[DEBUG] %v" , err )
198
208
log .Printf ("[DEBUG] Error comparing JSON: %v, %v" , old , new )
@@ -1278,7 +1288,13 @@ func ResourceBigQueryTable() *schema.Resource {
1278
1288
Computed : true ,
1279
1289
Description : `A hash of the resource.` ,
1280
1290
},
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
+ },
1282
1298
// LastModifiedTime: [Output-only] The time when this table was last
1283
1299
// modified, in milliseconds since the epoch.
1284
1300
"last_modified_time" : {
@@ -2070,7 +2086,7 @@ type TableReference struct {
2070
2086
2071
2087
func resourceBigQueryTableUpdate (d * schema.ResourceData , meta interface {}) error {
2072
2088
// 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 }
2074
2090
clientSideOnly := true
2075
2091
for field := range ResourceBigQueryTable ().Schema {
2076
2092
if d .HasChange (field ) && ! clientSideFields [field ] {
0 commit comments