Skip to content

Commit

Permalink
Fixed when private_ips is empty (fixed #103)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko committed Jun 15, 2019
1 parent cbc3bb2 commit bc0a43c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
21 changes: 11 additions & 10 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ module "ec2" {

instance_count = 2

name = "example-normal"
ami = data.aws_ami.amazon_linux.id
instance_type = "c5.large"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
private_ip = ["123.0.0.1", "123.0.0.2"]
name = "example-normal"
ami = data.aws_ami.amazon_linux.id
instance_type = "c5.large"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
// private_ips = ["172.31.32.5", "172.31.46.20"]
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true
placement_group = aws_placement_group.web.id
Expand All @@ -90,11 +90,12 @@ module "ec2_with_t2_unlimited" {

instance_count = 1

name = "example-t2-unlimited"
ami = data.aws_ami.amazon_linux.id
instance_type = "t2.micro"
cpu_credits = "unlimited"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
name = "example-t2-unlimited"
ami = data.aws_ami.amazon_linux.id
instance_type = "t2.micro"
cpu_credits = "unlimited"
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
// private_ip = "172.31.32.10"
vpc_security_group_ids = [module.security_group.this_security_group_id]
associate_public_ip_address = true
}
Expand Down
20 changes: 6 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ resource "aws_instance" "this" {
iam_instance_profile = var.iam_instance_profile

associate_public_ip_address = var.associate_public_ip_address
private_ip = element(
distinct(compact(concat([var.private_ip], var.private_ips))),
count.index,
)
ipv6_address_count = var.ipv6_address_count
ipv6_addresses = var.ipv6_addresses
private_ip = length(var.private_ips) > 0 ? element(var.private_ips, count.index) : var.private_ip
ipv6_address_count = var.ipv6_address_count
ipv6_addresses = var.ipv6_addresses

ebs_optimized = var.ebs_optimized

Expand Down Expand Up @@ -90,7 +87,6 @@ resource "aws_instance" "this" {
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments
ignore_changes = [
private_ip,
root_block_device,
ebs_block_device,
]
Expand All @@ -113,12 +109,9 @@ resource "aws_instance" "this_t2" {
iam_instance_profile = var.iam_instance_profile

associate_public_ip_address = var.associate_public_ip_address
private_ip = element(
distinct(compact(concat([var.private_ip], var.private_ips))),
count.index,
)
ipv6_address_count = var.ipv6_address_count
ipv6_addresses = var.ipv6_addresses
private_ip = length(var.private_ips) > 0 ? element(var.private_ips, count.index) : var.private_ip
ipv6_address_count = var.ipv6_address_count
ipv6_addresses = var.ipv6_addresses

ebs_optimized = var.ebs_optimized

Expand Down Expand Up @@ -183,7 +176,6 @@ resource "aws_instance" "this_t2" {
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments
ignore_changes = [
private_ip,
root_block_device,
ebs_block_device,
]
Expand Down

0 comments on commit bc0a43c

Please sign in to comment.