github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/resource_aws_ecs_cluster_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/service/ecs"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccAWSEcsCluster_basic(t *testing.T) {
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:     func() { testAccPreCheck(t) },
    16  		Providers:    testAccProviders,
    17  		CheckDestroy: testAccCheckAWSEcsClusterDestroy,
    18  		Steps: []resource.TestStep{
    19  			resource.TestStep{
    20  				Config: testAccAWSEcsCluster,
    21  				Check: resource.ComposeTestCheckFunc(
    22  					testAccCheckAWSEcsClusterExists("aws_ecs_cluster.foo"),
    23  				),
    24  			},
    25  		},
    26  	})
    27  }
    28  
    29  func testAccCheckAWSEcsClusterDestroy(s *terraform.State) error {
    30  	conn := testAccProvider.Meta().(*AWSClient).ecsconn
    31  
    32  	for _, rs := range s.RootModule().Resources {
    33  		if rs.Type != "aws_ecs_cluster" {
    34  			continue
    35  		}
    36  
    37  		out, err := conn.DescribeClusters(&ecs.DescribeClustersInput{
    38  			Clusters: []*string{aws.String(rs.Primary.ID)},
    39  		})
    40  
    41  		if err != nil {
    42  			return err
    43  		}
    44  
    45  		for _, c := range out.Clusters {
    46  			if *c.ClusterArn == rs.Primary.ID && *c.Status != "INACTIVE" {
    47  				return fmt.Errorf("ECS cluster still exists:\n%s", c)
    48  			}
    49  		}
    50  	}
    51  
    52  	return nil
    53  }
    54  
    55  func testAccCheckAWSEcsClusterExists(name string) resource.TestCheckFunc {
    56  	return func(s *terraform.State) error {
    57  		_, ok := s.RootModule().Resources[name]
    58  		if !ok {
    59  			return fmt.Errorf("Not found: %s", name)
    60  		}
    61  
    62  		return nil
    63  	}
    64  }
    65  
    66  var testAccAWSEcsCluster = `
    67  resource "aws_ecs_cluster" "foo" {
    68  	name = "red-grapes"
    69  }
    70  `