-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
324b074
to
c627eb3
Compare
38ec4a2
to
7c54f50
Compare
There was a problem hiding this 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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
👍
Add support for docker volume configuration to ecs task definitions Resolves hashicorp#5523 Signed-off-by: Edward Wilde <[email protected]>
24c8f17
to
a106e1f
Compare
@bflad thanks for the great feedback 👏 . All changes made, tests re-ran and all pass as before Test output:
|
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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{}) |
There was a problem hiding this comment.
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
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. |
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! |
Todo
Description
Adds docker volume support to ECS task definitions
Resolves #5523
Testing
I've added a new acceptance test
TestAccAWSEcsTaskDefinition_withDockerVolume
andTestAccAWSEcsTaskDefinition_withDockerVolumeMinimalConfig
Here is the output of all the ecs task definition acceptance tests including the new one: