Skip to content

Commit

Permalink
matching the network_interface attachment
Browse files Browse the repository at this point in the history
- Cloudformation has the network interfaces added at the time of the instance creation
  • Loading branch information
zachreborn committed Oct 8, 2024
1 parent f6335d2 commit d3efc8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
38 changes: 17 additions & 21 deletions modules/aws/vendor/velocloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ resource "aws_security_group" "velocloud_lan_sg" {
# EIP
############################################

# Per the documentation, the MGMT interface does not require an EIP
# resource "aws_eip" "mgmt_external_ip" {
# count = var.number
# domain = "vpc"
# }

# resource "aws_eip_association" "mgmt_external_ip" {
# count = var.number
# allocation_id = element(aws_eip.mgmt_external_ip[*].id, count.index)
# network_interface_id = element(aws_network_interface.mgmt_nic[*].id, count.index)
# }

resource "aws_eip" "wan_external_ip" {
count = var.number
domain = "vpc"
Expand Down Expand Up @@ -151,10 +139,6 @@ resource "aws_network_interface" "public_nic" {
source_dest_check = var.source_dest_check
subnet_id = element(var.public_subnet_ids, count.index)
tags = merge(var.tags, ({ "Name" = format("%s%d_public", var.instance_name_prefix, count.index + 1) }))
attachment {
instance = element(aws_instance.ec2_instance[*].id, count.index)
device_index = 1
}
}

resource "aws_network_interface" "private_nic" {
Expand All @@ -166,18 +150,14 @@ resource "aws_network_interface" "private_nic" {
source_dest_check = var.source_dest_check
subnet_id = element(var.private_subnet_ids, count.index)
tags = merge(var.tags, ({ "Name" = format("%s%d_private", var.instance_name_prefix, count.index + 1) }))

attachment {
instance = element(aws_instance.ec2_instance[*].id, count.index)
device_index = 2
}
}

############################################
# EC2 Instance
############################################

resource "aws_instance" "ec2_instance" {

ami = data.aws_ami.velocloud.id
count = var.number
ebs_optimized = var.ebs_optimized
Expand All @@ -204,11 +184,27 @@ resource "aws_instance" "ec2_instance" {
device_index = 0
}

network_interface {
network_interface_id = element(aws_network_interface.public_nic[*].id, count.index)
device_index = 1
}

network_interface {
network_interface_id = element(aws_network_interface.private_nic[*].id, count.index)
device_index = 2
}

root_block_device {
volume_type = var.root_volume_type
volume_size = var.root_volume_size
encrypted = var.root_ebs_volume_encrypted
}

depends_on = [
aws_network_interface.mgmt_nic,
aws_network_interface.public_nic,
aws_network_interface.private_nic
]
}

###################################################
Expand Down
9 changes: 0 additions & 9 deletions modules/aws/vendor/velocloud/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ output "ec2_instance_id" {
value = aws_instance.ec2_instance[*].id
}

# Per the documentation, the MGMT interface does not require an EIP
# output "mgmt_eip_id" {
# value = aws_eip.mgmt_external_ip[*].id
# }

# output "mgmt_eip_ip" {
# value = aws_eip.mgmt_external_ip[*].public_ip
# }

output "public_eip_id" {
value = aws_eip.wan_external_ip[*].id
}
Expand Down

0 comments on commit d3efc8a

Please sign in to comment.