ansible-collections / ansible-collections/google.cloud

gcp_compute_address can't create address for VPC_PEERING

Open
#477 1 comment 0 reactions 0 assignees View on GitHub
stale
Dominant language
Python
Stars
105
Forks
144
Avg merge
5d 10h
Merged PRs (30d)
4

Description

gcp_compute_address can't create address for VPC_PEERING
##### SUMMARY

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME

##### ANSIBLE VERSION

```paste below
ansible [core 2.12.1]
config file = /home/apinter/.ansible.cfg
configured module search path = ['/home/apinter/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/apinter/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/apinter/.ansible/collections:/usr/share/ansible/collections
executable location = /home/apinter/.local/bin/ansible
python version = 3.8.12 (default, Aug 31 2021, 01:23:42) [GCC]
jinja version = 3.0.3
libyaml = True
```

##### COLLECTION VERSION

```paste below
google.cloud 1.0.2
```

##### CONFIGURATION

```paste below
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
DEFAULT_HOST_LIST(/home/apinter/Project/Antavo/git/inventory/ansible.cfg) = ['/home/apinter/Project/Antavo/git/inventory/inventory.gcp.yml']
DEFAULT_PRIVATE_KEY_FILE(/home/apinter/Project/Antavo/git/inventory/ansible.cfg) = /home/apinter/.ssh/antavo_gcp
DEFAULT_REMOTE_USER(/home/apinter/Project/Antavo/git/inventory/ansible.cfg) = attila.pinter
DEFAULT_STDOUT_CALLBACK(/home/apinter/Project/Antavo/git/inventory/ansible.cfg) = yaml
HOST_KEY_CHECKING(/home/apinter/Project/Antavo/git/inventory/ansible.cfg) = False
INVENTORY_ENABLED(/home/apinter/Project/Antavo/git/inventory/ansible.cfg) = ['gcp_compute']
```

##### OS / ENVIRONMENT

openSUSE Tumbleweed, Fedora 35

##### STEPS TO REPRODUCE

```yaml
- name: create an address used for the gateway instance
gcp_compute_address:
name: "google-managed-services-{{ antavo_project_name }}"
address: '10.39.1.2'
address_type: "internal"
purpose: VPC_PEERING
subnetwork:
selfLink: 'projects/{{ gcp_project }}/regions/{{ region }}/subnetworks/db-sn2'
project: "{{ gcp_project }}"
region: "{{ region }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: sql_address
```

##### EXPECTED RESULTS

##### ACTUAL RESULTS

Doesn't work....

