From 03ced11d049e994ec7e8fb0e63572ccb832582d9 Mon Sep 17 00:00:00 2001 From: Sunil Kumar Mohanty Date: Mon, 19 Nov 2018 09:36:10 +0200 Subject: [PATCH 1/3] Add support for ECS IPC Mode/PID Mode --- aws/resource_aws_ecs_task_definition.go | 20 ++ aws/resource_aws_ecs_task_definition_test.go | 182 ++++++++++++++++++ .../docs/r/ecs_task_definition.html.markdown | 2 + 3 files changed, 204 insertions(+) diff --git a/aws/resource_aws_ecs_task_definition.go b/aws/resource_aws_ecs_task_definition.go index 6ffd916dcb1..7ae88764ab2 100644 --- a/aws/resource_aws_ecs_task_definition.go +++ b/aws/resource_aws_ecs_task_definition.go @@ -188,6 +188,18 @@ func resourceAwsEcsTaskDefinition() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, + "ipc_mode": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "pid_mode": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "tags": tagsSchema(), }, } @@ -241,6 +253,14 @@ func resourceAwsEcsTaskDefinitionCreate(d *schema.ResourceData, meta interface{} input.NetworkMode = aws.String(v.(string)) } + if v, ok := d.GetOk("ipc_mode"); ok { + input.IpcMode = aws.String(v.(string)) + } + + if v, ok := d.GetOk("pid_mode"); ok { + input.PidMode = aws.String(v.(string)) + } + if v, ok := d.GetOk("volume"); ok { volumes, err := expandEcsVolumes(v.(*schema.Set).List()) if err != nil { diff --git a/aws/resource_aws_ecs_task_definition_test.go b/aws/resource_aws_ecs_task_definition_test.go index 1a9e43176e8..6a0872dc20b 100644 --- a/aws/resource_aws_ecs_task_definition_test.go +++ b/aws/resource_aws_ecs_task_definition_test.go @@ -243,6 +243,56 @@ func TestAccAWSEcsTaskDefinition_withNetworkMode(t *testing.T) { }) } +func TestAccAWSEcsTaskDefinition_withIPCMode(t *testing.T) { + var def ecs.TaskDefinition + + rString := acctest.RandString(8) + roleName := fmt.Sprintf("tf_acc_ecs_td_with_ipc_mode_%s", rString) + policyName := fmt.Sprintf("tf_acc_ecs_td_with_ipc_mode_%s", rString) + tdName := fmt.Sprintf("tf_acc_td_with_ipc_mode_%s", rString) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEcsTaskDefinitionWithIpcMode(roleName, policyName, tdName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def), + resource.TestCheckResourceAttr( + "aws_ecs_task_definition.sleep", "ipc_mode", "host"), + ), + }, + }, + }) +} + +func TestAccAWSEcsTaskDefinition_withPidMode(t *testing.T) { + var def ecs.TaskDefinition + + rString := acctest.RandString(8) + roleName := fmt.Sprintf("tf_acc_ecs_td_with_pid_mode_%s", rString) + policyName := fmt.Sprintf("tf_acc_ecs_td_with_pid_mode_%s", rString) + tdName := fmt.Sprintf("tf_acc_td_with_pid_mode_%s", rString) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSEcsTaskDefinitionWithPidMode(roleName, policyName, tdName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def), + resource.TestCheckResourceAttr( + "aws_ecs_task_definition.sleep", "pid_mode", "host"), + ), + }, + }, + }) +} + func TestAccAWSEcsTaskDefinition_constraint(t *testing.T) { var def ecs.TaskDefinition @@ -1083,6 +1133,138 @@ TASK_DEFINITION }`, roleName, policyName, tdName) } +func testAccAWSEcsTaskDefinitionWithIpcMode(roleName, policyName, tdName string) string { + return fmt.Sprintf(` + resource "aws_iam_role" "role_test" { + name = "%s" + path = "/test/" + assume_role_policy = < Date: Mon, 19 Nov 2018 22:37:39 +0200 Subject: [PATCH 2/3] add validation for ipcmode and pidmode for ecs task definition --- aws/resource_aws_ecs_task_definition.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/aws/resource_aws_ecs_task_definition.go b/aws/resource_aws_ecs_task_definition.go index 7ae88764ab2..f58a4f5ab46 100644 --- a/aws/resource_aws_ecs_task_definition.go +++ b/aws/resource_aws_ecs_task_definition.go @@ -192,12 +192,21 @@ func resourceAwsEcsTaskDefinition() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + ecs.IpcModeHost, + ecs.IpcModeNone, + ecs.IpcModeTask, + }, false), }, "pid_mode": { Type: schema.TypeString, Optional: true, ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + ecs.PidModeHost, + ecs.PidModeTask, + }, false), }, "tags": tagsSchema(), From 1f84b6c42a72a9477dd06a053eb2f0f35c67b33e Mon Sep 17 00:00:00 2001 From: Sunil Kumar Mohanty Date: Mon, 19 Nov 2018 22:38:07 +0200 Subject: [PATCH 3/3] fix typos --- website/docs/r/ecs_task_definition.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/ecs_task_definition.html.markdown b/website/docs/r/ecs_task_definition.html.markdown index 711bd96aeab..937ba9d9ae7 100644 --- a/website/docs/r/ecs_task_definition.html.markdown +++ b/website/docs/r/ecs_task_definition.html.markdown @@ -83,7 +83,7 @@ official [Developer Guide](https://docs.aws.amazon.com/AmazonECS/latest/develope * `execution_role_arn` - (Optional) The Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume. * `network_mode` - (Optional) The Docker networking mode to use for the containers in the task. The valid values are `none`, `bridge`, `awsvpc`, and `host`. * `ipc_mode` - (Optional) The IPC resource namespace to be used for the containers in the task The valid values are `host`, `task`, and `none`. -* `pid_mode` - (Optional) TheThe process namespace to use for the containers in the task. The valid values are `host` and `task`. +* `pid_mode` - (Optional) The process namespace to use for the containers in the task. The valid values are `host` and `task`. * `volume` - (Optional) A set of [volume blocks](#volume-block-arguments) that containers in your task may use. * `placement_constraints` - (Optional) A set of [placement constraints](#placement-constraints-arguments) rules that are taken into consideration during task placement. Maximum number of `placement_constraints` is `10`. * `cpu` - (Optional) The number of cpu units used by the task. If the `requires_compatibilities` is `FARGATE` this field is required.