在 Terraform 中使用模块将 EIP 关联到我的 NAT 网关后出现错误
Got an error after associating EIP to my NAT Gateway in Terraform with modules
我正在尝试使用带模块的 Terraform 在 AWS 中创建基础设施。所以我得到了 2 个模块,一个用于我的 Nat 网关,一个用于 EIP 创建和关联。在我的主文件中,为了将 EIP 关联到 NAT 网关,我使用 NAT GW 和 EIP 的 2 个输出属性,它们是 NAT 的 ID 和 EIP ID,如下所示:
module "eip_assoc" {
source = "../Modules/eip_assoc"
nat_gw_qa = module.NAT_GW.aws_nat_gateway_id_output
nat_gw_association = module.EIP.eip_one_id_output
}
其余基础设施一切正常,当我应用主文件时,它会在 AWS 中创建资源并将 EIP 关联到 NAT GW,但在控制台的末尾会显示如下错误这个:
“错误:关联 EIP 时出错:InvalidNetworkInterfaceId.Malformed:无效 ID:“nat-0c15axxxxxxxxxx”(应为“eni-...”)”
好吧,它说我需要 NAT GW 的 eni-... 输出而不是 Allocation_id,我将输出更改为 network_interface_id,其中 returns NAT GW 的 ENI ID,但在那之后我得到了另一个不同的错误:
错误:关联 EIP 时出错:AuthFailure:您没有访问指定资源的权限。
在这种情况下,与以前一样,它在 AWS 中创建基础设施,并且毫无问题地将 EIP 关联到 NAT GW,但在 Terraform 文档中查找该错误消息后,它说“不要使用 network_interface 将 EIP 关联到 aws_lb 或 aws_nat_gateway 资源。而是使用这些资源中可用的 allocation_id 以允许 AWS 管理关联,否则您将看到AuthFailure 错误。
因此,如果我使用分配 ID,它会显示期望 ENI ID 的错误,如果使用 ENI ID,它会显示 AuthFailure 错误,在这两种情况下都会部署整个资源,但会收到这些错误消息。
我从这个片段中看到了什么
module "eip_assoc" {
source = "../Modules/eip_assoc"
nat_gw_qa = module.NAT_GW.aws_nat_gateway_id_output
nat_gw_association = module.EIP.eip_one_id_output
}
In my main file, to associate the EIP to the NAT Gateway I use 2 output attributes of my NAT GW and EIP which are the ID of the NAT and the EIP ID
顺序问题,你必须已经有一个EIP或者创建一个新的NAT网关创建或者换句话说,你不能创建EIP和NAT网关然后将EIP与NAT相关联网关。
这就是为什么我们无法在创建 NAT 网关后交换 EIP 的原因。
You cannot disassociate an Elastic IP address from a NAT gateway after it's created. To use a different Elastic IP address for your NAT gateway, you must create a new NAT gateway with the required address, update your route tables, and then delete the existing NAT gateway if it's no longer required.
To use the same Elastic IP address for the NAT gateway that you currently use for your NAT instance, you must first also disassociate the Elastic IP address from your NAT instance and then associate it with your NAT gateway when you create the gateway.
Specify the subnet in which to create the NAT gateway, and select the allocation ID of an Elastic IP address to associate with the NAT gateway.
我正在尝试使用带模块的 Terraform 在 AWS 中创建基础设施。所以我得到了 2 个模块,一个用于我的 Nat 网关,一个用于 EIP 创建和关联。在我的主文件中,为了将 EIP 关联到 NAT 网关,我使用 NAT GW 和 EIP 的 2 个输出属性,它们是 NAT 的 ID 和 EIP ID,如下所示:
module "eip_assoc" {
source = "../Modules/eip_assoc"
nat_gw_qa = module.NAT_GW.aws_nat_gateway_id_output
nat_gw_association = module.EIP.eip_one_id_output
}
其余基础设施一切正常,当我应用主文件时,它会在 AWS 中创建资源并将 EIP 关联到 NAT GW,但在控制台的末尾会显示如下错误这个:
“错误:关联 EIP 时出错:InvalidNetworkInterfaceId.Malformed:无效 ID:“nat-0c15axxxxxxxxxx”(应为“eni-...”)”
好吧,它说我需要 NAT GW 的 eni-... 输出而不是 Allocation_id,我将输出更改为 network_interface_id,其中 returns NAT GW 的 ENI ID,但在那之后我得到了另一个不同的错误:
错误:关联 EIP 时出错:AuthFailure:您没有访问指定资源的权限。
在这种情况下,与以前一样,它在 AWS 中创建基础设施,并且毫无问题地将 EIP 关联到 NAT GW,但在 Terraform 文档中查找该错误消息后,它说“不要使用 network_interface 将 EIP 关联到 aws_lb 或 aws_nat_gateway 资源。而是使用这些资源中可用的 allocation_id 以允许 AWS 管理关联,否则您将看到AuthFailure 错误。
因此,如果我使用分配 ID,它会显示期望 ENI ID 的错误,如果使用 ENI ID,它会显示 AuthFailure 错误,在这两种情况下都会部署整个资源,但会收到这些错误消息。
我从这个片段中看到了什么
module "eip_assoc" {
source = "../Modules/eip_assoc"
nat_gw_qa = module.NAT_GW.aws_nat_gateway_id_output
nat_gw_association = module.EIP.eip_one_id_output
}
In my main file, to associate the EIP to the NAT Gateway I use 2 output attributes of my NAT GW and EIP which are the ID of the NAT and the EIP ID
顺序问题,你必须已经有一个EIP或者创建一个新的NAT网关创建或者换句话说,你不能创建EIP和NAT网关然后将EIP与NAT相关联网关。
这就是为什么我们无法在创建 NAT 网关后交换 EIP 的原因。
You cannot disassociate an Elastic IP address from a NAT gateway after it's created. To use a different Elastic IP address for your NAT gateway, you must create a new NAT gateway with the required address, update your route tables, and then delete the existing NAT gateway if it's no longer required.
To use the same Elastic IP address for the NAT gateway that you currently use for your NAT instance, you must first also disassociate the Elastic IP address from your NAT instance and then associate it with your NAT gateway when you create the gateway.
Specify the subnet in which to create the NAT gateway, and select the allocation ID of an Elastic IP address to associate with the NAT gateway.