Skip to content

Commit 5f50210

Browse files
committed
Correctly extract external IP for IPv6 only environments
1 parent 02ac018 commit 5f50210

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tests/scripts/create-and-setup-gcp-vm.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ gcloud compute instances create "${RESOURCE_NAME}" --project="${GKE_PROJECT}" --
4545

4646
# Add VM IP to GKE master control node access, if required
4747
if [ "${ADD_VM_IP_AUTH_NETWORKS}" = "true" ]; then
48-
NETWORK_INTERFACES=$(gcloud compute instances describe "${RESOURCE_NAME}" --project="${GKE_PROJECT}" --zone="${GKE_CLUSTER_ZONE}" \
49-
--format='value(networkInterfaces)')
50-
ACCESS_CONFIGS=$(gcloud compute instances describe "${RESOURCE_NAME}" --project="${GKE_PROJECT}" --zone="${GKE_CLUSTER_ZONE}" \
51-
--format='value(networkInterfaces[0].accessConfigs)')
52-
EXTERNAL_IP=$(gcloud compute instances describe "${RESOURCE_NAME}" --project="${GKE_PROJECT}" --zone="${GKE_CLUSTER_ZONE}" \
53-
--format='value(networkInterfaces[0].accessConfigs[0].natIP)')
48+
49+
if [ "${IPV6_ENABLED}" = "true" ]; then
50+
echo "IPv6 is enabled, fetching the external IPv6 address"
51+
EXTERNAL_IP=$(gcloud compute instances describe "${RESOURCE_NAME}" --project="${GKE_PROJECT}" --zone="${GKE_CLUSTER_ZONE}" \
52+
--format='value(networkInterfaces[0].ipv6AccessConfigs[0].externalIpv6)')
53+
else
54+
echo "IPv6 is not enabled, fetching the external IPv4 address"
55+
EXTERNAL_IP=$(gcloud compute instances describe "${RESOURCE_NAME}" --project="${GKE_PROJECT}" --zone="${GKE_CLUSTER_ZONE}" \
56+
--format='value(networkInterfaces[0].accessConfigs[0].natIP)')
57+
fi
5458

55-
echo "Network interfaces of the VM are: ${NETWORK_INTERFACES}"
56-
echo "Access configs of the VM are: ${ACCESS_CONFIGS}"
5759
echo "External IP of the VM is: ${EXTERNAL_IP}"
58-
60+
5961
CURRENT_AUTH_NETWORK=$(gcloud container clusters describe "${GKE_CLUSTER_NAME}" --zone="${GKE_CLUSTER_ZONE}" \
6062
--format="value(masterAuthorizedNetworksConfig.cidrBlocks[0])" | sed 's/cidrBlock=//')
6163
echo "Current GKE master authorized networks: ${CURRENT_AUTH_NETWORK}"

0 commit comments

Comments
 (0)