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{
|
"host_path": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
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 {
|
func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ecsconn
|
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 = `
|
var testAccAWSEcsTaskDefinitionModifier = `
|
||||||
resource "aws_ecs_task_definition" "jenkins" {
|
resource "aws_ecs_task_definition" "jenkins" {
|
||||||
family = "terraform-acc-test"
|
family = "terraform-acc-test"
|
||||||
|
|
|
@ -62,9 +62,13 @@ func expandEcsVolumes(configured []interface{}) ([]*ecs.Volume, error) {
|
||||||
|
|
||||||
l := &ecs.Volume{
|
l := &ecs.Volume{
|
||||||
Name: aws.String(data["name"].(string)),
|
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)
|
volumes = append(volumes, l)
|
||||||
|
@ -314,9 +318,13 @@ func flattenEcsVolumes(list []*ecs.Volume) []map[string]interface{} {
|
||||||
result := make([]map[string]interface{}, 0, len(list))
|
result := make([]map[string]interface{}, 0, len(list))
|
||||||
for _, volume := range list {
|
for _, volume := range list {
|
||||||
l := map[string]interface{}{
|
l := map[string]interface{}{
|
||||||
"name": *volume.Name,
|
"name": *volume.Name,
|
||||||
"host_path": *volume.Host.SourcePath,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if volume.Host.SourcePath != nil {
|
||||||
|
l["host_path"] = *volume.Host.SourcePath
|
||||||
|
}
|
||||||
|
|
||||||
result = append(result, l)
|
result = append(result, l)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue