Skip to content

Commit

Permalink
Merge pull request #30354 from grahamhar/main
Browse files Browse the repository at this point in the history
fix: Add skip_destroy to be present in diff.
  • Loading branch information
ewbankkit authored Dec 11, 2023
2 parents 35862fe + 802db91 commit e5494a2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .changelog/30354.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_cloudwatch_log_group: Fix `invalid new value for .skip_destroy: was cty.False, but now null` errors
```
2 changes: 2 additions & 0 deletions internal/service/logs/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set("name", lg.LogGroupName)
d.Set("name_prefix", create.NamePrefixFromName(aws.ToString(lg.LogGroupName)))
d.Set("retention_in_days", lg.RetentionInDays)
// Support in-place update of non-refreshable attribute.
d.Set("skip_destroy", d.Get("skip_destroy"))

tags, err := listLogGroupTags(ctx, conn, d.Id())

Expand Down
72 changes: 48 additions & 24 deletions internal/service/logs/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ func TestAccLogsGroup_basic(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand All @@ -79,10 +78,9 @@ func TestAccLogsGroup_nameGenerate(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand All @@ -108,10 +106,9 @@ func TestAccLogsGroup_namePrefix(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down Expand Up @@ -162,10 +159,9 @@ func TestAccLogsGroup_tags(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccGroupConfig_tags2(rName, "key1", "value1updated", "key2", "value2"),
Expand Down Expand Up @@ -210,10 +206,9 @@ func TestAccLogsGroup_kmsKey(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccGroupConfig_kmsKey(rName, 1),
Expand Down Expand Up @@ -287,10 +282,9 @@ func TestAccLogsGroup_retentionPolicy(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccGroupConfig_retentionPolicy(rName, 0),
Expand Down Expand Up @@ -352,6 +346,36 @@ func TestAccLogsGroup_skipDestroy(t *testing.T) {
})
}

func TestAccLogsGroup_skipDestroyInconsistentPlan(t *testing.T) {
ctx := acctest.Context(t)
var v types.LogGroup
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
resourceName := "aws_cloudwatch_log_group.test"

acctest.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.CloudWatchLogsEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckGroupDestroy(ctx, t),
Steps: []resource.TestStep{
{
Config: testAccGroupConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupExists(ctx, t, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "skip_destroy", "false"),
),
},
{
Config: testAccGroupConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupExists(ctx, t, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "skip_destroy", "false"),
),
},
},
})
}

func testAccCheckGroupExists(ctx context.Context, t *testing.T, n string, v *types.LogGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down

0 comments on commit e5494a2

Please sign in to comment.