Invalid value for "list" parameter: element 0: string required when I am trying to upgrade from TF 0.11.X to 0.12.X

Hello ,

I am facing the errors in TF plan while upgrading from tf 0.11 to tf 0.12

Error: Invalid function argument

on …/…/…/…/resource_module/network/customizable_infosys_vpc/main.tf line 1206, in resource “aws_route53_resolver_rule_association” “this”:
1206: resolver_rule_id = “${flatten(element(compact(concat(var.resolver_rule_ids, list(”“))), count.index))}”
|----------------
| var.resolver_rule_ids is list of list of string with 1 element

Invalid value for “list” parameter: element 0: string required.

Error: Invalid function argument

on …/…/…/…/resource_module/network/customizable_infosys_vpc/main.tf line 1208, in resource “aws_route53_resolver_rule_association” “this”:
1208: name = “${element(compact(concat(var.resolver_rule_ids, list(”“))), count.index)}”
|----------------
| var.resolver_rule_ids is list of list of string with 1 element

Invalid value for “list” parameter: element 0: string required.

Code snippet

This resource module is used in my VPC code.

resource “aws_route53_resolver_rule_association” “this” {
count = “{var.create_rule_association ? var.resolver_rule_count : 0}" resolver_rule_id = "{flatten(element(compact(concat(var.resolver_rule_ids, list(”“))), count.index))}”
vpc_id = “{aws_vpc.this.id}" name = "{element(compact(concat(var.resolver_rule_ids, list(”“))), count.index)}”
}

Can anyone help in this topic to fix the errors.

The forum software has scrambled the formatting of your code. You must surround it in lines containing only ``` to avoid this.

Have you used the terraform 0.12checklist and terraform 0.12upgrade commands as documented in the upgrade guide? Upgrading to Terraform 0.12 | Terraform | HashiCorp Developer

Hello @maxb

I am pasting the code and Error message of terraform plan again.

Code :

main.tf

resource "aws_route53_resolver_rule_association" "this" {

  count            = "${var.create_rule_association ? var.resolver_rule_count : 0}"

  resolver_rule_id = "${element(compact(concat(var.resolver_rule_ids, list(""))), count.index)}"

  vpc_id           = "${aws_vpc.this.id}"

  name             = "${element(compact(concat(var.resolver_rule_ids, list(""))), count.index)}"

}

Variables.tf

variable "resolver_rule_count" {
  default = 0
}

variable "resolver_rule_ids" {
  default = []
  type    = "list"
}

variable "create_rule_association" {
   default = true
 }

Error Message in terraform plan

 on ../../../../resource_module/network/customizable_infosys_vpc/main.tf line 1206, in resource "aws_route53_resolver_rule_association" "this":
1206:   resolver_rule_id = "${flatten(element(compact(concat(var.resolver_rule_ids, list(""))), count.index))}"
    |----------------
    | var.resolver_rule_ids is list of list of string with 1 element
Invalid value for "list" parameter: element 0: string required.

Error: Invalid function argument
  on ../../../../resource_module/network/customizable_infosys_vpc/main.tf line 1206, in resource "aws_route53_resolver_rule_association" "this":
1206:   resolver_rule_id = "${(element(compact(concat(var.resolver_rule_ids, list(""))), count.index)}"
    |----------------
    | var.resolver_rule_ids is list of list of string with 1 element

In my project we are using terraform as docker containers in Jenkins CI /CD pipeline.

We have three type of terraform docker images like 0.11.15, 0.12.9, 0.13.5 in the project.

The above resource module which is defined in vpc code is working well with terraform version 0.11.15, but now I when I am planning to change the dockerized terraform image to 0.12.9 ,it gives error in the resource module while running my CI/CD pipeline.

Most of the Errors on vpc resource module I am able to fix it, but this is some of the errors still present.

Please let me know if anyway it can be fixed.

Please re-read my earlier replies. You either haven’t read them, or haven’t acted on them.

Hi @saurabh71669,

I’ve used my moderator powers to fix the code and error message formatting in your most recent comment.

This module still seems to be using Terraform 0.11-style expressions, which suggests that you haven’t yet migrated it with the upgrade tools.

There is a full guide on the upgrade process for this particular upgrade:

I would suggest starting by following the instructions described there. If you encounter problems while following those instructions I’m happy to try to help, if you share which step of the guide you were following and what messages Terraform produced that the upgrade guide isn’t clear about.

Thanks!