Skip to content

Commit 2b14ee9

Browse files
authored
Add helper script for creating deployment connectivity resources (#1306)
1 parent 8d62672 commit 2b14ee9

File tree

1 file changed

+170
-2
lines changed

1 file changed

+170
-2
lines changed

content/nginxaas-google/getting-started/create-deployment/deploy-console.md

Lines changed: 170 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,190 @@ In the NGINXaaS Console,
8989

9090
To set up connectivity to your NGINXaaS deployment, you will need to configure a [Private Service Connect backend](https://cloud.google.com/vpc/docs/private-service-connect-backends).
9191

92-
1. Access the [Google Cloud Console](https://console.cloud.google.com/).
92+
1. Access the [Google Cloud Console](https://console.cloud.google.com/) and select the project where your networking resources for connecting to your F5 NGINXaaS deployment should be created.
93+
1. Create or reuse a [VPC network](https://cloud.google.com/vpc/docs/create-modify-vpc-networks).
94+
1. Create a proxy-only subnet in your consumer VPC. See [Google's documentation on creating a proxy-only subnet](https://cloud.google.com/load-balancing/docs/tcp/set-up-ext-reg-tcp-proxy-zonal#console_1) for a step-by-step guide.
9395
1. Create a public IP address. See [Google's documentation on reserving a static address](https://cloud.google.com/load-balancing/docs/tcp/set-up-ext-reg-tcp-proxy-zonal#console_3) for a step-by-step guide.
9496
1. Create a Private Service Connect Network Endpoint Group (PSC NEG). See [Google's documentation on creating a NEG](https://cloud.google.com/vpc/docs/access-apis-managed-services-private-service-connect-backends#console) for a step-by-step guide.
9597
- Set **Network endpoint group type** to **Private Service Connect NEG (Regional)**.
9698
- Set **Taget** to **Published service**.
9799
- For **Target service**, enter your NGINXaaS deployment's Service Attachment, which is visible on the `Deployment Details` section for your deployment.
98100
- For **Producer port**, enter the port your NGINX server is listening on. If you're using the default NGINX config, enter port `80`.
99101
- For **Network** and **Subnetwork** select your consumer VPC network and subnet.
100-
1. Create a proxy-only subnet in your consumer VPC. See [Google's documentation on creating a proxy-only subnet](https://cloud.google.com/load-balancing/docs/tcp/set-up-ext-reg-tcp-proxy-zonal#console_1) for a step-by-step guide.
101102
1. Create a regional external proxy Network Load Balancer. See [Google's documentation on configuring the load balancer](https://cloud.google.com/load-balancing/docs/tcp/set-up-ext-reg-tcp-proxy-zonal#console_6) for a step-by-step guide.
102103
- For **Network**, select your consumer VPC network.
103104
- For **Backend configuration**, follow [Google's step-by-step guide to add a backend](https://cloud.google.com/vpc/docs/access-apis-managed-services-private-service-connect-backends#console_5).
104105
- In the **Frontend configuration** section,
105106
- For **IP address**, select the public IP address created earlier.
106107
- For **Port number**, enter the same port as your NEG's Producer port, for example, port `80`.
107108

109+
110+
Each listening port configured on NGINX requires its own PSC network endpoint group with a matching port. You can use the following helper script to automate these steps:
111+
112+
{{< details summary="Show helper script" >}}
113+
114+
```bash
115+
#!/bin/bash
116+
set -euo pipefail
117+
# Default values
118+
PROJECT=""
119+
REGION=""
120+
NETWORK=""
121+
SA_URI=""
122+
PORTS="80"
123+
PROXY_SUBNET="psc-proxy-subnet"
124+
VIPNAME="psc-vip"
125+
126+
# Prerequisites:
127+
# - gcloud CLI installed and configured
128+
# - An existing projectID and a VPC network created in that project
129+
# - A valid Service Attachment URI from F5 NGINXaaS
130+
131+
# Function to display usage
132+
usage() {
133+
cat << EOF
134+
Usage: $0 --project PROJECT --region REGION --network NETWORK --service-attachment SA_URI [--ports PORTS]
135+
136+
Options:
137+
--project GCP Project ID
138+
--region GCP Region
139+
--network VPC Network name
140+
--service-attachment Service Attachment Self Link
141+
--ports Comma-separated list of ports (default: 80)
142+
--help Show this help message
143+
144+
Note: Proxy subnet and public IP will be automatically created as 'psc-proxy-subnet' and 'psc-vip' respectively.
145+
These resources will not be deleted, if deleted this script will create new ones.
146+
147+
Example:
148+
$0 --project my-project --region us-central1 --network my-vpc \\
149+
--service-attachment "projects/producer-proj/regions/us-central1/serviceAttachments/my-service" \\
150+
--ports "80,443,8080"
151+
EOF
152+
}
153+
154+
# Parse command line arguments
155+
while [[ $# -gt 0 ]]; do
156+
case $1 in
157+
--project)
158+
PROJECT="$2"
159+
shift 2
160+
;;
161+
--region)
162+
REGION="$2"
163+
shift 2
164+
;;
165+
--network)
166+
NETWORK="$2"
167+
shift 2
168+
;;
169+
--service-attachment)
170+
SA_URI="$2"
171+
shift 2
172+
;;
173+
--ports)
174+
PORTS="$2"
175+
shift 2
176+
;;
177+
--help|-h)
178+
usage
179+
exit 0
180+
;;
181+
*)
182+
echo "Unknown option: $1"
183+
usage
184+
exit 1
185+
;;
186+
esac
187+
done
188+
189+
# Validate required parameters
190+
missing_params=()
191+
[[ -z "$PROJECT" ]] && missing_params+=("--project")
192+
[[ -z "$REGION" ]] && missing_params+=("--region")
193+
[[ -z "$NETWORK" ]] && missing_params+=("--network")
194+
[[ -z "$SA_URI" ]] && missing_params+=("--service-attachment")
195+
196+
if [[ ${#missing_params[@]} -gt 0 ]]; then
197+
echo "Error: Missing required parameters: ${missing_params[*]}"
198+
usage
199+
exit 1
200+
fi
201+
202+
# Create proxy-only subnet (skip if exists)
203+
echo "Creating proxy-only subnet if it doesn't already exist..."
204+
if ! gcloud compute networks subnets describe $PROXY_SUBNET --region=$REGION --project=$PROJECT >/dev/null 2>&1; then
205+
gcloud compute networks subnets create $PROXY_SUBNET \
206+
--project=$PROJECT --region=$REGION \
207+
--network=$NETWORK \
208+
--range=192.168.1.0/24 \
209+
--purpose=REGIONAL_MANAGED_PROXY \
210+
--role=ACTIVE
211+
fi
212+
213+
echo "Using proxy-only subnet: $PROXY_SUBNET"
214+
215+
# Create regional VIP address (skip if exists)
216+
echo "Creating regional VIP address..."
217+
if ! gcloud compute addresses describe $VIPNAME --region=$REGION --project=$PROJECT >/dev/null 2>&1; then
218+
gcloud compute addresses create $VIPNAME --region=$REGION --project=$PROJECT
219+
fi
220+
VIP=$(gcloud compute addresses describe $VIPNAME --region=$REGION --project=$PROJECT --format='get(address)')
221+
echo "Using VIP address: $VIP"
222+
223+
# Convert comma-separated ports to array
224+
IFS=',' read -ra PORTS_ARRAY <<< "$PORTS"
225+
226+
for P in "${PORTS_ARRAY[@]}"; do
227+
echo "Processing port $P..."
228+
229+
# Create Network Endpoint Group (skip if exists)
230+
if ! gcloud compute network-endpoint-groups describe psc-neg-$P --region=$REGION --project=$PROJECT >/dev/null 2>&1; then
231+
gcloud compute network-endpoint-groups create psc-neg-$P \
232+
--project=$PROJECT --region=$REGION \
233+
--network-endpoint-type=private-service-connect \
234+
--psc-target-service="$SA_URI" \
235+
--network=$NETWORK \
236+
--producer-port=$P
237+
fi
238+
239+
# Create Backend Service (skip if exists) - NO HEALTH CHECKS for PSC
240+
if ! gcloud compute backend-services describe be-$P --region=$REGION --project=$PROJECT >/dev/null 2>&1; then
241+
gcloud compute backend-services create be-$P \
242+
--project=$PROJECT --region=$REGION \
243+
--protocol=TCP --load-balancing-scheme=EXTERNAL_MANAGED
244+
245+
# Add backend to service
246+
gcloud compute backend-services add-backend be-$P \
247+
--project=$PROJECT --region=$REGION \
248+
--network-endpoint-group=psc-neg-$P \
249+
--network-endpoint-group-region=$REGION
250+
fi
251+
252+
# Create Target TCP Proxy (skip if exists)
253+
if ! gcloud compute target-tcp-proxies describe tp-$P --region=$REGION --project=$PROJECT >/dev/null 2>&1; then
254+
gcloud compute target-tcp-proxies create tp-$P \
255+
--project=$PROJECT --region=$REGION --backend-service=be-$P
256+
fi
257+
258+
# Create Forwarding Rule (skip if exists)
259+
if ! gcloud compute forwarding-rules describe fr-$P --region=$REGION --project=$PROJECT >/dev/null 2>&1; then
260+
gcloud compute forwarding-rules create fr-$P \
261+
--project=$PROJECT --region=$REGION \
262+
--address=$VIP --network=$NETWORK \
263+
--target-tcp-proxy=tp-$P --target-tcp-proxy-region=$REGION \
264+
--ports=$P --load-balancing-scheme=EXTERNAL_MANAGED \
265+
--network-tier=PREMIUM --ip-protocol=TCP
266+
fi
267+
268+
echo "Completed setup for port $P"
269+
done
270+
echo "Setup complete! Public Virtual IP: $VIP"
271+
272+
```
273+
274+
{{< /details >}}
275+
108276
## Test your deployment
109277
110278
1. To test your deployment, go to the IP address created in [Set up connectivity to your deployment]({{< ref "/nginxaas-google/getting-started/create-deployment/deploy-console.md#set-up-connectivity-to-your-deployment" >}}) using your favorite web browser.

0 commit comments

Comments
 (0)