Commit c92e80cb authored by craigsands's avatar craigsands Committed by Anton Babenko

Allow multiple subnet ids (#67)

* Allow specifying a list of subnet IDs to iterate instances over
parent e6d2f70e
...@@ -84,6 +84,7 @@ data "aws_ami" "ubuntu-xenial" { ...@@ -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` * `network_interface` can't be specified together with `associate_public_ip_address`, which makes `network_interface`
not configurable using this module at the moment 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). * 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 --> <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs ## Inputs
...@@ -111,7 +112,8 @@ data "aws_ami" "ubuntu-xenial" { ...@@ -111,7 +112,8 @@ data "aws_ami" "ubuntu-xenial" {
| private\_ip | Private IP address to associate with the instance in a VPC | string | `""` | no | | 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 | | 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 | | 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 | | 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 | | 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 | | user\_data | The user data to provide when launching the instance | string | `""` | no |
......
...@@ -11,7 +11,7 @@ resource "aws_instance" "this" { ...@@ -11,7 +11,7 @@ resource "aws_instance" "this" {
ami = "${var.ami}" ami = "${var.ami}"
instance_type = "${var.instance_type}" instance_type = "${var.instance_type}"
user_data = "${var.user_data}" 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}" key_name = "${var.key_name}"
monitoring = "${var.monitoring}" monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"] vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
...@@ -50,7 +50,7 @@ resource "aws_instance" "this_t2" { ...@@ -50,7 +50,7 @@ resource "aws_instance" "this_t2" {
ami = "${var.ami}" ami = "${var.ami}"
instance_type = "${var.instance_type}" instance_type = "${var.instance_type}"
user_data = "${var.user_data}" 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}" key_name = "${var.key_name}"
monitoring = "${var.monitoring}" monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"] vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
......
...@@ -57,6 +57,13 @@ variable "vpc_security_group_ids" { ...@@ -57,6 +57,13 @@ variable "vpc_security_group_ids" {
variable "subnet_id" { variable "subnet_id" {
description = "The VPC Subnet ID to launch in" 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" { variable "associate_public_ip_address" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment