Skip to content

Commit 8082079

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

File tree

1 file changed

+171
-2
lines changed

1 file changed

+171
-2
lines changed

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

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

104273
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)