Skip to content

Commit 5042819

Browse files
authored
Merge pull request #35535 from iandrewt/b-aws_eks_access_entry-eventual-consistency
fix: add iam retry to eks access entry
2 parents 0857486 + 87f54b7 commit 5042819

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

.changelog/35535.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_eks_access_entry: Retry IAM eventual consistency errors on create
3+
```

internal/service/eks/access_entry.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ func resourceAccessEntryCreate(ctx context.Context, d *schema.ResourceData, meta
120120
input.Username = aws.String(v.(string))
121121
}
122122

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

125127
if err != nil {
126128
return sdkdiag.AppendErrorf(diags, "creating EKS Access Entry (%s): %s", id, err)

internal/service/eks/access_entry_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,43 @@ func TestAccEKSAccessEntry_username(t *testing.T) {
257257
})
258258
}
259259

260+
func TestAccEKSAccessEntry_eventualConsistency(t *testing.T) {
261+
ctx := acctest.Context(t)
262+
if testing.Short() {
263+
t.Skip("skipping long-running test in short mode")
264+
}
265+
266+
var accessentry types.AccessEntry
267+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
268+
resourceName := "aws_eks_access_entry.test"
269+
270+
resource.ParallelTest(t, resource.TestCase{
271+
PreCheck: func() {
272+
acctest.PreCheck(ctx, t)
273+
testAccPreCheck(ctx, t)
274+
},
275+
ErrorCheck: acctest.ErrorCheck(t, names.EKSEndpointID),
276+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
277+
CheckDestroy: testAccCheckAccessEntryDestroy(ctx),
278+
Steps: []resource.TestStep{
279+
{
280+
Config: testAccAccessEntryConfig_eventualConsistency(rName),
281+
Check: resource.ComposeTestCheckFunc(
282+
testAccCheckAccessEntryExists(ctx, resourceName, &accessentry),
283+
acctest.CheckResourceAttrGreaterThanOrEqualValue(resourceName, "kubernetes_groups.#", 1),
284+
resource.TestCheckResourceAttr(resourceName, "type", "EC2_LINUX"),
285+
resource.TestCheckResourceAttrSet(resourceName, "user_name"),
286+
),
287+
},
288+
{
289+
ResourceName: resourceName,
290+
ImportState: true,
291+
ImportStateVerify: true,
292+
},
293+
},
294+
})
295+
}
296+
260297
func testAccCheckAccessEntryDestroy(ctx context.Context) resource.TestCheckFunc {
261298
return func(s *terraform.State) error {
262299
conn := acctest.Provider.Meta().(*conns.AWSClient).EKSClient(ctx)
@@ -449,6 +486,36 @@ resource "aws_eks_access_entry" "test" {
449486
`, rName))
450487
}
451488

489+
func testAccAccessEntryConfig_eventualConsistency(rName string) string {
490+
return acctest.ConfigCompose(testAccAccessEntryConfig_base(rName), `
491+
resource "aws_iam_role" "test2" {
492+
name = "${aws_eks_cluster.test.name}-2"
493+
494+
assume_role_policy = <<POLICY
495+
{
496+
"Version": "2012-10-17",
497+
"Statement": [
498+
{
499+
"Effect": "Allow",
500+
"Principal": {
501+
"Service": "eks.${data.aws_partition.current.dns_suffix}"
502+
},
503+
"Action": "sts:AssumeRole"
504+
}
505+
]
506+
}
507+
POLICY
508+
}
509+
510+
resource "aws_eks_access_entry" "test" {
511+
cluster_name = aws_eks_cluster.test.name
512+
principal_arn = aws_iam_role.test2.arn
513+
514+
type = "EC2_LINUX"
515+
}
516+
`)
517+
}
518+
452519
func testAccAccessEntryConfig_username(rName, username string) string {
453520
return acctest.ConfigCompose(testAccAccessEntryConfig_base(rName), fmt.Sprintf(`
454521
resource "aws_iam_user" "test" {

0 commit comments

Comments
 (0)