provider/aws: Support `task_role_arn` on `aws_ecs_task_definition` (#7653)

Fixes #7633
This commit is contained in:
Paul Stack 2016-07-20 17:00:57 +01:00 committed by GitHub
parent f529cae42a
commit 0edf83008c
2 changed files with 90 additions and 0 deletions

View File

@ -46,6 +46,12 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
}, },
}, },
"task_role_arn": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"volume": &schema.Schema{ "volume": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
@ -83,6 +89,10 @@ func resourceAwsEcsTaskDefinitionCreate(d *schema.ResourceData, meta interface{}
Family: aws.String(d.Get("family").(string)), 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 { if v, ok := d.GetOk("volume"); ok {
volumes, err := expandEcsVolumes(v.(*schema.Set).List()) volumes, err := expandEcsVolumes(v.(*schema.Set).List())
if err != nil { if err != nil {
@ -127,6 +137,7 @@ func resourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{})
d.Set("family", *taskDefinition.Family) d.Set("family", *taskDefinition.Family)
d.Set("revision", *taskDefinition.Revision) d.Set("revision", *taskDefinition.Revision)
d.Set("container_definitions", taskDefinition.ContainerDefinitions) d.Set("container_definitions", taskDefinition.ContainerDefinitions)
d.Set("task_role_arn", taskDefinition.TaskRoleArn)
d.Set("volumes", flattenEcsVolumes(taskDefinition.Volumes)) d.Set("volumes", flattenEcsVolumes(taskDefinition.Volumes))
return nil return nil

View File

@ -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 { func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecsconn conn := testAccProvider.Meta().(*AWSClient).ecsconn
@ -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.arn}"
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 = ` var testAccAWSEcsTaskDefinitionWithEcsService = `
resource "aws_ecs_cluster" "default" { resource "aws_ecs_cluster" "default" {
name = "terraform-acc-test" name = "terraform-acc-test"