Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_ecs_task_definition: Add docker volume configuration #5727

Merged
merged 1 commit into from
Sep 12, 2018

Conversation

ewilde
Copy link
Contributor

@ewilde ewilde commented Aug 29, 2018

Todo

  • Update schema
  • Read resource (update to support new schema)
  • Create resource (update to support new schema)
  • Add new test to cover docker volume configuration schema
  • Update PR text
  • Update documentation
  • Manually test new provider

Description

Adds docker volume support to ECS task definitions

Resolves #5523

Testing

I've added a new acceptance test TestAccAWSEcsTaskDefinition_withDockerVolume and TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig

Here is the output of all the ecs task definition acceptance tests including the new one:

GOROOT=/usr/lib/go-1.10 #gosetup
GOPATH=/home/ewilde/data/go #gosetup
/usr/lib/go-1.10/bin/go test -c -i -o /tmp/___resource_aws_ecs_task_definition_test_go github.com/terraform-providers/terraform-provider-aws/aws #gosetup
/usr/lib/go-1.10/bin/go tool test2json -t /tmp/___resource_aws_ecs_task_definition_test_go -test.v -test.run "^TestAccAWSEcsTaskDefinition_basic|TestAccAWSEcsTaskDefinition_withScratchVolume|TestAccAWSEcsTaskDefinition_withDockerVolume|TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig|TestAccAWSEcsTaskDefinition_withEcsService|TestAccAWSEcsTaskDefinition_withTaskRoleArn|TestAccAWSEcsTaskDefinition_withNetworkMode|TestAccAWSEcsTaskDefinition_constraint|TestAccAWSEcsTaskDefinition_changeVolumesForcesNewResource|TestAccAWSEcsTaskDefinition_arrays|TestAccAWSEcsTaskDefinition_Fargate|TestAccAWSEcsTaskDefinition_ExecutionRole|TestAccAWSEcsTaskDefinition_Inactive|TestValidateAwsEcsTaskDefinitionContainerDefinitions$" #gosetup
=== RUN   TestAccAWSEcsTaskDefinition_basic
--- PASS: TestAccAWSEcsTaskDefinition_basic (35.46s)
=== RUN   TestAccAWSEcsTaskDefinition_withScratchVolume
--- PASS: TestAccAWSEcsTaskDefinition_withScratchVolume (19.96s)
=== RUN   TestAccAWSEcsTaskDefinition_withDockerVolume
--- PASS: TestAccAWSEcsTaskDefinition_withDockerVolume (21.30s)
=== RUN   TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig
--- PASS: TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig (19.54s)
=== RUN   TestAccAWSEcsTaskDefinition_withEcsService
--- PASS: TestAccAWSEcsTaskDefinition_withEcsService (73.59s)
=== RUN   TestAccAWSEcsTaskDefinition_withTaskRoleArn
--- PASS: TestAccAWSEcsTaskDefinition_withTaskRoleArn (22.05s)
=== RUN   TestAccAWSEcsTaskDefinition_withNetworkMode
--- PASS: TestAccAWSEcsTaskDefinition_withNetworkMode (23.36s)
=== RUN   TestAccAWSEcsTaskDefinition_constraint
--- PASS: TestAccAWSEcsTaskDefinition_constraint (19.37s)
=== RUN   TestAccAWSEcsTaskDefinition_changeVolumesForcesNewResource
--- PASS: TestAccAWSEcsTaskDefinition_changeVolumesForcesNewResource (34.43s)
=== RUN   TestAccAWSEcsTaskDefinition_arrays
--- PASS: TestAccAWSEcsTaskDefinition_arrays (19.65s)
=== RUN   TestAccAWSEcsTaskDefinition_Fargate
--- PASS: TestAccAWSEcsTaskDefinition_Fargate (20.31s)
=== RUN   TestAccAWSEcsTaskDefinition_ExecutionRole
--- PASS: TestAccAWSEcsTaskDefinition_ExecutionRole (25.31s)
=== RUN   TestAccAWSEcsTaskDefinition_Inactive
--- PASS: TestAccAWSEcsTaskDefinition_Inactive (33.76s)
=== RUN   TestValidateAwsEcsTaskDefinitionContainerDefinitions
--- PASS: TestValidateAwsEcsTaskDefinitionContainerDefinitions (0.00s)
PASS

Process finished with exit code 0

@ewilde ewilde force-pushed the ecs-docker-volume-config branch 2 times, most recently from 324b074 to c627eb3 Compare August 30, 2018 09:45
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/ecs Issues and PRs that pertain to the ecs service. labels Aug 30, 2018
@ewilde ewilde force-pushed the ecs-docker-volume-config branch 2 times, most recently from 38ec4a2 to 7c54f50 Compare August 30, 2018 18:45
@ewilde ewilde changed the title [WIP] resource/aws_ecs_task_definition: Add docker volume configuration resource/aws_ecs_task_definition: Add docker volume configuration Aug 30, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ewilde 👋 Nice work so far. Left you some initial comments. Can you please take a look and let us know if you have any questions or do not have time to implement the feedback? Thanks!

@@ -108,6 +108,44 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
Optional: true,
ForceNew: true,
},

"docker_volume_configuration": {
Type: schema.TypeSet,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using MaxItems: 1 we should prefer schema.TypeList instead of schema.TypeSet for simplification (e.g. no hash function).

"docker_volume_configuration": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all underlying elements be ForceNew: true as well? I believe in Terraform 0.11 the behavior of ForceNew: true propagating to all children attributes was changed/removed.

Optional: true,
},
"driver_opts": {
Type: schema.TypeMap,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the schema validator errantly allows it in Terraform 0.11, we should always set Elem with schema.TypeMap, e.g.

Elem: &schema.Schema{Type: schema.TypeString},

See also: #5350

Optional: true,
},
"labels": {
Type: schema.TypeMap,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note about Elem with this attribute as well. 👍

return hashcode.String(buf.String())
}

func dockerVolumeConfigurationHash(v interface{}) int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function goes away when converting TypeSet to TypeList 👍

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Sep 4, 2018
Add support for docker volume configuration to ecs task definitions

Resolves hashicorp#5523

Signed-off-by: Edward Wilde <[email protected]>
@ewilde ewilde force-pushed the ecs-docker-volume-config branch from 24c8f17 to a106e1f Compare September 7, 2018 20:10
@ewilde
Copy link
Contributor Author

ewilde commented Sep 7, 2018

@bflad thanks for the great feedback 👏 . All changes made, tests re-ran and all pass as before

Test output:

GOROOT=/usr/lib/go-1.10 #gosetup
GOPATH=/home/ewilde/data/go #gosetup
/usr/lib/go-1.10/bin/go test -c -i -o /tmp/___resource_aws_ecs_task_definition_test_go github.com/terraform-providers/terraform-provider-aws/aws #gosetup
/usr/lib/go-1.10/bin/go tool test2json -t /tmp/___resource_aws_ecs_task_definition_test_go -test.v -test.run "^TestAccAWSEcsTaskDefinition_basic|TestAccAWSEcsTaskDefinition_withScratchVolume|TestAccAWSEcsTaskDefinition_withDockerVolume|TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig|TestAccAWSEcsTaskDefinition_withEcsService|TestAccAWSEcsTaskDefinition_withTaskRoleArn|TestAccAWSEcsTaskDefinition_withNetworkMode|TestAccAWSEcsTaskDefinition_constraint|TestAccAWSEcsTaskDefinition_changeVolumesForcesNewResource|TestAccAWSEcsTaskDefinition_arrays|TestAccAWSEcsTaskDefinition_Fargate|TestAccAWSEcsTaskDefinition_ExecutionRole|TestAccAWSEcsTaskDefinition_Inactive|TestValidateAwsEcsTaskDefinitionContainerDefinitions$" #gosetup
=== RUN   TestAccAWSEcsTaskDefinition_basic
--- PASS: TestAccAWSEcsTaskDefinition_basic (35.06s)
=== RUN   TestAccAWSEcsTaskDefinition_withScratchVolume
--- PASS: TestAccAWSEcsTaskDefinition_withScratchVolume (19.70s)
=== RUN   TestAccAWSEcsTaskDefinition_withDockerVolume
--- PASS: TestAccAWSEcsTaskDefinition_withDockerVolume (21.84s)
=== RUN   TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig
--- PASS: TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig (19.61s)
=== RUN   TestAccAWSEcsTaskDefinition_withEcsService
--- PASS: TestAccAWSEcsTaskDefinition_withEcsService (63.58s)
=== RUN   TestAccAWSEcsTaskDefinition_withTaskRoleArn
--- PASS: TestAccAWSEcsTaskDefinition_withTaskRoleArn (24.13s)
=== RUN   TestAccAWSEcsTaskDefinition_withNetworkMode
--- PASS: TestAccAWSEcsTaskDefinition_withNetworkMode (22.39s)
=== RUN   TestAccAWSEcsTaskDefinition_constraint
--- PASS: TestAccAWSEcsTaskDefinition_constraint (19.59s)
=== RUN   TestAccAWSEcsTaskDefinition_changeVolumesForcesNewResource
--- PASS: TestAccAWSEcsTaskDefinition_changeVolumesForcesNewResource (35.03s)
=== RUN   TestAccAWSEcsTaskDefinition_arrays
--- PASS: TestAccAWSEcsTaskDefinition_arrays (19.93s)
=== RUN   TestAccAWSEcsTaskDefinition_Fargate
--- PASS: TestAccAWSEcsTaskDefinition_Fargate (21.29s)
=== RUN   TestAccAWSEcsTaskDefinition_ExecutionRole
--- PASS: TestAccAWSEcsTaskDefinition_ExecutionRole (23.42s)
=== RUN   TestAccAWSEcsTaskDefinition_Inactive
--- PASS: TestAccAWSEcsTaskDefinition_Inactive (34.06s)
=== RUN   TestValidateAwsEcsTaskDefinitionContainerDefinitions
--- PASS: TestValidateAwsEcsTaskDefinitionContainerDefinitions (0.00s)
PASS

