provider/aws: ECS Placement constraints fix (#11475)
* fixing AWS ECS placement constraints * correcting AWS ECS task definition doc * reverting unnecessary change to resource_aws_ecs_task_definition * provider/aws: ECS Placement constraints fix Expands upon #11446 from @bgetsug Adds: - Acceptance Test - Improves `nil` check on constraint expression Fixes: #10968
This commit is contained in:
parent
061c8cc7ef
commit
96f6044908
|
@ -202,10 +202,14 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
if err := validateAwsEcsPlacementConstraint(t, e); err != nil {
|
if err := validateAwsEcsPlacementConstraint(t, e); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pc = append(pc, &ecs.PlacementConstraint{
|
constraint := &ecs.PlacementConstraint{
|
||||||
Type: aws.String(t),
|
Type: aws.String(t),
|
||||||
Expression: aws.String(e),
|
}
|
||||||
})
|
if e != "" {
|
||||||
|
constraint.Expression = aws.String(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
pc = append(pc, constraint)
|
||||||
}
|
}
|
||||||
input.PlacementConstraints = pc
|
input.PlacementConstraints = pc
|
||||||
}
|
}
|
||||||
|
@ -336,7 +340,10 @@ func flattenServicePlacementConstraints(pcs []*ecs.PlacementConstraint) []map[st
|
||||||
for _, pc := range pcs {
|
for _, pc := range pcs {
|
||||||
c := make(map[string]interface{})
|
c := make(map[string]interface{})
|
||||||
c["type"] = *pc.Type
|
c["type"] = *pc.Type
|
||||||
c["expression"] = *pc.Expression
|
if pc.Expression != nil {
|
||||||
|
c["expression"] = *pc.Expression
|
||||||
|
}
|
||||||
|
|
||||||
results = append(results, c)
|
results = append(results, c)
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -298,6 +298,23 @@ func TestAccAWSEcsServiceWithPlacementConstraints(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSEcsServiceWithPlacementConstraints_emptyExpression(t *testing.T) {
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAWSEcsServiceWithPlacementConstraintEmptyExpression,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo"),
|
||||||
|
resource.TestCheckResourceAttr("aws_ecs_service.mongo", "placement_constraints.#", "1"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSEcsServiceDestroy(s *terraform.State) error {
|
func testAccCheckAWSEcsServiceDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ecsconn
|
conn := testAccProvider.Meta().(*AWSClient).ecsconn
|
||||||
|
|
||||||
|
@ -465,6 +482,35 @@ resource "aws_ecs_service" "mongo" {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var testAccAWSEcsServiceWithPlacementConstraintEmptyExpression = `
|
||||||
|
resource "aws_ecs_cluster" "default" {
|
||||||
|
name = "terraformecstest212"
|
||||||
|
}
|
||||||
|
resource "aws_ecs_task_definition" "mongo" {
|
||||||
|
family = "mongodb"
|
||||||
|
container_definitions = <<DEFINITION
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"cpu": 128,
|
||||||
|
"essential": true,
|
||||||
|
"image": "mongo:latest",
|
||||||
|
"memory": 128,
|
||||||
|
"name": "mongodb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
DEFINITION
|
||||||
|
}
|
||||||
|
resource "aws_ecs_service" "mongo" {
|
||||||
|
name = "mongodb"
|
||||||
|
cluster = "${aws_ecs_cluster.default.id}"
|
||||||
|
task_definition = "${aws_ecs_task_definition.mongo.arn}"
|
||||||
|
desired_count = 1
|
||||||
|
placement_constraints {
|
||||||
|
type = "distinctInstance"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
var testAccAWSEcsService_withIamRole = `
|
var testAccAWSEcsService_withIamRole = `
|
||||||
resource "aws_ecs_cluster" "main" {
|
resource "aws_ecs_cluster" "main" {
|
||||||
name = "terraformecstest11"
|
name = "terraformecstest11"
|
||||||
|
|
|
@ -92,9 +92,9 @@ parameter of container definition in the `mountPoints` section.
|
||||||
|
|
||||||
`placement_constraints` support the following:
|
`placement_constraints` support the following:
|
||||||
|
|
||||||
* `type` - (Required) The type of constraint. The only valid values at this time are `memberOf` or `distinctInstance`.
|
* `type` - (Required) The type of constraint. Use `memberOf` to restrict selection to a group of valid candidates.
|
||||||
* `expression` - (Optional) Cluster Query Language expression to apply to the constraint. Does not need to be specified
|
Note that `distinctInstance` is not supported in task definitions.
|
||||||
for the `distinctInstance` type.
|
* `expression` - (Optional) Cluster Query Language expression to apply to the constraint.
|
||||||
For more information, see [Cluster Query Language in the Amazon EC2 Container
|
For more information, see [Cluster Query Language in the Amazon EC2 Container
|
||||||
Service Developer
|
Service Developer
|
||||||
Guide](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html).
|
Guide](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html).
|
||||||
|
|
Loading…
Reference in New Issue