7373 --project={{ infra__gcp_project }}
7474 --network={{ infra__vpc_name }}
7575 --service=servicenetworking.googleapis.com
76- --ranges={{ infra__vpc_svcnet_name }}
76+ --ranges={{ infra__vpc_svcnet_name }}
77+
78+ # Cloud Router and Cloud NAT for L2 networking
79+ - name : Create a Cloud Router
80+ when :
81+ - infra__tunnel
82+ - not infra__public_endpoint_access
83+ google.cloud.gcp_compute_router :
84+ name : " {{ infra__gcp_cloud_router_name }}"
85+ network : " {{ __gcp_vpc_info }}"
86+ bgp :
87+ asn : " {{ infra__gcp_cloud_router_asn }}"
88+ advertise_mode : DEFAULT
89+ region : " {{ infra__region }}"
90+ project : " {{ infra__gcp_project }}"
91+ state : present
92+
93+ - name : Discover Cloud NAT and Create if required
94+ when :
95+ - infra__tunnel
96+ - not infra__public_endpoint_access
97+ block :
98+ - name : Discover Cloud NAT
99+ ansible.builtin.command : >
100+ gcloud compute routers nats describe {{ infra__gcp_cloud_nat_name }}
101+ --router={{ infra__gcp_cloud_router_name }}
102+ --router-region={{ infra__region }}
103+ ignore_errors : true
104+ register : __gcp_nat_discovered
105+
106+ - name : Create Cloud NAT if not discovered
107+ when :
108+ - __gcp_nat_discovered is failed
109+ ansible.builtin.command : >
110+ gcloud compute routers nats create {{ infra__gcp_cloud_nat_name }}
111+ --router={{ infra__gcp_cloud_router_name }}
112+ --router-region={{ infra__region }}
113+ --auto-allocate-nat-external-ips
114+ --nat-all-subnet-ip-ranges
115+ --enable-logging
0 commit comments