Skip to content

Commit

Permalink
Fixed #51. t2 and t3 instances can be unlimited
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko committed Oct 6, 2018
1 parent fcf0c6e commit 936c26a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 15 additions & 1 deletion examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module "ec2" {
module "ec2_with_t2_unlimited" {
source = "../../"

instance_count = 2
instance_count = 1

name = "example-t2-unlimited"
ami = "${data.aws_ami.amazon_linux.id}"
Expand All @@ -76,3 +76,17 @@ module "ec2_with_t2_unlimited" {
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
associate_public_ip_address = true
}

module "ec2_with_t3_unlimited" {
source = "../../"

instance_count = 1

name = "example-t3-unlimited"
ami = "${data.aws_ami.amazon_linux.id}"
instance_type = "t3.large"
cpu_credits = "unlimited"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
vpc_security_group_ids = ["${module.security_group.this_security_group_id}"]
associate_public_ip_address = true
}
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
locals {
is_t2_instance_type = "${replace(var.instance_type, "/^t2\\..*$/", "1") == "1" ? "1" : "0"}"
is_t_instance_type = "${replace(var.instance_type, "/^t[23]{1}\\..*$/", "1") == "1" ? "1" : "0"}"
}

######
# Note: network_interface can't be specified together with associate_public_ip_address
######
resource "aws_instance" "this" {
count = "${var.instance_count * (1 - local.is_t2_instance_type)}"
count = "${var.instance_count * (1 - local.is_t_instance_type)}"

ami = "${var.ami}"
instance_type = "${var.instance_type}"
Expand Down Expand Up @@ -45,7 +45,7 @@ resource "aws_instance" "this" {
}

resource "aws_instance" "this_t2" {
count = "${var.instance_count * local.is_t2_instance_type}"
count = "${var.instance_count * local.is_t_instance_type}"

ami = "${var.ami}"
instance_type = "${var.instance_type}"
Expand Down

0 comments on commit 936c26a

Please sign in to comment.