Skip to content

Commit 0701f48

Browse files
committed
fix: resource/aws_efs_file_system: Fix perpetual drift with REPLICATING protection state
Fixes #36811 Adds REPLICATING state support and diff suppression to prevent perpetual drift when AWS sets protection.replication_overwrite to REPLICATING for replication destination file systems.
1 parent 8927020 commit 0701f48

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

.changelog/36811.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_efs_file_system: Fix perpetual drift when `protection.replication_overwrite` is in `REPLICATING` state for replication destination file systems
3+
```

internal/service/efs/file_system.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ func resourceFileSystem() *schema.Resource {
138138
ValidateFunc: validation.StringInSlice(enum.Slice(
139139
awstypes.ReplicationOverwriteProtectionEnabled,
140140
awstypes.ReplicationOverwriteProtectionDisabled,
141+
awstypes.ReplicationOverwriteProtectionReplicating,
141142
), false),
143+
DiffSuppressFunc: SuppressReplicationOverwriteProtectionDiff,
142144
},
143145
},
144146
},
@@ -609,3 +611,22 @@ func flattenFileSystemProtectionDescription(apiObject *awstypes.FileSystemProtec
609611

610612
return []any{tfMap}
611613
}
614+
615+
func SuppressReplicationOverwriteProtectionDiff(k, old, new string, d *schema.ResourceData) bool {
616+
// When a file system becomes a replication destination, AWS automatically
617+
// sets replication_overwrite to "REPLICATING". This is a read-only state
618+
// that cannot be changed while replication is active. AWS rejects all
619+
// update attempts with: "ReplicationOverwriteProtection cannot be changed
620+
// while the file system is a replication destination."
621+
//
622+
// Suppress diff when current state is REPLICATING to prevent perpetual
623+
// drift and failed update attempts. When replication is removed, AWS
624+
// automatically allows the protection setting to be changed again.
625+
626+
if old == string(awstypes.ReplicationOverwriteProtectionReplicating) {
627+
// REPLICATING is AWS-managed and read-only; suppress any attempted change
628+
return true
629+
}
630+
631+
return false
632+
}

internal/service/efs/file_system_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,75 @@ func TestAccEFSFileSystem_protection(t *testing.T) {
148148
})
149149
}
150150

151+
func TestSuppressReplicationOverwriteProtectionDiff(t *testing.T) {
152+
t.Parallel()
153+
154+
cases := []struct {
155+
name string
156+
old string
157+
new string
158+
expected bool
159+
}{
160+
{
161+
name: "REPLICATING to DISABLED should be suppressed",
162+
old: "REPLICATING",
163+
new: "DISABLED",
164+
expected: true,
165+
},
166+
{
167+
name: "REPLICATING to ENABLED should be suppressed",
168+
old: "REPLICATING",
169+
new: "ENABLED",
170+
expected: true,
171+
},
172+
{
173+
name: "REPLICATING to REPLICATING should be suppressed",
174+
old: "REPLICATING",
175+
new: "REPLICATING",
176+
expected: true,
177+
},
178+
{
179+
name: "DISABLED to ENABLED should not be suppressed",
180+
old: "DISABLED",
181+
new: "ENABLED",
182+
expected: false,
183+
},
184+
{
185+
name: "ENABLED to DISABLED should not be suppressed",
186+
old: "ENABLED",
187+
new: "DISABLED",
188+
expected: false,
189+
},
190+
{
191+
name: "DISABLED to DISABLED should not be suppressed",
192+
old: "DISABLED",
193+
new: "DISABLED",
194+
expected: false,
195+
},
196+
{
197+
name: "ENABLED to REPLICATING should not be suppressed",
198+
old: "ENABLED",
199+
new: "REPLICATING",
200+
expected: false,
201+
},
202+
{
203+
name: "DISABLED to REPLICATING should not be suppressed",
204+
old: "DISABLED",
205+
new: "REPLICATING",
206+
expected: false,
207+
},
208+
}
209+
210+
for _, tc := range cases {
211+
t.Run(tc.name, func(t *testing.T) {
212+
actual := tfefs.SuppressReplicationOverwriteProtectionDiff("protection.0.replication_overwrite", tc.old, tc.new, nil)
213+
if actual != tc.expected {
214+
t.Errorf("expected %v, got %v", tc.expected, actual)
215+
}
216+
})
217+
}
218+
}
219+
151220
func TestAccEFSFileSystem_availabilityZoneName(t *testing.T) {
152221
ctx := acctest.Context(t)
153222
var desc awstypes.FileSystemDescription

0 commit comments

Comments
 (0)