2015-05-04 23:48:09 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ecs"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-06-08 01:18:14 +02:00
|
|
|
func TestAccAWSEcsCluster_basic(t *testing.T) {
|
2015-05-04 23:48:09 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSEcsClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSEcsCluster,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSEcsClusterExists("aws_ecs_cluster.foo"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSEcsClusterDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ecsconn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_ecs_cluster" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err := conn.DescribeClusters(&ecs.DescribeClustersInput{
|
|
|
|
Clusters: []*string{aws.String(rs.Primary.ID)},
|
|
|
|
})
|
|
|
|
|
2015-12-17 15:20:36 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-05-04 23:48:09 +02:00
|
|
|
}
|
|
|
|
|
2015-12-17 15:20:36 +01:00
|
|
|
for _, c := range out.Clusters {
|
|
|
|
if *c.ClusterArn == rs.Primary.ID && *c.Status != "INACTIVE" {
|
|
|
|
return fmt.Errorf("ECS cluster still exists:\n%s", c)
|
|
|
|
}
|
|
|
|
}
|
2015-05-04 23:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSEcsClusterExists(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
_, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAccAWSEcsCluster = `
|
|
|
|
resource "aws_ecs_cluster" "foo" {
|
|
|
|
name = "red-grapes"
|
|
|
|
}
|
|
|
|
`
|