From 5ee198704f74d6f46f4ffe84116885570324b09b Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 14 Jul 2016 12:12:35 +0100 Subject: [PATCH] [WIP] provider/aws: Support `task_role_arn` on `aws_ecs_task_definition` Fixes #7633 --- .../aws/resource_aws_ecs_task_definition.go | 11 +++ .../resource_aws_ecs_task_definition_test.go | 79 +++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/builtin/providers/aws/resource_aws_ecs_task_definition.go b/builtin/providers/aws/resource_aws_ecs_task_definition.go index b9b40d6bfd2e..117bbcdf2fc4 100644 --- a/builtin/providers/aws/resource_aws_ecs_task_definition.go +++ b/builtin/providers/aws/resource_aws_ecs_task_definition.go @@ -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, @@ -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 { @@ -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 diff --git a/builtin/providers/aws/resource_aws_ecs_task_definition_test.go b/builtin/providers/aws/resource_aws_ecs_task_definition_test.go index 9972bba7b974..6b1278c49644 100644 --- a/builtin/providers/aws/resource_aws_ecs_task_definition_test.go +++ b/builtin/providers/aws/resource_aws_ecs_task_definition_test.go @@ -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 @@ -182,6 +198,69 @@ TASK_DEFINITION } ` +var testAccAWSEcsTaskDefinitionWithTaskRoleArn = ` +resource "aws_iam_role" "role_test" { + name = "tf_old_name" + path = "/test/" + assume_role_policy = <