-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
removing unfound ecs service from state file #6039
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,13 +148,30 @@ func TestAccAWSEcsService_basicImport(t *testing.T) { | |
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
// Test non-existent resource import | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSEcsService_disappears(t *testing.T) { | ||
var service ecs.Service | ||
rString := acctest.RandString(8) | ||
|
||
clusterName := fmt.Sprintf("tf-acc-cluster-svc-w-arn-%s", rString) | ||
tdName := fmt.Sprintf("tf-acc-td-svc-w-arn-%s", rString) | ||
svcName := fmt.Sprintf("tf-acc-svc-w-arn-%s", rString) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSEcsServiceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
ResourceName: resourceName, | ||
ImportStateId: fmt.Sprintf("%s/nonexistent", clusterName), | ||
ImportState: true, | ||
ImportStateVerify: false, | ||
ExpectError: regexp.MustCompile(`No ECS service found`), | ||
Config: testAccAWSEcsService(clusterName, tdName, svcName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo", &service), | ||
testAccCheckAWSEcsServiceDisappears(&service), | ||
), | ||
ExpectNonEmptyPlan: true, | ||
}, | ||
}, | ||
}) | ||
|
@@ -803,6 +820,22 @@ func testAccCheckAWSEcsServiceExists(name string, service *ecs.Service) resource | |
} | ||
} | ||
|
||
func testAccCheckAWSEcsServiceDisappears(service *ecs.Service) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).ecsconn | ||
|
||
input := &ecs.DeleteServiceInput{ | ||
Cluster: aws.String(*service.ClusterArn), | ||
Service: aws.String(*service.ServiceName), | ||
Force: aws.Bool(true), | ||
} | ||
|
||
_, err := conn.DeleteService(input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out the ECS service needs some additional checking to ensure its gone func testAccCheckAWSEcsServiceDisappears(service *ecs.Service) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecsconn
input := &ecs.DeleteServiceInput{
Cluster: service.ClusterArn,
Service: service.ServiceName,
Force: aws.Bool(true),
}
_, err := conn.DeleteService(input)
if err != nil {
return err
}
// Wait until it's deleted
wait := resource.StateChangeConf{
Pending: []string{"ACTIVE", "DRAINING"},
Target: []string{"INACTIVE"},
Timeout: 10 * time.Minute,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := conn.DescribeServices(&ecs.DescribeServicesInput{
Cluster: service.ClusterArn,
Services: []*string{service.ServiceName},
})
if err != nil {
return resp, "FAILED", err
}
return resp, aws.StringValue(resp.Services[0].Status), nil
},
}
_, err = wait.WaitForState()
return err
}
} |
||
|
||
return err | ||
} | ||
} | ||
|
||
func testAccAWSEcsService(clusterName, tdName, svcName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_ecs_cluster" "default" { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually want to keep this test as its currently the only way we can verify the condition you were originally seeing. We just needed to grab something out of the new error message from import failing (properly!):
I went with: