Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eventual consistency protection to efs_file_system_policy #21734

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/21734.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_efs_file_system_policy: Retry IAM eventual consistency errors
```
12 changes: 12 additions & 0 deletions internal/service/efs/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package efs

import (
"time"
)

const (
propagationTimeout = 2 * time.Minute
)
20 changes: 10 additions & 10 deletions internal/service/efs/file_system_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func ResourceFileSystemPolicy() *schema.Resource {
ReadWithoutTimeout: resourceFileSystemPolicyRead,
UpdateWithoutTimeout: resourceFileSystemPolicyPut,
DeleteWithoutTimeout: resourceFileSystemPolicyDelete,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down Expand Up @@ -62,9 +63,8 @@ func resourceFileSystemPolicyPut(ctx context.Context, d *schema.ResourceData, me
conn := meta.(*conns.AWSClient).EFSConn(ctx)

policy, err := structure.NormalizeJsonString(d.Get("policy").(string))

if err != nil {
return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", policy, err)
return sdkdiag.AppendFromErr(diags, err)
}

fsID := d.Get("file_system_id").(string)
Expand All @@ -74,15 +74,17 @@ func resourceFileSystemPolicyPut(ctx context.Context, d *schema.ResourceData, me
Policy: aws.String(policy),
}

log.Printf("[DEBUG] Putting EFS File System Policy: %s", input)

_, err = conn.PutFileSystemPolicyWithContext(ctx, input)
_, err = tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout, func() (interface{}, error) {
return conn.PutFileSystemPolicyWithContext(ctx, input)
}, efs.ErrCodeInvalidPolicyException, "Policy contains invalid Principal block")

if err != nil {
return sdkdiag.AppendErrorf(diags, "putting EFS File System Policy (%s): %s", fsID, err)
}

d.SetId(fsID)
if d.IsNewResource() {
d.SetId(fsID)
}

return append(diags, resourceFileSystemPolicyRead(ctx, d, meta)...)
}
Expand All @@ -106,15 +108,13 @@ func resourceFileSystemPolicyRead(ctx context.Context, d *schema.ResourceData, m
d.Set("file_system_id", output.FileSystemId)

policyToSet, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), aws.StringValue(output.Policy))

if err != nil {
return sdkdiag.AppendErrorf(diags, "while setting policy (%s), encountered: %s", policyToSet, err)
return sdkdiag.AppendFromErr(diags, err)
}

policyToSet, err = structure.NormalizeJsonString(policyToSet)

if err != nil {
return sdkdiag.AppendErrorf(diags, "policy (%s) is an invalid JSON: %s", policyToSet, err)
return sdkdiag.AppendFromErr(diags, err)
}

d.Set("policy", policyToSet)
Expand Down