Created
July 26, 2023 20:48
-
-
Save webgtx/41c904f679f2fc94dab5596814b1ca54 to your computer and use it in GitHub Desktop.
Attaching an EIP to an Instance with a pre-assigned private ip (VPC Only) [AWS]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_vpc" "default" { | |
cidr_block = "10.0.0.0/16" | |
enable_dns_hostnames = true | |
} | |
resource "aws_internet_gateway" "gw" { | |
vpc_id = aws_vpc.default.id | |
} | |
resource "aws_subnet" "tf_test_subnet" { | |
vpc_id = aws_vpc.default.id | |
cidr_block = "10.0.0.0/24" | |
map_public_ip_on_launch = true | |
depends_on = [aws_internet_gateway.gw] | |
} | |
resource "aws_instance" "foo" { | |
# us-west-2 | |
ami = "ami-5189a661" | |
instance_type = "t2.micro" | |
private_ip = "10.0.0.12" | |
subnet_id = aws_subnet.tf_test_subnet.id | |
} | |
resource "aws_eip" "bar" { | |
domain = "vpc" | |
instance = aws_instance.foo.id | |
associate_with_private_ip = "10.0.0.12" | |
depends_on = [aws_internet_gateway.gw] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment