Skip to content

Commit aeeba70

Browse files
authoredNov 26, 2024··
fix(aws): change CPU and Memory type of ContainerDefinition to a string (#7995)
1 parent 4cfb2a9 commit aeeba70

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed
 

‎pkg/iac/adapters/cloudformation/aws/ecs/ecs_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Resources:
3232
-
3333
Name: "busybox"
3434
Image: "busybox"
35-
Cpu: 256
36-
Memory: 512
35+
Cpu: "256"
36+
Memory: "512"
3737
Essential: true
3838
Privileged: true
3939
Environment:
@@ -68,8 +68,8 @@ Resources:
6868
{
6969
Name: types.StringTest("busybox"),
7070
Image: types.StringTest("busybox"),
71-
CPU: types.IntTest(256),
72-
Memory: types.IntTest(512),
71+
CPU: types.StringTest("256"),
72+
Memory: types.StringTest("512"),
7373
Essential: types.BoolTest(true),
7474
Privileged: types.BoolTest(true),
7575
Environment: []ecs.EnvVar{

‎pkg/iac/adapters/cloudformation/aws/ecs/task_definition.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func getContainerDefinitions(r *parser.Resource) ([]ecs.ContainerDefinition, err
4545
Metadata: containerDef.Metadata(),
4646
Name: containerDef.GetStringProperty("Name"),
4747
Image: containerDef.GetStringProperty("Image"),
48-
CPU: containerDef.GetIntProperty("Cpu"),
49-
Memory: containerDef.GetIntProperty("Memory"),
48+
CPU: containerDef.GetStringProperty("Cpu"),
49+
Memory: containerDef.GetStringProperty("Memory"),
5050
Essential: containerDef.GetBoolProperty("Essential"),
5151
Privileged: containerDef.GetBoolProperty("Privileged"),
5252
Environment: envVars,

‎pkg/iac/adapters/terraform/aws/ecs/adapt_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ func Test_adaptTaskDefinitionResource(t *testing.T) {
9191
"name": "my_service",
9292
"image": "my_image",
9393
"essential": true,
94-
"memory": 256,
95-
"cpu": 2,
94+
"memory": "256",
95+
"cpu": "2",
9696
"environment": [
9797
{ "name": "ENVIRONMENT", "value": "development" }
9898
]
@@ -125,8 +125,8 @@ func Test_adaptTaskDefinitionResource(t *testing.T) {
125125
Metadata: iacTypes.NewTestMetadata(),
126126
Name: iacTypes.String("my_service", iacTypes.NewTestMetadata()),
127127
Image: iacTypes.String("my_image", iacTypes.NewTestMetadata()),
128-
CPU: iacTypes.Int(2, iacTypes.NewTestMetadata()),
129-
Memory: iacTypes.Int(256, iacTypes.NewTestMetadata()),
128+
CPU: iacTypes.String("2", iacTypes.NewTestMetadata()),
129+
Memory: iacTypes.String("256", iacTypes.NewTestMetadata()),
130130
Essential: iacTypes.Bool(true, iacTypes.NewTestMetadata()),
131131
Privileged: iacTypes.Bool(false, iacTypes.NewTestMetadata()),
132132
Environment: []ecs.EnvVar{

‎pkg/iac/providers/aws/ecs/ecs.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func CreateDefinitionsFromString(metadata iacTypes.Metadata, str string) ([]Cont
4343
type containerDefinitionJSON struct {
4444
Name string `json:"name"`
4545
Image string `json:"image"`
46-
CPU int `json:"cpu"`
47-
Memory int `json:"memory"`
46+
CPU string `json:"cpu"`
47+
Memory string `json:"memory"`
4848
Essential bool `json:"essential"`
4949
PortMappings []portMappingJSON `json:"portMappings"`
5050
EnvVars []envVarJSON `json:"environment"`
@@ -77,8 +77,8 @@ func (j containerDefinitionJSON) convert(metadata iacTypes.Metadata) ContainerDe
7777
Metadata: metadata,
7878
Name: iacTypes.String(j.Name, metadata),
7979
Image: iacTypes.String(j.Image, metadata),
80-
CPU: iacTypes.Int(j.CPU, metadata),
81-
Memory: iacTypes.Int(j.Memory, metadata),
80+
CPU: iacTypes.String(j.CPU, metadata),
81+
Memory: iacTypes.String(j.Memory, metadata),
8282
Essential: iacTypes.Bool(j.Essential, metadata),
8383
PortMappings: mappings,
8484
Environment: envVars,
@@ -87,13 +87,11 @@ func (j containerDefinitionJSON) convert(metadata iacTypes.Metadata) ContainerDe
8787
}
8888

8989
type ContainerDefinition struct {
90-
Metadata iacTypes.Metadata
91-
Name iacTypes.StringValue
92-
Image iacTypes.StringValue
93-
// TODO: CPU and Memory are strings
94-
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html#cfn-ecs-taskdefinition-cpu
95-
CPU iacTypes.IntValue
96-
Memory iacTypes.IntValue
90+
Metadata iacTypes.Metadata
91+
Name iacTypes.StringValue
92+
Image iacTypes.StringValue
93+
CPU iacTypes.StringValue
94+
Memory iacTypes.StringValue
9795
Essential iacTypes.BoolValue
9896
PortMappings []PortMapping
9997
Environment []EnvVar

‎pkg/iac/rego/schemas/cloud.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@
18591859
},
18601860
"cpu": {
18611861
"type": "object",
1862-
"$ref": "#/definitions/github.com.aquasecurity.trivy.pkg.iac.types.IntValue"
1862+
"$ref": "#/definitions/github.com.aquasecurity.trivy.pkg.iac.types.StringValue"
18631863
},
18641864
"environment": {
18651865
"type": "array",
@@ -1878,7 +1878,7 @@
18781878
},
18791879
"memory": {
18801880
"type": "object",
1881-
"$ref": "#/definitions/github.com.aquasecurity.trivy.pkg.iac.types.IntValue"
1881+
"$ref": "#/definitions/github.com.aquasecurity.trivy.pkg.iac.types.StringValue"
18821882
},
18831883
"name": {
18841884
"type": "object",

‎pkg/iac/scanners/terraform/scanner_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,15 @@ resource "aws_ecs_task_definition" "test" {
284284
[
285285
{
286286
"privileged": true,
287-
"cpu": 10,
287+
"cpu": "10",
288288
"command": ["sleep", "10"],
289289
"entryPoint": ["/"],
290290
"environment": [
291291
{"name": "VARNAME", "value": "VARVAL"}
292292
],
293293
"essential": true,
294294
"image": "jenkins",
295-
"memory": 128,
295+
"memory": "128",
296296
"name": "jenkins",
297297
"portMappings": [
298298
{

0 commit comments

Comments
 (0)
Please sign in to comment.