Skip to content

Commit 14f3116

Browse files
committed
Add helper script for creating deployment connectivity resources
1 parent 4d7955a commit 14f3116

File tree

1 file changed

+172
-2
lines changed

1 file changed

+172
-2
lines changed

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

Lines changed: 172 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,192 @@ In the NGINXaaS Console,
8585

8686
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).
8787

88-
1. Access the [Google Cloud Console](https://console.cloud.google.com/).
88+
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.
89+
1. Create or reuse a [VPC network](https://cloud.google.com/vpc/docs/create-modify-vpc-networks).
90+
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.
8991
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.
9092
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.
9193
- Set **Network endpoint group type** to **Private Service Connect NEG (Regional)**.
9294
- Set **Taget** to **Published service**.
9395
- For **Target service**, enter your NGINXaaS deployment's Service Attachment, which is visible on the `Deployment Details` section for your deployment.
9496
- For **Producer port**, enter the port your NGINX server is listening on. If you're using the default NGINX config, enter port `80`.
9597
- For **Network** and **Subnetwork** select your consumer VPC network and subnet.
96-
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.
9798
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.
9899
- For **Network**, select your consumer VPC network.
99100
- 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).
100101
- In the **Frontend configuration** section,
101102
- For **IP address**, select the public IP address created earlier.
102103
- For **Port number**, enter the same port as your NEG's Producer port, for example, port `80`.
103104

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