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
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
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:
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