Skip to content

create multiple instances of modules #673

Closed Answered by arsci
dbd-infra asked this question in How do I
Discussion options

You must be logged in to vote

Hi @dbd-infra, you can use the Terraform for_each argument directly with those modules. Here's a (simplified) example:

The locals block here is just an example input of the for_each argument. You could also set this through variables

This example will create 3 sets of an SQS queue, SNS topic, and connection.

locals {
  to_create = toset(["1","2","3"])
}

module "sqs" {

  for_each = local.to_create

  source = "git::[email protected]:gruntwork-io/terraform-aws-messaging.git//modules/sqs?ref=v0.9.1"

  name = each.key
}

module "sns" {

  for_each = local.to_create

  source = "git::[email protected]:gruntwork-io/terraform-aws-messaging.git//modules/sns?ref=v0.9.1"

  name = each.key
}

module "…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dbd-infra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants