github.com/bendemaree/terraform@v0.5.4-0.20150613200311-f50d97d6eee6/builtin/providers/aws/resource_aws_ecs_task_definition_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 TestAccAWSEcsTaskDefinition_basic(t *testing.T) {
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:     func() { testAccPreCheck(t) },
    16  		Providers:    testAccProviders,
    17  		CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
    18  		Steps: []resource.TestStep{
    19  			resource.TestStep{
    20  				Config: testAccAWSEcsTaskDefinition,
    21  				Check: resource.ComposeTestCheckFunc(
    22  					testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"),
    23  				),
    24  			},
    25  		},
    26  	})
    27  }
    28  
    29  func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error {
    30  	conn := testAccProvider.Meta().(*AWSClient).ecsconn
    31  
    32  	for _, rs := range s.RootModule().Resources {
    33  		if rs.Type != "aws_ecs_task_definition" {
    34  			continue
    35  		}
    36  
    37  		out, err := conn.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
    38  			TaskDefinition: aws.String(rs.Primary.ID),
    39  		})
    40  
    41  		if err == nil {
    42  			if out.TaskDefinition != nil {
    43  				return fmt.Errorf("ECS task definition still exists:\n%#v", *out.TaskDefinition)
    44  			}
    45  		}
    46  
    47  		return err
    48  	}
    49  
    50  	return nil
    51  }
    52  
    53  func testAccCheckAWSEcsTaskDefinitionExists(name string) resource.TestCheckFunc {
    54  	return func(s *terraform.State) error {
    55  		_, ok := s.RootModule().Resources[name]
    56  		if !ok {
    57  			return fmt.Errorf("Not found: %s", name)
    58  		}
    59  
    60  		return nil
    61  	}
    62  }
    63  
    64  var testAccAWSEcsTaskDefinition = `
    65  resource "aws_ecs_task_definition" "jenkins" {
    66    family = "jenkins"
    67    container_definitions = <<TASK_DEFINITION
    68  [
    69  	{
    70  		"cpu": 10,
    71  		"command": ["sleep", "10"],
    72  		"entryPoint": ["/"],
    73  		"environment": [
    74  			{"name": "VARNAME", "value": "VARVAL"}
    75  		],
    76  		"essential": true,
    77  		"image": "jenkins",
    78  		"links": ["mongodb"],
    79  		"memory": 128,
    80  		"name": "jenkins",
    81  		"portMappings": [
    82  			{
    83  				"containerPort": 80,
    84  				"hostPort": 8080
    85  			}
    86  		]
    87  	},
    88  	{
    89  		"cpu": 10,
    90  		"command": ["sleep", "10"],
    91  		"entryPoint": ["/"],
    92  		"essential": true,
    93  		"image": "mongodb",
    94  		"memory": 128,
    95  		"name": "mongodb",
    96  		"portMappings": [
    97  			{
    98  				"containerPort": 28017,
    99  				"hostPort": 28017
   100  			}
   101  		]
   102  	}
   103  ]
   104  TASK_DEFINITION
   105  
   106    volume {
   107      name = "jenkins-home"
   108      host_path = "/ecs/jenkins-home"
   109    }
   110  }
   111  `