Process finished with exit code 0

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 12, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @ewilde! 🚀

13 tests passed (all tests)
--- PASS: TestAccAWSEcsTaskDefinition_withDockerVolume (4.40s)
--- PASS: TestAccAWSEcsTaskDefinition_arrays (4.54s)
--- PASS: TestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig (4.48s)
--- PASS: TestAccAWSEcsTaskDefinition_constraint (4.62s)
--- PASS: TestAccAWSEcsTaskDefinition_withScratchVolume (4.63s)
--- PASS: TestAccAWSEcsTaskDefinition_ExecutionRole (10.04s)
--- PASS: TestAccAWSEcsTaskDefinition_Fargate (10.71s)
--- PASS: TestAccAWSEcsTaskDefinition_Inactive (11.89s)
--- PASS: TestAccAWSEcsTaskDefinition_basic (12.13s)
--- PASS: TestAccAWSEcsTaskDefinition_withNetworkMode (12.73s)
--- PASS: TestAccAWSEcsTaskDefinition_changeVolumesForcesNewResource (20.56s)
--- PASS: TestAccAWSEcsTaskDefinition_withTaskRoleArn (21.08s)
--- PASS: TestAccAWSEcsTaskDefinition_withEcsService (53.02s)

@@ -621,15 +647,47 @@ func flattenEcsVolumes(list []*ecs.Volume) []map[string]interface{} {
"name": *volume.Name,
}

if volume.Host.SourcePath != nil {
if volume.Host != nil && volume.Host.SourcePath != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

@@ -113,6 +113,32 @@ func expandEcsVolumes(configured []interface{}) ([]*ecs.Volume, error) {
}
}

configList, ok := data["docker_volume_configuration"].([]interface{})
if ok && len(configList) > 0 {
config := configList[0].(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may also want to add a nil check for configList[0] for this at some point in the future to prevent a potential panic, since things can get a little weird if the nested configuration has all zero-values -- see also: #5852

@bflad bflad added this to the v1.36.0 milestone Sep 12, 2018
@bflad bflad merged commit 53a9838 into hashicorp:master Sep 12, 2018
bflad added a commit that referenced this pull request Sep 12, 2018
@ewilde ewilde deleted the ecs-docker-volume-config branch September 12, 2018 21:49
@bflad
Copy link
Contributor

bflad commented Sep 13, 2018

This has been released in version 1.36.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: ECS Docker volume support
2 participants