Skip to content

Commit

Permalink
Merge pull request #19666 from hashicorp/b-aws_batch_job_definition-r…
Browse files Browse the repository at this point in the history
…ecreate

r/aws_batch_job_definition: Match equivalency of `null` and `[]` for `linuxParameters.devices` and `linuxParameters.tmpfs`
  • Loading branch information
ewbankkit authored Jun 9, 2021
2 parents 3e886e7 + cb49ce0 commit 7c13773
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/19666.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_batch_job_definition: Suppress differences for empty `linuxParameters.devices` and `linuxParameters.tmpfs` arrays in the `container_properties` argument
```
26 changes: 26 additions & 0 deletions aws/internal/service/batch/equivalency/container_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,34 @@ func (cp *containerProperties) Reduce() error {
}
}

if cp.LinuxParameters != nil {
if len(cp.LinuxParameters.Devices) == 0 {
cp.LinuxParameters.Devices = nil
}

for _, device := range cp.LinuxParameters.Devices {
if len(device.Permissions) == 0 {
device.Permissions = nil
}
}

if len(cp.LinuxParameters.Tmpfs) == 0 {
cp.LinuxParameters.Tmpfs = nil
}

for _, tmpfs := range cp.LinuxParameters.Tmpfs {
if len(tmpfs.MountOptions) == 0 {
tmpfs.MountOptions = nil
}
}
}

// Prevent difference of API response that adds an empty array when not configured during the request
if cp.LogConfiguration != nil {
if len(cp.LogConfiguration.Options) == 0 {
cp.LogConfiguration.Options = nil
}

if len(cp.LogConfiguration.SecretOptions) == 0 {
cp.LogConfiguration.SecretOptions = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,89 @@ func TestEquivalentBatchContainerPropertiesJSON(t *testing.T) {
}
]
}
`,
ExpectEquivalent: true,
},
{
Name: "empty linuxParameters.devices, linuxParameters.tmpfs, logConfiguration.options",
ApiJson: `
{
"image": "123.dkr.ecr.us-east-1.amazonaws.com/my-app",
"vcpus": 1,
"memory": 4096,
"jobRoleArn": "arn:aws:iam::123:role/role-test",
"environment": [{"name":"ENVIRONMENT","value":"test"}],
"linuxParameters": {
"devices": [],
"initProcessEnabled": true,
"tmpfs": []
},
"logConfiguration": {
"logDriver": "awslogs",
"options": {}
}
}
`,
ConfigurationJson: `
{
"image": "123.dkr.ecr.us-east-1.amazonaws.com/my-app",
"vcpus": 1,
"memory": 4096,
"jobRoleArn": "arn:aws:iam::123:role/role-test",
"environment": [{"name":"ENVIRONMENT","value":"test"}],
"linuxParameters": {
"initProcessEnabled": true
},
"logConfiguration": {
"logDriver": "awslogs"
}
}
`,
ExpectEquivalent: true,
},
{
Name: "empty linuxParameters.devices.permissions, linuxParameters.tmpfs.mountOptions",
ApiJson: `
{
"image": "123.dkr.ecr.us-east-1.amazonaws.com/my-app",
"vcpus": 1,
"memory": 4096,
"jobRoleArn": "arn:aws:iam::123:role/role-test",
"environment": [{"name":"ENVIRONMENT","value":"test"}],
"linuxParameters": {
"devices": [{
"containerPath": "/test",
"hostPath": "/tmp",
"permissions": []
}],
"initProcessEnabled": true,
"tmpfs": [{
"containerPath": "/tmp",
"mountOptions": [],
"size": 4096
}]
}
}
`,
ConfigurationJson: `
{
"image": "123.dkr.ecr.us-east-1.amazonaws.com/my-app",
"vcpus": 1,
"memory": 4096,
"jobRoleArn": "arn:aws:iam::123:role/role-test",
"environment": [{"name":"ENVIRONMENT","value":"test"}],
"linuxParameters": {
"devices": [{
"containerPath": "/test",
"hostPath": "/tmp"
}],
"initProcessEnabled": true,
"tmpfs": [{
"containerPath": "/tmp",
"size": 4096
}]
}
}
`,
ExpectEquivalent: true,
},
Expand Down

0 comments on commit 7c13773

Please sign in to comment.