Skip to content

Commit

Permalink
Merge pull request #2402 from hashicorp/f-aws-ecs-td-deregistration
Browse files Browse the repository at this point in the history
provider/aws: Deregister ECS task definition correctly
  • Loading branch information
radeksimko committed Jun 30, 2015
2 parents c4f3ec8 + f5eb581 commit 8acc55a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
29 changes: 25 additions & 4 deletions builtin/providers/aws/resource_aws_ecs_task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,39 @@ func resourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{})
}

func resourceAwsEcsTaskDefinitionUpdate(d *schema.ResourceData, meta interface{}) error {
return resourceAwsEcsTaskDefinitionCreate(d, meta)
oldArn := d.Get("arn").(string)

log.Printf("[DEBUG] Creating new revision of task definition %q", d.Id())
err := resourceAwsEcsTaskDefinitionCreate(d, meta)
if err != nil {
return err
}
log.Printf("[DEBUG] New revision of %q created: %q", d.Id(), d.Get("arn").(string))

log.Printf("[DEBUG] Deregistering old revision of task definition %q: %q", d.Id(), oldArn)
conn := meta.(*AWSClient).ecsconn
_, err = conn.DeregisterTaskDefinition(&ecs.DeregisterTaskDefinitionInput{
TaskDefinition: aws.String(oldArn),
})
if err != nil {
return err
}
log.Printf("[DEBUG] Old revision of task definition deregistered: %q", oldArn)

return resourceAwsEcsTaskDefinitionRead(d, meta)
}

func resourceAwsEcsTaskDefinitionDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ecsconn

// NOT YET IMPLEMENTED o_O
_, err := conn.DeregisterTaskDefinition(&ecs.DeregisterTaskDefinitionInput{
TaskDefinition: aws.String(d.Id()),
TaskDefinition: aws.String(d.Get("arn").(string)),
})
if err != nil {
return err
}

log.Printf("[DEBUG] Deregistering task definition %s returned %#v", d.Id(), err)
log.Printf("[DEBUG] Task definition %q deregistered.", d.Get("arn").(string))

return nil
}
Expand Down
57 changes: 56 additions & 1 deletion builtin/providers/aws/resource_aws_ecs_task_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func TestAccAWSEcsTaskDefinition_basic(t *testing.T) {
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"),
),
},
resource.TestStep{
Config: testAccAWSEcsTaskDefinitionModifier,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"),
),
},
},
})
}
Expand Down Expand Up @@ -63,7 +69,7 @@ func testAccCheckAWSEcsTaskDefinitionExists(name string) resource.TestCheckFunc

var testAccAWSEcsTaskDefinition = `
resource "aws_ecs_task_definition" "jenkins" {
family = "jenkins"
family = "terraform-acc-test"
container_definitions = <<TASK_DEFINITION
[
{
Expand Down Expand Up @@ -109,3 +115,52 @@ TASK_DEFINITION
}
}
`

var testAccAWSEcsTaskDefinitionModifier = `
resource "aws_ecs_task_definition" "jenkins" {
family = "terraform-acc-test"
container_definitions = <<TASK_DEFINITION
[
{
"cpu": 10,
"command": ["sleep", "10"],
"entryPoint": ["/"],
"environment": [
{"name": "VARNAME", "value": "VARVAL"}
],
"essential": true,
"image": "jenkins",
"links": ["mongodb"],
"memory": 128,
"name": "jenkins",
"portMappings": [
{
"containerPort": 80,
"hostPort": 8080
}
]
},
{
"cpu": 20,
"command": ["sleep", "10"],
"entryPoint": ["/"],
"essential": true,
"image": "mongodb",
"memory": 128,
"name": "mongodb",
"portMappings": [
{
"containerPort": 28017,
"hostPort": 28017
}
]
}
]
TASK_DEFINITION
volume {
name = "jenkins-home"
host_path = "/ecs/jenkins-home"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ description: |-

Provides an ECS task definition to be used in `aws_ecs_service`.

~> **NOTE:** There is currently no way to unregister
any previously registered task definition.
See related [thread in AWS forum](https://forums.aws.amazon.com/thread.jspa?threadID=170378&tstart=0).

## Example Usage

```
Expand Down

0 comments on commit 8acc55a

Please sign in to comment.