| 1 |
--- |
| 2 |
# ---------------------------------------------------------------------------- |
| 3 |
# |
| 4 |
# *** AUTO GENERATED CODE *** Type: MMv1 *** |
| 5 |
# |
| 6 |
# ---------------------------------------------------------------------------- |
| 7 |
# |
| 8 |
# This file is automatically generated by Magic Modules and manual |
| 9 |
# changes will be clobbered when the file is regenerated. |
| 10 |
# |
| 11 |
# Please read more about how to change this file at |
| 12 |
# https://www.github.com/GoogleCloudPlatform/magic-modules |
| 13 |
# |
| 14 |
# ---------------------------------------------------------------------------- |
| 15 |
# Pre-test setup |
| 16 |
- name: Create a disk |
| 17 |
google.cloud.gcp_compute_disk: |
| 18 |
name: "{{ resource_prefix }}" |
| 19 |
size_gb: 50 |
| 20 |
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-minimal-2204-lts |
| 21 |
zone: us-central1-a |
| 22 |
project: "{{ gcp_project }}" |
| 23 |
auth_kind: "{{ gcp_cred_kind }}" |
| 24 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 25 |
state: present |
| 26 |
register: disk |
| 27 |
- name: Create a network |
| 28 |
google.cloud.gcp_compute_network: |
| 29 |
name: "{{ resource_prefix }}" |
| 30 |
project: "{{ gcp_project }}" |
| 31 |
auth_kind: "{{ gcp_cred_kind }}" |
| 32 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 33 |
auto_create_subnetworks: true |
| 34 |
state: present |
| 35 |
register: network |
| 36 |
- name: Create a address |
| 37 |
google.cloud.gcp_compute_address: |
| 38 |
name: address-instance |
| 39 |
region: us-central1 |
| 40 |
project: "{{ gcp_project }}" |
| 41 |
auth_kind: "{{ gcp_cred_kind }}" |
| 42 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 43 |
state: present |
| 44 |
register: address |
| 45 |
- name: Delete a instance |
| 46 |
google.cloud.gcp_compute_instance: |
| 47 |
name: "{{ resource_name }}" |
| 48 |
machine_type: n1-standard-1 |
| 49 |
disks: |
| 50 |
- auto_delete: "true" |
| 51 |
boot: "true" |
| 52 |
source: "{{ disk }}" |
| 53 |
- auto_delete: "true" |
| 54 |
interface: NVME |
| 55 |
type: SCRATCH |
| 56 |
initialize_params: |
| 57 |
disk_type: local-ssd |
| 58 |
metadata: |
| 59 |
cost-center: "12345" |
| 60 |
labels: |
| 61 |
environment: production |
| 62 |
network_interfaces: |
| 63 |
- network: "{{ network }}" |
| 64 |
access_configs: |
| 65 |
- name: External NAT |
| 66 |
nat_ip: "{{ address }}" |
| 67 |
type: ONE_TO_ONE_NAT |
| 68 |
zone: us-central1-a |
| 69 |
project: "{{ gcp_project }}" |
| 70 |
auth_kind: "{{ gcp_cred_kind }}" |
| 71 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 72 |
state: absent |
| 73 |
# ---------------------------------------------------------- |
| 74 |
- name: Create a instance |
| 75 |
google.cloud.gcp_compute_instance: |
| 76 |
name: "{{ resource_name }}" |
| 77 |
machine_type: n1-standard-1 |
| 78 |
disks: |
| 79 |
- auto_delete: "true" |
| 80 |
boot: "true" |
| 81 |
source: "{{ disk }}" |
| 82 |
- auto_delete: "true" |
| 83 |
interface: NVME |
| 84 |
type: SCRATCH |
| 85 |
initialize_params: |
| 86 |
disk_type: local-ssd |
| 87 |
metadata: |
| 88 |
cost-center: "12345" |
| 89 |
labels: |
| 90 |
environment: production |
| 91 |
network_interfaces: |
| 92 |
- network: "{{ network }}" |
| 93 |
access_configs: |
| 94 |
- name: External NAT |
| 95 |
nat_ip: "{{ address }}" |
| 96 |
type: ONE_TO_ONE_NAT |
| 97 |
zone: us-central1-a |
| 98 |
project: "{{ gcp_project }}" |
| 99 |
auth_kind: "{{ gcp_cred_kind }}" |
| 100 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 101 |
state: present |
| 102 |
register: result |
| 103 |
- name: Assert changed is true |
| 104 |
ansible.builtin.assert: |
| 105 |
that: |
| 106 |
- result.changed == true |
| 107 |
- name: Verify that instance was created |
| 108 |
google.cloud.gcp_compute_instance_info: |
| 109 |
filters: |
| 110 |
- name = {{ resource_name }} |
| 111 |
zone: us-central1-a |
| 112 |
project: "{{ gcp_project }}" |
| 113 |
auth_kind: "{{ gcp_cred_kind }}" |
| 114 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 115 |
scopes: |
| 116 |
- https://www.googleapis.com/auth/compute |
| 117 |
register: results |
| 118 |
- name: Verify that command succeeded |
| 119 |
ansible.builtin.assert: |
| 120 |
that: |
| 121 |
- results['resources'] | length == 1 |
| 122 |
# ---------------------------------------------------------------------------- |
| 123 |
- name: Create a instance that already exists |
| 124 |
google.cloud.gcp_compute_instance: |
| 125 |
name: "{{ resource_name }}" |
| 126 |
machine_type: n1-standard-1 |
| 127 |
disks: |
| 128 |
- auto_delete: "true" |
| 129 |
boot: "true" |
| 130 |
source: "{{ disk }}" |
| 131 |
- auto_delete: "true" |
| 132 |
interface: NVME |
| 133 |
type: SCRATCH |
| 134 |
initialize_params: |
| 135 |
disk_type: local-ssd |
| 136 |
metadata: |
| 137 |
cost-center: "12345" |
| 138 |
labels: |
| 139 |
environment: production |
| 140 |
network_interfaces: |
| 141 |
- network: "{{ network }}" |
| 142 |
access_configs: |
| 143 |
- name: External NAT |
| 144 |
nat_ip: "{{ address }}" |
| 145 |
type: ONE_TO_ONE_NAT |
| 146 |
zone: us-central1-a |
| 147 |
project: "{{ gcp_project }}" |
| 148 |
auth_kind: "{{ gcp_cred_kind }}" |
| 149 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 150 |
state: present |
| 151 |
register: result |
| 152 |
- name: Assert changed is false |
| 153 |
ansible.builtin.assert: |
| 154 |
that: |
| 155 |
- result.changed == false |
| 156 |
# ---------------------------------------------------------- |
| 157 |
- name: Delete a instance |
| 158 |
google.cloud.gcp_compute_instance: |
| 159 |
name: "{{ resource_name }}" |
| 160 |
machine_type: n1-standard-1 |
| 161 |
disks: |
| 162 |
- auto_delete: "true" |
| 163 |
boot: "true" |
| 164 |
source: "{{ disk }}" |
| 165 |
- auto_delete: "true" |
| 166 |
interface: NVME |
| 167 |
type: SCRATCH |
| 168 |
initialize_params: |
| 169 |
disk_type: local-ssd |
| 170 |
metadata: |
| 171 |
cost-center: "12345" |
| 172 |
labels: |
| 173 |
environment: production |
| 174 |
network_interfaces: |
| 175 |
- network: "{{ network }}" |
| 176 |
access_configs: |
| 177 |
- name: External NAT |
| 178 |
nat_ip: "{{ address }}" |
| 179 |
type: ONE_TO_ONE_NAT |
| 180 |
zone: us-central1-a |
| 181 |
project: "{{ gcp_project }}" |
| 182 |
auth_kind: "{{ gcp_cred_kind }}" |
| 183 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 184 |
state: absent |
| 185 |
register: result |
| 186 |
- name: Assert changed is true |
| 187 |
ansible.builtin.assert: |
| 188 |
that: |
| 189 |
- result.changed == true |
| 190 |
- name: Verify that instance was deleted |
| 191 |
google.cloud.gcp_compute_instance_info: |
| 192 |
filters: |
| 193 |
- name = {{ resource_name }} |
| 194 |
zone: us-central1-a |
| 195 |
project: "{{ gcp_project }}" |
| 196 |
auth_kind: "{{ gcp_cred_kind }}" |
| 197 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 198 |
scopes: |
| 199 |
- https://www.googleapis.com/auth/compute |
| 200 |
register: results |
| 201 |
- name: Verify that command succeeded |
| 202 |
ansible.builtin.assert: |
| 203 |
that: |
| 204 |
- results['resources'] | length == 0 |
| 205 |
# ---------------------------------------------------------------------------- |
| 206 |
- name: Delete a instance that does not exist |
| 207 |
google.cloud.gcp_compute_instance: |
| 208 |
name: "{{ resource_name }}" |
| 209 |
machine_type: n1-standard-1 |
| 210 |
disks: |
| 211 |
- auto_delete: "true" |
| 212 |
boot: "true" |
| 213 |
source: "{{ disk }}" |
| 214 |
- auto_delete: "true" |
| 215 |
interface: NVME |
| 216 |
type: SCRATCH |
| 217 |
initialize_params: |
| 218 |
disk_type: local-ssd |
| 219 |
metadata: |
| 220 |
cost-center: "12345" |
| 221 |
labels: |
| 222 |
environment: production |
| 223 |
network_interfaces: |
| 224 |
- network: "{{ network }}" |
| 225 |
access_configs: |
| 226 |
- name: External NAT |
| 227 |
nat_ip: "{{ address }}" |
| 228 |
type: ONE_TO_ONE_NAT |
| 229 |
zone: us-central1-a |
| 230 |
project: "{{ gcp_project }}" |
| 231 |
auth_kind: "{{ gcp_cred_kind }}" |
| 232 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 233 |
state: absent |
| 234 |
register: result |
| 235 |
- name: Assert changed is false |
| 236 |
ansible.builtin.assert: |
| 237 |
that: |
| 238 |
- result.changed == false |
| 239 |
# --------------------------------------------------------- |
| 240 |
# Post-test teardown |
| 241 |
# If errors happen, don't crash the playbook! |
| 242 |
- name: Delete a address |
| 243 |
google.cloud.gcp_compute_address: |
| 244 |
name: address-instance |
| 245 |
region: us-central1 |
| 246 |
project: "{{ gcp_project }}" |
| 247 |
auth_kind: "{{ gcp_cred_kind }}" |
| 248 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 249 |
state: absent |
| 250 |
register: address |
| 251 |
ignore_errors: true |
| 252 |
- name: Delete a network |
| 253 |
google.cloud.gcp_compute_network: |
| 254 |
name: "{{ resource_prefix }}" |
| 255 |
project: "{{ gcp_project }}" |
| 256 |
auth_kind: "{{ gcp_cred_kind }}" |
| 257 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 258 |
auto_create_subnetworks: true |
| 259 |
state: absent |
| 260 |
register: network |
| 261 |
ignore_errors: true |
| 262 |
- name: Delete a disk |
| 263 |
google.cloud.gcp_compute_disk: |
| 264 |
name: "{{ resource_prefix }}" |
| 265 |
size_gb: 50 |
| 266 |
source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-minimal-2204-lts |
| 267 |
zone: us-central1-a |
| 268 |
project: "{{ gcp_project }}" |
| 269 |
auth_kind: "{{ gcp_cred_kind }}" |
| 270 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 271 |
state: absent |
| 272 |
register: disk |
| 273 |
ignore_errors: true |