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

Error: Invalid value for module argument #72

Closed
jeremywadsack opened this issue Dec 16, 2019 · 1 comment
Closed

Error: Invalid value for module argument #72

jeremywadsack opened this issue Dec 16, 2019 · 1 comment

Comments

@jeremywadsack
Copy link
Contributor

When trying to migrate our configuration to 3.0.0, I ran into a syntax/type error. I tested this using the example from the documentation and it produces the same error:

Error: Invalid value for module argument

  on gclb/main.tf line 35, in module "gce-lb-https":
  35:   backends = {
  36:     default = {
  37:       description                     = null
  38:       protocol                        = "HTTP"
  39:       port                            = 443
  40:       port_name                       = "default-https"
  41:       timeout_sec                     = 10
  42:       connection_draining_timeout_sec = null
  43:       enable_cdn                      = false
  45:       health_check = {
  46:         check_interval_sec  = null
  47:         timeout_sec         = null
  48:         healthy_threshold   = null
  49:         unhealthy_threshold = null
  50:         request_path        = "/"
  51:         port                = 443
  52:         host                = null
  53:       }
  55:       groups = [
  56:         {
  57:           # Each node pool instance group should be added to the backend.
  58:           group                        = var.backend
  59:           balancing_mode               = null
  60:           capacity_scaler              = null
  61:           description                  = null
  62:           max_connections              = null
  63:           max_connections_per_instance = null
  64:           max_connections_per_endpoint = null
  65:           max_rate                     = null
  66:           max_rate_per_instance        = null
  67:           max_rate_per_endpoint        = null
  68:           max_utilization              = null
  69:         },
  70:       ]
  71:     }
  72:   }

The given value is not suitable for child module variable "backends" defined
at
.terraform/modules/lb.gce-lb-https/terraform-google-modules-terraform-google-lb-http-d65708d/variables.tf:62,1-20:
element "default": attribute "protocol": string required.

The error message at the end ("element "default": attribute "protocol": string required.") changes from one attribute to another when I re-run terraform apply:

element "default": attribute "protocol": string required.
element "default": attribute "enable_cdn": bool required.
element "default": attribute "timeout_sec": number required.
element "default": attribute "port": number required.

No matter what the message is, the type always is correct. e.g. in the error above, you see protocol is "HTTP", which is a string.

I've got the latest terraform:

$ terraform --version
Terraform v0.12.18

And I've pinned GoogleCloudPlatform/lb-http/google at version 3.0.0 (clearly because when I try 2.0.0 I get "argument "backend_params" is required" error which makes sense because that syntax changed).

Any ideas where to look on this one? I'm kinda stumped.

@jeremywadsack
Copy link
Contributor Author

I have resolved this.

The errors were not pointing to the correct invalid value. The problem I had was that var.backend was a list(string) rather than a string. My solution was to map this:

       groups = [
         # Each node pool instance group should be added to the backend.
         for backend in var.backend:
         {
           group                        = backend
           balancing_mode               = null
           ...
         }
       ]

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

No branches or pull requests

1 participant