ansible-collections / ansible-collections/google.cloud

google.cloud.gcp_sql_instance can't create private sql instance

Open
#476 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

##### SUMMARY

The `google.cloud.gcp_sql_instance` can't create an instance that is using internal ip addresses as it can't be connected to a network.
##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME

google.cloud.gcp_sql_instance
```
- name: create a instance
google.cloud.gcp_sql_instance:
name: "{{ antavo_project_name }}-sql"
database_version: 'MYSQL_5_6'
max_disk_size: '10737418240'
settings:
availability_type: 'REGIONAL'
backup_configuration:
binary_log_enabled: True
enabled: True
ip_configuration:
ipv4_enabled: True
authorized_networks:
- name: google dns server
value: 8.8.8.8/32
tier: db-n1-standard-1
region: "{{ region }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: sql_instance
```
There is no reference in the [documentation](https://docs.ansible.com/ansible/latest/collections/google/cloud/gcp_sql_instance_module.html#ansible-collections-google-cloud-gcp-sql-instance-module) to network either.
##### ANSIBLE VERSION

```bash
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

```bash

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 (same experience)

##### STEPS TO REPRODUCE

```yaml
- name: Allocate address for MySQL service
ansible.builtin.shell: |
export GOOGLE_APPLICATION_CREDENTIALS={{ gcp_cred_file }}

gcloud compute addresses create google-managed-services-{{ antavo_project_name}} \
--global --purpose=VPC_PEERING --prefix-length=16 \
--network=projects/{{ gcp_project }}/global/networks/test-net \
--project={{ gcp_project }}
ignore_errors: True
register: sql_address
- name: VPC Peering connection for MySQL service
ansible.builtin.shell: |
export GOOGLE_APPLICATION_CREDENTIALS={{ gcp_cred_file }}

gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com \
--ranges=google-managed-services-{{ antavo_project_name }} \
--network=test-net --project={{ gcp_project }}
ignore_errors: True
register: vpc_peering_sql
- name: create a instance
google.cloud.gcp_sql_instance:
name: "{{ antavo_project_name }}-sql"
database_version: 'MYSQL_5_6'
max_disk_size: '10737418240'
settings:
availability_type: 'REGIONAL'
backup_configuration:
binary_log_enabled: True
enabled: True
ip_configuration:
ipv4_enabled: True
authorized_networks:
- name: google dns server
value: 8.8.8.8/32
tier: db-n1-standard-1
region: "{{ region }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
state: present
register: sql_instance

```

##### EXPECTED RESULTS

The allocated address and VPC_Peering will be utilized by the SQL instance

##### ACTUAL RESULTS

It doesn't...

```paste below
TASK [VPC Peering connection for MySQL service] ******************************************************************************************
task path: /home/apinter/Project/Antavo/git/inventory/test_sql_playbook.yml:192
<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-1645524457.2077277-22664-115807961216236 `" && echo ansible-tmp-1645524457.2077277-22664-115807961216236="` echo /home/apinter/.ansible/tmp/ansible-tmp-1645524457.2077277-22664-115807961216236 `" ) && sleep 0'
Using module file /home/apinter/.local/lib/python3.8/site-packages/ansible/modules/command.py
<127.0.0.1> PUT /home/apinter/.ansible/tmp/ansible-local-22470b6xr8d8w/tmp2aklcq6t TO /home/apinter/.ansible/tmp/ansible-tmp-1645524457.2077277-22664-115807961216236/AnsiballZ_command.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/apinter/.ansible/tmp/ansible-tmp-1645524457.2077277-22664-115807961216236/ /home/apinter/.ansible/tmp/ansible-tmp-1645524457.2077277-22664-115807961216236/AnsiballZ_command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.8 /home/apinter/.ansible/tmp/ansible-tmp-1645524457.2077277-22664-115807961216236/AnsiballZ_command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/apinter/.ansible/tmp/ansible-tmp-1645524457.2077277-22664-115807961216236/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => changed=true
cmd: |-
export GOOGLE_APPLICATION_CREDENTIALS=/home/apinter/Project/Antavo/git/inventory/devops-sandbox.json

gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --ranges=google-managed-services-loyalty-sandbox --network=test-net --project=devops-sandbox-319813
delta: '0:00:21.586552'
end: '2022-02-22 17:07:58.956240'
invocation:
module_args:
_raw_params: |-
export GOOGLE_APPLICATION_CREDENTIALS=/home/apinter/Project/Antavo/git/inventory/devops-sandbox.json

gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --ranges=google-managed-services-loyalty-sandbox --network=test-net --project=devops-sandbox-319813
_uses_shell: true
argv: null
chdir: null
creates: null
executable: null
removes: null
stdin: null
stdin_add_newline: true
strip_empty_ends: true
warn: false
msg: ''
rc: 0
start: '2022-02-22 17:07:37.369688'
stderr: Operation "operations/pssn.p24-1015831777091-0f420252-32a8-4f7d-ba06-67f04342ba8f" finished successfully.
stderr_lines:
stdout: ''
stdout_lines:

TASK [create a instance] *****************************************************************************************************************
task path: /home/apinter/Project/Antavo/git/inventory/test_sql_playbook.yml:201
<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-1645524479.000601-23564-258429121099568 `" && echo ansible-tmp-1645524479.000601-23564-258429121099568="` echo /home/apinter/.ansible/tmp/ansible-tmp-1645524479.000601-23564-258429121099568 `" ) && sleep 0'
Using module file /home/apinter/.ansible/collections/ansible_collections/google/cloud/plugins/modules/gcp_sql_instance.py
<127.0.0.1> PUT /home/apinter/.ansible/tmp/ansible-local-22470b6xr8d8w/tmpqjdgbsgu TO /home/apinter/.ansible/tmp/ansible-tmp-1645524479.000601-23564-258429121099568/AnsiballZ_gcp_sql_instance.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/apinter/.ansible/tmp/ansible-tmp-1645524479.000601-23564-258429121099568/ /home/apinter/.ansible/tmp/ansible-tmp-1645524479.000601-23564-258429121099568/AnsiballZ_gcp_sql_instance.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.8 /home/apinter/.ansible/tmp/ansible-tmp-1645524479.000601-23564-258429121099568/AnsiballZ_gcp_sql_instance.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/apinter/.ansible/tmp/ansible-tmp-1645524479.000601-23564-258429121099568/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => changed=true
backendType: SECOND_GEN
connectionName: devops-sandbox-319813:europe-west4:loyalty-sandbox-sql
createTime: '2022-02-22T10:08:01.418Z'
databaseInstalledVersion: MYSQL_5_6_51
databaseVersion: MYSQL_5_6
etag: f97d016eddb313b7dd55d28ac7f3066d615429f7b3a97137b48c50c7c7361260
failoverReplica:
available: true
gceZone: europe-west4-c
instanceType: CLOUD_SQL_INSTANCE
invocation:
module_args:
auth_kind: serviceaccount
backend_type: null
connection_name: null
database_version: MYSQL_5_6
disk_encryption_configuration: null
disk_encryption_status: null
env_type: null
failover_replica: null
instance_type: null
ipv6_address: null
master_instance_name: null
max_disk_size: 10737418240
name: loyalty-sandbox-sql
project: devops-sandbox-319813
region: europe-west4
replica_configuration: null
scopes:
- https://www.googleapis.com/auth/sqlservice.admin
service_account_contents: null
service_account_email: null
service_account_file: /home/apinter/Project/Antavo/git/inventory/devops-sandbox.json
settings:
availability_type: REGIONAL
backup_configuration:
binary_log_enabled: true
enabled: true
start_time: null
database_flags: null
ip_configuration:
authorized_networks:
- expiration_time: null
name: google dns server
value: 8.8.8.8/32
ipv4_enabled: true
require_ssl: null
tier: db-n1-standard-1
user_labels: null
state: present
ipAddresses:
- ipAddress: 34.147.71.188
type: PRIMARY
kind: sql#instance
name: loyalty-sandbox-sql
project: devops-sandbox-319813
region: europe-west4
secondaryGceZone: europe-west4-a
selfLink: https://sqladmin.googleapis.com/sql/v1beta4/projects/devops-sandbox-319813/instances/loyalty-sandbox-sql
serverCaCert:
cert: |-
-----BEGIN CERTIFICATE-----
MIIDfzCCAmegAwIBAgIBADANBgkqhkiG9w0BAQsFADB3MS0wKwYDVQQuEyQ0NGJj
NjFlNC0xODE0LTQzNjMtYTc3Mi1jYjhkYzQzMzBmMmUxIzAhBgNVBAMTGkdvb2ds
ZSBDbG91ZCBTUUwgU2VydmVyIENBMRQwEgYDVQQKEwtHb29nbGUs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,O=Google\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=44bc61e4-1814-4363-a772-cb8dc4330f2e
createTime: '2022-02-22T10:09:35.450Z'
expirationTime: '2032-02-20T10:10:35.450Z'
instance: loyalty-sandbox-sql
kind: sql#sslCert
sha1Fingerprint: 7dfa22e3c4baf9591b858830d017054437d11e46
serviceAccountEmailAddress: p1015831777091-r0gpyh@gcp-sa-cloud-sql.iam.gserviceaccount.com
settings:
activationPolicy: ALWAYS
authorizedGaeApplications: []
availabilityType: REGIONAL
backupConfiguration:
backupRetentionSettings:
retainedBackups: 7
retentionUnit: COUNT
binaryLogEnabled: true
enabled: true
kind: sql#backupConfiguration
startTime: '12:00'
transactionLogRetentionDays: 7
dataDiskSizeGb: '10'
dataDiskType: PD_SSD
ipConfiguration:
authorizedNetworks:
- kind: sql#aclEntry
name: google dns server
value: 8.8.8.8/32
ipv4Enabled: true
kind: sql#settings
locationPreference:
kind: sql#locationPreference
zone: europe-west4-c
pricingPlan: PER_USE
replicationType: SYNCHRONOUS
settingsVersion: '3'
storageAutoResize: true
storageAutoResizeLimit: '0'
tier: db-n1-standard-1
state: RUNNABLE
```

Contributor guide

Open the contributing guide

Research direction

Start at the google.cloud.gcp_sql_instance module entry point and its documentation, using the reproduced playbook's settings.ip_configuration and VPC peering steps as the case to understand. Confirm how the module handles network selection; done means a private SQL instance can use the allocated VPC peering network and the supported option is documented.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.