@@ -38,6 +38,12 @@ import (
38
38
39
39
const datasetIdRegexp = `^[0-9A-Za-z_]+$`
40
40
41
+ var bigqueryDatasetAccessPrimitiveToRoleMap = map [string ]string {
42
+ "OWNER" : "roles/bigquery.dataOwner" ,
43
+ "WRITER" : "roles/bigquery.dataEditor" ,
44
+ "READER" : "roles/bigquery.dataViewer" ,
45
+ }
46
+
41
47
func validateDatasetId (v interface {}, k string ) (ws []string , errors []error ) {
42
48
value := v .(string )
43
49
if ! regexp .MustCompile (datasetIdRegexp ).MatchString (value ) {
@@ -62,6 +68,31 @@ func validateDefaultTableExpirationMs(v interface{}, k string) (ws []string, err
62
68
return
63
69
}
64
70
71
+ // bigqueryDatasetAccessHash is a custom hash function for the access block.
72
+ // It normalizes the 'role' field before hashing, treating legacy roles
73
+ // and their modern IAM equivalents as the same.
74
+ func resourceBigqueryDatasetAccessHash (v interface {}) int {
75
+ m , ok := v .(map [string ]interface {})
76
+ if ! ok {
77
+ return 0
78
+ }
79
+ // Make a copy of the map to avoid modifying the underlying data.
80
+ copy := make (map [string ]interface {}, len (m ))
81
+ for k , val := range m {
82
+ copy [k ] = val
83
+ }
84
+
85
+ // Normalize the role if it exists and matches a legacy role.
86
+ if role , ok := copy ["role" ].(string ); ok {
87
+ if newRole , ok := bigqueryDatasetAccessPrimitiveToRoleMap [role ]; ok {
88
+ copy ["role" ] = newRole
89
+ }
90
+ }
91
+
92
+ // Use the default HashResource function on the (potentially modified) copy.
93
+ return schema .HashResource (bigqueryDatasetAccessSchema ())(copy )
94
+ }
95
+
65
96
func ResourceBigQueryDataset () * schema.Resource {
66
97
return & schema.Resource {
67
98
Create : resourceBigQueryDatasetCreate ,
@@ -101,7 +132,7 @@ underscores (_). The maximum length is 1,024 characters.`,
101
132
Optional : true ,
102
133
Description : `An array of objects that define dataset access for one or more entities.` ,
103
134
Elem : bigqueryDatasetAccessSchema (),
104
- // Default schema.HashSchema is used.
135
+ Set : resourceBigqueryDatasetAccessHash ,
105
136
},
106
137
"default_collation" : {
107
138
Type : schema .TypeString ,
@@ -1034,7 +1065,7 @@ func flattenBigQueryDatasetAccess(v interface{}, d *schema.ResourceData, config
1034
1065
return v
1035
1066
}
1036
1067
l := v .([]interface {})
1037
- transformed := schema .NewSet (schema . HashResource ( bigqueryDatasetAccessSchema ()) , []interface {}{})
1068
+ transformed := schema .NewSet (resourceBigqueryDatasetAccessHash , []interface {}{})
1038
1069
for _ , raw := range l {
1039
1070
original := raw .(map [string ]interface {})
1040
1071
if len (original ) < 1 {
0 commit comments