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:
commit
ac6efd86ed
|
@ -58,7 +58,7 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
|
|||
|
||||
"host_path": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
@ -315,8 +319,12 @@ func flattenEcsVolumes(list []*ecs.Volume) []map[string]interface{} {
|
|||
for _, volume := range list {
|
||||
l := map[string]interface{}{
|
||||
"name": *volume.Name,
|
||||
"host_path": *volume.Host.SourcePath,
|
||||
}
|
||||
|
||||
if volume.Host.SourcePath != nil {
|
||||
l["host_path"] = *volume.Host.SourcePath
|
||||
}
|
||||
|
||||
result = append(result, l)
|
||||
}
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue