Skip to content

Commit a6d330d

Browse files
Add job to ensure expected GCP integration network is created
Why --- The bats and test-stemcells-ipv4 jobs assume a GCP subnetwork named stemcell-builder-integration-<subnet_int> exists in the bosh-concourse VPC, with a /24 at 10.100.<subnet_int>.0/24, private Google access, and IPV4_ONLY stack type. They also require a matching ingress firewall rule (all-protocol, source CIDR → tags test-stemcells-bats/bat) so that compilation VMs and BAT deployment VMs can reach the BOSH director's NATS server. Until now both resources had to be created and maintained out of band; their absence caused consistent compilation-VM agent timeouts (builds 466–475). What ---- * ci/tasks/gcp/ensure-integration-network.sh - Authenticates via GCP_JSON_KEY service account. - Derives SUBNET_NAME and SUBNET_CIDR from SUBNET_INT. - For the subnetwork: calls gcloud describe once, capturing exit code for existence and attributes for drift detection in a single API call. Checks network, ipCidrRange, privateIpGoogleAccess, stackType and exits non-zero with a clear error on any mismatch; creates the subnet if absent. - For the firewall rule: same single-call pattern, checking network, direction, and sourceRanges[0]; creates the rule if absent. * ci/tasks/gcp/ensure-integration-network.yml - Concourse task definition. All params (GCP_JSON_KEY, GCP_PROJECT_ID, GCP_REGION, GCP_NETWORK_NAME, SUBNET_INT) are required; no defaults, values are provided explicitly by the pipeline. * ci/pipelines/builder.yml - New infrastructure group containing the new job. - New job ensure-integration-network: * serial: true, manual trigger only. * Gets bosh-stemcells-ci and bosh-integration-image, then runs the task with GCP_REGION=europe-north2 and GCP_NETWORK_NAME=bosh-concourse passed explicitly. * No passed: constraint on existing jobs; run on demand when the subnet/firewall needs to be created or reconciled. Verification ------------ * ytt -f ci/pipelines/builder.yml -f ci/pipelines/vars.yml renders successfully. * fly validate-pipeline -c <rendered> reports "looks good". Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4a792ed commit a6d330d

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

ci/pipelines/builder.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ groups:
4444
- name: docker
4545
jobs:
4646
- build-os-image-stemcell-builder
47+
- name: infrastructure
48+
jobs:
49+
- ensure-integration-network
4750

4851
#@yaml/text-templated-strings
4952
jobs:
@@ -89,6 +92,25 @@ jobs:
8992
get_params:
9093
skip_download: true
9194

95+
#! Manually triggered job that idempotently ensures the GCP subnetwork and
96+
#! firewall rule consumed by deploy-director / cleanup-bats-vms / prepare-bats
97+
#! in the test-stemcells-ipv4 and bats jobs below exist. GCP is the source of
98+
#! truth — no state file is required.
99+
- name: ensure-integration-network
100+
serial: true
101+
plan:
102+
- get: bosh-stemcells-ci
103+
- get: bosh-integration-image
104+
- task: ensure-integration-network
105+
file: bosh-stemcells-ci/ci/tasks/gcp/ensure-integration-network.yml
106+
image: bosh-integration-image
107+
params:
108+
GCP_JSON_KEY: ((gcp_json_key))
109+
GCP_PROJECT_ID: ((gcp_project_id))
110+
GCP_REGION: europe-north2
111+
GCP_NETWORK_NAME: bosh-concourse
112+
SUBNET_INT: (@= data.values.stemcell_details.subnet_int @)
113+
92114
- name: process-high-critical-cves
93115
serial_groups: [log-cves]
94116
plan:
@@ -885,7 +907,6 @@ resource_types:
885907
type: registry-image
886908
source:
887909
repository: frodenas/gcs-resource
888-
889910
#@yaml/text-templated-strings
890911
resources:
891912
- name: daily
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
: "${GCP_JSON_KEY:?}"
5+
: "${GCP_PROJECT_ID:?}"
6+
: "${GCP_REGION:?}"
7+
: "${GCP_NETWORK_NAME:?}"
8+
: "${SUBNET_INT:?}"
9+
10+
echo "${GCP_JSON_KEY}" | gcloud auth activate-service-account --key-file - --project "${GCP_PROJECT_ID}"
11+
12+
SUBNET_NAME="stemcell-builder-integration-${SUBNET_INT}"
13+
SUBNET_CIDR="10.100.${SUBNET_INT}.0/24"
14+
15+
# Ensure subnet exists and is correctly configured
16+
echo "Checking for subnet '${SUBNET_NAME}' in region '${GCP_REGION}'..."
17+
if current_subnet="$(gcloud compute networks subnets describe "${SUBNET_NAME}" \
18+
--region="${GCP_REGION}" \
19+
--project="${GCP_PROJECT_ID}" \
20+
--format='csv[no-heading](network.basename(),ipCidrRange,privateIpGoogleAccess,stackType)' 2>/dev/null)"; then
21+
expected_subnet="${GCP_NETWORK_NAME},${SUBNET_CIDR},True,IPV4_ONLY"
22+
if [[ "${current_subnet}" != "${expected_subnet}" ]]; then
23+
echo "ERROR: Subnet '${SUBNET_NAME}' exists but is misconfigured."
24+
echo " Expected: ${expected_subnet}"
25+
echo " Actual: ${current_subnet}"
26+
exit 1
27+
fi
28+
echo "Subnet '${SUBNET_NAME}' already exists and matches expected configuration."
29+
else
30+
echo "Creating subnet '${SUBNET_NAME}'..."
31+
gcloud compute networks subnets create "${SUBNET_NAME}" \
32+
--network="${GCP_NETWORK_NAME}" \
33+
--region="${GCP_REGION}" \
34+
--range="${SUBNET_CIDR}" \
35+
--enable-private-ip-google-access \
36+
--stack-type=IPV4_ONLY \
37+
--project="${GCP_PROJECT_ID}"
38+
echo "Subnet '${SUBNET_NAME}' created."
39+
fi
40+
41+
# Ensure firewall rule exists and is correctly configured
42+
echo "Checking for firewall rule '${SUBNET_NAME}'..."
43+
if current_fw="$(gcloud compute firewall-rules describe "${SUBNET_NAME}" \
44+
--project="${GCP_PROJECT_ID}" \
45+
--format='csv[no-heading](network.basename(),direction,sourceRanges[0])' 2>/dev/null)"; then
46+
expected_fw="${GCP_NETWORK_NAME},INGRESS,${SUBNET_CIDR}"
47+
if [[ "${current_fw}" != "${expected_fw}" ]]; then
48+
echo "ERROR: Firewall rule '${SUBNET_NAME}' exists but is misconfigured."
49+
echo " Expected: ${expected_fw}"
50+
echo " Actual: ${current_fw}"
51+
exit 1
52+
fi
53+
echo "Firewall rule '${SUBNET_NAME}' already exists and matches expected configuration."
54+
else
55+
echo "Creating firewall rule '${SUBNET_NAME}'..."
56+
gcloud compute firewall-rules create "${SUBNET_NAME}" \
57+
--network="${GCP_NETWORK_NAME}" \
58+
--project="${GCP_PROJECT_ID}" \
59+
--direction=INGRESS \
60+
--priority=1000 \
61+
--allow=all \
62+
--source-ranges="${SUBNET_CIDR}" \
63+
--target-tags=test-stemcells-bats,bat
64+
echo "Firewall rule '${SUBNET_NAME}' created."
65+
fi
66+
67+
echo "Integration network '${SUBNET_NAME}' is ready."
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
platform: linux
3+
4+
inputs:
5+
- name: bosh-stemcells-ci
6+
7+
params:
8+
GCP_JSON_KEY:
9+
GCP_PROJECT_ID:
10+
GCP_REGION:
11+
GCP_NETWORK_NAME:
12+
SUBNET_INT:
13+
14+
run:
15+
path: bosh-stemcells-ci/ci/tasks/gcp/ensure-integration-network.sh

0 commit comments

Comments
 (0)