Skip to content

Commit

Permalink
Merge commit '0788318d02a308ed6a437a5868ed93603d28e261'
Browse files Browse the repository at this point in the history
  • Loading branch information
jocgir committed Nov 24, 2017
2 parents df2156c + 0788318 commit b508b13
Show file tree
Hide file tree
Showing 18 changed files with 764 additions and 45 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
## 1.3.1 (November 20, 2017)

BUG FIXES:

* resource/aws_ecs_task_definition: Fix equivalency comparator ([#2339](https://github.com/terraform-providers/terraform-provider-aws/issues/2339))
* resource/aws_batch_job_queue: Return errors correctly if deletion fails ([#2322](https://github.com/terraform-providers/terraform-provider-aws/issues/2322))
* resource/aws_security_group_rule: Parse `description` correctly ([#1959](https://github.com/terraform-providers/terraform-provider-aws/issues/1959))
* Fixed Cognito Lambda Config Validation for optional ARN configurations ([#2370](https://github.com/terraform-providers/terraform-provider-aws/issues/2370))
* resource/aws_cognito_identity_pool_roles_attachment: Fix typo "authenticated" -> "unauthenticated" ([#2358](https://github.com/terraform-providers/terraform-provider-aws/issues/2358))

## 1.3.0 (November 16, 2017)

NOTES:

* resource/aws_redshift_cluster: Field `enable_logging`, `bucket_name` and `s3_key_prefix` were deprecated in favour of a new `logging` block ([#2230](https://github.com/terraform-providers/terraform-provider-aws/issues/2230))
* resource/aws_lb_target_group: We no longer provide defaults for `health_check`'s `path` nor `matcher` in order to support network load balancers where these arguments aren't valid. Creating _new_ ALB will therefore require you to specify these two arguments. Existing deployments are unaffected. ([#2251](https://github.com/terraform-providers/terraform-provider-aws/issues/2251))

FEATURES:

Expand Down
22 changes: 21 additions & 1 deletion aws/ecs_task_definition_equivalency.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package aws
import (
"bytes"
"encoding/json"
"log"
"reflect"
"sort"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/mitchellh/copystructure"
Expand Down Expand Up @@ -34,19 +37,31 @@ func ecsContainerDefinitionsAreEquivalent(def1, def2 string) (bool, error) {
if err != nil {
return false, err
}

canonicalJson2, err := jsonutil.BuildJSON(obj2)
if err != nil {
return false, err
}

return bytes.Compare(canonicalJson1, canonicalJson2) == 0, nil
equal := bytes.Compare(canonicalJson1, canonicalJson2) == 0
if !equal {
log.Printf("[DEBUG] Canonical definitions are not equal.\nFirst: %s\nSecond: %s\n",
canonicalJson1, canonicalJson2)
}
return equal, nil
}

type containerDefinitions []*ecs.ContainerDefinition

func (cd containerDefinitions) Reduce() error {
for i, def := range cd {
// Deal with special fields which have defaults
if def.Cpu != nil && *def.Cpu == 0 {
def.Cpu = nil
}
if def.Essential == nil {
def.Essential = aws.Bool(true)
}
for j, pm := range def.PortMappings {
if pm.Protocol != nil && *pm.Protocol == "tcp" {
cd[i].PortMappings[j].Protocol = nil
Expand All @@ -56,6 +71,11 @@ func (cd containerDefinitions) Reduce() error {
}
}

// Deal with fields which may be re-ordered in the API
sort.Slice(def.Environment, func(i, j int) bool {
return *def.Environment[i].Name < *def.Environment[j].Name
})

// Create a mutable copy
defCopy, err := copystructure.Copy(def)
if err != nil {
Expand Down
253 changes: 253 additions & 0 deletions aws/ecs_task_definition_equivalency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,259 @@ func TestAwsEcsContainerDefinitionsAreEquivalent_portMappings(t *testing.T) {
}
}

func TestAwsEcsContainerDefinitionsAreEquivalent_arrays(t *testing.T) {
cfgRepresention := `
[
{
"name": "wordpress",
"image": "wordpress",
"essential": true,
"links": ["container1", "container2", "container3"],
"portMappings": [
{"containerPort": 80},
{"containerPort": 81},
{"containerPort": 82}
],
"environment": [
{"name": "VARNAME1", "value": "VARVAL1"},
{"name": "VARNAME2", "value": "VARVAL2"},
{"name": "VARNAME3", "value": "VARVAL3"}
],
"extraHosts": [
{"hostname": "host1", "ipAddress": "127.0.0.1"},
{"hostname": "host2", "ipAddress": "127.0.0.2"},
{"hostname": "host3", "ipAddress": "127.0.0.3"}
],
"mountPoints": [
{"sourceVolume": "vol1", "containerPath": "/vol1"},
{"sourceVolume": "vol2", "containerPath": "/vol2"},
{"sourceVolume": "vol3", "containerPath": "/vol3"}
],
"volumesFrom": [
{"sourceContainer": "container1"},
{"sourceContainer": "container2"},
{"sourceContainer": "container3"}
],
"ulimits": [
{
"name": "core",
"softLimit": 10, "hardLimit": 20
},
{
"name": "cpu",
"softLimit": 10, "hardLimit": 20
},
{
"name": "fsize",
"softLimit": 10, "hardLimit": 20
}
],
"linuxParameters": {
"capabilities": {
"add": ["AUDIT_CONTROL", "AUDIT_WRITE", "BLOCK_SUSPEND"],
"drop": ["CHOWN", "IPC_LOCK", "KILL"]
}
},
"devices": [
{
"hostPath": "/path1",
"permissions": ["read", "write", "mknod"]
},
{
"hostPath": "/path2",
"permissions": ["read", "write"]
},
{
"hostPath": "/path3",
"permissions": ["read", "mknod"]
}
],
"dockerSecurityOptions": ["label:one", "label:two", "label:three"],
"memory": 500,
"cpu": 10
},
{
"name": "container1",
"image": "busybox",
"memory": 100
},
{
"name": "container2",
"image": "busybox",
"memory": 100
},
{
"name": "container3",
"image": "busybox",
"memory": 100
}
]`

apiRepresentation := `
[
{
"cpu": 10,
"dockerSecurityOptions": [
"label:one",
"label:two",
"label:three"
],
"environment": [
{
"name": "VARNAME3",
"value": "VARVAL3"
},
{
"name": "VARNAME2",
"value": "VARVAL2"
},
{
"name": "VARNAME1",
"value": "VARVAL1"
}
],
"essential": true,
"extraHosts": [
{
"hostname": "host1",
"ipAddress": "127.0.0.1"
},
{
"hostname": "host2",
"ipAddress": "127.0.0.2"
},
{
"hostname": "host3",
"ipAddress": "127.0.0.3"
}
],
"image": "wordpress",
"links": [
"container1",
"container2",
"container3"
],
"linuxParameters": {
"capabilities": {
"add": [
"AUDIT_CONTROL",
"AUDIT_WRITE",
"BLOCK_SUSPEND"
],
"drop": [
"CHOWN",
"IPC_LOCK",
"KILL"
]
}
},
"memory": 500,
"mountPoints": [
{
"containerPath": "/vol1",
"sourceVolume": "vol1"
},
{
"containerPath": "/vol2",
"sourceVolume": "vol2"
},
{
"containerPath": "/vol3",
"sourceVolume": "vol3"
}
],
"name": "wordpress",
"portMappings": [
{
"containerPort": 80,
"hostPort": 0,
"protocol": "tcp"
},
{
"containerPort": 81,
"hostPort": 0,
"protocol": "tcp"
},
{
"containerPort": 82,
"hostPort": 0,
"protocol": "tcp"
}
],
"ulimits": [
{
"hardLimit": 20,
"name": "core",
"softLimit": 10
},
{
"hardLimit": 20,
"name": "cpu",
"softLimit": 10
},
{
"hardLimit": 20,
"name": "fsize",
"softLimit": 10
}
],
"volumesFrom": [
{
"sourceContainer": "container1"
},
{
"sourceContainer": "container2"
},
{
"sourceContainer": "container3"
}
]
},
{
"cpu": 0,
"environment": [],
"essential": true,
"image": "busybox",
"memory": 100,
"mountPoints": [],
"name": "container1",
"portMappings": [],
"volumesFrom": []
},
{
"cpu": 0,
"environment": [],
"essential": true,
"image": "busybox",
"memory": 100,
"mountPoints": [],
"name": "container2",
"portMappings": [],
"volumesFrom": []
},
{
"cpu": 0,
"environment": [],
"essential": true,
"image": "busybox",
"memory": 100,
"mountPoints": [],
"name": "container3",
"portMappings": [],
"volumesFrom": []
}
]
`

equal, err := ecsContainerDefinitionsAreEquivalent(cfgRepresention, apiRepresentation)
if err != nil {
t.Fatal(err)
}
if !equal {
t.Fatal("Expected definitions to be equal.")
}
}

func TestAwsEcsContainerDefinitionsAreEquivalent_negative(t *testing.T) {
cfgRepresention := `
[
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,7 @@ resource "aws_lb_target_group" "test" {
healthy_threshold = "2"
timeout = "2"
interval = "5"
matcher = "200"
}
tags {
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_batch_job_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func resourceAwsBatchJobQueueDelete(d *schema.ResourceData, meta interface{}) er
_, err = conn.DeleteJobQueue(&batch.DeleteJobQueueInput{
JobQueue: aws.String(sn),
})
if err == nil {
return nil
if err != nil {
return err
}

deleteStateConf := &resource.StateChangeConf{
Expand Down
14 changes: 10 additions & 4 deletions aws/resource_aws_ecr_lifecycle_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSEcrLifecyclePolicy_basic(t *testing.T) {
randString := acctest.RandString(10)
rName := fmt.Sprintf("tf-acc-test-lifecycle-%s", randString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcrLifecyclePolicyDestroy,
Steps: []resource.TestStep{
{
Config: testAccEcrLifecyclePolicyConfig,
Config: testAccEcrLifecyclePolicyConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcrLifecyclePolicyExists("aws_ecr_lifecycle_policy.foo"),
),
Expand Down Expand Up @@ -68,9 +72,10 @@ func testAccCheckAWSEcrLifecyclePolicyExists(name string) resource.TestCheckFunc
}
}

const testAccEcrLifecyclePolicyConfig = `
func testAccEcrLifecyclePolicyConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_ecr_repository" "foo" {
name = "bar"
name = "%s"
}
resource "aws_ecr_lifecycle_policy" "foo" {
repository = "${aws_ecr_repository.foo.name}"
Expand All @@ -94,4 +99,5 @@ resource "aws_ecr_lifecycle_policy" "foo" {
}
EOF
}
`
`, rName)
}
Loading

0 comments on commit b508b13

Please sign in to comment.