Skip to content

Commit ac0a45a

Browse files
jimrightJeremy Wietrzykowski
andcommitted
Add changes for GCP L2 deployment
Co-authored-by: Jeremy Wietrzykowski <[email protected]> Co-authored-by: Jim Enright <[email protected]> Signed-off-by: Jim Enright <[email protected]>
1 parent 7e1e5a4 commit ac0a45a

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed

roles/common/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ common__datalake_name: "{{ env.datalake.name | default([commo
149149
common__datalake_name_suffix: "{{ env.datalake.suffix | default(common__datalake_suffix) }}"
150150
common__tunnel: "{{ env.tunnel | default(False) }}"
151151
common__public_endpoint_access: "{{ env.public_endpoint_access | default(not common__tunnel) }}"
152+
common__use_public_ip: "{{ env.public_endpoint_access | default(not common__tunnel) }}"
152153

153154
common__env_admin_password: "{{ globals.admin_password | mandatory }}"
154155
common__aws_policy_urls_default_root: "https://raw.githubusercontent.com/hortonworks/cloudbreak/master/cloud-aws-common/src/main/resources/definitions/cdp"

roles/infrastructure/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ infra__gcp_project: "{{ common__gcp_project }}"
134134
infra__gcp_storage_location_data: "{{ infra.gcp.storage.path.data | default([infra__storage_name, infra__data_path] | join('-')) }}"
135135
infra__gcp_storage_location_logs: "{{ infra.gcp.storage.path.logs | default([infra__storage_name, infra__logs_path] | join('-')) }}"
136136

137+
infra__gcp_cloud_router_name: "{{ infra.gcp.network.router.name | default([infra__namespace, 'router'] | join('-')) }}"
138+
infra__gcp_cloud_router_asn: "{{ infra.gcp.network.router.asn | default(64514) }}"
139+
infra__gcp_cloud_nat_name: "{{ infra.gcp.network.nat.name | default([infra__namespace, 'nat'] | join('-')) }}"
140+
137141
# Azure
138142
infra__azure_metagroup_name: "{{ common__azure_metagroup_name }}"
139143

roles/infrastructure/tasks/setup_gcp_network.yml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,43 @@
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

roles/infrastructure/tasks/teardown_gcp_network.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@
3232
name: "{{ infra__security_group_default_name }}"
3333
state: absent
3434

35+
36+
# CREATE NAT
37+
- name: Discover Cloud NAT and Delete if required
38+
block:
39+
- name: Delete Cloud NAT
40+
ansible.builtin.command: >
41+
gcloud compute routers nats describe {{ infra__gcp_cloud_nat_name }}
42+
--router={{ infra__gcp_cloud_router_name }}
43+
--router-region={{ infra__region }}
44+
ignore_errors: true
45+
register: __gcp_nat_discovered
46+
47+
- name: Delete Cloud NAT if discovered
48+
when:
49+
- __gcp_nat_discovered is succeeded
50+
ansible.builtin.command: >
51+
gcloud compute routers nats delete {{ infra__gcp_cloud_nat_name }}
52+
--router={{ infra__gcp_cloud_router_name }}
53+
--router-region={{ infra__region }}
54+
55+
- name: Delete a Cloud Router
56+
google.cloud.gcp_compute_router:
57+
name: "{{ infra__gcp_cloud_router_name }}"
58+
network: "{{ __gcp_vpc_info }}"
59+
region: "{{ infra__region }}"
60+
project: "{{ infra__gcp_project }}"
61+
state: absent
62+
3563
- name: Remove GCP VPC Subnets
3664
google.cloud.gcp_compute_subnetwork:
3765
region: "{{ infra__region }}"

roles/platform/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ plat__xacccount_credential_name: "{{ common__xaccount_credential_na
7777
plat__workload_analytics: "{{ env.workload_analytics | default(True) }}"
7878
plat__tunnel: "{{ common__tunnel }}"
7979
plat__public_endpoint_access: "{{ common__public_endpoint_access }}"
80+
plat__use_public_ip: "{{ common__use_public_ip }}"
8081

8182
plat__env_admin_password: "{{ common__env_admin_password }}"
8283

roles/platform/tasks/setup_gcp_env.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
cloud: "{{ plat__infra_type }}"
2323
region: "{{ plat__region }}"
2424
public_key_text: "{{ plat__public_key_text }}"
25-
public_ip: yes
25+
public_ip: "{{ plat__use_public_ip }}"
2626
log_location: "gs://{{ plat__gcp_storage_location_logs }}"
2727
log_identity: "{{ plat__gcp_log_identity_name }}@{{ plat__gcp_project }}.iam.gserviceaccount.com"
2828
vpc_id: "{{ plat__vpc_name }}"

0 commit comments

Comments
 (0)