github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_ecs_task_definition_test.go (about) 1 package aws 2 3 import ( 4 "regexp" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 ) 9 10 func TestAccAWSEcsDataSource_ecsTaskDefinition(t *testing.T) { 11 resource.Test(t, resource.TestCase{ 12 PreCheck: func() { testAccPreCheck(t) }, 13 Providers: testAccProviders, 14 Steps: []resource.TestStep{ 15 resource.TestStep{ 16 Config: testAccCheckAwsEcsTaskDefinitionDataSourceConfig, 17 Check: resource.ComposeTestCheckFunc( 18 resource.TestMatchResourceAttr("data.aws_ecs_task_definition.mongo", "id", regexp.MustCompile("^arn:aws:ecs:us-west-2:[0-9]{12}:task-definition/mongodb:[1-9][0-9]*$")), 19 resource.TestCheckResourceAttr("data.aws_ecs_task_definition.mongo", "family", "mongodb"), 20 resource.TestCheckResourceAttr("data.aws_ecs_task_definition.mongo", "network_mode", "bridge"), 21 resource.TestMatchResourceAttr("data.aws_ecs_task_definition.mongo", "revision", regexp.MustCompile("^[1-9][0-9]*$")), 22 resource.TestCheckResourceAttr("data.aws_ecs_task_definition.mongo", "status", "ACTIVE"), 23 resource.TestMatchResourceAttr("data.aws_ecs_task_definition.mongo", "task_role_arn", regexp.MustCompile("^arn:aws:iam::[0-9]{12}:role/mongo_role$")), 24 ), 25 }, 26 }, 27 }) 28 } 29 30 const testAccCheckAwsEcsTaskDefinitionDataSourceConfig = ` 31 resource "aws_iam_role" "mongo_role" { 32 name = "mongo_role" 33 assume_role_policy = <<POLICY 34 { 35 "Version": "2012-10-17", 36 "Statement": [ 37 { 38 "Action": "sts:AssumeRole", 39 "Principal": { 40 "Service": "ec2.amazonaws.com" 41 }, 42 "Effect": "Allow", 43 "Sid": "" 44 } 45 ] 46 } 47 POLICY 48 } 49 50 resource "aws_ecs_task_definition" "mongo" { 51 family = "mongodb" 52 task_role_arn = "${aws_iam_role.mongo_role.arn}" 53 network_mode = "bridge" 54 container_definitions = <<DEFINITION 55 [ 56 { 57 "cpu": 128, 58 "environment": [{ 59 "name": "SECRET", 60 "value": "KEY" 61 }], 62 "essential": true, 63 "image": "mongo:latest", 64 "memory": 128, 65 "memoryReservation": 64, 66 "name": "mongodb" 67 } 68 ] 69 DEFINITION 70 } 71 72 data "aws_ecs_task_definition" "mongo" { 73 task_definition = "${aws_ecs_task_definition.mongo.family}" 74 } 75 `