provider/aws: ecs task definition is deregistered correctly

This commit is contained in:
Radek Simko 2015-06-19 08:15:49 +01:00
parent da1cac623d
commit f5eb581425
3 changed files with 81 additions and 9 deletions

View File

@ -132,18 +132,39 @@ func resourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{})
} }
func resourceAwsEcsTaskDefinitionUpdate(d *schema.ResourceData, meta interface{}) error { 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 { func resourceAwsEcsTaskDefinitionDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ecsconn conn := meta.(*AWSClient).ecsconn
// NOT YET IMPLEMENTED o_O
_, err := conn.DeregisterTaskDefinition(&ecs.DeregisterTaskDefinitionInput{ _, 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 return nil
} }

View File

@ -22,6 +22,12 @@ func TestAccAWSEcsTaskDefinition_basic(t *testing.T) {
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"), 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 = ` var testAccAWSEcsTaskDefinition = `
resource "aws_ecs_task_definition" "jenkins" { resource "aws_ecs_task_definition" "jenkins" {
family = "jenkins" family = "terraform-acc-test"
container_definitions = <<TASK_DEFINITION container_definitions = <<TASK_DEFINITION
[ [
{ {
@ -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"
}
}
`

View File

@ -10,10 +10,6 @@ description: |-
Provides an ECS task definition to be used in `aws_ecs_service`. 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 ## Example Usage
``` ```