Merge pull request #3810 from TimeIncOSS/f-aws-ecs-ephemeral-volumes

provider/aws: Support scratch volumes in ecs_task_definition
This commit is contained in:
Radek Simko 2015-11-10 23:22:22 +00:00
commit ac6efd86ed
3 changed files with 53 additions and 6 deletions

View File

@ -58,7 +58,7 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
"host_path": &schema.Schema{
Type: schema.TypeString,
Required: true,
Optional: true,
},
},
},

View File

@ -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
@ -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"

View File

@ -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)
@ -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