错误:创建路由表关联错误:InvalidRouteTableID。NotFound: The routeTable ID 'rtb-0208e6570f55bc571' does not exist状态码:400,请求ID: ecc6960b-2351-4603-add2-60e30ca77e10
但是我可以手动关联它而没有任何问题。它只有"rt_assocation_oregon"资源。
Full code:
#Create VPC in us-east-1
provider "aws" {
region = "us-east-1"
profile = " test1"
}
#Create VPC in us-west-2
provider "aws" {
region = "us-west-2"
profile = "test1"
alias = "west"
}
#Create VPC in us-east-1
resource "aws_vpc" "vpc_master" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "master-vpc-jenkins"
}
}
resource "aws_vpc" "vpc_master_oregon" {
cidr_block = "192.168.0.0/16"
instance_tenancy = "default"
enable_dns_support = true
enable_dns_hostnames = true
provider = aws.west
tags = {
Name = "worker-vpc-jenkins"
}
}
#Create IGW in us-east-1
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.vpc_master.id
tags = {
Name = "master_igw"
}
}
#Create IGW in us-west-2
resource "aws_internet_gateway" "igw-oregon" {
vpc_id = aws_vpc.vpc_master_oregon.id
provider = aws.west
tags = {
Name = "worker_igw"
}
}
#Create subnet # 1 in us-east-1
resource "aws_subnet" "subnet_1" {
vpc_id = aws_vpc.vpc_master.id
cidr_block = "10.0.1.0/24"
availability_zone = data.aws_availability_zones.available.names[0]
tags = {
Name = "master_subnet1"
}
}
#Create subnet in us-west-2
resource "aws_subnet" "subnet_oregon_1" {
vpc_id = aws_vpc.vpc_master_oregon.id
cidr_block = "192.168.1.0/24"
provider = aws.west
tags = {
Name = "worker_subnet1"
}
}
#Initiate Peering connection request from us-east1
resource "aws_vpc_peering_connection" "useast1_uswest2" {
peer_vpc_id = aws_vpc.vpc_master_oregon.id
vpc_id = aws_vpc.vpc_master.id
auto_accept = false
peer_region = "us-west-2"
tags = {
Name = "VPC Peering between vpc_master and vpc_master_oregon"
}
}
#Accept VPC peering request in us-west-2 from us-east-1
resource "aws_vpc_peering_connection_accepter" "accepter_peering" {
provider = aws.west
vpc_peering_connection_id = aws_vpc_peering_connection.useast1_uswest2.id
auto_accept = true
tags = {
Side = "Receiver"
}
}
#Create route table in us-east-1
resource "aws_route_table" "internet_route" {
vpc_id = aws_vpc.vpc_master.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
route {
cidr_block = "192.168.1.0/24"
vpc_peering_connection_id = aws_vpc_peering_connection.useast1_uswest2.id
}
lifecycle {
ignore_changes = all
}
tags = {
Name = "Master-Region-RT"
}
}
resource "aws_route_table_association" "rt_assocation_east" {
subnet_id = aws_subnet.subnet_1.id
route_table_id = aws_route_table.internet_route.id
}
#Create route table in us-west-2
resource "aws_route_table" "internet_route_oregon" {
provider = aws.west
vpc_id = aws_vpc.vpc_master_oregon.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw-oregon.id
}
route {
cidr_block = "10.0.1.0/24"
vpc_peering_connection_id = aws_vpc_peering_connection.useast1_uswest2.id
}
lifecycle {
ignore_changes = all
}
tags = {
Name = "Worker-Region-RT"
}
}
resource "aws_route_table_association" "rt_association_oregon" {
subnet_id = aws_subnet.subnet_oregon_1.id
route_table_id = aws_route_table.internet_route_oregon.id
}
您的aws_subnet.subnet_oregon_1
和aws_route_table.internet_route_oregon
是在us-west-2
中创建的,但您正在尝试在us-west-1
中创建关联。应该是:
resource "aws_route_table_association" "rt_association_oregon" {
provider = aws.west
subnet_id = aws_subnet.subnet_oregon_1.id
route_table_id = aws_route_table.internet_route_oregon.id
}