# Problems with gcp\_compute\_instance

**URL:** <https://forum.ansible.com/t/problems-with-gcp-compute-instance/32538>\
**Category:** Ansible Project\
**Tags:** gcp\
**Created:** [March 26, 2020, 11:26am UTC](https://forum.ansible.com/t/problems-with-gcp-compute-instance/32538 "2020-03-26T11:26:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Kube](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Thomas\_Kube](https://forum.ansible.com/u/Thomas_Kube)\
**Post date:** [March 26, 2020, 11:26am UTC](https://forum.ansible.com/t/problems-with-gcp-compute-instance/32538/1 "2020-03-26T11:26:11Z")

</div>

Hello,

I’m branching to a problem with gcp\_compute\_instance. The server should be created inside a project that has a shared subnet in custom mode.

These are the individual steps to gather the informations for the network:

- name: “Gather network information for {{ vpc\_project }}”  
gcp\_compute\_network\_info:  
filters:

- name = “{{ vpc\_network }}”  
project: “{{ vpc\_project }}”  
auth\_kind: “{{ gcp\_cred\_kind }}”  
service\_account\_file: “{{ gcp\_cred\_file }}”  
register: vpcnetwork

- name: Create dictionary VPCselfLink  
set\_fact:  
VPCselfLink: “{{ VPCselfLink|default({}) | combine( {‘selfLink’: vpcnetwork[‘items’][0].selfLink} ) }}”

- name: “Gather subnet information from project {{ vpc\_project }} and subnetwork {{ vpc\_subnetwork }}”  
gcp\_compute\_subnetwork\_info:  
region: region  
project: myproject  
filters:

- name = “{{ vpc\_subnetwork }}”  
auth\_kind: “{{ gcp\_cred\_kind }}”  
service\_account\_file: “{{ gcp\_cred\_file }}”  
scopes:

- [https://www.googleapis.com/auth/compute](https://www.googleapis.com/auth/compute)  
register: vpcsubnetwork

- name: Create dictionary selfLink  
set\_fact:  
selfLink: “{{ selfLink|default({}) | combine( {‘selfLink’: vpcsubnetwork[‘items’][0].selfLink} ) }}”

- name: “Create IP address for server {{ instancename }}”  
gcp\_compute\_address:  
name: “ip-{{ instancename }}”  
region: “{{ region }}”  
project: “{{ gcp\_project }}”  
address\_type: INTERNAL  
subnetwork: “{{ selfLink }}”  
auth\_kind: “{{ gcp\_cred\_kind }}”  
service\_account\_file: “{{ gcp\_cred\_file }}”  
scopes:

- [https://www.googleapis.com/auth/compute](https://www.googleapis.com/auth/compute)  
state: present  
register: ipaddress

When I make this call for the network:

network\_interfaces:

- network: “{{ VPCselfLink }}”
- network\_ip: “{{ ipaddress.address }}”
- subnetwork: “{{ selfLink }}”

I get this error:

Fatal: [localhost]: FAILED! =\> {“changed”: false, “msg”: “GCP returned error: {‘error’: {‘errors’: [{‘domain’: ‘global’, ‘reason’: ‘invalid’, ‘message’: ‘Invalid value for field \‘resource.networkInterfaces[0]\’: \’{ "network": "[https://www.googleapis.com/compute/v1/projects/](https://www.googleapis.com/compute/v1/projects/)/global/networks/…\‘. Subnetwork should be specified for custom subnetmode network’}], ‘code’: 400, ‘message’: ‘Invalid value for field \‘resource.networkInterfaces[0]\’: \’{ "network": "[https://www.googleapis.com/compute/v1/projects/sap-shared-vpn/global/networks/vpc-ott](https://www.googleapis.com/compute/v1/projects/sap-shared-vpn/global/networks/vpc-ott)…\‘. Subnetwork should be specified for custom subnetmode network’}}”}

When I make this call for the network:

network\_interfaces:

- network\_ip: “{{ ipaddress.address }}”
- subnetwork: “{{ selfLink }}”

I get this error:

fatal: [localhost]: FAILED! =\> {“changed”: false, “msg”: “GCP returned error: {‘error’: {‘errors’: [{‘domain’: ‘global’, ‘reason’: ‘invalid’, ‘message’: "Invalid value for field ‘resource.networkInterfaces[0].network’: ‘’. The referenced network resource cannot be found."}], ‘code’: 400, ‘message’: "Invalid value for field ‘resource.networkInterfaces[0].network’: ‘’. The referenced network resource cannot be found."}}”}

What am I doing wrong? I am grateful for any help.

Thomas from Germany

---

<div class="post-metadata">

**Author:** ![Thomas\_Kube](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Thomas\_Kube](https://forum.ansible.com/u/Thomas_Kube)\
**Post date:** [March 26, 2020, 11:53am UTC](https://forum.ansible.com/t/problems-with-gcp-compute-instance/32538/2 "2020-03-26T11:53:47Z")

</div>

If I specify only the subnetwork value, then the server is assigned an IP address:

network\_interfaces:

- subnetwork: “{{ selfLink }}”

Thomas

---

<div class="post-metadata">

**Author:** ![Thomas\_Kube](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@Thomas\_Kube](https://forum.ansible.com/u/Thomas_Kube)\
**Post date:** [March 26, 2020, 1:44pm UTC](https://forum.ansible.com/t/problems-with-gcp-compute-instance/32538/3 "2020-03-26T13:44:57Z")

</div>

Sorry, found it:

network\_interfaces:

- network\_ip: “{{ ipaddress.address }}”
- subnetwork: “{{ selfLink }}”

is wrong

network\_interfaces:

- subnetwork: “{{ selfLink }}”

network\_ip: “{{ ipaddress.address }}”

is right. My fault.

Thomas

---

<div class="post-metadata">

**Author:** ![Sanjay\_Sreeram](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@Sanjay\_Sreeram](https://forum.ansible.com/u/Sanjay_Sreeram)\
**Post date:** [October 2, 2020, 3:38pm UTC](https://forum.ansible.com/t/problems-with-gcp-compute-instance/32538/4 "2020-10-02T15:38:26Z")

</div>

Following resolved the issue for me,

network\_interfaces:

- subnetwork:  
selfLink: “{{ subnet.resources[0].selfLink }}”  
Note: i have created register:subnet to gcp\_compute\_subnetwork\_info.
