github.com/jorgemarey/terraform@v0.6.7-0.20151113041428-536ba76b21bb/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 resource.TestStep{ 26 Config: testAccAWSEcsTaskDefinitionModifier, 27 Check: resource.ComposeTestCheckFunc( 28 testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"), 29 ), 30 }, 31 }, 32 }) 33 } 34 35 // Regression for https://github.com/hashicorp/terraform/issues/2370 36 func TestAccAWSEcsTaskDefinition_withScratchVolume(t *testing.T) { 37 resource.Test(t, resource.TestCase{ 38 PreCheck: func() { testAccPreCheck(t) }, 39 Providers: testAccProviders, 40 CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy, 41 Steps: []resource.TestStep{ 42 resource.TestStep{ 43 Config: testAccAWSEcsTaskDefinitionWithScratchVolume, 44 Check: resource.ComposeTestCheckFunc( 45 testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep"), 46 ), 47 }, 48 }, 49 }) 50 } 51 52 func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error { 53 conn := testAccProvider.Meta().(*AWSClient).ecsconn 54 55 for _, rs := range s.RootModule().Resources { 56 if rs.Type != "aws_ecs_task_definition" { 57 continue 58 } 59 60 out, err := conn.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{ 61 TaskDefinition: aws.String(rs.Primary.ID), 62 }) 63 64 if err == nil { 65 if out.TaskDefinition != nil { 66 return fmt.Errorf("ECS task definition still exists:\n%#v", *out.TaskDefinition) 67 } 68 } 69 70 return err 71 } 72 73 return nil 74 } 75 76 func testAccCheckAWSEcsTaskDefinitionExists(name string) resource.TestCheckFunc { 77 return func(s *terraform.State) error { 78 _, ok := s.RootModule().Resources[name] 79 if !ok { 80 return fmt.Errorf("Not found: %s", name) 81 } 82 83 return nil 84 } 85 } 86 87 var testAccAWSEcsTaskDefinition = ` 88 resource "aws_ecs_task_definition" "jenkins" { 89 family = "terraform-acc-test" 90 container_definitions = <<TASK_DEFINITION 91 [ 92 { 93 "cpu": 10, 94 "command": ["sleep", "10"], 95 "entryPoint": ["/"], 96 "environment": [ 97 {"name": "VARNAME", "value": "VARVAL"} 98 ], 99 "essential": true, 100 "image": "jenkins", 101 "links": ["mongodb"], 102 "memory": 128, 103 "name": "jenkins", 104 "portMappings": [ 105 { 106 "containerPort": 80, 107 "hostPort": 8080 108 } 109 ] 110 }, 111 { 112 "cpu": 10, 113 "command": ["sleep", "10"], 114 "entryPoint": ["/"], 115 "essential": true, 116 "image": "mongodb", 117 "memory": 128, 118 "name": "mongodb", 119 "portMappings": [ 120 { 121 "containerPort": 28017, 122 "hostPort": 28017 123 } 124 ] 125 } 126 ] 127 TASK_DEFINITION 128 129 volume { 130 name = "jenkins-home" 131 host_path = "/ecs/jenkins-home" 132 } 133 } 134 ` 135 136 var testAccAWSEcsTaskDefinitionWithScratchVolume = ` 137 resource "aws_ecs_task_definition" "sleep" { 138 family = "terraform-acc-sc-volume-test" 139 container_definitions = <<TASK_DEFINITION 140 [ 141 { 142 "name": "sleep", 143 "image": "busybox", 144 "cpu": 10, 145 "command": ["sleep","360"], 146 "memory": 10, 147 "essential": true 148 } 149 ] 150 TASK_DEFINITION 151 152 volume { 153 name = "database_scratch" 154 } 155 } 156 ` 157 158 var testAccAWSEcsTaskDefinitionModifier = ` 159 resource "aws_ecs_task_definition" "jenkins" { 160 family = "terraform-acc-test" 161 container_definitions = <<TASK_DEFINITION 162 [ 163 { 164 "cpu": 10, 165 "command": ["sleep", "10"], 166 "entryPoint": ["/"], 167 "environment": [ 168 {"name": "VARNAME", "value": "VARVAL"} 169 ], 170 "essential": true, 171 "image": "jenkins", 172 "links": ["mongodb"], 173 "memory": 128, 174 "name": "jenkins", 175 "portMappings": [ 176 { 177 "containerPort": 80, 178 "hostPort": 8080 179 } 180 ] 181 }, 182 { 183 "cpu": 20, 184 "command": ["sleep", "10"], 185 "entryPoint": ["/"], 186 "essential": true, 187 "image": "mongodb", 188 "memory": 128, 189 "name": "mongodb", 190 "portMappings": [ 191 { 192 "containerPort": 28017, 193 "hostPort": 28017 194 } 195 ] 196 } 197 ] 198 TASK_DEFINITION 199 200 volume { 201 name = "jenkins-home" 202 host_path = "/ecs/jenkins-home" 203 } 204 } 205 `