Skip to content

Commit

Permalink
Merge pull request #40853 from hashicorp/b-aws_ecs_task_definition.vo…
Browse files Browse the repository at this point in the history
…lume-diffs

r/aws_ecs_task_definition: Correctly detect `volume` differences
  • Loading branch information
ewbankkit authored Jan 10, 2025
2 parents 5dc754e + 10e2736 commit 6170ceb
Show file tree
Hide file tree
Showing 5 changed files with 564 additions and 325 deletions.
3 changes: 3 additions & 0 deletions .changelog/40853.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecs_task_definition: Correctly detect differences in `volume.configure_at_launch` and `volume.docker_volume_configuration`
```
20 changes: 20 additions & 0 deletions internal/sdkv2/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package sdkv2

import (
"maps"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -43,3 +45,21 @@ func SimpleSchemaSetFunc(keys ...string) schema.SchemaSetFunc {
return create.StringHashcode(str.String())
}
}

// HashStringValueMap returns a non-negative hash value for a map[string]string.
func HashStringValueMap(m map[string]string) int {
if len(m) == 0 {
return 0
}

var str strings.Builder

for _, k := range slices.Sorted(maps.Keys(m)) {
str.WriteString(k)
str.WriteRune('=')
str.WriteString(m[k])
str.WriteRune(',')
}

return create.StringHashcode(str.String())
}
23 changes: 22 additions & 1 deletion internal/sdkv2/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestSimpleSchemaSetFuncNil(t *testing.T) {
f := SimpleSchemaSetFunc("key1", "key3", "key4")

if got, want := f(v), 0; got != want {
t.Errorf("SimpleSchemaSetFunc(%q) err %q, want %q", v, got, want)
t.Errorf("SimpleSchemaSetFunc(%q) got %q, want %q", v, got, want)
}
}

Expand Down Expand Up @@ -64,3 +64,24 @@ func TestSimpleSchemaSetFunc(t *testing.T) {
t.Errorf("expected not equal")
}
}

func TestHashStringValueMapNil(t *testing.T) {
t.Parallel()

if got, want := HashStringValueMap(nil), 0; got != want {
t.Errorf("HashStringValueMap(nil) got %d, want %d", got, want)
}
}

func TestHashStringValueMap(t *testing.T) {
t.Parallel()

m := map[string]string{
"Key1": "Value1",
"Key2": "Value2",
}

if got := HashStringValueMap(m); got < 0 {
t.Errorf("HashStringValueMap(%v) got %d", m, got)
}
}
Loading

0 comments on commit 6170ceb

Please sign in to comment.