I've set the following via Terraform:
Task-definition level:
network_mode = "bridge"
Container level:
portMappings = [
{
hostPort = 0,
containerPort = 8080
}
]
Terraform will check state and ask me to confirm, but then fail:
Error: port should be set when target type is instance
This structure seems to be the general theme of all of the dozens of subtly-conflicting recommendations on Google.
It's not even clear where/how/if I am expected to provide containerPortRange
. It doesn't seem necessary, seems often not mentioned, but seems like it'd be a great idea. That said, based on the naming ("container" vs "host"), it seems like it's supposed to represent the port on the container and this seems like the one place that it really shouldn't matter. Some clarification on this would be appreciated.
Note that there's a chance that "awsvpc" should work just as well as "bridge":
However, when I use "awsvpc", I get both the above error as well as this one (two separate paragraphs):
Error: creating ECS Task Definition (sellback-website-staging): ClientException: When networkMode=awsvpc, the host ports and container ports in port mappings must match.
I've lost so much time on this one thing over all of the times that I've tried to accomplish it that it's pretty frustrating. I'm having to maintain a wasteful number of EC2 instances to compensate.
If someone could even provide an example of doing this via Terraform as a form of documentation, it might squash almost all questions at once.