mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Bug fixes for gcp_compute_instance (#42815)
This commit is contained in:
parent
7a92b8c9ed
commit
f977590a2a
2 changed files with 180 additions and 163 deletions
|
@ -15,36 +15,30 @@
|
|||
# Pre-test setup
|
||||
- name: create a disk
|
||||
gcp_compute_disk:
|
||||
name: 'disk-instance'
|
||||
name: "disk-instance"
|
||||
size_gb: 50
|
||||
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts'
|
||||
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: present
|
||||
register: disk
|
||||
- name: create a network
|
||||
gcp_compute_network:
|
||||
name: 'network-instance'
|
||||
name: "network-instance"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: present
|
||||
register: network
|
||||
- name: create a address
|
||||
gcp_compute_address:
|
||||
name: 'address-instance'
|
||||
region: 'us-central1'
|
||||
name: "address-instance"
|
||||
region: us-central1
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: present
|
||||
register: address
|
||||
- name: delete a instance
|
||||
|
@ -52,24 +46,22 @@
|
|||
name: "{{ resource_name }}"
|
||||
machine_type: n1-standard-1
|
||||
disks:
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
metadata:
|
||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
||||
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||
cost-center: '12345'
|
||||
network_interfaces:
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: 'External NAT'
|
||||
nat_ip: "{{ address }}"
|
||||
type: 'ONE_TO_ONE_NAT'
|
||||
zone: 'us-central1-a'
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: External NAT
|
||||
nat_ip: "{{ address }}"
|
||||
type: ONE_TO_ONE_NAT
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: absent
|
||||
#----------------------------------------------------------
|
||||
- name: create a instance
|
||||
|
@ -77,24 +69,22 @@
|
|||
name: "{{ resource_name }}"
|
||||
machine_type: n1-standard-1
|
||||
disks:
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
metadata:
|
||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
||||
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||
cost-center: '12345'
|
||||
network_interfaces:
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: 'External NAT'
|
||||
nat_ip: "{{ address }}"
|
||||
type: 'ONE_TO_ONE_NAT'
|
||||
zone: 'us-central1-a'
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: External NAT
|
||||
nat_ip: "{{ address }}"
|
||||
type: ONE_TO_ONE_NAT
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: present
|
||||
register: result
|
||||
- name: assert changed is true
|
||||
|
@ -103,37 +93,42 @@
|
|||
- result.changed == true
|
||||
- "result.kind == 'compute#instance'"
|
||||
- name: verify that instance was created
|
||||
shell: |
|
||||
gcloud compute instances describe --project="{{ gcp_project }}" --zone="us-central1-a" "{{ resource_name }}"
|
||||
gcp_compute_instance_facts:
|
||||
filters:
|
||||
- name = {{ resource_name }}
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
register: results
|
||||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- results.rc == 0
|
||||
- results['items'] | length == 1
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: create a instance that already exists
|
||||
gcp_compute_instance:
|
||||
name: "{{ resource_name }}"
|
||||
machine_type: n1-standard-1
|
||||
disks:
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
metadata:
|
||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
||||
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||
cost-center: '12345'
|
||||
network_interfaces:
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: 'External NAT'
|
||||
nat_ip: "{{ address }}"
|
||||
type: 'ONE_TO_ONE_NAT'
|
||||
zone: 'us-central1-a'
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: External NAT
|
||||
nat_ip: "{{ address }}"
|
||||
type: ONE_TO_ONE_NAT
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: present
|
||||
register: result
|
||||
- name: assert changed is false
|
||||
|
@ -147,24 +142,22 @@
|
|||
name: "{{ resource_name }}"
|
||||
machine_type: n1-standard-1
|
||||
disks:
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
metadata:
|
||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
||||
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||
cost-center: '12345'
|
||||
network_interfaces:
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: 'External NAT'
|
||||
nat_ip: "{{ address }}"
|
||||
type: 'ONE_TO_ONE_NAT'
|
||||
zone: 'us-central1-a'
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: External NAT
|
||||
nat_ip: "{{ address }}"
|
||||
type: ONE_TO_ONE_NAT
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: absent
|
||||
register: result
|
||||
- name: assert changed is true
|
||||
|
@ -173,39 +166,42 @@
|
|||
- result.changed == true
|
||||
- result.has_key('kind') == False
|
||||
- name: verify that instance was deleted
|
||||
shell: |
|
||||
gcloud compute instances describe --project="{{ gcp_project }}" --zone="us-central1-a" "{{ resource_name }}"
|
||||
gcp_compute_instance_facts:
|
||||
filters:
|
||||
- name = {{ resource_name }}
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
register: results
|
||||
failed_when: results.rc == 0
|
||||
- name: verify that command succeeded
|
||||
assert:
|
||||
that:
|
||||
- results.rc == 1
|
||||
- "\"'projects/{{ gcp_project }}/zones/us-central1-a/instances/{{ resource_name }}' was not found\" in results.stderr"
|
||||
- results['items'] | length == 0
|
||||
# ----------------------------------------------------------------------------
|
||||
- name: delete a instance that does not exist
|
||||
gcp_compute_instance:
|
||||
name: "{{ resource_name }}"
|
||||
machine_type: n1-standard-1
|
||||
disks:
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
- auto_delete: true
|
||||
boot: true
|
||||
source: "{{ disk }}"
|
||||
metadata:
|
||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
||||
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||
cost-center: '12345'
|
||||
network_interfaces:
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: 'External NAT'
|
||||
nat_ip: "{{ address }}"
|
||||
type: 'ONE_TO_ONE_NAT'
|
||||
zone: 'us-central1-a'
|
||||
- network: "{{ network }}"
|
||||
access_configs:
|
||||
- name: External NAT
|
||||
nat_ip: "{{ address }}"
|
||||
type: ONE_TO_ONE_NAT
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: absent
|
||||
register: result
|
||||
- name: assert changed is false
|
||||
|
@ -217,35 +213,29 @@
|
|||
# Post-test teardown
|
||||
- name: delete a address
|
||||
gcp_compute_address:
|
||||
name: 'address-instance'
|
||||
region: 'us-central1'
|
||||
name: "address-instance"
|
||||
region: us-central1
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: absent
|
||||
register: address
|
||||
- name: delete a network
|
||||
gcp_compute_network:
|
||||
name: 'network-instance'
|
||||
name: "network-instance"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: absent
|
||||
register: network
|
||||
- name: delete a disk
|
||||
gcp_compute_disk:
|
||||
name: 'disk-instance'
|
||||
name: "disk-instance"
|
||||
size_gb: 50
|
||||
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts'
|
||||
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
state: absent
|
||||
register: disk
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue