Skip to content

Commit 4adef3e

Browse files
authored
Merge pull request #43661 from hhassen/b-vpc_managed_prefix_list-prefixlistversionmismatch-fix
fix: avoid PrefixListVersionMismatch when changing description of entries
2 parents a6812dd + 0924373 commit 4adef3e

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

.changelog/43661.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_ec2_managed_prefix_list: Fix `PrefixListVersionMismatch: The prefix list has the incorrect version number` errors when updating entry description
3+
```

internal/service/ec2/vpc_managed_prefix_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ func resourceManagedPrefixListUpdate(ctx context.Context, d *schema.ResourceData
248248
}
249249

250250
if len(descriptionOnlyRemovals) > 0 {
251-
input := ec2.ModifyManagedPrefixListInput{
251+
removeInput := ec2.ModifyManagedPrefixListInput{
252252
CurrentVersion: input.CurrentVersion,
253253
PrefixListId: aws.String(d.Id()),
254254
RemoveEntries: descriptionOnlyRemovals,
255255
}
256-
_, err := conn.ModifyManagedPrefixList(ctx, &input)
256+
_, err := conn.ModifyManagedPrefixList(ctx, &removeInput)
257257

258258
if err != nil {
259259
return sdkdiag.AppendErrorf(diags, "updating EC2 Managed Prefix List (%s): %s", d.Id(), err)

internal/service/ec2/vpc_managed_prefix_list_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,41 @@ func TestAccVPCManagedPrefixList_tags(t *testing.T) {
358358
})
359359
}
360360

361+
func TestAccVPCManagedPrefixList_descriptionOnlyChange(t *testing.T) {
362+
ctx := acctest.Context(t)
363+
resourceName := "aws_ec2_managed_prefix_list.test"
364+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
365+
366+
resource.ParallelTest(t, resource.TestCase{
367+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckManagedPrefixList(ctx, t) },
368+
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
369+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
370+
CheckDestroy: testAccCheckManagedPrefixListDestroy(ctx),
371+
Steps: []resource.TestStep{
372+
{
373+
Config: testAccVPCManagedPrefixListConfig_simpleDescriptionChange(rName, "old description"),
374+
Check: resource.ComposeAggregateTestCheckFunc(
375+
testAccManagedPrefixListExists(ctx, resourceName),
376+
resource.TestCheckResourceAttr(resourceName, "entry.#", "1"),
377+
),
378+
},
379+
{
380+
// This reproduces the bug: change ONLY the description
381+
// Before the fix, this would fail with "PrefixListVersionMismatch"
382+
Config: testAccVPCManagedPrefixListConfig_simpleDescriptionChange(rName, "new description"),
383+
Check: resource.ComposeAggregateTestCheckFunc(
384+
testAccManagedPrefixListExists(ctx, resourceName),
385+
resource.TestCheckResourceAttr(resourceName, "entry.#", "1"),
386+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "entry.*", map[string]string{
387+
"cidr": "1.0.0.0/8",
388+
names.AttrDescription: "new description",
389+
}),
390+
),
391+
},
392+
},
393+
})
394+
}
395+
361396
func testAccCheckManagedPrefixListDestroy(ctx context.Context) resource.TestCheckFunc {
362397
return func(s *terraform.State) error {
363398
conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx)
@@ -556,3 +591,18 @@ resource "aws_ec2_managed_prefix_list" "test" {
556591
}
557592
`, rName, tagKey1, tagValue1, tagKey2, tagValue2)
558593
}
594+
595+
func testAccVPCManagedPrefixListConfig_simpleDescriptionChange(rName string, description string) string {
596+
return fmt.Sprintf(`
597+
resource "aws_ec2_managed_prefix_list" "test" {
598+
address_family = "IPv4"
599+
max_entries = 1
600+
name = %[1]q
601+
602+
entry {
603+
cidr = "1.0.0.0/8"
604+
description = %[2]q
605+
}
606+
}
607+
`, rName, description)
608+
}

0 commit comments

Comments
 (0)