Hello, I have created a module that allows me to create systems with a single interface in AWS. I want to use this module to build a 5 node cluster with a single shared IP. Is there a way to add a secondary IP to one of the servers during the provision process.
Here’s what the module looks like.
resource “aws_network_interface” “node” {
count = length(var.node_ips)
subnet_id = var.subnet_id
private_ips = [var.node_ips[count.index]]
security_groups = [var.security_group_id]
source_dest_check = “true”
description = element(var.node_host, count.index)
tags = merge(
local.common_tags,
{
“Name” = element(var.node_host, count.index)
},
)
}
resource “aws_instance” “node_” {
count = length(var.node_ips)
instance_type = var.instance_type
ami = var.ami
key_name = var.key_id
network_interface {
device_index = 0
network_interface_id = element(aws_network_interface.node.*.id, count.index)
}
tags = merge(
local.common_tags,
{
“Name” = element(var.node_host, count.index)
},
)
}
module nodes {
source = “./modules/my_module”
instance_type = “t2.small”
volume_size = “16”
ami = “{module.amis.latest_ubuntu_id}"
key_pair_id = "{module.vpc.key_id}”
subnet_id = “{module.subnet_id}"
security_group_allow_all_id = "{module.vpc.security_group_id}”
availability_zone = “${module.vpc.az}”
node_host = [“system1”, “system2”, “system3”, “system4”, “system5”, “system6”]
node_ips = {
“0” = “x.x.x.1”
“1” = “x.x.x.2”
“2” = “x.x.x.3”
“3” = “x.x.x.4”
“4” = “x.x.x.5”
“5” = “x.x.x.6”
}
}
Ordinarily I would just add the following to the aws_netwwork_interface resource to get the secondary IP.
private_ips = [var.node_ips[count.index], var.node_vip[count.index]]
If I applied this to the module here it would try to add the same IP to each interface of each node and fail. Is there any trick to make this work.
When everything is up I want it to look like the following
system1, eth0: x.x.x.1 and x.x.x.10 (vip)
system2, eth0: x.x.x.2
system3, eth0: x.x.x.3
system4, eth0: x.x.x.4
system5, eth0: x.x.x.5
system6, eth0: x.x.x.6