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

fix: strengthen types, simplify logic #154

Merged
merged 5 commits into from
Jun 7, 2023

Conversation

obataku
Copy link
Contributor

@obataku obataku commented Aug 9, 2022

what

  • enable & use optional attributes where AWS API marks fields optional
  • remove redundant lookups
  • strengthen types for log_configuration, repository_credentials, system_controls, container_definition
  • reorder object var attributes to match AWS docs
  • simplify log configuration sanitization/munging
  • simplify secret & environment var sorting
  • expose unencoded container definition output directly without requiring pointless jsonencode/jsondecode cycle

why

  • optional obviates lookup(..., null) calls for objects
  • lookup(o, k) without a default is deprecated in favor of o[k] or direct attr access (o.k)
  • log_configuration, repository_credentials, and system_controls had needlessly opaque any types which hinder DX and make subtle bugs more likely (e.g. in the types of log_configuration.options values)
  • since all attributes of container_definition are now typed there's no reason not to type it as well
  • following the AWS documentation's field order makes types easier to verify for completeness & correctness
  • typing log_configuration appropriately obviates explicit tostring & null handling; resolves Log Configuration Options should be options #151
  • env/secret map sorting can be dramatically simplified since for-expressions iterate over maps & objects by key in lexicographic order
  • jsonencode-ing the final container definition only to jsondecode for json_map_object is redundant

* enable & use optional attrs
* strengthen types for log_configuration, repository_credentials, system_controls, container_definition
* rm redundant lookups
* simplify secret & environment var sorting
@obataku obataku requested review from a team as code owners August 9, 2022 04:01
}))
description = "A list of VolumesFrom maps which contain \"sourceContainer\" (name of the container that has the volumes to mount) and \"readOnly\" (whether the container can write to the volume)"
default = []
default = null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description = "Container mount points. This is a list of maps, where each map should contain `containerPath`, `sourceVolume` and `readOnly`"
default = []
default = null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description = "Log configuration options to send to a custom log driver for the container. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html"
default = null
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html
variable "firelens_configuration" {
type = object({
options = optional(map(string))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop = list(string)
})
devices = list(object({
capabilities = optional(object({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@nitrocode nitrocode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see discussion in cloudposse/terraform-aws-ecs-web-app#189

@Gowiem
Copy link
Member

Gowiem commented Apr 24, 2023

@obataku can you get back to Nitro's requested changes and deal with the branch conflicts that you have? And if no longer relevant, feel free to close out. Thanks!

@goruha goruha self-assigned this Jun 7, 2023
@goruha
Copy link
Member

goruha commented Jun 7, 2023

/terratest

@goruha goruha changed the base branch from main to strict-types June 7, 2023 11:45
@goruha
Copy link
Member

goruha commented Jun 7, 2023

@obataku
Thanks for your contribution.

I merged your PR into the feature branch to polish the code, fix conflicts and will merge it into the main branch and cut new release

@goruha goruha merged commit 0e6ea24 into cloudposse:strict-types Jun 7, 2023
goruha added a commit that referenced this pull request Jun 9, 2023
* fix: strengthen types, simplify logic (#154)

* fix: strengthen types, simplify logic

* enable & use optional attrs
* strengthen types for log_configuration, repository_credentials, system_controls, container_definition
* rm redundant lookups
* simplify secret & environment var sorting

* Auto Format

* fix: address missing optional; update examples/complete

* Auto Format

---------

Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>
Co-authored-by: Igor Rodionov <goruha@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andriy Knysh <aknysh@users.noreply.github.com>
Co-authored-by: obataku <19821199+obataku@users.noreply.github.com>
Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Andriy Knysh <aknysh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log Configuration Options should be options
5 participants