在分离IGW之前取消关联EIP

时间:2018-08-19 19:43:50

标签: amazon-web-services amazon-ec2 terraform

当我修改VPC的子网时,将置备一个全新的VPC。 IGW从旧的VPC移到了新的VPC。如果由于弹性IP仍附加到实例而没有阻止移动,那将是很好的。

我尝试了depends_on的许多组合。

如果我手动取消关联EIP,则地形IGW修改将永远停止等待。

########################
#      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
}

您知道在IGW尝试移至新VPC之前解除EIP关联的正确方法是什么吗?

0 个答案:

没有答案