github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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", "image_digest", "latest"), 19 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "memory", "128"), 20 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "memory_reservation", "64"), 21 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "cpu", "128"), 22 resource.TestCheckResourceAttr("data.aws_ecs_container_definition.mongo", "environment.SECRET", "KEY"), 23 ), 24 }, 25 }, 26 }) 27 } 28 29 const testAccCheckAwsEcsContainerDefinitionDataSourceConfig = ` 30 resource "aws_ecs_cluster" "default" { 31 name = "terraformecstest1" 32 } 33 34 resource "aws_ecs_task_definition" "mongo" { 35 family = "mongodb" 36 container_definitions = <<DEFINITION 37 [ 38 { 39 "cpu": 128, 40 "environment": [{ 41 "name": "SECRET", 42 "value": "KEY" 43 }], 44 "essential": true, 45 "image": "mongo:latest", 46 "memory": 128, 47 "memoryReservation": 64, 48 "name": "mongodb" 49 } 50 ] 51 DEFINITION 52 } 53 54 resource "aws_ecs_service" "mongo" { 55 name = "mongodb" 56 cluster = "${aws_ecs_cluster.default.id}" 57 task_definition = "${aws_ecs_task_definition.mongo.arn}" 58 desired_count = 1 59 } 60 61 data "aws_ecs_container_definition" "mongo" { 62 task_definition = "${aws_ecs_task_definition.mongo.id}" 63 container_name = "mongodb" 64 } 65 `