Skip to content

Commit

Permalink
Merge pull request #3810 from TimeIncOSS/f-aws-ecs-ephemeral-volumes
Browse files Browse the repository at this point in the history
provider/aws: Support scratch volumes in ecs_task_definition
  • Loading branch information
radeksimko committed Nov 10, 2015
2 parents 8cca366 + 63049c0 commit ac6efd8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion builtin/providers/aws/resource_aws_ecs_task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {

"host_path": &schema.Schema{
Type: schema.TypeString,
Required: true,
Optional: true,
},
},
},
Expand Down
39 changes: 39 additions & 0 deletions builtin/providers/aws/resource_aws_ecs_task_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ func TestAccAWSEcsTaskDefinition_basic(t *testing.T) {
})
}

// Regression for https://github.com/hashicorp/terraform/issues/2370
func TestAccAWSEcsTaskDefinition_withScratchVolume(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEcsTaskDefinitionWithScratchVolume,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep"),
),
},
},
})
}

func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecsconn

Expand Down Expand Up @@ -116,6 +133,28 @@ TASK_DEFINITION
}
`

var testAccAWSEcsTaskDefinitionWithScratchVolume = `
resource "aws_ecs_task_definition" "sleep" {
family = "terraform-acc-sc-volume-test"
container_definitions = <<TASK_DEFINITION
[
{
"name": "sleep",
"image": "busybox",
"cpu": 10,
"command": ["sleep","360"],
"memory": 10,
"essential": true
}
]
TASK_DEFINITION
volume {
name = "database_scratch"
}
}
`

var testAccAWSEcsTaskDefinitionModifier = `
resource "aws_ecs_task_definition" "jenkins" {
family = "terraform-acc-test"
Expand Down
18 changes: 13 additions & 5 deletions builtin/providers/aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ func expandEcsVolumes(configured []interface{}) ([]*ecs.Volume, error) {

l := &ecs.Volume{
Name: aws.String(data["name"].(string)),
Host: &ecs.HostVolumeProperties{
SourcePath: aws.String(data["host_path"].(string)),
},
}

hostPath := data["host_path"].(string)
if hostPath != "" {
l.Host = &ecs.HostVolumeProperties{
SourcePath: aws.String(hostPath),
}
}

volumes = append(volumes, l)
Expand Down Expand Up @@ -314,9 +318,13 @@ func flattenEcsVolumes(list []*ecs.Volume) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(list))
for _, volume := range list {
l := map[string]interface{}{
"name": *volume.Name,
"host_path": *volume.Host.SourcePath,
"name": *volume.Name,
}

if volume.Host.SourcePath != nil {
l["host_path"] = *volume.Host.SourcePath
}

result = append(result, l)
}
return result
Expand Down

0 comments on commit ac6efd8

Please sign in to comment.