简体   繁体   English

无法在 GCP 中使用 Terraform 创建基于经典路由的 VPN 隧道

[英]Cannot create a classic route based VPN tunnel with Terraform in GCP

What I want to accomplish:我想要完成的事情:

I want Terraform to create a Classic route based VPN tunnel in GCP.我想要 Terraform 在 GCP 中创建一个基于经典路由的 VPN 隧道。

Background:背景:

When setting up a VPN tunnel in GCP there are three options for routing BGP Route based Policy based在 GCP 中设置 VPN 隧道时,有三个选项用于路由 BGP Route based Policy based

When creating a Route based VPN tunnel in GCP you need to specify the remote su.nets.在 GCP 中创建基于路由的 VPN 隧道时,您需要指定远程 su.net。 If you are creating a Policy based VPN tunnel you also need to specify local su.nets.如果您正在创建基于策略的 VPN 隧道,您还需要指定本地 su.net。

Since I want to create a route based VPN tunnel I only need to provide remote su.nets.因为我想创建一个基于路由的 VPN 隧道,所以我只需要提供远程 su.net。

The problem:问题:

However in Terraform, there is no option for the resource "google_compute_vpn_tunnel" that has to do with what routing type to use.但是在 Terraform 中,没有与要使用的路由类型有关的资源“google_compute_vpn_tunnel”的选项。 Okay maybe its determined by the lack of "local_traffic_selector" and then becomes a route based VPN tunnel.好吧,也许它是由缺少“local_traffic_selector”决定的,然后变成了基于路由的 VPN 隧道。 But even if I ommit the "local_traffic_selector" option in my main.tf it is still there in the plan.但即使我在我的 main.tf 中省略了“local_traffic_selector”选项,它仍然在计划中。

' + local_traffic_selector = (known after apply) ' + local_traffic_selector =(申请后知道)

Since I have not specified any value for it, Terraform tries to use it with an empty value, which is not possible.由于我没有为它指定任何值,Terraform 尝试将它与空值一起使用,这是不可能的。

