Skip to content
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

r/aws_ecs_task_definition: Correctly detect volume differences #40853

Merged
merged 13 commits into from
Jan 10, 2025
Merged
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
Loading