Skip to content

Commit

Permalink
[WIP] provider/aws: Support task_role_arn on aws_ecs_task_definition
Browse files Browse the repository at this point in the history
Fixes #7633
  • Loading branch information
stack72 committed Jul 15, 2016
1 parent f262566 commit 5ee1987
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
11 changes: 11 additions & 0 deletions builtin/providers/aws/resource_aws_ecs_task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
},
},

"task_role_arn": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"volume": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -83,6 +89,10 @@ func resourceAwsEcsTaskDefinitionCreate(d *schema.ResourceData, meta interface{}
Family: aws.String(d.Get("family").(string)),
}

if v, ok := d.GetOk("task_role_arn"); ok {
input.TaskRoleArn = aws.String(v.(string))
}

if v, ok := d.GetOk("volume"); ok {
volumes, err := expandEcsVolumes(v.(*schema.Set).List())
if err != nil {
Expand Down Expand Up @@ -127,6 +137,7 @@ func resourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{})
d.Set("family", *taskDefinition.Family)
d.Set("revision", *taskDefinition.Revision)
d.Set("container_definitions", taskDefinition.ContainerDefinitions)
d.Set("task_role_arn", taskDefinition.TaskRoleArn)
d.Set("volumes", flattenEcsVolumes(taskDefinition.Volumes))

return nil
Expand Down
79 changes: 79 additions & 0 deletions builtin/providers/aws/resource_aws_ecs_task_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ func TestAccAWSEcsTaskDefinition_withEcsService(t *testing.T) {
})
}

func TestAccAWSEcsTaskDefinition_withTaskRoleArn(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEcsTaskDefinitionWithTaskRoleArn,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep"),
),
},
},
})
}

func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecsconn

Expand Down Expand Up @@ -182,6 +198,69 @@ TASK_DEFINITION
}
`

var testAccAWSEcsTaskDefinitionWithTaskRoleArn = `
resource "aws_iam_role" "role_test" {
name = "tf_old_name"
path = "/test/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy" "role_test" {
name = "role_update_test"
role = "${aws_iam_role.role_test.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
}
]
}
EOF
}
resource "aws_ecs_task_definition" "sleep" {
family = "terraform-acc-sc-volume-test"
task_role_arn = "${aws_iam_role.role_test.id}"
container_definitions = <<TASK_DEFINITION
[
{
"name": "sleep",
"image": "busybox",
"cpu": 10,
"command": ["sleep","360"],
"memory": 10,
"essential": true
}
]
TASK_DEFINITION
volume {
name = "database_scratch"
}
}
`

var testAccAWSEcsTaskDefinitionWithEcsService = `
resource "aws_ecs_cluster" "default" {
name = "terraform-acc-test"
Expand Down

0 comments on commit 5ee1987

Please sign in to comment.