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

module invocations should support count #1471

Closed
EvanKrall opened this issue Apr 9, 2015 · 7 comments
Closed

module invocations should support count #1471

EvanKrall opened this issue Apr 9, 2015 · 7 comments

Comments

@EvanKrall
Copy link
Contributor

I tried to do something like nested loops of sorts by writing code that looks like:

module "group" {
    count = "${var.group_count}"
    source = "./group"
    argument = "${element(split(" ", var.arguments), count.index)}"
}

This results in a crash:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4db834]

goroutine 518 [running]:
github.com/hashicorp/terraform/terraform.(*Interpolater).valueCountVar(0xc2084b74a0, 0xc208439880, 0xc2081cc990, 0xb, 0xc2080bf200, 0xc20843b0b0, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/interpolate.go:89 +0x124
github.com/hashicorp/terraform/terraform.(*Interpolater).Values(0xc2084b74a0, 0xc208439880, 0xc2081d24b0, 0x3, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/interpolate.go:58 +0x5a7
github.com/hashicorp/terraform/terraform.(*BuiltinEvalContext).Interpolate(0xc208081980, 0xc2081c7800, 0x0, 0x0, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/eval_context_builtin.go:208 +0x118
github.com/hashicorp/terraform/terraform.(*EvalInterpolate).Eval(0xc2084397e0, 0x7f4d5e183300, 0xc208081980, 0x0, 0x0, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/eval_interpolate.go:16 +0x68
github.com/hashicorp/terraform/terraform.EvalRaw(0x7f4d5e183550, 0xc2084397e0, 0x7f4d5e183300, 0xc208081980, 0x0, 0x0, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/eval.go:53 +0x254
github.com/hashicorp/terraform/terraform.(*EvalSequence).Eval(0xc208439840, 0x7f4d5e183300, 0xc208081980, 0x0, 0x0, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/eval_sequence.go:10 +0xf9
github.com/hashicorp/terraform/terraform.EvalRaw(0x7f4d5e183500, 0xc208439840, 0x7f4d5e183300, 0xc208081980, 0x0, 0x0, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/eval.go:53 +0x254
github.com/hashicorp/terraform/terraform.Eval(0x7f4d5e183500, 0xc208439840, 0x7f4d5e183300, 0xc208081980, 0x0, 0x0, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/eval.go:34 +0x79
github.com/hashicorp/terraform/terraform.func·027(0x99d460, 0xc20812d980, 0x0, 0x0)
    /root/build/src/github.com/hashicorp/terraform/terraform/graph.go:158 +0x754
github.com/hashicorp/terraform/dag.func·006(0x99d460, 0xc20812d980, 0xc20859d980, 0xc20859dc20)
    /root/build/src/github.com/hashicorp/terraform/dag/dag.go:215 +0x106
created by github.com/hashicorp/terraform/dag.(*AcyclicGraph).Walk
    /root/build/src/github.com/hashicorp/terraform/dag/dag.go:224 +0x845

It would be nice to be able to call a module multiple times, passing different arguments each time.

I think I can get around this with judicious use of count=${inner * outer} and modulo and division, but it feels a bit dirty.

@catsby catsby added the core label Apr 14, 2015
@JeanMertz
Copy link
Contributor

I think I have a use case for this as well:

Given three AWS instances, I want to create a round-robin DNS record at DNSMadeEasy.

Current implementation (using ELB) is:

resource "dme_record" "vpn" {
  domainid = "xxx"
  name = "cluster.${var.stack}.vpn"
  type = "A"
  value = "${aws_eip.vpn.public_ip}"
  ttl = 60
}

What I'd like to do is use aws_instance.vpn.{1,2,3}.public_ip in a dynamic way, where I create a single DNS record with the same name but different IP for each AWS instance.

I believe this is currently not possible, and I also believe that this feature request would solve my problem.

@JeanMertz
Copy link
Contributor

I spoke too soon, my use case is solved using count with the element function:

resource "dme_record" "vpn" {
  count = "${var.vpn_count}"

  domainid = "xxx"
  name = "cluster.${var.stack}.vpn"
  type = "A"
  value = "${element(aws_instance.vpn.*.public_ip, count.index)}"
  ttl = 60
}

@jwthomp
Copy link

jwthomp commented May 15, 2015

I am also hitting the need for count support in modules support. The use case is for using the docker provider to launch swarm agents across a list of nodes. I have put the swarm agent setup in a module to allow for being able to dynamically set up the docker provider based on a list of nodes.

module "agent" {
  source           = "./agent"
  docker_ip        = "${lookup(var.docker_ip, count.index)}"
  docker_port      = "${lookup(var.docker_port, count.index)}"
  swarm_version    = "${var.swarm_version}"
  swarm_token      = "${var.swarm_token}"
  count            = 3
}

NOTE: I've reposted this here as a similar issue on this topic was closed, and figured it would be more useful to attach to an open issue.

@jjshoe
Copy link

jjshoe commented May 20, 2015

My use case is a module with 8 resources used for configuring infrastructure related to applications. For each application I'd like to just adjust things in a tfvars file, and not have to copy/pasta a module call.

@jjshoe
Copy link

jjshoe commented May 20, 2015

#953

@catsby
Copy link
Contributor

catsby commented Nov 8, 2016

Hey Friends – I'm closing this as a duplicate of #953

@ghost
Copy link

ghost commented Apr 20, 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 20, 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

6 participants