[Feature] Add force_destroy argument to aws_cloudwatch_log_group resource #44680
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds the
force_destroy
argument to theaws_cloudwatch_log_group
resource to enable reliable deletion of log groups with retention policies.When
force_destroy = true
, the resource will:ResourceAlreadyExistsException
errors on immediate re-creationThis enhancement addresses issues in CI/CD pipelines and ephemeral environments where log groups need to be reliably deleted and recreated.
Closes
Closes #44676
New and Affected Resources
aws_cloudwatch_log_group
Output from Acceptance Testing
Note: Full acceptance tests require AWS credentials. Manual testing results provided below.
Manual Testing Results
Schema Recognition Test
Before Implementation:
After Implementation:
Resource Lifecycle Test
force_destroy = true
force_destroy = true
ResourceAlreadyExistsException
Backward Compatibility Test
Default behavior unchanged when
force_destroy
is not specified (defaults tofalse
).Features
New Argument:
force_destroy
bool
true
false
Behavior Matrix
force_destroy = false
(default)force_destroy = true
ResourceAlreadyExistsException
Example Usage
Basic Usage
With Retention Policy
CI/CD Pipeline Usage
Implementation Details
Schema Changes
Enhanced Deletion Logic
force_destroy = true
, removes retention policies before deletionwaitLogGroupDeleted()
to ensure complete deletionResourceNotFoundException
during deletionforce_destroy = true
Key Code Changes
Files Changed
Testing Strategy
Acceptance Tests
TestAccLogsLogGroup_forceDestroy
: Verifies force_destroy attribute functionalityManual Testing Coverage
Related Patterns
This implementation follows the same pattern as other AWS resources with
force_destroy
functionality:aws_s3_bucket
aws_iam_role
aws_kms_key
Performance Considerations
force_destroy = false
)Backward Compatibility
false
maintains existing behaviorforce_destroy = true
Notes for Reviewers
force_destroy
conventions in the codebaseAdditional Context
Problem Solved
Use Cases