Skip to content

Commit 84fda72

Browse files
authored
Fix permadiff when schema is unchanged for a google_bigquery_table with row access policies (#15764)
1 parent 1500bd5 commit 84fda72

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

mmv1/third_party/terraform/services/bigquery/resource_bigquery_table.go.tmpl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,19 @@ func resourceBigQueryTableSchemaIsChangeable(old, new interface{}, isExternalTab
351351
sameNameColumns += 1
352352
}
353353
}
354-
// in-place column dropping alongside column additions is not allowed
355-
// as of now because user intention can be ambiguous (e.g. column renaming)
356-
newColumns := len(arrayNew) - sameNameColumns
357-
isSchemaChangeable := (droppedColumns == 0) || (newColumns == 0)
358-
if isSchemaChangeable && topLevel {
354+
// In-place column dropping is not supported when there are row access
355+
// policies on the table.
356+
hasDroppedColumns := droppedColumns > 0
357+
if hasDroppedColumns && topLevel {
359358
hasRowAccessPolicy, err := hasRowAccessPolicyFunc()
360-
if err != nil {
361-
// Default behavior when we can't get row access policies data.
362-
return isSchemaChangeable, nil
363-
}
364-
if hasRowAccessPolicy {
365-
isSchemaChangeable = false
359+
if err == nil && hasRowAccessPolicy {
360+
return false, nil
366361
}
367362
}
363+
// In-place column dropping alongside column additions is not allowed
364+
// as of now because user intention can be ambiguous (e.g. column renaming)
365+
newColumns := len(arrayNew) - sameNameColumns
366+
isSchemaChangeable := (droppedColumns == 0) || (newColumns == 0)
368367
return isSchemaChangeable, nil
369368
case map[string]interface{}:
370369
objectOld := old.(map[string]interface{})

mmv1/third_party/terraform/services/bigquery/resource_bigquery_table_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,34 @@ func TestAccBigQueryTable_invalidSchemas(t *testing.T) {
18021802
})
18031803
}
18041804

1805+
func TestAccBigQueryTable_schemaUnchangedWithRowAccessPolicy(t *testing.T) {
1806+
t.Parallel()
1807+
1808+
context := map[string]interface{}{
1809+
"project_id": envvar.GetTestProjectFromEnv(),
1810+
"dataset_id": fmt.Sprintf("tf_test_dataset_%s", acctest.RandString(t, 10)),
1811+
"table_id": fmt.Sprintf("tf_test_table_%s", acctest.RandString(t, 10)),
1812+
"policy_id": fmt.Sprintf("tf_test_policy_%s", acctest.RandString(t, 10)),
1813+
}
1814+
1815+
acctest.VcrTest(t, resource.TestCase{
1816+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1817+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1818+
CheckDestroy: testAccCheckBigQueryTableDestroyProducer(t),
1819+
Steps: []resource.TestStep{
1820+
{
1821+
Config: testAccBigQueryTableWithSchemaAndRowAccessPolicy(context),
1822+
},
1823+
{
1824+
ResourceName: "google_bigquery_table.test",
1825+
ImportState: true,
1826+
ImportStateVerify: true,
1827+
ImportStateVerifyIgnore: []string{"deletion_protection", "ignore_auto_generated_schema", "generated_schema_columns"},
1828+
},
1829+
},
1830+
})
1831+
}
1832+
18051833
func TestAccBigQueryTable_schemaColumnDropWithRowAccessPolicy(t *testing.T) {
18061834
t.Parallel()
18071835

0 commit comments

Comments
 (0)