Skip to content

Commit 33bd7dc

Browse files
committed
Add helper script for creating deployment connectivity resources
1 parent 693fa7d commit 33bd7dc

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,20 +85,190 @@ 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 choose a project where you would like to create resources for connecting to your F5 NGINXaaS deployment.
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 Network Endpoint Group (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
- For **Target service**, enter your NGINXaaS deployment's Service Attachment, which is visible on the `Deployment Details` section for your deployment.
9294
- For **Producer port**, enter the port your NGINX server is listening on. If you're using the default NGINX config, enter port `80`.
9395
- For **Network** and **Subnetwork** select your consumer VPC network and subnet.
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.
9596
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.
9697
- For **Network**, select your consumer VPC network.
9798
- 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).
9899
- In the **Frontend configuration** section,
99100
- For **IP address**, select the public IP address created earlier.
100101
- For **Port number**, enter the same port as your NEG's Producer port, for example, port `80`.
101102

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