diff --git a/builtin/providers/aws/resource_aws_ecs_task_definition.go b/builtin/providers/aws/resource_aws_ecs_task_definition.go index bdc260a41..fe28252f2 100644 --- a/builtin/providers/aws/resource_aws_ecs_task_definition.go +++ b/builtin/providers/aws/resource_aws_ecs_task_definition.go @@ -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 } 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 df37eba4e..2cff051c5 100644 --- a/builtin/providers/aws/resource_aws_ecs_task_definition_test.go +++ b/builtin/providers/aws/resource_aws_ecs_task_definition_test.go @@ -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"), + ), + }, }, }) } @@ -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 = < **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 ```