mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02: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
|
@ -122,7 +122,9 @@ options:
|
||||||
required: false
|
required: false
|
||||||
disk_type:
|
disk_type:
|
||||||
description:
|
description:
|
||||||
- A reference to DiskType resource.
|
- Reference to a gcompute_disk_type resource.
|
||||||
|
- Specifies the disk type to use to create the instance.
|
||||||
|
- If not specified, the default is pd-standard.
|
||||||
required: false
|
required: false
|
||||||
source_image:
|
source_image:
|
||||||
description:
|
description:
|
||||||
|
@ -165,7 +167,10 @@ options:
|
||||||
choices: ['READ_WRITE', 'READ_ONLY']
|
choices: ['READ_WRITE', 'READ_ONLY']
|
||||||
source:
|
source:
|
||||||
description:
|
description:
|
||||||
- A reference to Disk resource.
|
- Reference to a gcompute_disk resource. When creating a new instance, one of initializeParams.sourceImage
|
||||||
|
or disks.source is required.
|
||||||
|
- If desired, you can also attach existing non-root persistent disks using this property.
|
||||||
|
This field is only applicable for persistent disks.
|
||||||
required: false
|
required: false
|
||||||
type:
|
type:
|
||||||
description:
|
description:
|
||||||
|
@ -200,7 +205,7 @@ options:
|
||||||
required: false
|
required: false
|
||||||
machine_type:
|
machine_type:
|
||||||
description:
|
description:
|
||||||
- A reference to MachineType resource.
|
- A reference to a machine type which defines VM kind.
|
||||||
required: false
|
required: false
|
||||||
min_cpu_platform:
|
min_cpu_platform:
|
||||||
description:
|
description:
|
||||||
|
@ -238,8 +243,13 @@ options:
|
||||||
required: true
|
required: true
|
||||||
nat_ip:
|
nat_ip:
|
||||||
description:
|
description:
|
||||||
- A reference to Address resource.
|
- Specifies the title of a gcompute_address.
|
||||||
required: true
|
- An external IP address associated with this instance.
|
||||||
|
- Specify an unused static external IP address available to the project or leave this
|
||||||
|
field undefined to use an IP from a shared ephemeral IP address pool. If you specify
|
||||||
|
a static external IP address, it must live in the same region as the zone of the
|
||||||
|
instance.
|
||||||
|
required: false
|
||||||
type:
|
type:
|
||||||
description:
|
description:
|
||||||
- The type of configuration. The default and only option is ONE_TO_ONE_NAT.
|
- The type of configuration. The default and only option is ONE_TO_ONE_NAT.
|
||||||
|
@ -272,7 +282,10 @@ options:
|
||||||
required: false
|
required: false
|
||||||
network:
|
network:
|
||||||
description:
|
description:
|
||||||
- A reference to Network resource.
|
- Specifies the title of an existing gcompute_network. When creating an instance,
|
||||||
|
if neither the network nor the subnetwork is specified, the default network global/networks/default
|
||||||
|
is used; if the network is not specified but the subnetwork is specified, the network
|
||||||
|
is inferred.
|
||||||
required: false
|
required: false
|
||||||
network_ip:
|
network_ip:
|
||||||
description:
|
description:
|
||||||
|
@ -281,7 +294,10 @@ options:
|
||||||
required: false
|
required: false
|
||||||
subnetwork:
|
subnetwork:
|
||||||
description:
|
description:
|
||||||
- A reference to Subnetwork resource.
|
- Reference to a gcompute_subnetwork resource.
|
||||||
|
- If the network resource is in legacy mode, do not provide this property. If the
|
||||||
|
network is in auto subnet mode, providing the subnetwork is optional. If the network
|
||||||
|
is in custom subnet mode, then this field should be specified.
|
||||||
required: false
|
required: false
|
||||||
scheduling:
|
scheduling:
|
||||||
description:
|
description:
|
||||||
|
@ -345,7 +361,7 @@ options:
|
||||||
required: false
|
required: false
|
||||||
zone:
|
zone:
|
||||||
description:
|
description:
|
||||||
- A reference to Zone resource.
|
- A reference to the zone where the machine resides.
|
||||||
required: true
|
required: true
|
||||||
extends_documentation_fragment: gcp
|
extends_documentation_fragment: gcp
|
||||||
'''
|
'''
|
||||||
|
@ -353,64 +369,56 @@ extends_documentation_fragment: gcp
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: create a disk
|
- name: create a disk
|
||||||
gcp_compute_disk:
|
gcp_compute_disk:
|
||||||
name: 'disk-instance'
|
name: "disk-instance"
|
||||||
size_gb: 50
|
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
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: disk
|
register: disk
|
||||||
|
|
||||||
- name: create a network
|
- name: create a network
|
||||||
gcp_compute_network:
|
gcp_compute_network:
|
||||||
name: 'network-instance'
|
name: "network-instance"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: network
|
register: network
|
||||||
|
|
||||||
- name: create a address
|
- name: create a address
|
||||||
gcp_compute_address:
|
gcp_compute_address:
|
||||||
name: 'address-instance'
|
name: "address-instance"
|
||||||
region: 'us-central1'
|
region: us-central1
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: address
|
register: address
|
||||||
|
|
||||||
- name: create a instance
|
- name: create a instance
|
||||||
gcp_compute_instance:
|
gcp_compute_instance:
|
||||||
name: testObject
|
name: "test_object"
|
||||||
machine_type: n1-standard-1
|
machine_type: n1-standard-1
|
||||||
disks:
|
disks:
|
||||||
- auto_delete: true
|
- auto_delete: true
|
||||||
boot: true
|
boot: true
|
||||||
source: "{{ disk }}"
|
source: "{{ disk }}"
|
||||||
metadata:
|
metadata:
|
||||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||||
cost-center: '12345'
|
cost-center: '12345'
|
||||||
network_interfaces:
|
network_interfaces:
|
||||||
- network: "{{ network }}"
|
- network: "{{ network }}"
|
||||||
access_configs:
|
access_configs:
|
||||||
- name: 'External NAT'
|
- name: External NAT
|
||||||
nat_ip: "{{ address }}"
|
nat_ip: "{{ address }}"
|
||||||
type: 'ONE_TO_ONE_NAT'
|
type: ONE_TO_ONE_NAT
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: testProject
|
project: "test_project"
|
||||||
auth_kind: service_account
|
auth_kind: "service_account"
|
||||||
service_account_file: /tmp/auth.pem
|
service_account_file: "/tmp/auth.pem"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -511,7 +519,9 @@ RETURN = '''
|
||||||
type: int
|
type: int
|
||||||
disk_type:
|
disk_type:
|
||||||
description:
|
description:
|
||||||
- A reference to DiskType resource.
|
- Reference to a gcompute_disk_type resource.
|
||||||
|
- Specifies the disk type to use to create the instance.
|
||||||
|
- If not specified, the default is pd-standard.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
source_image:
|
source_image:
|
||||||
|
@ -559,7 +569,10 @@ RETURN = '''
|
||||||
type: str
|
type: str
|
||||||
source:
|
source:
|
||||||
description:
|
description:
|
||||||
- A reference to Disk resource.
|
- Reference to a gcompute_disk resource. When creating a new instance, one of initializeParams.sourceImage
|
||||||
|
or disks.source is required.
|
||||||
|
- If desired, you can also attach existing non-root persistent disks using this property.
|
||||||
|
This field is only applicable for persistent disks.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
type:
|
type:
|
||||||
|
@ -605,7 +618,7 @@ RETURN = '''
|
||||||
type: dict
|
type: dict
|
||||||
machine_type:
|
machine_type:
|
||||||
description:
|
description:
|
||||||
- A reference to MachineType resource.
|
- A reference to a machine type which defines VM kind.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
min_cpu_platform:
|
min_cpu_platform:
|
||||||
|
@ -649,7 +662,12 @@ RETURN = '''
|
||||||
type: str
|
type: str
|
||||||
nat_ip:
|
nat_ip:
|
||||||
description:
|
description:
|
||||||
- A reference to Address resource.
|
- Specifies the title of a gcompute_address.
|
||||||
|
- An external IP address associated with this instance.
|
||||||
|
- Specify an unused static external IP address available to the project or leave this
|
||||||
|
field undefined to use an IP from a shared ephemeral IP address pool. If you specify
|
||||||
|
a static external IP address, it must live in the same region as the zone of the
|
||||||
|
instance.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
type:
|
type:
|
||||||
|
@ -688,7 +706,10 @@ RETURN = '''
|
||||||
type: str
|
type: str
|
||||||
network:
|
network:
|
||||||
description:
|
description:
|
||||||
- A reference to Network resource.
|
- Specifies the title of an existing gcompute_network. When creating an instance,
|
||||||
|
if neither the network nor the subnetwork is specified, the default network global/networks/default
|
||||||
|
is used; if the network is not specified but the subnetwork is specified, the network
|
||||||
|
is inferred.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
network_ip:
|
network_ip:
|
||||||
|
@ -699,7 +720,10 @@ RETURN = '''
|
||||||
type: str
|
type: str
|
||||||
subnetwork:
|
subnetwork:
|
||||||
description:
|
description:
|
||||||
- A reference to Subnetwork resource.
|
- Reference to a gcompute_subnetwork resource.
|
||||||
|
- If the network resource is in legacy mode, do not provide this property. If the
|
||||||
|
network is in auto subnet mode, providing the subnetwork is optional. If the network
|
||||||
|
is in custom subnet mode, then this field should be specified.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
scheduling:
|
scheduling:
|
||||||
|
@ -741,7 +765,7 @@ RETURN = '''
|
||||||
description:
|
description:
|
||||||
- Email address of the service account.
|
- Email address of the service account.
|
||||||
returned: success
|
returned: success
|
||||||
type: bool
|
type: str
|
||||||
scopes:
|
scopes:
|
||||||
description:
|
description:
|
||||||
- The list of scopes to be made available for this service account.
|
- The list of scopes to be made available for this service account.
|
||||||
|
@ -783,7 +807,7 @@ RETURN = '''
|
||||||
type: list
|
type: list
|
||||||
zone:
|
zone:
|
||||||
description:
|
description:
|
||||||
- A reference to Zone resource.
|
- A reference to the zone where the machine resides.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
'''
|
'''
|
||||||
|
@ -846,7 +870,7 @@ def main():
|
||||||
network_interfaces=dict(type='list', elements='dict', options=dict(
|
network_interfaces=dict(type='list', elements='dict', options=dict(
|
||||||
access_configs=dict(type='list', elements='dict', options=dict(
|
access_configs=dict(type='list', elements='dict', options=dict(
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
nat_ip=dict(required=True, type='dict'),
|
nat_ip=dict(type='dict'),
|
||||||
type=dict(required=True, type='str', choices=['ONE_TO_ONE_NAT'])
|
type=dict(required=True, type='str', choices=['ONE_TO_ONE_NAT'])
|
||||||
)),
|
)),
|
||||||
alias_ip_ranges=dict(type='list', elements='dict', options=dict(
|
alias_ip_ranges=dict(type='list', elements='dict', options=dict(
|
||||||
|
@ -875,6 +899,9 @@ def main():
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not module.params['scopes']:
|
||||||
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
kind = 'compute#instance'
|
kind = 'compute#instance'
|
||||||
|
|
||||||
|
@ -884,10 +911,10 @@ def main():
|
||||||
if fetch:
|
if fetch:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if is_different(module, fetch):
|
if is_different(module, fetch):
|
||||||
fetch = update(module, self_link(module), kind, fetch)
|
fetch = update(module, self_link(module), kind)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
delete(module, self_link(module), kind, fetch)
|
delete(module, self_link(module), kind)
|
||||||
fetch = {}
|
fetch = {}
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
|
@ -907,12 +934,12 @@ def create(module, link, kind):
|
||||||
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
||||||
|
|
||||||
|
|
||||||
def delete(module, link, kind, fetch):
|
def delete(module, link, kind):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
return wait_for_operation(module, auth.delete(link))
|
return wait_for_operation(module, auth.delete(link))
|
||||||
|
|
||||||
|
@ -922,15 +949,15 @@ def resource_to_request(module):
|
||||||
u'kind': 'compute#instance',
|
u'kind': 'compute#instance',
|
||||||
u'canIpForward': module.params.get('can_ip_forward'),
|
u'canIpForward': module.params.get('can_ip_forward'),
|
||||||
u'disks': InstanceDisksArray(module.params.get('disks', []), module).to_request(),
|
u'disks': InstanceDisksArray(module.params.get('disks', []), module).to_request(),
|
||||||
u'guestAccelerators': InstancGuestAccelerArray(module.params.get('guest_accelerators', []), module).to_request(),
|
u'guestAccelerators': InstanceGuestAcceleratorsArray(module.params.get('guest_accelerators', []), module).to_request(),
|
||||||
u'labelFingerprint': module.params.get('label_fingerprint'),
|
u'labelFingerprint': module.params.get('label_fingerprint'),
|
||||||
u'metadata': module.params.get('metadata'),
|
u'metadata': module.params.get('metadata'),
|
||||||
u'machineType': machine_type_selflink(module.params.get('machine_type'), module.params),
|
u'machineType': machine_type_selflink(module.params.get('machine_type'), module.params),
|
||||||
u'minCpuPlatform': module.params.get('min_cpu_platform'),
|
u'minCpuPlatform': module.params.get('min_cpu_platform'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'networkInterfaces': InstancNetworkInterfaArray(module.params.get('network_interfaces', []), module).to_request(),
|
u'networkInterfaces': InstanceNetworkInterfacesArray(module.params.get('network_interfaces', []), module).to_request(),
|
||||||
u'scheduling': InstanceScheduling(module.params.get('scheduling', {}), module).to_request(),
|
u'scheduling': InstanceScheduling(module.params.get('scheduling', {}), module).to_request(),
|
||||||
u'serviceAccounts': InstancServiceAccountArray(module.params.get('service_accounts', []), module).to_request(),
|
u'serviceAccounts': InstanceServiceAccountsArray(module.params.get('service_accounts', []), module).to_request(),
|
||||||
u'tags': InstanceTags(module.params.get('tags', {}), module).to_request()
|
u'tags': InstanceTags(module.params.get('tags', {}), module).to_request()
|
||||||
}
|
}
|
||||||
request = encode_request(request, module)
|
request = encode_request(request, module)
|
||||||
|
@ -1007,16 +1034,16 @@ def response_to_hash(module, response):
|
||||||
u'cpuPlatform': response.get(u'cpuPlatform'),
|
u'cpuPlatform': response.get(u'cpuPlatform'),
|
||||||
u'creationTimestamp': response.get(u'creationTimestamp'),
|
u'creationTimestamp': response.get(u'creationTimestamp'),
|
||||||
u'disks': InstanceDisksArray(module.params.get('disks', []), module).to_request(),
|
u'disks': InstanceDisksArray(module.params.get('disks', []), module).to_request(),
|
||||||
u'guestAccelerators': InstancGuestAccelerArray(response.get(u'guestAccelerators', []), module).from_response(),
|
u'guestAccelerators': InstanceGuestAcceleratorsArray(response.get(u'guestAccelerators', []), module).from_response(),
|
||||||
u'id': response.get(u'id'),
|
u'id': response.get(u'id'),
|
||||||
u'labelFingerprint': response.get(u'labelFingerprint'),
|
u'labelFingerprint': response.get(u'labelFingerprint'),
|
||||||
u'metadata': response.get(u'metadata'),
|
u'metadata': response.get(u'metadata'),
|
||||||
u'machineType': response.get(u'machineType'),
|
u'machineType': response.get(u'machineType'),
|
||||||
u'minCpuPlatform': response.get(u'minCpuPlatform'),
|
u'minCpuPlatform': response.get(u'minCpuPlatform'),
|
||||||
u'name': response.get(u'name'),
|
u'name': response.get(u'name'),
|
||||||
u'networkInterfaces': InstancNetworkInterfaArray(response.get(u'networkInterfaces', []), module).from_response(),
|
u'networkInterfaces': InstanceNetworkInterfacesArray(response.get(u'networkInterfaces', []), module).from_response(),
|
||||||
u'scheduling': InstanceScheduling(response.get(u'scheduling', {}), module).from_response(),
|
u'scheduling': InstanceScheduling(response.get(u'scheduling', {}), module).from_response(),
|
||||||
u'serviceAccounts': InstancServiceAccountArray(response.get(u'serviceAccounts', []), module).from_response(),
|
u'serviceAccounts': InstanceServiceAccountsArray(response.get(u'serviceAccounts', []), module).from_response(),
|
||||||
u'status': response.get(u'status'),
|
u'status': response.get(u'status'),
|
||||||
u'statusMessage': response.get(u'statusMessage'),
|
u'statusMessage': response.get(u'statusMessage'),
|
||||||
u'tags': InstanceTags(response.get(u'tags', {}), module).from_response()
|
u'tags': InstanceTags(response.get(u'tags', {}), module).from_response()
|
||||||
|
@ -1053,7 +1080,7 @@ def async_op_url(module, extra_data=None):
|
||||||
def wait_for_operation(module, response):
|
def wait_for_operation(module, response):
|
||||||
op_result = return_if_object(module, response, 'compute#operation')
|
op_result = return_if_object(module, response, 'compute#operation')
|
||||||
if op_result is None:
|
if op_result is None:
|
||||||
return None
|
return {}
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
wait_done = wait_for_completion(status, op_result, module)
|
wait_done = wait_for_completion(status, op_result, module)
|
||||||
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instance')
|
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instance')
|
||||||
|
@ -1154,9 +1181,9 @@ class InstanceDisksArray(object):
|
||||||
u'autoDelete': item.get('auto_delete'),
|
u'autoDelete': item.get('auto_delete'),
|
||||||
u'boot': item.get('boot'),
|
u'boot': item.get('boot'),
|
||||||
u'deviceName': item.get('device_name'),
|
u'deviceName': item.get('device_name'),
|
||||||
u'diskEncryptionKey': InstaDiskEncryKey(item.get('disk_encryption_key', {}), self.module).to_request(),
|
u'diskEncryptionKey': InstanceDiskEncryptionKey(item.get('disk_encryption_key', {}), self.module).to_request(),
|
||||||
u'index': item.get('index'),
|
u'index': item.get('index'),
|
||||||
u'initializeParams': InstancInitialParams(item.get('initialize_params', {}), self.module).to_request(),
|
u'initializeParams': InstanceInitializeParams(item.get('initialize_params', {}), self.module).to_request(),
|
||||||
u'interface': item.get('interface'),
|
u'interface': item.get('interface'),
|
||||||
u'mode': item.get('mode'),
|
u'mode': item.get('mode'),
|
||||||
u'source': replace_resource_dict(item.get(u'source', {}), 'selfLink'),
|
u'source': replace_resource_dict(item.get(u'source', {}), 'selfLink'),
|
||||||
|
@ -1168,9 +1195,9 @@ class InstanceDisksArray(object):
|
||||||
u'autoDelete': item.get(u'autoDelete'),
|
u'autoDelete': item.get(u'autoDelete'),
|
||||||
u'boot': item.get(u'boot'),
|
u'boot': item.get(u'boot'),
|
||||||
u'deviceName': item.get(u'deviceName'),
|
u'deviceName': item.get(u'deviceName'),
|
||||||
u'diskEncryptionKey': InstaDiskEncryKey(item.get(u'diskEncryptionKey', {}), self.module).from_response(),
|
u'diskEncryptionKey': InstanceDiskEncryptionKey(item.get(u'diskEncryptionKey', {}), self.module).from_response(),
|
||||||
u'index': item.get(u'index'),
|
u'index': item.get(u'index'),
|
||||||
u'initializeParams': InstancInitialParams(self.module.params.get('initialize_params', {}), self.module).to_request(),
|
u'initializeParams': InstanceInitializeParams(self.module.params.get('initialize_params', {}), self.module).to_request(),
|
||||||
u'interface': item.get(u'interface'),
|
u'interface': item.get(u'interface'),
|
||||||
u'mode': item.get(u'mode'),
|
u'mode': item.get(u'mode'),
|
||||||
u'source': item.get(u'source'),
|
u'source': item.get(u'source'),
|
||||||
|
@ -1178,7 +1205,7 @@ class InstanceDisksArray(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstaDiskEncryKey(object):
|
class InstanceDiskEncryptionKey(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -1201,7 +1228,7 @@ class InstaDiskEncryKey(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstancInitialParams(object):
|
class InstanceInitializeParams(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -1215,7 +1242,7 @@ class InstancInitialParams(object):
|
||||||
u'diskSizeGb': self.request.get('disk_size_gb'),
|
u'diskSizeGb': self.request.get('disk_size_gb'),
|
||||||
u'diskType': disk_type_selflink(self.request.get('disk_type'), self.module.params),
|
u'diskType': disk_type_selflink(self.request.get('disk_type'), self.module.params),
|
||||||
u'sourceImage': self.request.get('source_image'),
|
u'sourceImage': self.request.get('source_image'),
|
||||||
u'sourceImageEncryptionKey': InstSourImagEncrKey(self.request.get('source_image_encryption_key', {}), self.module).to_request()
|
u'sourceImageEncryptionKey': InstanceSourceImageEncryptionKey(self.request.get('source_image_encryption_key', {}), self.module).to_request()
|
||||||
})
|
})
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
|
@ -1224,11 +1251,11 @@ class InstancInitialParams(object):
|
||||||
u'diskSizeGb': self.request.get(u'diskSizeGb'),
|
u'diskSizeGb': self.request.get(u'diskSizeGb'),
|
||||||
u'diskType': self.request.get(u'diskType'),
|
u'diskType': self.request.get(u'diskType'),
|
||||||
u'sourceImage': self.request.get(u'sourceImage'),
|
u'sourceImage': self.request.get(u'sourceImage'),
|
||||||
u'sourceImageEncryptionKey': InstSourImagEncrKey(self.request.get(u'sourceImageEncryptionKey', {}), self.module).from_response()
|
u'sourceImageEncryptionKey': InstanceSourceImageEncryptionKey(self.request.get(u'sourceImageEncryptionKey', {}), self.module).from_response()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstSourImagEncrKey(object):
|
class InstanceSourceImageEncryptionKey(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -1249,7 +1276,7 @@ class InstSourImagEncrKey(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstancGuestAccelerArray(object):
|
class InstanceGuestAcceleratorsArray(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -1282,7 +1309,7 @@ class InstancGuestAccelerArray(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstancNetworkInterfaArray(object):
|
class InstanceNetworkInterfacesArray(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -1304,8 +1331,8 @@ class InstancNetworkInterfaArray(object):
|
||||||
|
|
||||||
def _request_for_item(self, item):
|
def _request_for_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({
|
||||||
u'accessConfigs': InstancAccessConfigsArray(item.get('access_configs', []), self.module).to_request(),
|
u'accessConfigs': InstanceAccessConfigsArray(item.get('access_configs', []), self.module).to_request(),
|
||||||
u'aliasIpRanges': InstaAliasIpRangeArray(item.get('alias_ip_ranges', []), self.module).to_request(),
|
u'aliasIpRanges': InstanceAliasIpRangesArray(item.get('alias_ip_ranges', []), self.module).to_request(),
|
||||||
u'name': item.get('name'),
|
u'name': item.get('name'),
|
||||||
u'network': replace_resource_dict(item.get(u'network', {}), 'selfLink'),
|
u'network': replace_resource_dict(item.get(u'network', {}), 'selfLink'),
|
||||||
u'networkIP': item.get('network_ip'),
|
u'networkIP': item.get('network_ip'),
|
||||||
|
@ -1314,8 +1341,8 @@ class InstancNetworkInterfaArray(object):
|
||||||
|
|
||||||
def _response_from_item(self, item):
|
def _response_from_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({
|
||||||
u'accessConfigs': InstancAccessConfigsArray(item.get(u'accessConfigs', []), self.module).from_response(),
|
u'accessConfigs': InstanceAccessConfigsArray(item.get(u'accessConfigs', []), self.module).from_response(),
|
||||||
u'aliasIpRanges': InstaAliasIpRangeArray(item.get(u'aliasIpRanges', []), self.module).from_response(),
|
u'aliasIpRanges': InstanceAliasIpRangesArray(item.get(u'aliasIpRanges', []), self.module).from_response(),
|
||||||
u'name': item.get(u'name'),
|
u'name': item.get(u'name'),
|
||||||
u'network': item.get(u'network'),
|
u'network': item.get(u'network'),
|
||||||
u'networkIP': item.get(u'networkIP'),
|
u'networkIP': item.get(u'networkIP'),
|
||||||
|
@ -1323,7 +1350,7 @@ class InstancNetworkInterfaArray(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstancAccessConfigsArray(object):
|
class InstanceAccessConfigsArray(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -1358,7 +1385,7 @@ class InstancAccessConfigsArray(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstaAliasIpRangeArray(object):
|
class InstanceAliasIpRangesArray(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
@ -1414,7 +1441,7 @@ class InstanceScheduling(object):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class InstancServiceAccountArray(object):
|
class InstanceServiceAccountsArray(object):
|
||||||
def __init__(self, request, module):
|
def __init__(self, request, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
if request:
|
if request:
|
||||||
|
|
|
@ -15,36 +15,30 @@
|
||||||
# Pre-test setup
|
# Pre-test setup
|
||||||
- name: create a disk
|
- name: create a disk
|
||||||
gcp_compute_disk:
|
gcp_compute_disk:
|
||||||
name: 'disk-instance'
|
name: "disk-instance"
|
||||||
size_gb: 50
|
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
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: disk
|
register: disk
|
||||||
- name: create a network
|
- name: create a network
|
||||||
gcp_compute_network:
|
gcp_compute_network:
|
||||||
name: 'network-instance'
|
name: "network-instance"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: network
|
register: network
|
||||||
- name: create a address
|
- name: create a address
|
||||||
gcp_compute_address:
|
gcp_compute_address:
|
||||||
name: 'address-instance'
|
name: "address-instance"
|
||||||
region: 'us-central1'
|
region: us-central1
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: address
|
register: address
|
||||||
- name: delete a instance
|
- name: delete a instance
|
||||||
|
@ -56,20 +50,18 @@
|
||||||
boot: true
|
boot: true
|
||||||
source: "{{ disk }}"
|
source: "{{ disk }}"
|
||||||
metadata:
|
metadata:
|
||||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||||
cost-center: '12345'
|
cost-center: '12345'
|
||||||
network_interfaces:
|
network_interfaces:
|
||||||
- network: "{{ network }}"
|
- network: "{{ network }}"
|
||||||
access_configs:
|
access_configs:
|
||||||
- name: 'External NAT'
|
- name: External NAT
|
||||||
nat_ip: "{{ address }}"
|
nat_ip: "{{ address }}"
|
||||||
type: 'ONE_TO_ONE_NAT'
|
type: ONE_TO_ONE_NAT
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
- name: create a instance
|
- name: create a instance
|
||||||
|
@ -81,20 +73,18 @@
|
||||||
boot: true
|
boot: true
|
||||||
source: "{{ disk }}"
|
source: "{{ disk }}"
|
||||||
metadata:
|
metadata:
|
||||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||||
cost-center: '12345'
|
cost-center: '12345'
|
||||||
network_interfaces:
|
network_interfaces:
|
||||||
- network: "{{ network }}"
|
- network: "{{ network }}"
|
||||||
access_configs:
|
access_configs:
|
||||||
- name: 'External NAT'
|
- name: External NAT
|
||||||
nat_ip: "{{ address }}"
|
nat_ip: "{{ address }}"
|
||||||
type: 'ONE_TO_ONE_NAT'
|
type: ONE_TO_ONE_NAT
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is true
|
- name: assert changed is true
|
||||||
|
@ -103,13 +93,20 @@
|
||||||
- result.changed == true
|
- result.changed == true
|
||||||
- "result.kind == 'compute#instance'"
|
- "result.kind == 'compute#instance'"
|
||||||
- name: verify that instance was created
|
- name: verify that instance was created
|
||||||
shell: |
|
gcp_compute_instance_facts:
|
||||||
gcloud compute instances describe --project="{{ gcp_project }}" --zone="us-central1-a" "{{ resource_name }}"
|
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
|
register: results
|
||||||
- name: verify that command succeeded
|
- name: verify that command succeeded
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- results.rc == 0
|
- results['items'] | length == 1
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
- name: create a instance that already exists
|
- name: create a instance that already exists
|
||||||
gcp_compute_instance:
|
gcp_compute_instance:
|
||||||
|
@ -120,20 +117,18 @@
|
||||||
boot: true
|
boot: true
|
||||||
source: "{{ disk }}"
|
source: "{{ disk }}"
|
||||||
metadata:
|
metadata:
|
||||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||||
cost-center: '12345'
|
cost-center: '12345'
|
||||||
network_interfaces:
|
network_interfaces:
|
||||||
- network: "{{ network }}"
|
- network: "{{ network }}"
|
||||||
access_configs:
|
access_configs:
|
||||||
- name: 'External NAT'
|
- name: External NAT
|
||||||
nat_ip: "{{ address }}"
|
nat_ip: "{{ address }}"
|
||||||
type: 'ONE_TO_ONE_NAT'
|
type: ONE_TO_ONE_NAT
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
@ -151,20 +146,18 @@
|
||||||
boot: true
|
boot: true
|
||||||
source: "{{ disk }}"
|
source: "{{ disk }}"
|
||||||
metadata:
|
metadata:
|
||||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||||
cost-center: '12345'
|
cost-center: '12345'
|
||||||
network_interfaces:
|
network_interfaces:
|
||||||
- network: "{{ network }}"
|
- network: "{{ network }}"
|
||||||
access_configs:
|
access_configs:
|
||||||
- name: 'External NAT'
|
- name: External NAT
|
||||||
nat_ip: "{{ address }}"
|
nat_ip: "{{ address }}"
|
||||||
type: 'ONE_TO_ONE_NAT'
|
type: ONE_TO_ONE_NAT
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is true
|
- name: assert changed is true
|
||||||
|
@ -173,15 +166,20 @@
|
||||||
- result.changed == true
|
- result.changed == true
|
||||||
- result.has_key('kind') == False
|
- result.has_key('kind') == False
|
||||||
- name: verify that instance was deleted
|
- name: verify that instance was deleted
|
||||||
shell: |
|
gcp_compute_instance_facts:
|
||||||
gcloud compute instances describe --project="{{ gcp_project }}" --zone="us-central1-a" "{{ resource_name }}"
|
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
|
register: results
|
||||||
failed_when: results.rc == 0
|
|
||||||
- name: verify that command succeeded
|
- name: verify that command succeeded
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- results.rc == 1
|
- results['items'] | length == 0
|
||||||
- "\"'projects/{{ gcp_project }}/zones/us-central1-a/instances/{{ resource_name }}' was not found\" in results.stderr"
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
- name: delete a instance that does not exist
|
- name: delete a instance that does not exist
|
||||||
gcp_compute_instance:
|
gcp_compute_instance:
|
||||||
|
@ -192,20 +190,18 @@
|
||||||
boot: true
|
boot: true
|
||||||
source: "{{ disk }}"
|
source: "{{ disk }}"
|
||||||
metadata:
|
metadata:
|
||||||
startup-script-url: 'gs:://graphite-playground/bootstrap.sh'
|
startup-script-url: gs:://graphite-playground/bootstrap.sh
|
||||||
cost-center: '12345'
|
cost-center: '12345'
|
||||||
network_interfaces:
|
network_interfaces:
|
||||||
- network: "{{ network }}"
|
- network: "{{ network }}"
|
||||||
access_configs:
|
access_configs:
|
||||||
- name: 'External NAT'
|
- name: External NAT
|
||||||
nat_ip: "{{ address }}"
|
nat_ip: "{{ address }}"
|
||||||
type: 'ONE_TO_ONE_NAT'
|
type: ONE_TO_ONE_NAT
|
||||||
zone: 'us-central1-a'
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: assert changed is false
|
- name: assert changed is false
|
||||||
|
@ -217,35 +213,29 @@
|
||||||
# Post-test teardown
|
# Post-test teardown
|
||||||
- name: delete a address
|
- name: delete a address
|
||||||
gcp_compute_address:
|
gcp_compute_address:
|
||||||
name: 'address-instance'
|
name: "address-instance"
|
||||||
region: 'us-central1'
|
region: us-central1
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
register: address
|
register: address
|
||||||
- name: delete a network
|
- name: delete a network
|
||||||
gcp_compute_network:
|
gcp_compute_network:
|
||||||
name: 'network-instance'
|
name: "network-instance"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
register: network
|
register: network
|
||||||
- name: delete a disk
|
- name: delete a disk
|
||||||
gcp_compute_disk:
|
gcp_compute_disk:
|
||||||
name: 'disk-instance'
|
name: "disk-instance"
|
||||||
size_gb: 50
|
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
|
zone: us-central1-a
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file }}"
|
service_account_file: "{{ gcp_cred_file }}"
|
||||||
scopes:
|
|
||||||
- https://www.googleapis.com/auth/compute
|
|
||||||
state: absent
|
state: absent
|
||||||
register: disk
|
register: disk
|
||||||
|
|
Loading…
Reference in a new issue