@@ -60,17 +60,26 @@ func ResourceBucketACL() *schema.Resource {
6060 Type : schema .TypeString ,
6161 Computed : true ,
6262 },
63+ "uri" : {
64+ Type : schema .TypeString ,
65+ Optional : true ,
66+ Description : "The uri of the grantee if you are granting permissions to a predefined group." ,
67+ ValidateFunc : validation .StringInSlice ([]string {
68+ "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" ,
69+ "http://acs.amazonaws.com/groups/global/AllUsers" ,
70+ }, false ),
71+ },
6372 "id" : {
6473 Type : schema .TypeString ,
65- Required : true ,
74+ Optional : true ,
6675 Description : "The project ID owner of the grantee." ,
6776 ValidateDiagFunc : verify .IsUUID (),
6877 },
6978 "type" : {
7079 Type : schema .TypeString ,
71- Required : true ,
72- Description : "Type of grantee. Valid values: `CanonicalUser`" ,
73- ValidateFunc : validation .StringInSlice ([]string {string (s3Types .TypeCanonicalUser )}, false ),
80+ Optional : true ,
81+ Description : "Type of grantee. Valid values: `CanonicalUser`, `Group` " ,
82+ ValidateFunc : validation .StringInSlice ([]string {string (s3Types .TypeCanonicalUser ), string ( s3Types . TypeGroup ) }, false ),
7483 },
7584 },
7685 },
@@ -183,7 +192,12 @@ func resourceBucketACLCreate(ctx context.Context, d *schema.ResourceData, m any)
183192 }
184193
185194 if v , ok := d .GetOk ("access_control_policy" ); ok && len (v .([]any )) > 0 && v .([]any )[0 ] != nil {
186- input .AccessControlPolicy = expandBucketACLAccessControlPolicy (v .([]any ))
195+ accessControlPolicy , err := expandAndValidateBucketACLAccessControlPolicy (v .([]any ))
196+ if err != nil {
197+ return diag .FromErr (err )
198+ }
199+
200+ input .AccessControlPolicy = accessControlPolicy
187201 }
188202
189203 out , err := conn .PutBucketAcl (ctx , input )
@@ -198,30 +212,35 @@ func resourceBucketACLCreate(ctx context.Context, d *schema.ResourceData, m any)
198212 return resourceBucketACLRead (ctx , d , m )
199213}
200214
201- func expandBucketACLAccessControlPolicy (l []any ) * s3Types.AccessControlPolicy {
215+ func expandAndValidateBucketACLAccessControlPolicy (l []any ) ( * s3Types.AccessControlPolicy , error ) {
202216 if len (l ) == 0 || l [0 ] == nil {
203- return nil
217+ return nil , nil
204218 }
205219
206220 tfMap , ok := l [0 ].(map [string ]any )
207221 if ! ok {
208- return nil
222+ return nil , nil
209223 }
210224
211225 result := & s3Types.AccessControlPolicy {}
212226
213227 if v , ok := tfMap ["grant" ].(* schema.Set ); ok && v .Len () > 0 {
214- result .Grants = expandBucketACLAccessControlPolicyGrants (v .List ())
228+ grants , err := expandAndValidateBucketACLAccessControlPolicyGrants (v .List ())
229+ if err != nil {
230+ return nil , err
231+ }
232+
233+ result .Grants = grants
215234 }
216235
217236 if v , ok := tfMap ["owner" ].([]any ); ok && len (v ) > 0 && v [0 ] != nil {
218237 result .Owner = expandBucketACLAccessControlPolicyOwner (v )
219238 }
220239
221- return result
240+ return result , nil
222241}
223242
224- func expandBucketACLAccessControlPolicyGrants (l []any ) []s3Types.Grant {
243+ func expandAndValidateBucketACLAccessControlPolicyGrants (l []any ) ( []s3Types.Grant , error ) {
225244 grants := make ([]s3Types.Grant , 0 , len (l ))
226245
227246 for _ , tfMapRaw := range l {
@@ -233,7 +252,12 @@ func expandBucketACLAccessControlPolicyGrants(l []any) []s3Types.Grant {
233252 grant := s3Types.Grant {}
234253
235254 if v , ok := tfMap ["grantee" ].([]any ); ok && len (v ) > 0 && v [0 ] != nil {
236- grant .Grantee = expandBucketACLAccessControlPolicyGrantsGrantee (v )
255+ grantee , err := expandAndValidateBucketACLAccessControlPolicyGrantsGrantee (v )
256+ if err != nil {
257+ return nil , err
258+ }
259+
260+ grant .Grantee = grantee
237261 }
238262
239263 if v , ok := tfMap ["permission" ].(string ); ok && v != "" {
@@ -243,17 +267,17 @@ func expandBucketACLAccessControlPolicyGrants(l []any) []s3Types.Grant {
243267 grants = append (grants , grant )
244268 }
245269
246- return grants
270+ return grants , nil
247271}
248272
249- func expandBucketACLAccessControlPolicyGrantsGrantee (l []any ) * s3Types.Grantee {
273+ func expandAndValidateBucketACLAccessControlPolicyGrantsGrantee (l []any ) ( * s3Types.Grantee , error ) {
250274 if len (l ) == 0 || l [0 ] == nil {
251- return nil
275+ return nil , nil
252276 }
253277
254278 tfMap , ok := l [0 ].(map [string ]any )
255279 if ! ok {
256- return nil
280+ return nil , nil
257281 }
258282
259283 result := & s3Types.Grantee {}
@@ -262,11 +286,23 @@ func expandBucketACLAccessControlPolicyGrantsGrantee(l []any) *s3Types.Grantee {
262286 result .ID = buildBucketOwnerID (aws .String (v ))
263287 }
264288
289+ if v , ok := tfMap ["uri" ].(string ); ok && v != "" {
290+ result .URI = aws .String (v )
291+ }
292+
265293 if v , ok := tfMap ["type" ].(string ); ok && v != "" {
266294 result .Type = s3Types .Type (v )
267295 }
268296
269- return result
297+ if result .Type == s3Types .TypeCanonicalUser && result .ID == nil {
298+ return nil , errors .New ("id is required when grantee type is CanonicalUser" )
299+ }
300+
301+ if result .Type == s3Types .TypeGroup && result .URI == nil {
302+ return nil , errors .New ("uri is required when grantee type is Group" )
303+ }
304+
305+ return result , nil
270306}
271307
272308func expandBucketACLAccessControlPolicyOwner (l []any ) * s3Types.Owner {
@@ -345,6 +381,10 @@ func flattenBucketACLAccessControlPolicyGrantsGrantee(grantee *s3Types.Grantee)
345381 m ["display_name" ] = NormalizeOwnerID (grantee .DisplayName )
346382 }
347383
384+ if grantee .URI != nil {
385+ m ["uri" ] = * grantee .URI
386+ }
387+
348388 if grantee .ID != nil {
349389 m ["id" ] = NormalizeOwnerID (grantee .ID )
350390 }
@@ -451,7 +491,12 @@ func resourceBucketACLUpdate(ctx context.Context, d *schema.ResourceData, m any)
451491 }
452492
453493 if d .HasChange ("access_control_policy" ) {
454- input .AccessControlPolicy = expandBucketACLAccessControlPolicy (d .Get ("access_control_policy" ).([]any ))
494+ accessControlPolicy , err := expandAndValidateBucketACLAccessControlPolicy (d .Get ("access_control_policy" ).([]any ))
495+ if err != nil {
496+ return diag .FromErr (err )
497+ }
498+
499+ input .AccessControlPolicy = accessControlPolicy
455500 }
456501
457502 _ , err = conn .PutBucketAcl (ctx , input )
0 commit comments