Disassociate EIP before detaching IGW

Disassociate EIP before detaching IGW



When I modify the subnet of my VPC, a whole new VPC is provisioned. The IGW is moved from the old VPC to the new one. Which would be fine if it wasn't prevented from moving because the Elastic IP is still attached to the instance.



I tried many combinations with depends_on.


depends_on



If I manually disassociate the EIP, terraform IGW modification stops waiting for ever.


########################
# ELASTIC IP #
########################
resource "aws_eip" "ip"

# EIP association isolated for testing "depends on"
resource "aws_eip_association" "eip_assoc"
instance_id = "$aws_instance.vpn_server.id"
allocation_id = "$aws_eip.ip.id"
depends_on = ["aws_internet_gateway.gw","aws_vpc.vpc"]


########################
# VPC CREATION #
########################
resource "aws_vpc" "vpc"
cidr_block = "$var.cidr"
enable_dns_support = true
enable_dns_hostnames = true
assign_generated_ipv6_cidr_block = "$var.ipv6"


########################
# IGW CREATION #
########################
resource "aws_internet_gateway" "gw"
vpc_id = "$aws_vpc.vpc.id"


########################
# Instance #
########################
resource "aws_instance" "vpn_server"
ami = "$data.aws_ami.ami_amzn2.id"
instance_type = "t2.micro"
key_name = "$aws_key_pair.key.key_name"
subnet_id = "$aws_subnet.a.id"
associate_public_ip_address = true
ipv6_address_count = 1
vpc_security_group_ids = ["$aws_default_security_group.sg.id"]
lifecycle create_before_destroy = true
depends_on = ["aws_internet_gateway.gw"]
user_data = "$data.template_file.user_data.rendered"


########################
# Subnets Creation #
########################
data "aws_availability_zones" "available"

resource "aws_subnet" "a"
availability_zone = "$data.aws_availability_zones.available.names[0]"
vpc_id = "$aws_vpc.vpc.id"
cidr_block = "$cidrsubnet(aws_vpc.vpc.cidr_block, 2, 0)"
map_public_ip_on_launch = true

# Bug Issue 688: https://github.com/terraform-providers/terraform-provider-aws/issues/688
# Soon set even if no IPv6 for VPC
# https://github.com/terraform-providers/terraform-provider-aws/pull/2103
ipv6_cidr_block = "$var.ipv6 ? cidrsubnet(aws_vpc.vpc.ipv6_cidr_block, 8, 10) : """
assign_ipv6_address_on_creation = true



Any idea what would be the correct way of disassociating the EIP before the IGW tries to move to the new VPC?





Internet Gateways don't cost anything, so it's hard to see a reason to move an IGW from one VPC to another.
– Michael - sqlbot
Aug 19 at 22:59





@chriscatfr When you modify the subnet are you changing "$aws_subnet.a.id"? If so, can you show that code?
– kenlukas
Aug 20 at 16:54





@Michael-sqlbot, Terraform is the one wanting to move it from the old VPC. I simply wanted to change the VPC ip range and keep the same Elastic IP for my server.
– chriscatfr
Aug 20 at 21:34






@kenlukas, I edited the question to add the subnet
– chriscatfr
Aug 20 at 21:38









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj