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

Allow multiple subnet ids #67

Merged
merged 3 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ data "aws_ami" "ubuntu-xenial" {
* `network_interface` can't be specified together with `associate_public_ip_address`, which makes `network_interface`
not configurable using this module at the moment
* Changes in `ebs_block_device` argument will be ignored. Use [aws_volume_attachment](https://www.terraform.io/docs/providers/aws/r/volume_attachment.html) resource to attach and detach volumes from AWS EC2 instances. See [this example](https://github.com/terraform-aws-modules/terraform-aws-ec2-instance/tree/master/examples/volume-attachment).
* One of `subnet_id` or `subnet_ids` is required. If both are provided, the value of `subnet_id` is prepended to the value of `subnet_ids`.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs
Expand Down Expand Up @@ -111,7 +112,8 @@ data "aws_ami" "ubuntu-xenial" {
| private\_ip | Private IP address to associate with the instance in a VPC | string | `""` | no |
| root\_block\_device | Customize details about the root block device of the instance. See Block Devices below for details | list | `<list>` | no |
| source\_dest\_check | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs. | string | `"true"` | no |
| subnet\_id | The VPC Subnet ID to launch in | string | n/a | yes |
| subnet\_id* | The VPC Subnet ID to launch in | string | `""` | no |
| subnet\_ids* | A list of VPC Subnet IDs to launch in | string | `<list>` | no |
| tags | A mapping of tags to assign to the resource | map | `<map>` | no |
| tenancy | The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host. | string | `"default"` | no |
| user\_data | The user data to provide when launching the instance | string | `""` | no |
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resource "aws_instance" "this" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
user_data = "${var.user_data}"
subnet_id = "${var.subnet_id}"
subnet_id = "${element(distinct(compact(concat(list(var.subnet_id), var.subnet_ids))),count.index)}"
key_name = "${var.key_name}"
monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
Expand Down Expand Up @@ -50,7 +50,7 @@ resource "aws_instance" "this_t2" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
user_data = "${var.user_data}"
subnet_id = "${var.subnet_id}"
subnet_id = "${element(distinct(compact(concat(list(var.subnet_id), var.subnet_ids))),count.index)}"
key_name = "${var.key_name}"
monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
Expand Down
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ variable "vpc_security_group_ids" {

variable "subnet_id" {
description = "The VPC Subnet ID to launch in"
default = ""
}

variable "subnet_ids" {
description = "A list of VPC Subnet IDs to launch in"
default = []
type = "list"
}

variable "associate_public_ip_address" {
Expand Down