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

How can use this module to configure each EC2 Instance to use a different AZ #54

Closed
deveshmehta opened this issue Oct 22, 2018 · 5 comments

Comments

@deveshmehta
Copy link

The type of subnet_id is string

subnet_id The VPC Subnet ID to launch in string

So how can use this module to configure each EC2 Instance to use a different AZ?

Thanks in advance.
Devesh

@deveshmehta
Copy link
Author

I manage to solve this by changing the type of subnet_id from string to list (subnet_ids) in variable.tf

variable "subnet_ids" {
description = "The VPC Subnet ID to launch in"
type = "list"
}

Below change in main.tf

subnet_id = "${element(var.subnet_ids,count.index)}"

It is working as expected :)

@veilig2000
Copy link

Why don't you put this into a pull request? Also, how would this work if you are spinning up fewer instances than subnets provided? ie: two instances but only gave a list of one subnet.

@craigsands
Copy link
Contributor

I added the pull request. Terraform uses modular arithmetic with the element function. So if more instances are requested than provided subnet ids, Terraform will just wrap around the list of ids and start from the beginning. See element-list-index.

@antonbabenko
Copy link
Member

Fixed in v1.15.0 by @craigsands

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants