@@ -39,35 +39,46 @@ var iamAuditConfigSchema = map[string]*schema.Schema{
39
39
}
40
40
41
41
func ResourceIamAuditConfig (parentSpecificSchema map [string ]* schema.Schema , newUpdaterFunc newResourceIamUpdaterFunc , resourceIdParser resourceIdParserFunc ) * schema.Resource {
42
+ return ResourceIamAuditConfigWithBatching (parentSpecificSchema , newUpdaterFunc , resourceIdParser , IamBatchingDisabled )
43
+ }
44
+
45
+ func ResourceIamAuditConfigWithBatching (parentSpecificSchema map [string ]* schema.Schema , newUpdaterFunc newResourceIamUpdaterFunc , resourceIdParser resourceIdParserFunc , enableBatching bool ) * schema.Resource {
42
46
return & schema.Resource {
43
- Create : resourceIamAuditConfigCreate (newUpdaterFunc ),
47
+ Create : resourceIamAuditConfigCreate (newUpdaterFunc , enableBatching ),
44
48
Read : resourceIamAuditConfigRead (newUpdaterFunc ),
45
- Update : resourceIamAuditConfigUpdate (newUpdaterFunc ),
46
- Delete : resourceIamAuditConfigDelete (newUpdaterFunc ),
49
+ Update : resourceIamAuditConfigUpdate (newUpdaterFunc , enableBatching ),
50
+ Delete : resourceIamAuditConfigDelete (newUpdaterFunc , enableBatching ),
47
51
Schema : mergeSchemas (iamAuditConfigSchema , parentSpecificSchema ),
48
52
Importer : & schema.ResourceImporter {
49
53
State : iamAuditConfigImport (resourceIdParser ),
50
54
},
51
55
}
52
56
}
53
57
54
- func resourceIamAuditConfigCreate (newUpdaterFunc newResourceIamUpdaterFunc ) schema.CreateFunc {
58
+ func resourceIamAuditConfigCreate (newUpdaterFunc newResourceIamUpdaterFunc , enableBatching bool ) schema.CreateFunc {
55
59
return func (d * schema.ResourceData , meta interface {}) error {
56
60
config := meta .(* Config )
57
61
updater , err := newUpdaterFunc (d , config )
58
62
if err != nil {
59
63
return err
60
64
}
61
65
62
- p := getResourceIamAuditConfig (d )
63
- err = iamPolicyReadModifyWrite ( updater , func (ep * cloudresourcemanager.Policy ) error {
64
- ep .AuditConfigs = mergeAuditConfigs (append (ep .AuditConfigs , p ))
66
+ ac := getResourceIamAuditConfig (d )
67
+ modifyF := func (ep * cloudresourcemanager.Policy ) error {
68
+ ep .AuditConfigs = mergeAuditConfigs (append (ep .AuditConfigs , ac ))
65
69
return nil
66
- })
70
+ }
71
+
72
+ if enableBatching {
73
+ err = BatchRequestModifyIamPolicy (updater , modifyF , config , fmt .Sprintf (
74
+ "Add audit config for service %s on resource %q" , ac .Service , updater .DescribeResource ()))
75
+ } else {
76
+ err = iamPolicyReadModifyWrite (updater , modifyF )
77
+ }
67
78
if err != nil {
68
79
return err
69
80
}
70
- d .SetId (updater .GetResourceId () + "/audit_config/" + p .Service )
81
+ d .SetId (updater .GetResourceId () + "/audit_config/" + ac .Service )
71
82
return resourceIamAuditConfigRead (newUpdaterFunc )(d , meta )
72
83
}
73
84
}
@@ -139,7 +150,7 @@ func iamAuditConfigImport(resourceIdParser resourceIdParserFunc) schema.StateFun
139
150
}
140
151
}
141
152
142
- func resourceIamAuditConfigUpdate (newUpdaterFunc newResourceIamUpdaterFunc ) schema.UpdateFunc {
153
+ func resourceIamAuditConfigUpdate (newUpdaterFunc newResourceIamUpdaterFunc , enableBatching bool ) schema.UpdateFunc {
143
154
return func (d * schema.ResourceData , meta interface {}) error {
144
155
config := meta .(* Config )
145
156
updater , err := newUpdaterFunc (d , config )
@@ -148,11 +159,17 @@ func resourceIamAuditConfigUpdate(newUpdaterFunc newResourceIamUpdaterFunc) sche
148
159
}
149
160
150
161
ac := getResourceIamAuditConfig (d )
151
- err = iamPolicyReadModifyWrite ( updater , func (p * cloudresourcemanager.Policy ) error {
152
- cleaned := removeAllAuditConfigsWithService (p .AuditConfigs , ac .Service )
153
- p .AuditConfigs = append (cleaned , ac )
162
+ modifyF := func (ep * cloudresourcemanager.Policy ) error {
163
+ cleaned := removeAllAuditConfigsWithService (ep .AuditConfigs , ac .Service )
164
+ ep .AuditConfigs = append (cleaned , ac )
154
165
return nil
155
- })
166
+ }
167
+ if enableBatching {
168
+ err = BatchRequestModifyIamPolicy (updater , modifyF , config , fmt .Sprintf (
169
+ "Overwrite audit config for service %s on resource %q" , ac .Service , updater .DescribeResource ()))
170
+ } else {
171
+ err = iamPolicyReadModifyWrite (updater , modifyF )
172
+ }
156
173
if err != nil {
157
174
return err
158
175
}
@@ -161,7 +178,7 @@ func resourceIamAuditConfigUpdate(newUpdaterFunc newResourceIamUpdaterFunc) sche
161
178
}
162
179
}
163
180
164
- func resourceIamAuditConfigDelete (newUpdaterFunc newResourceIamUpdaterFunc ) schema.DeleteFunc {
181
+ func resourceIamAuditConfigDelete (newUpdaterFunc newResourceIamUpdaterFunc , enableBatching bool ) schema.DeleteFunc {
165
182
return func (d * schema.ResourceData , meta interface {}) error {
166
183
config := meta .(* Config )
167
184
updater , err := newUpdaterFunc (d , config )
@@ -170,10 +187,16 @@ func resourceIamAuditConfigDelete(newUpdaterFunc newResourceIamUpdaterFunc) sche
170
187
}
171
188
172
189
ac := getResourceIamAuditConfig (d )
173
- err = iamPolicyReadModifyWrite ( updater , func (p * cloudresourcemanager.Policy ) error {
174
- p .AuditConfigs = removeAllAuditConfigsWithService (p .AuditConfigs , ac .Service )
190
+ modifyF := func (ep * cloudresourcemanager.Policy ) error {
191
+ ep .AuditConfigs = removeAllAuditConfigsWithService (ep .AuditConfigs , ac .Service )
175
192
return nil
176
- })
193
+ }
194
+ if enableBatching {
195
+ err = BatchRequestModifyIamPolicy (updater , modifyF , config , fmt .Sprintf (
196
+ "Delete audit config for service %s on resource %q" , ac .Service , updater .DescribeResource ()))
197
+ } else {
198
+ err = iamPolicyReadModifyWrite (updater , modifyF )
199
+ }
177
200
if err != nil {
178
201
return handleNotFoundError (err , d , fmt .Sprintf ("Resource %s with IAM audit config %q" , updater .DescribeResource (), d .Id ()))
179
202
}
0 commit comments