cloudposse / terraform-aws-ecs-container-definition

Terraform module to generate well-formed JSON documents (container definitions) that are passed to the aws_ecs_task_definition Terraform resource
https://cloudposse.com/accelerate
Apache License 2.0
339 stars 244 forks source link

Terraform 0.15 error when specifying bool input #136

Closed darpham closed 3 years ago

darpham commented 3 years ago

Describe the Bug

After upgrading to Terraform 0.15.x , I'm now getting an error while trying to plan my changes. This seems to relate the the bool flag for readOnly within the mount_points inupt. Switching back to 0.14.x and the issue goes away.

Expected Behavior

My terraform plan should work with no issues and changes. No changes. Infrastructure is up-to-date.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create module with mount_points and specify readOnly bool to true or "true"
  2. terraform plan
  3. See error
    mount_points = [
    {
      containerPath = "/this/path"
      sourceVolume = "this_volume"
      readOnly = <"true" OR true>
    }
    ]

Screenshots

Error: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal string into Go struct field MountPoint.MountPoints.ReadOnly of type bool

with aws_ecs_task_definition.this,
on task_definition.tf line ??, in resource "aws_ecs_task_definition" "this":
83:   container_definitions = jsonencode([
84:     module.application_container_def.json_map_object,
85:   ])

Environment (please complete the following information):

borysbabii commented 3 years ago

the same for me, OSX 11.3.1, Apple M1

Terraform v0.15.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.41.0
borysbabii commented 3 years ago

for some reason it works as expected if you explicitly define variable type like this:

variable "mount_points" {
  type = list(object({
    containerPath = string
    sourceVolume  = string
    readOnly      = bool
  }))

  description = "Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`. The `readOnly` key is optional."
  default     = []
}
darpham commented 3 years ago

Thanks @borysbabii, I've created a PR to resolve this https://github.com/cloudposse/terraform-aws-ecs-container-definition/pull/137

antdking commented 3 years ago

Is this actually a Terraform bug? Their docs say the conversion should happen (assuming that jsonencode is just turning true into "true").

I've not seen anything in the Provider/SDK/Terraform changelogs to suggest differently.