github.com/grange74/terraform@v0.7.0-rc3.0.20160722171430-8c8803864753/builtin/providers/aws/data_source_aws_ecs_container_definition_test.go (about) 1 package aws 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/helper/resource" 7 ) 8 9 func TestAccAWSEcsDataSource_ecsContainerDefinition(t *testing.T) { 10 resource.Test(t, resource.TestCase{ 11 PreCheck: func() { testAccPreCheck(t) }, 12 Providers: testAccProviders, 13 Steps: []resource.TestStep{ 14 resource.TestStep{ 15 Config: testAccCheckAwsEcsContainerDefinitionDataSourceConfig, 16 Check: resource.ComposeTestCheckFunc( 17 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "image", "mongo:latest"), 18 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "memory", "128"), 19 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "cpu", "128"), 20 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "environment.SECRET", "KEY"), 21 ), 22 }, 23 }, 24 }) 25 } 26 27 const testAccCheckAwsEcsContainerDefinitionDataSourceConfig = ` 28 resource "aws_ecs_cluster" "default" { 29 name = "terraformecstest1" 30 } 31 32 resource "aws_ecs_task_definition" "mongo" { 33 family = "mongodb" 34 container_definitions = <<DEFINITION 35 [ 36 { 37 "cpu": 128, 38 "environment": [{ 39 "name": "SECRET", 40 "value": "KEY" 41 }], 42 "essential": true, 43 "image": "mongo:latest", 44 "memory": 128, 45 "name": "mongodb" 46 } 47 ] 48 DEFINITION 49 } 50 51 resource "aws_ecs_service" "mongo" { 52 name = "mongodb" 53 cluster = "${aws_ecs_cluster.default.id}" 54 task_definition = "${aws_ecs_task_definition.mongo.arn}" 55 desired_count = 1 56 } 57 58 data "aws_ecs_container_definition" "mongo" { 59 task_definition = "${aws_ecs_task_definition.mongo.id}" 60 container_name = "mongodb" 61 } 62 `