Skip to content

Commit 9d31a73

Browse files
authored
Added support for the list of private_ips (fixes #102) (#103)
1 parent f43568f commit 9d31a73

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

examples/basic/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module "ec2" {
6767
ami = data.aws_ami.amazon_linux.id
6868
instance_type = "c5.large"
6969
subnet_id = tolist(data.aws_subnet_ids.all.ids)[0]
70+
private_ip = ["123.0.0.1", "123.0.0.2"]
7071
vpc_security_group_ids = [module.security_group.this_security_group_id]
7172
associate_public_ip_address = true
7273
placement_group = aws_placement_group.web.id

main.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ resource "aws_instance" "this" {
2424
iam_instance_profile = var.iam_instance_profile
2525

2626
associate_public_ip_address = var.associate_public_ip_address
27-
private_ip = var.private_ip
28-
ipv6_address_count = var.ipv6_address_count
29-
ipv6_addresses = var.ipv6_addresses
27+
private_ip = element(
28+
distinct(compact(concat([var.private_ip], var.private_ips))),
29+
count.index,
30+
)
31+
ipv6_address_count = var.ipv6_address_count
32+
ipv6_addresses = var.ipv6_addresses
3033

3134
ebs_optimized = var.ebs_optimized
3235

@@ -110,9 +113,12 @@ resource "aws_instance" "this_t2" {
110113
iam_instance_profile = var.iam_instance_profile
111114

112115
associate_public_ip_address = var.associate_public_ip_address
113-
private_ip = var.private_ip
114-
ipv6_address_count = var.ipv6_address_count
115-
ipv6_addresses = var.ipv6_addresses
116+
private_ip = element(
117+
distinct(compact(concat([var.private_ip], var.private_ips))),
118+
count.index,
119+
)
120+
ipv6_address_count = var.ipv6_address_count
121+
ipv6_addresses = var.ipv6_addresses
116122

117123
ebs_optimized = var.ebs_optimized
118124

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ variable "private_ip" {
9090
default = ""
9191
}
9292

93+
variable "private_ips" {
94+
description = "A list of private IP address to associate with the instance in a VPC. Should match the number of instances."
95+
type = list(string)
96+
default = []
97+
}
98+
9399
variable "source_dest_check" {
94100
description = "Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs."
95101
type = bool

0 commit comments

Comments
 (0)