Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/aws_ecs_task_definition: add execution_role_arn attribute #28662

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/service/ecs/task_definition_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func DataSourceTaskDefinition() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"execution_role_arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -74,6 +78,7 @@ func dataSourceTaskDefinitionRead(d *schema.ResourceData, meta interface{}) erro
d.Set("revision", taskDefinition.Revision)
d.Set("status", taskDefinition.Status)
d.Set("task_role_arn", taskDefinition.TaskRoleArn)
d.Set("execution_role_arn", taskDefinition.ExecutionRoleArn)

if d.Id() == "" {
return fmt.Errorf("task definition %q not found", d.Get("task_definition").(string))
Expand Down
22 changes: 22 additions & 0 deletions internal/service/ecs/task_definition_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccECSTaskDefinitionDataSource_ecsTaskDefinition(t *testing.T) {
resource.TestMatchResourceAttr(resourceName, "revision", regexp.MustCompile("^[1-9][0-9]*$")),
resource.TestCheckResourceAttr(resourceName, "status", "ACTIVE"),
resource.TestCheckResourceAttrPair(resourceName, "task_role_arn", "aws_iam_role.mongo_role", "arn"),
resource.TestCheckResourceAttrPair(resourceName, "execution_role_arn", "aws_iam_role.execution", "arn"),
),
},
},
Expand Down Expand Up @@ -57,8 +58,29 @@ resource "aws_iam_role" "mongo_role" {
POLICY
}

resource "aws_iam_role" "execution" {
name = "%[1]s-execution"

assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}

resource "aws_ecs_task_definition" "mongo" {
family = "%[1]s"
execution_role_arn = aws_iam_role.execution.arn
task_role_arn = aws_iam_role.mongo_role.arn
network_mode = "bridge"

Expand Down
1 change: 1 addition & 0 deletions website/docs/d/ecs_task_definition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ In addition to all arguments above, the following attributes are exported:
* `revision` - Revision of this task definition
* `status` - Status of this task definition
* `task_role_arn` - ARN of the IAM role that containers in this task can assume
* `execution_role_arn` - ARN of the task execution role that the Amazon ECS container agent and the Docker daemon can assume