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

panic trying to use nested maps in 0.7_rc2 #7637

Closed
pccowboy opened this issue Jul 14, 2016 · 6 comments
Closed

panic trying to use nested maps in 0.7_rc2 #7637

pccowboy opened this issue Jul 14, 2016 · 6 comments

Comments

@pccowboy
Copy link

pccowboy commented Jul 14, 2016

Terraform Version

dswift@bebox terraform (chore-121334261)*$ terraform --version
Terraform v0.7.0-rc2 (46a0709)

Affected Resource(s)

N/A

Terraform Configuration Files

dswift@bebox terraform (chore-121334261)*$ cat t/test.tf
variable db_replica_alarms {
    default = {
      "total" = {
         "count" = "2"
         "take" = "2"
      }
      "0" = {
        "0"="a"
        "1"="b"
        "desc" = "one desc"
      }
      "1" = {
        "2"="c"
        "3"="d"
        "desc" = "two desc"
      }
      "2" = {
        "4" = "e"
        "5"="f"
        "desc" = "three desc"
      }
      "desc" = {
        "0" = "one d"
        "1" = "two d"
        "2" = "tre d"
      }
    }
}

resource "aws_cloudwatch_metric_alarm" "replica_alarms" {
    count = "${element(var.db_replica_alarms["total"], 0)}"

    alarm_description = "${lookup(var.db_replica_alarms[count.index], "desc")}"
}

Debug Output

https://gist.github.com/pccowboy/c9d4e9f94ec404a718f745b2053351a5

Panic Output

https://gist.github.com/pccowboy/c9d4e9f94ec404a718f745b2053351a5

Expected Behavior

Trying to figure out how to access a variable in a nested map. I expected an error, due to the aws_cloudwatch_metric_alarm resource being incomplete.

Actual Behavior

crash

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan t

Important Factoids

N/A

References

N/A

@pccowboy
Copy link
Author

Prior to this crash, the config file looked like this:

variable db_replica_alarms {
    default = {
      "total" = {
         "count" = "2"
         "take" = "2"
      }
      "0" = {
        "0"="a"
        "1"="b"
        "desc" = "one desc"
      }
      "1" = {
        "2"="c"
        "3"="d"
        "desc" = "two desc"
      }
      "2" = {
        "4" = "e"
        "5"="f"
        "desc" = "three desc"
      }
      "desc" = {
        "0" = "one d"
        "1" = "two d"
        "2" = "tre d"
      }
    }
}

resource "aws_cloudwatch_metric_alarm" "replica_alarms" {
    count = "${lookup(var.db_replica_alarms["total"], "count")}"

    alarm_description = "${lookup(var.db_replica_alarms[count.index], "desc")}"
}

and gave this error:

dswift@bebox terraform (chore-121334261)*$ terraform plan t
provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Default: us-east-1
  Enter a value:

Error configuring: 1 error(s) occurred:

* At column 3, line 1: lookup: argument 1 should be type map, got type list in:

${lookup(var.db_replica_alarms["total"], "count")}

@jen20
Copy link
Contributor

jen20 commented Jul 14, 2016

Thanks for the report, @pccowboy! I can reproduce this (though slightly differently) with the master branch and will investigate today.

@jen20 jen20 added the crash label Jul 14, 2016
@jen20
Copy link
Contributor

jen20 commented Jul 14, 2016

Hi @pccowboy! I'll address the panic soon, but the correct way to do this is as follows:

variable "db_replica_alarms_totals" {
    type = "map"
    default = {
        count = "2"
        take = "2"
    }
}

variable "db_replica_alarms_settings" {
    type = "list"
    default = [
        {
            "0" = "a"
            "1" = "b"
            "desc" = "one desc"
        },
        {
            "0" = "c"
            "1" = "d"
            "desc" = "two desc"
        },
    ]
}

resource "aws_cloudwatch_metric_alarm" "replica_alarms" {
    count = "${var.db_replica_alarms_totals["count"]}"

    alarm_description = "${lookup(var.db_replica_alarms_settings[count.index], "desc")}"
}

@pccowboy
Copy link
Author

@jen20 Thanks for the pointer, I am still wrapping my head around HCL and terraform. I had similar code working in 0.6.16, but in that version each map in db_replica_alarms_settings was a separate variable - one for description, one for action, etc. My old Perl habits were hoping to intermix objects in 0.7 a bit more than I maybe should hope for.

Looking forward to 0.7 GA, thanks again!

@jen20
Copy link
Contributor

jen20 commented Jul 28, 2016

The panic is fixed by #7834. Thanks for reporting @pccowboy!

@jen20 jen20 closed this as completed Jul 28, 2016
@ghost
Copy link

ghost commented Apr 23, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants