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

fix: add iam retry to eks access entry #35535

Merged
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/35535.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_eks_access_entry: Retry IAM eventual consistency errors on create
```
4 changes: 3 additions & 1 deletion internal/service/eks/access_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func resourceAccessEntryCreate(ctx context.Context, d *schema.ResourceData, meta
input.Username = aws.String(v.(string))
}

_, err := conn.CreateAccessEntry(ctx, input)
_, err := tfresource.RetryWhenIsAErrorMessageContains[*types.InvalidParameterException](ctx, propagationTimeout, func() (interface{}, error) {
return conn.CreateAccessEntry(ctx, input)
}, "The specified principalArn is invalid: invalid principal")

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating EKS Access Entry (%s): %s", id, err)
Expand Down
67 changes: 67 additions & 0 deletions internal/service/eks/access_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,43 @@ func TestAccEKSAccessEntry_username(t *testing.T) {
})
}

func TestAccEKSAccessEntry_eventualConsistency(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var accessentry types.AccessEntry
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_eks_access_entry.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.EKSEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAccessEntryDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccAccessEntryConfig_eventualConsistency(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAccessEntryExists(ctx, resourceName, &accessentry),
acctest.CheckResourceAttrGreaterThanOrEqualValue(resourceName, "kubernetes_groups.#", 1),
resource.TestCheckResourceAttr(resourceName, "type", "EC2_LINUX"),
resource.TestCheckResourceAttrSet(resourceName, "user_name"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckAccessEntryDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).EKSClient(ctx)
Expand Down Expand Up @@ -449,6 +486,36 @@ resource "aws_eks_access_entry" "test" {
`, rName))
}

func testAccAccessEntryConfig_eventualConsistency(rName string) string {
return acctest.ConfigCompose(testAccAccessEntryConfig_base(rName), `
resource "aws_iam_role" "test2" {
name = "${aws_eks_cluster.test.name}-2"

assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.${data.aws_partition.current.dns_suffix}"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}

resource "aws_eks_access_entry" "test" {
cluster_name = aws_eks_cluster.test.name
principal_arn = aws_iam_role.test2.arn

type = "EC2_LINUX"
}
`)
}

func testAccAccessEntryConfig_username(rName, username string) string {
return acctest.ConfigCompose(testAccAccessEntryConfig_base(rName), fmt.Sprintf(`
resource "aws_iam_user" "test" {
Expand Down
Loading