Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't destroy aws_cloudwatch_log_stream if group has been destroyed #6776

Merged
merged 3 commits into from
Dec 17, 2018

Conversation

ahl
Copy link
Contributor

@ahl ahl commented Dec 8, 2018

consider this config:

resource "aws_cloudwatch_log_group" "index-logs" {
  name = "/ahl/test"
}

resource "aws_cloudwatch_log_stream" "index-log-stream" {
  name           = "S3Delivery"
  log_group_name = "${aws_cloudwatch_log_group.index-logs.name}"
}

If you delete the log group it will implicitly delete the log stream. A subsequent terraform plan will result in an error:

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

aws_cloudwatch_log_group.index-logs: Refreshing state... (ID: /ahl/test)
aws_cloudwatch_log_stream.index-log-stream: Refreshing state... (ID: S3Delivery)

Error: Error refreshing state: 1 error(s) occurred:

* aws_cloudwatch_log_stream.index-log-stream: 1 error(s) occurred:

* aws_cloudwatch_log_stream.index-log-stream: aws_cloudwatch_log_stream.index-log-stream: ResourceNotFoundException: The specified log group does not exist.
	status code: 400, request id: b4d05427-fab0-11e8-a129-c9ad87f29baf

The problem is that resourceAwsCloudWatchLogStreamRead doesn't properly interpret an error looking up the log stream in the case that the log group doesn't exist.

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSCloudWatchLogStream*'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSCloudWatchLogStream* -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSCloudWatchLogStream_basic
=== PAUSE TestAccAWSCloudWatchLogStream_basic
=== RUN   TestAccAWSCloudWatchLogStream_disappears
=== PAUSE TestAccAWSCloudWatchLogStream_disappears
=== RUN   TestAccAWSCloudWatchLogStream_disappears2
=== PAUSE TestAccAWSCloudWatchLogStream_disappears2
=== CONT  TestAccAWSCloudWatchLogStream_basic
=== CONT  TestAccAWSCloudWatchLogStream_disappears2
=== CONT  TestAccAWSCloudWatchLogStream_disappears
--- PASS: TestAccAWSCloudWatchLogStream_disappears2 (8.60s)
--- PASS: TestAccAWSCloudWatchLogStream_disappears (11.38s)
--- PASS: TestAccAWSCloudWatchLogStream_basic (11.52s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	11.569s

Added a new test that fails without the fix:

$ make testacc TESTARGS='-run=TestAccAWSCloudWatchLogStream_disappears2'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSCloudWatchLogStream_disappears2 -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSCloudWatchLogStream_disappears2
=== PAUSE TestAccAWSCloudWatchLogStream_disappears2
=== CONT  TestAccAWSCloudWatchLogStream_disappears2
--- FAIL: TestAccAWSCloudWatchLogStream_disappears2 (7.69s)
    testing.go:538: Step 0 error: Error on follow-up refresh: 1 error occurred:
        	* aws_cloudwatch_log_stream.foobar: 1 error occurred:
        	* aws_cloudwatch_log_stream.foobar: aws_cloudwatch_log_stream.foobar: ResourceNotFoundException: The specified log group does not exist.
        	status code: 400, request id: 512d5254-fab1-11e8-9764-fb75fda2d9b2
        
        
        
        
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	7.731s
make: *** [testacc] Error 1

@ghost ghost added size/S Managed by automation to categorize the size of a PR. service/cloudwatchlogs tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Dec 8, 2018
@ahl ahl changed the title Aws cloudwatch log stream can't destroy aws_cloudwatch_log_stream if group has been destroyed Dec 8, 2018
@bflad bflad added the bug Addresses a defect in current functionality. label Dec 12, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this, @ahl. It'll be good to get this fixed. 👍 Left some initial comments below -- please let us know if you have any questions or do not have time to implement the feedback.

Config: testAccAWSCloudWatchLogStreamConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudWatchLogStreamExists("aws_cloudwatch_log_stream.foobar", &ls),
testAccCheckCloudWatchLogStreamDisappears2(&ls, rName),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new custom function can be replaced with the existing functions from TestAccAWSCloudWatchLogGroup_disappears(), e.g.

var lg cloudwatchlogs.LogGroup
// ...
testAccCheckCloudWatchLogGroupExists("aws_cloudwatch_log_group.foobar", &lg),
testAccCheckCloudWatchLogGroupDisappears(&lg),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm less convinced that this is an improvement, but I made the change.

aws/resource_aws_cloudwatch_log_stream_test.go Outdated Show resolved Hide resolved
aws/resource_aws_cloudwatch_log_stream.go Outdated Show resolved Hide resolved
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Dec 12, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @ahl 🚀

--- PASS: TestAccAWSCloudWatchLogStream_disappears_LogGroup (2.96s)
--- PASS: TestAccAWSCloudWatchLogStream_basic (3.95s)
--- PASS: TestAccAWSCloudWatchLogStream_disappears (4.09s)

@bflad bflad added this to the v1.53.0 milestone Dec 17, 2018
@bflad bflad merged commit 533c68f into hashicorp:master Dec 17, 2018
bflad added a commit that referenced this pull request Dec 17, 2018
@bflad
Copy link
Contributor

bflad commented Dec 20, 2018

This has been released in version 1.53.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. size/S Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants