Description
If a VM without an external IP needs to reach a supported Google API, check Private Google Access on the subnet its interface uses.
Potential impact
An API-dependent workload can fail when it has no usable path. Check the subnet and existing connectivity before adding an external IP to a VM.
Remediation
Set private_ip_google_access: yes where needed. Check DNS, routes, firewall rules and the caller’s API permissions. Test the required API from a VM without an external IP. Manage general internet access separately.
Examples
Pass the network result object in network, replace test_project with the project ID and replace /tmp/auth.pem with the path to the service account JSON file. The first task omits the setting, so check the existing subnet’s value. The second explicitly enables it.
Before
- name: Create a subnet
google.cloud.gcp_compute_subnetwork:
name: ansiblenet
region: us-west1
network: "{{ network }}"
ip_cidr_range: 172.16.0.0/16
project: test_project
auth_kind: serviceaccount
service_account_file: /tmp/auth.pem
state: present
After
- name: Create a subnet
google.cloud.gcp_compute_subnetwork:
name: ansiblenet
region: us-west1
network: "{{ network }}"
ip_cidr_range: 172.16.0.0/16
project: test_project
auth_kind: serviceaccount
service_account_file: /tmp/auth.pem
private_ip_google_access: yes
state: present