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

Normalize aws_ecs_task_definition healthCheck #38872

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .changelog/38870.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
```release-note:bug
resource/aws_ecs_task_definition: Remove `null`s from `container_definition` array fields
resource/aws_ecs_task_definition: Remove `null`s from `container_definition` array fields
```
3 changes: 3 additions & 0 deletions .changelog/38872.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecs_task_definition: Fix perpetual `container_definitions` diffs on `healthCheck`'s default values
```
16 changes: 15 additions & 1 deletion internal/service/ecs/container_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,25 @@ func (cd containerDefinitions) reduce(isAWSVPC bool) {
// Compact any sparse lists.
cd.compactArrays()

// Deal with special fields which have defaults.
// See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definitions.
for i, def := range cd {
// Deal with special fields which have defaults.
if def.Essential == nil {
cd[i].Essential = aws.Bool(true)
}

if hc := def.HealthCheck; hc != nil {
if hc.Interval == nil {
hc.Interval = aws.Int32(30)
}
if hc.Retries == nil {
hc.Retries = aws.Int32(3)
}
if hc.Timeout == nil {
hc.Timeout = aws.Int32(5)
}
}

for j, pm := range def.PortMappings {
if pm.Protocol == awstypes.TransportProtocolTcp {
cd[i].PortMappings[j].Protocol = ""
Expand Down
73 changes: 73 additions & 0 deletions internal/service/ecs/container_definitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,3 +624,76 @@ func TestContainerDefinitionsAreEquivalent_sparseArrays(t *testing.T) {
t.Fatal("Expected definitions to be equal.")
}
}

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

cfgRepresentation := `
[
{
"cpu": 512,
"environment": [],
"healthCheck": {
"command": [
"CMD-SHELL",
"curl -f http://localhost:8080/health || exit 1"
]
},
"image": "nginx",
"memory": 2048,
"name": "nginx",
"startTimeout": 10,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "foo-bar-e196c99",
"awslogs-region": "region-1",
"awslogs-stream-prefix": "nginx"
}
}
}
]`

apiRepresentation := `
[
{
"cpu": 512,
"environment": [],
"essential": true,
"healthCheck": {
"command": [
"CMD-SHELL",
"curl -f http://localhost:8080/health || exit 1"
],
"interval": 30,
"retries": 3,
"timeout": 5
},
"image": "nginx",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "foo-bar-e196c99",
"awslogs-region": "region-1",
"awslogs-stream-prefix": "nginx"
}
},
"memory": 2048,
"mountPoints": [],
"name": "nginx",
"portMappings": [],
"startTimeout": 10,
"systemControls": [],
"volumesFrom": []
}
]
`

equal, err := containerDefinitionsAreEquivalent(cfgRepresentation, apiRepresentation, false)
if err != nil {
t.Fatal(err)
}
if !equal {
t.Fatal("Expected definitions to be equal.")
}
}
Loading