Skip to content

Commit

Permalink
fix: Add skip_destroy to be present in diff.
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamhar committed Mar 30, 2023
1 parent 517da47 commit 7c3cb09
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions internal/service/logs/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set("name", lg.LogGroupName)
d.Set("name_prefix", create.NamePrefixFromName(aws.StringValue(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
42 changes: 36 additions & 6 deletions internal/service/logs/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAccLogsGroup_basic(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ImportStateVerifyIgnore: []string{"retention_in_days"},
},
},
})
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestAccLogsGroup_nameGenerate(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ImportStateVerifyIgnore: []string{"retention_in_days"},
},
},
})
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestAccLogsGroup_namePrefix(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy", "name_prefix"},
ImportStateVerifyIgnore: []string{"retention_in_days", "name_prefix"},
},
},
})
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestAccLogsGroup_tags(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ImportStateVerifyIgnore: []string{"retention_in_days"},
},
{
Config: testAccGroupConfig_tags2(rName, "key1", "value1updated", "key2", "value2"),
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestAccLogsGroup_kmsKey(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ImportStateVerifyIgnore: []string{"retention_in_days"},
},
{
Config: testAccGroupConfig_kmsKey(rName, 1),
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestAccLogsGroup_retentionPolicy(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"retention_in_days", "skip_destroy"},
ImportStateVerifyIgnore: []string{"retention_in_days"},
},
{
Config: testAccGroupConfig_retentionPolicy(rName, 0),
Expand Down Expand Up @@ -314,6 +314,36 @@ func TestAccLogsGroup_skipDestroy(t *testing.T) {
})
}

func TestAccLogsGroup_skipDestroyInconsistentPlan(t *testing.T) {
ctx := acctest.Context(t)
var v cloudwatchlogs.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, cloudwatchlogs.EndpointsID),
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 *cloudwatchlogs.LogGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down

0 comments on commit 7c3cb09

Please sign in to comment.