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 1 commit
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
13 changes: 13 additions & 0 deletions internal/service/ecs/container_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ func (cd containerDefinitions) reduce(isAWSVPC bool) {
if def.Essential == nil {
cd[i].Essential = aws.Bool(true)
}
// Replace nil HealthCheck values with default values. For each property, the default value can be found
// in the doc comment for this property.
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 @@
t.Fatal("Expected definitions to be equal.")
}
}

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

cfgRepresentation := `

Check failure on line 631 in internal/service/ecs/container_definitions_test.go

View workflow job for this annotation

GitHub Actions / providerlint

AWSAT003: regions should not be hardcoded, use aws_region and aws_availability_zones data sources instead
[
{
"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": "us-east-1",
"awslogs-stream-prefix": "nginx"
}
}
}
]`

apiRepresentation := `

Check failure on line 657 in internal/service/ecs/container_definitions_test.go

View workflow job for this annotation

GitHub Actions / providerlint

AWSAT003: regions should not be hardcoded, use aws_region and aws_availability_zones data sources instead
[
{
"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": "us-east-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