```paste below
--- git/inventory ‹main* D?› » ansible-playbook test_sql_playbook.yml -vvvv 2 ↵
ansible-playbook [core 2.12.1]
config file = /home/apinter/Project/Antavo/git/inventory/ansible.cfg
configured module search path = ['/home/apinter/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/apinter/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/apinter/.ansible/collections:/usr/share/ansible/collections
executable location = /home/apinter/.local/bin/ansible-playbook
python version = 3.8.12 (default, Aug 31 2021, 01:23:42) [GCC]
jinja version = 3.0.3
libyaml = True
Using /home/apinter/Project/Antavo/git/inventory/ansible.cfg as config file
setting up inventory plugins
redirecting (type: inventory) ansible.builtin.gcp_compute to google.cloud.gcp_compute
Loading collection google.cloud from /home/apinter/.ansible/collections/ansible_collections/google/cloud
Parsed /home/apinter/Project/Antavo/git/inventory/inventory.gcp.yml inventory source with ansible_collections.google.cloud.plugins.inventory.gcp_compute plugin
redirecting (type: modules) ansible.builtin.gcp_compute_address to google.cloud.gcp_compute_address
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Loading collection community.general from /home/apinter/.ansible/collections/ansible_collections/community/general
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Loading callback plugin community.general.yaml of type stdout, v2.0 from /home/apinter/.ansible/collections/ansible_collections/community/general/plugins/callback/yaml.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: test_sql_playbook.yml **********************************************************************************************************
Positional arguments: test_sql_playbook.yml
verbosity: 4
private_key_file: /home/apinter/.ssh/antavo_gcp
remote_user: attila.pinter
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/home/apinter/Project/Antavo/git/inventory/inventory.gcp.yml',)
forks: 5
1 plays in test_sql_playbook.yml

PLAY [Create an instance] ****************************************************************************************************************
META: ran handlers

TASK [create an address used for the gateway instance] ***********************************************************************************
task path: /home/apinter/Project/Antavo/git/inventory/test_sql_playbook.yml:168
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: apinter
<127.0.0.1> EXEC /bin/sh -c 'echo ~apinter && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/apinter/.ansible/tmp `"&& mkdir "` echo /home/apinter/.ansible/tmp/ansible-tmp-1645527559.5705075-14699-18958540088417 `" && echo ansible-tmp-1645527559.5705075-14699-18958540088417="` echo /home/apinter/.ansible/tmp/ansible-tmp-1645527559.5705075-14699-18958540088417 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.gcp_compute_address to google.cloud.gcp_compute_address
Using module file /home/apinter/.ansible/collections/ansible_collections/google/cloud/plugins/modules/gcp_compute_address.py
<127.0.0.1> PUT /home/apinter/.ansible/tmp/ansible-local-1463673q8oiqv/tmpl41bfs4q TO /home/apinter/.ansible/tmp/ansible-tmp-1645527559.5705075-14699-18958540088417/AnsiballZ_gcp_compute_address.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/apinter/.ansible/tmp/ansible-tmp-1645527559.5705075-14699-18958540088417/ /home/apinter/.ansible/tmp/ansible-tmp-1645527559.5705075-14699-18958540088417/AnsiballZ_gcp_compute_address.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.8 /home/apinter/.ansible/tmp/ansible-tmp-1645527559.5705075-14699-18958540088417/AnsiballZ_gcp_compute_address.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/apinter/.ansible/tmp/ansible-tmp-1645527559.5705075-14699-18958540088417/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
File "/tmp/ansible_gcp_compute_address_payload_oep7rjg6/ansible_gcp_compute_address_payload.zip/ansible_collections/google/cloud/plugins/module_utils/gcp_utils.py", line 312, in raise_for_status
response.raise_for_status()
File "/home/apinter/.local/lib/python3.8/site-packages/requests/models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
fatal: [localhost]: FAILED! => changed=false
invocation:
module_args:
address: 10.39.1.2
address_type: internal
auth_kind: serviceaccount
description: null
env_type: null
name: google-managed-services-loyalty-sandbox
network_tier: null
project: devops-sandbox-319813
purpose: VPC_PEERING
region: europe-west4
scopes:
- https://www.googleapis.com/auth/compute
service_account_contents: null
service_account_email: null
service_account_file: /home/apinter/Project/Antavo/git/inventory/devops-sandbox.json
state: present
subnetwork:
selfLink: projects/devops-sandbox-319813/regions/europe-west4/subnetworks/db-sn2
msg: 'GCP returned error: {''error'': {''code'': 400, ''message'': "Invalid value for field ''resource.purpose'': ''VPC_PEERING''. The type/purpose values are invalid for subnetwork address.", ''errors'': [{''message'': "Invalid value for field ''resource.purpose'': ''VPC_PEERING''. The type/purpose values are invalid for subnetwork address.", ''domain'': ''global'', ''reason'': ''invalid''}]}}'

PLAY RECAP *******************************************************************************************************************************

```

Contributor guide

Open the contributing guide

Research direction

Start with google/cloud/plugins/modules/gcp_compute_address.py and the gcp_utils.py traceback, then reproduce the failure from test_sql_playbook.yml at line 168 using the provided playbook task. Check how the module handles the VPC_PEERING purpose with a subnetwork; done means the task creates the requested address without the GCP invalid-purpose error.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, gcp, python
Domain
cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.