Skip to content

Commit

Permalink
Merge pull request #7712 from terraform-providers/td-aws_ecs_service-…
Browse files Browse the repository at this point in the history
…remove-deprecated

resource/aws_ecs_service: Remove deprecated placement_strategy configuration block
  • Loading branch information
bflad authored Feb 26, 2019
2 parents 1a78e3a + 5574c38 commit 332aca0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 74 deletions.
84 changes: 12 additions & 72 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ func resourceAwsEcsService() *schema.Resource {
},
},
"placement_strategy": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MaxItems: 5,
ConflictsWith: []string{"ordered_placement_strategy"},
Deprecated: "Use `ordered_placement_strategy` instead",
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MaxItems: 5,
Removed: "Use `ordered_placement_strategy` configuration block(s) instead",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Expand Down Expand Up @@ -247,11 +246,10 @@ func resourceAwsEcsService() *schema.Resource {
},
},
"ordered_placement_strategy": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 5,
ConflictsWith: []string{"placement_strategy"},
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 5,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Expand Down Expand Up @@ -434,12 +432,6 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error
return err
}
input.PlacementStrategy = ps
} else {
ps, err := expandPlacementStrategyDeprecated(d.Get("placement_strategy").(*schema.Set))
if err != nil {
return err
}
input.PlacementStrategy = ps
}

constraints := d.Get("placement_constraints").(*schema.Set).List()
Expand Down Expand Up @@ -630,15 +622,10 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("load_balancer", flattenEcsLoadBalancers(service.LoadBalancers))
}

if _, ok := d.GetOk("placement_strategy"); ok {
if err := d.Set("placement_strategy", flattenPlacementStrategyDeprecated(service.PlacementStrategy)); err != nil {
return fmt.Errorf("error setting placement_strategy: %s", err)
}
} else {
if err := d.Set("ordered_placement_strategy", flattenPlacementStrategy(service.PlacementStrategy)); err != nil {
return fmt.Errorf("error setting ordered_placement_strategy: %s", err)
}
if err := d.Set("ordered_placement_strategy", flattenPlacementStrategy(service.PlacementStrategy)); err != nil {
return fmt.Errorf("error setting ordered_placement_strategy: %s", err)
}

if err := d.Set("placement_constraints", flattenServicePlacementConstraints(service.PlacementConstraints)); err != nil {
log.Printf("[ERR] Error setting placement_constraints for (%s): %s", d.Id(), err)
}
Expand Down Expand Up @@ -739,29 +726,6 @@ func flattenServicePlacementConstraints(pcs []*ecs.PlacementConstraint) []map[st
return results
}

func flattenPlacementStrategyDeprecated(pss []*ecs.PlacementStrategy) []map[string]interface{} {
if len(pss) == 0 {
return nil
}
results := make([]map[string]interface{}, 0)
for _, ps := range pss {
c := make(map[string]interface{})
c["type"] = *ps.Type

if ps.Field != nil {
c["field"] = *ps.Field

// for some fields the API requires lowercase for creation but will return uppercase on query
if *ps.Field == "MEMORY" || *ps.Field == "CPU" {
c["field"] = strings.ToLower(*ps.Field)
}
}

results = append(results, c)
}
return results
}

func expandPlacementStrategy(s []interface{}) ([]*ecs.PlacementStrategy, error) {
if len(s) == 0 {
return nil, nil
Expand All @@ -786,30 +750,6 @@ func expandPlacementStrategy(s []interface{}) ([]*ecs.PlacementStrategy, error)
return pss, nil
}

func expandPlacementStrategyDeprecated(s *schema.Set) ([]*ecs.PlacementStrategy, error) {
if len(s.List()) == 0 {
return nil, nil
}
pss := make([]*ecs.PlacementStrategy, 0)
for _, raw := range s.List() {
p := raw.(map[string]interface{})
t := p["type"].(string)
f := p["field"].(string)
if err := validateAwsEcsPlacementStrategy(t, f); err != nil {
return nil, err
}
ps := &ecs.PlacementStrategy{
Type: aws.String(t),
}
if f != "" {
// Field must be omitted (i.e. not empty string) for random strategy
ps.Field = aws.String(f)
}
pss = append(pss, ps)
}
return pss, nil
}

func flattenPlacementStrategy(pss []*ecs.PlacementStrategy) []interface{} {
if len(pss) == 0 {
return nil
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ resource "aws_ecs_service" "mongo" {
cluster = "${aws_ecs_cluster.default.id}"
task_definition = "${aws_ecs_task_definition.mongo.arn}"
desired_count = 1
placement_strategy {
ordered_placement_strategy {
field = "host"
type = "spread"
}
Expand Down
1 change: 0 additions & 1 deletion website/docs/r/ecs_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ The following arguments are supported:
* `deployment_minimum_healthy_percent` - (Optional) The lower limit (as a percentage of the service's desiredCount) of the number of running tasks that must remain running and healthy in a service during a deployment.
* `enable_ecs_managed_tags` - (Optional) Specifies whether to enable Amazon ECS managed tags for the tasks within the service.
* `propagate_tags` - (Optional) Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are `SERVICE` and `TASK_DEFINITION`.
* `placement_strategy` - (Optional) **Deprecated**, use `ordered_placement_strategy` instead.
* `ordered_placement_strategy` - (Optional) Service level strategy rules that are taken into consideration during task placement. List from top to bottom in order of precedence. The maximum number of `ordered_placement_strategy` blocks is `5`. Defined below.
* `health_check_grace_period_seconds` - (Optional) Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 7200. Only valid for services configured to use load balancers.
* `load_balancer` - (Optional) A load balancer block. Load balancers documented below.
Expand Down

0 comments on commit 332aca0

Please sign in to comment.