Error: Error creating VpnTunnel: googleapi: Error 400: Invalid value for field 'resource.localTrafficSelector[0]': ''. The local_traffic_selector field cannot be empty for network in custom subnet mode., invalid

  on main.tf line 51, in resource "google_compute_vpn_tunnel" "tunnel1":
  51: resource "google_compute_vpn_tunnel" "tunnel1" {

If I do specify it, the VPN tunnel will be of type Policy based instead of Route based.如果我确实指定了它,VPN 隧道将是基于策略的类型,而不是基于路由的类型。

Is there no support for Terraform to create a route based classic VPN tunnel in GCP? GCP 不支持 Terraform 创建基于路由的经典 VPN 隧道吗?

Another strange thing is when creating the VPN gateway.另一个奇怪的事情是在创建 VPN 网关时。 When you do it in the GCP console you need to specify what external IP address the VPN gateway have.当您在 GCP 控制台中执行此操作时,您需要指定 VPN 网关具有的外部 IP 地址。 That is a pretty important property.这是一个非常重要的属性。 But Terraform has no option for setting the IP address for the resource "google_compute_vpn_gateway" In the examples here: https://www.terraform.io/docs/providers/google/r/compute_vpn_gateway.html they create an static IP object, but its never assigned to the VPN gateway in the configuration. But Terraform has no option for setting the IP address for the resource "google_compute_vpn_gateway" In the examples here: https://www.terraform.io/docs/providers/google/r/compute_vpn_gateway.html they create an static IP object, but它从未分配给配置中的 VPN 网关。

 resource "google_compute_vpn_tunnel" "tunnel1" {
   name          = "tunnel1"
   peer_ip       = "15.0.0.120"
   shared_secret = "a secret message"
   local_traffic_selector= ["0.0.0.0/0"]
   remote_traffic_selector=["0.0.0.0/0"] 

Add remote_traffic_selector field as 0.0.0.0/0 and create routes pointing to tunnel independently it will create route based VPN.将 remote_traffic_selector 字段添加为 0.0.0.0/0 并独立创建指向隧道的路由,这将创建基于路由的 VPN。

According with the documentation of VPN routing policies , the Route Based = Policy based if the local selector is in 0.0.0.0/0 根据VPN路由策略的文档,如果本地选择器位于0.0.0.0/0 ,则Route Based = Route Based Policy based

Route based VPN tunnels are similar to tunnels that use policy based routing, except that only the remote IP ranges (right side) are specified. 基于路由的VPN隧道与使用基于策略的路由的隧道相似,只是仅指定了远程IP范围(右侧)。 The list of local IP ranges is assumed to be any network (0.0.0.0/0), so you only specify the remote traffic selector. 假定本地IP范围的列表是任何网络(0.0.0.0/0),所以您仅指定远程流量选择器。

By the way add local_traffic_selector= ["0.0.0.0/0"] in your tunnel definition, like this ( here in the default example of Terraform ) 顺便说一句,在您的隧道定义中添加local_traffic_selector= ["0.0.0.0/0"] ,如下所示( 在Terraform的默认示例中

resource "google_compute_vpn_tunnel" "tunnel1" {
  name          = "tunnel1"
  peer_ip       = "15.0.0.120"
  shared_secret = "a secret message"
  local_traffic_selector= ["0.0.0.0/0"]
  ...

Yes, of course, the created VPN tunnel is set as Policy Based in the GUI but with a local network to 0.0.0.0/0, thus technically equivalent to Route Based config. 是的,当然,在GUI中将创建的VPN隧道设置为Policy Based ,但本地网络为0.0.0.0/0,因此在技术上等效于“ Route Based配置。

About the static IP, it's the standard (and boring) behavior of Terraform. 关于静态IP,这是Terraform的标准(无聊)行为。 You have to create the static IP with Terraform, for having the state saved in TFSTATE file, and then having the capability to reuse it. 您必须使用Terraform创建静态IP,以将状态保存在TFSTATE文件中,然后才能重用它。 Try this: 尝试这个:

  • Keep only the external ip creation in your main.tf file 仅将外部IP创建保留在main.tf文件中
resource "google_compute_address" "vpn_static_ip" {
  name   = "my-vpn-ip"
}
  • Apply this configuration 应用此配置
  • Now add the rest of the configuration 现在添加其余配置
  • Apply again the update of the configuration 再次应用配置更新

As you could see, Terraform retrieve the IP from the previous state and reuse it without creating a new IP. 如您所见,Terraform从先前的状态中检索IP并重新使用它而无需创建新IP。

google_compute_address.vpn_static_ip: Refreshing state... [id=******PROJECT_ID*****/us-central1/my-vpn-ip]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 GCP VPN (Classic) 和 Zscaler ZEN (Zscaler Enforcement Node) 之间建立 IPSec 隧道 - Unable to establish IPSec tunnel between GCP VPN (Classic) and Zscaler ZEN (Zscaler Enforcement Node) Terraform - GCP 在 google_compute_vpn_gateway 上添加 IP 部分 - Terraform - GCP adding IP section on google_compute_vpn_gateway 如何在 GCP Cloud VPN 和我的 PC ubuntu 之间建立 VPN 隧道? - How can i make VPN Tunnel Between GCP Cloud VPN and my PC ubuntu? 在 GCP VPN 和 Cisco ASA 之间设置隧道时出现身份验证问题 - Authenticatication issue while setting up a tunnel between GCP VPN and Cisco ASA Terraform compute.networks.create 的 GCP 错误 - Terraform Error with GCP for compute.networks.create terraform 在尝试创建负载均衡器时为 GCP 返回“invalid_grant”,我无法以所有者身份查看或编辑 SA 权限 - terraform returns 'invalid_grant' for GCP when attempting to create load balancer and I cannot view or edit SA permissions as owner 如何在 Terraform 中设置基于 GCP 监控日志的警报? - How to set up a GCP Monitoring log-based alert in Terraform? Terraform 和 GCP - 在现有的共享 VPC 和子网中创建新的计算 VM - Terraform and GCP - Create new Compute VM in existing Shared VPC and Subnet 无法通过 Terraform 使用 GCP Cloud Build 对 GitHub 存储库进行身份验证 - Cannot authenticate GitHub repository with GCP Cloud Build via Terraform 我想使用 terraform 在 GCP 中创建公共和私有 Su.net - I want to create Public and Private Subnet in GCP using terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM