1
0
Fork 0
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_template (#42818)

This commit is contained in:
Alex Stephen 2018-08-13 12:29:48 -07:00 committed by Ryan Brown
parent 829dcf1d23
commit b0542217e2
2 changed files with 185 additions and 159 deletions

View file

@ -150,7 +150,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:
@ -193,7 +195,11 @@ 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.
- Note that for InstanceTemplate, specify the disk name, not the URL for the disk.
required: false required: false
type: type:
description: description:
@ -203,7 +209,7 @@ options:
choices: ['SCRATCH', 'PERSISTENT'] choices: ['SCRATCH', 'PERSISTENT']
machine_type: machine_type:
description: description:
- A reference to MachineType resource. - Reference to a gcompute_machine_type resource.
required: true required: true
metadata: metadata:
description: description:
@ -245,8 +251,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.
@ -279,7 +290,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:
@ -288,7 +302,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:
@ -326,7 +343,6 @@ options:
description: description:
- Email address of the service account. - Email address of the service account.
required: false required: false
type: bool
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.
@ -357,48 +373,42 @@ extends_documentation_fragment: gcp
EXAMPLES = ''' EXAMPLES = '''
- name: create a network - name: create a network
gcp_compute_network: gcp_compute_network:
name: 'network-instancetemplate' name: "network-instancetemplate"
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-instancetemplate' name: "address-instancetemplate"
region: 'us-west1' region: us-west1
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 template - name: create a instance template
gcp_compute_instance_template: gcp_compute_instance_template:
name: testObject name: "test_object"
properties: properties:
disks: disks:
- auto_delete: true - auto_delete: true
boot: true boot: true
initialize_params: initialize_params:
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
machine_type: n1-standard-1 machine_type: n1-standard-1
network_interfaces: network_interfaces:
- network: "{{ network }}" - network: "{{ network }}"
access_configs: access_configs:
- name: 'test-config' - name: test-config
type: 'ONE_TO_ONE_NAT' type: ONE_TO_ONE_NAT
nat_ip: "{{ address }}" nat_ip: "{{ address }}"
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
''' '''
@ -525,7 +535,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:
@ -573,7 +585,11 @@ 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.
- Note that for InstanceTemplate, specify the disk name, not the URL for the disk.
returned: success returned: success
type: dict type: dict
type: type:
@ -584,7 +600,7 @@ RETURN = '''
type: str type: str
machine_type: machine_type:
description: description:
- A reference to MachineType resource. - Reference to a gcompute_machine_type resource.
returned: success returned: success
type: str type: str
metadata: metadata:
@ -634,7 +650,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:
@ -673,7 +694,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:
@ -684,7 +708,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:
@ -726,7 +753,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.
@ -816,7 +843,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(
@ -834,7 +861,7 @@ def main():
preemptible=dict(type='bool') preemptible=dict(type='bool')
)), )),
service_accounts=dict(type='list', elements='dict', options=dict( service_accounts=dict(type='list', elements='dict', options=dict(
email=dict(type='bool'), email=dict(type='str'),
scopes=dict(type='list', elements='str') scopes=dict(type='list', elements='str')
)), )),
tags=dict(type='dict', options=dict( tags=dict(type='dict', options=dict(
@ -845,6 +872,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#instanceTemplate' kind = 'compute#instanceTemplate'
@ -854,10 +884,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:
@ -877,12 +907,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))
@ -892,7 +922,7 @@ def resource_to_request(module):
u'kind': 'compute#instanceTemplate', u'kind': 'compute#instanceTemplate',
u'description': module.params.get('description'), u'description': module.params.get('description'),
u'name': module.params.get('name'), u'name': module.params.get('name'),
u'properties': InstancTemplatPropert(module.params.get('properties', {}), module).to_request() u'properties': InstanceTemplateProperties(module.params.get('properties', {}), module).to_request()
} }
request = encode_request(request, module) request = encode_request(request, module)
return_vals = {} return_vals = {}
@ -968,7 +998,7 @@ def response_to_hash(module, response):
u'description': response.get(u'description'), u'description': response.get(u'description'),
u'id': response.get(u'id'), u'id': response.get(u'id'),
u'name': response.get(u'name'), u'name': response.get(u'name'),
u'properties': InstancTemplatPropert(response.get(u'properties', {}), module).from_response() u'properties': InstanceTemplateProperties(response.get(u'properties', {}), module).from_response()
} }
@ -993,7 +1023,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#instanceTemplate') return fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#instanceTemplate')
@ -1050,7 +1080,10 @@ def metadata_encoder(metadata):
metadata_new = [] metadata_new = []
for key in metadata: for key in metadata:
value = metadata[key] value = metadata[key]
metadata_new.append({key: value}) metadata_new.append({
"key": key,
"value": value
})
return { return {
'items': metadata_new 'items': metadata_new
} }
@ -1062,11 +1095,11 @@ def metadata_decoder(metadata):
if 'items' in metadata: if 'items' in metadata:
metadata_items = metadata['items'] metadata_items = metadata['items']
for item in metadata_items: for item in metadata_items:
items[item.keys()[0]] = item[item.keys()[0]] items[item['key']] = item['value']
return items return items
class InstancTemplatPropert(object): class InstanceTemplateProperties(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1078,32 +1111,32 @@ class InstancTemplatPropert(object):
return remove_nones_from_dict({ return remove_nones_from_dict({
u'canIpForward': self.request.get('can_ip_forward'), u'canIpForward': self.request.get('can_ip_forward'),
u'description': self.request.get('description'), u'description': self.request.get('description'),
u'disks': InstancTemplatDisksArray(self.request.get('disks', []), self.module).to_request(), u'disks': InstanceTemplateDisksArray(self.request.get('disks', []), self.module).to_request(),
u'machineType': self.request.get('machine_type'), u'machineType': self.request.get('machine_type'),
u'metadata': self.request.get('metadata'), u'metadata': self.request.get('metadata'),
u'guestAccelerators': InstaTemplGuestAccelArray(self.request.get('guest_accelerators', []), self.module).to_request(), u'guestAccelerators': InstanceTemplateGuestAcceleratorsArray(self.request.get('guest_accelerators', []), self.module).to_request(),
u'networkInterfaces': InstaTemplNetwoInterArray(self.request.get('network_interfaces', []), self.module).to_request(), u'networkInterfaces': InstanceTemplateNetworkInterfacesArray(self.request.get('network_interfaces', []), self.module).to_request(),
u'scheduling': InstancTemplatSchedul(self.request.get('scheduling', {}), self.module).to_request(), u'scheduling': InstanceTemplateScheduling(self.request.get('scheduling', {}), self.module).to_request(),
u'serviceAccounts': InstaTemplServiAccouArray(self.request.get('service_accounts', []), self.module).to_request(), u'serviceAccounts': InstanceTemplateServiceAccountsArray(self.request.get('service_accounts', []), self.module).to_request(),
u'tags': InstancTemplatTags(self.request.get('tags', {}), self.module).to_request() u'tags': InstanceTemplateTags(self.request.get('tags', {}), self.module).to_request()
}) })
def from_response(self): def from_response(self):
return remove_nones_from_dict({ return remove_nones_from_dict({
u'canIpForward': self.request.get(u'canIpForward'), u'canIpForward': self.request.get(u'canIpForward'),
u'description': self.request.get(u'description'), u'description': self.request.get(u'description'),
u'disks': InstancTemplatDisksArray(self.request.get(u'disks', []), self.module).from_response(), u'disks': InstanceTemplateDisksArray(self.request.get(u'disks', []), self.module).from_response(),
u'machineType': self.request.get(u'machineType'), u'machineType': self.request.get(u'machineType'),
u'metadata': self.request.get(u'metadata'), u'metadata': self.request.get(u'metadata'),
u'guestAccelerators': InstaTemplGuestAccelArray(self.request.get(u'guestAccelerators', []), self.module).from_response(), u'guestAccelerators': InstanceTemplateGuestAcceleratorsArray(self.request.get(u'guestAccelerators', []), self.module).from_response(),
u'networkInterfaces': InstaTemplNetwoInterArray(self.request.get(u'networkInterfaces', []), self.module).from_response(), u'networkInterfaces': InstanceTemplateNetworkInterfacesArray(self.request.get(u'networkInterfaces', []), self.module).from_response(),
u'scheduling': InstancTemplatSchedul(self.request.get(u'scheduling', {}), self.module).from_response(), u'scheduling': InstanceTemplateScheduling(self.request.get(u'scheduling', {}), self.module).from_response(),
u'serviceAccounts': InstaTemplServiAccouArray(self.request.get(u'serviceAccounts', []), self.module).from_response(), u'serviceAccounts': InstanceTemplateServiceAccountsArray(self.request.get(u'serviceAccounts', []), self.module).from_response(),
u'tags': InstancTemplatTags(self.request.get(u'tags', {}), self.module).from_response() u'tags': InstanceTemplateTags(self.request.get(u'tags', {}), self.module).from_response()
}) })
class InstancTemplatDisksArray(object): class InstanceTemplateDisksArray(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1128,9 +1161,9 @@ class InstancTemplatDisksArray(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': InstTempDiskEncrKey(item.get('disk_encryption_key', {}), self.module).to_request(), u'diskEncryptionKey': InstanceTemplateDiskEncryptionKey(item.get('disk_encryption_key', {}), self.module).to_request(),
u'index': item.get('index'), u'index': item.get('index'),
u'initializeParams': InstaTemplInitiParam(item.get('initialize_params', {}), self.module).to_request(), u'initializeParams': InstanceTemplateInitializeParams(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', {}), 'name'), u'source': replace_resource_dict(item.get(u'source', {}), 'name'),
@ -1142,9 +1175,9 @@ class InstancTemplatDisksArray(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': InstTempDiskEncrKey(item.get(u'diskEncryptionKey', {}), self.module).from_response(), u'diskEncryptionKey': InstanceTemplateDiskEncryptionKey(item.get(u'diskEncryptionKey', {}), self.module).from_response(),
u'index': item.get(u'index'), u'index': item.get(u'index'),
u'initializeParams': InstaTemplInitiParam(self.module.params.get('initialize_params', {}), self.module).to_request(), u'initializeParams': InstanceTemplateInitializeParams(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'),
@ -1152,7 +1185,7 @@ class InstancTemplatDisksArray(object):
}) })
class InstTempDiskEncrKey(object): class InstanceTemplateDiskEncryptionKey(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1175,7 +1208,7 @@ class InstTempDiskEncrKey(object):
}) })
class InstaTemplInitiParam(object): class InstanceTemplateInitializeParams(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1189,7 +1222,7 @@ class InstaTemplInitiParam(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': InsTemSouImaEncKey(self.request.get('source_image_encryption_key', {}), self.module).to_request() u'sourceImageEncryptionKey': InstanceTemplateSourceImageEncryptionKey(self.request.get('source_image_encryption_key', {}), self.module).to_request()
}) })
def from_response(self): def from_response(self):
@ -1198,11 +1231,12 @@ class InstaTemplInitiParam(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': InsTemSouImaEncKey(self.request.get(u'sourceImageEncryptionKey', {}), self.module).from_response() u'sourceImageEncryptionKey':
InstanceTemplateSourceImageEncryptionKey(self.request.get(u'sourceImageEncryptionKey', {}), self.module).from_response()
}) })
class InsTemSouImaEncKey(object): class InstanceTemplateSourceImageEncryptionKey(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1223,7 +1257,7 @@ class InsTemSouImaEncKey(object):
}) })
class InstaTemplGuestAccelArray(object): class InstanceTemplateGuestAcceleratorsArray(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1256,7 +1290,7 @@ class InstaTemplGuestAccelArray(object):
}) })
class InstaTemplNetwoInterArray(object): class InstanceTemplateNetworkInterfacesArray(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1278,8 +1312,8 @@ class InstaTemplNetwoInterArray(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': InstaTemplAccesConfiArray(item.get('access_configs', []), self.module).to_request(), u'accessConfigs': InstanceTemplateAccessConfigsArray(item.get('access_configs', []), self.module).to_request(),
u'aliasIpRanges': InstTempAliaIpRangArray(item.get('alias_ip_ranges', []), self.module).to_request(), u'aliasIpRanges': InstanceTemplateAliasIpRangesArray(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'),
@ -1288,8 +1322,8 @@ class InstaTemplNetwoInterArray(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': InstaTemplAccesConfiArray(item.get(u'accessConfigs', []), self.module).from_response(), u'accessConfigs': InstanceTemplateAccessConfigsArray(item.get(u'accessConfigs', []), self.module).from_response(),
u'aliasIpRanges': InstTempAliaIpRangArray(item.get(u'aliasIpRanges', []), self.module).from_response(), u'aliasIpRanges': InstanceTemplateAliasIpRangesArray(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'),
@ -1297,7 +1331,7 @@ class InstaTemplNetwoInterArray(object):
}) })
class InstaTemplAccesConfiArray(object): class InstanceTemplateAccessConfigsArray(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1332,7 +1366,7 @@ class InstaTemplAccesConfiArray(object):
}) })
class InstTempAliaIpRangArray(object): class InstanceTemplateAliasIpRangesArray(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1365,7 +1399,7 @@ class InstTempAliaIpRangArray(object):
}) })
class InstancTemplatSchedul(object): class InstanceTemplateScheduling(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1388,7 +1422,7 @@ class InstancTemplatSchedul(object):
}) })
class InstaTemplServiAccouArray(object): class InstanceTemplateServiceAccountsArray(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:
@ -1421,7 +1455,7 @@ class InstaTemplServiAccouArray(object):
}) })
class InstancTemplatTags(object): class InstanceTemplateTags(object):
def __init__(self, request, module): def __init__(self, request, module):
self.module = module self.module = module
if request: if request:

View file

@ -15,23 +15,19 @@
# Pre-test setup # Pre-test setup
- name: create a network - name: create a network
gcp_compute_network: gcp_compute_network:
name: 'network-instancetemplate' name: "network-instancetemplate"
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-instancetemplate' name: "address-instancetemplate"
region: 'us-west1' region: us-west1
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 template - name: delete a instance template
@ -39,22 +35,20 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
properties: properties:
disks: disks:
- auto_delete: true - auto_delete: true
boot: true boot: true
initialize_params: initialize_params:
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
machine_type: n1-standard-1 machine_type: n1-standard-1
network_interfaces: network_interfaces:
- network: "{{ network }}" - network: "{{ network }}"
access_configs: access_configs:
- name: 'test-config' - name: test-config
type: 'ONE_TO_ONE_NAT' type: ONE_TO_ONE_NAT
nat_ip: "{{ address }}" nat_ip: "{{ address }}"
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 template - name: create a instance template
@ -62,22 +56,20 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
properties: properties:
disks: disks:
- auto_delete: true - auto_delete: true
boot: true boot: true
initialize_params: initialize_params:
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
machine_type: n1-standard-1 machine_type: n1-standard-1
network_interfaces: network_interfaces:
- network: "{{ network }}" - network: "{{ network }}"
access_configs: access_configs:
- name: 'test-config' - name: test-config
type: 'ONE_TO_ONE_NAT' type: ONE_TO_ONE_NAT
nat_ip: "{{ address }}" nat_ip: "{{ address }}"
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
@ -86,35 +78,39 @@
- result.changed == true - result.changed == true
- "result.kind == 'compute#instanceTemplate'" - "result.kind == 'compute#instanceTemplate'"
- name: verify that instance_template was created - name: verify that instance_template was created
shell: | gcp_compute_instance_template_facts:
gcloud compute instance-templates describe --project="{{ gcp_project}}" "{{ resource_name }}" filters:
- name = {{ resource_name }}
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 template that already exists - name: create a instance template that already exists
gcp_compute_instance_template: gcp_compute_instance_template:
name: "{{ resource_name }}" name: "{{ resource_name }}"
properties: properties:
disks: disks:
- auto_delete: true - auto_delete: true
boot: true boot: true
initialize_params: initialize_params:
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
machine_type: n1-standard-1 machine_type: n1-standard-1
network_interfaces: network_interfaces:
- network: "{{ network }}" - network: "{{ network }}"
access_configs: access_configs:
- name: 'test-config' - name: test-config
type: 'ONE_TO_ONE_NAT' type: ONE_TO_ONE_NAT
nat_ip: "{{ address }}" nat_ip: "{{ address }}"
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
@ -128,22 +124,20 @@
name: "{{ resource_name }}" name: "{{ resource_name }}"
properties: properties:
disks: disks:
- auto_delete: true - auto_delete: true
boot: true boot: true
initialize_params: initialize_params:
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
machine_type: n1-standard-1 machine_type: n1-standard-1
network_interfaces: network_interfaces:
- network: "{{ network }}" - network: "{{ network }}"
access_configs: access_configs:
- name: 'test-config' - name: test-config
type: 'ONE_TO_ONE_NAT' type: ONE_TO_ONE_NAT
nat_ip: "{{ address }}" nat_ip: "{{ address }}"
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
@ -152,37 +146,39 @@
- result.changed == true - result.changed == true
- result.has_key('kind') == False - result.has_key('kind') == False
- name: verify that instance_template was deleted - name: verify that instance_template was deleted
shell: | gcp_compute_instance_template_facts:
gcloud compute instance-templates describe --project="{{ gcp_project}}" "{{ resource_name }}" filters:
- name = {{ resource_name }}
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 }}/global/instanceTemplates/{{ resource_name }}' was not found\" in results.stderr"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
- name: delete a instance template that does not exist - name: delete a instance template that does not exist
gcp_compute_instance_template: gcp_compute_instance_template:
name: "{{ resource_name }}" name: "{{ resource_name }}"
properties: properties:
disks: disks:
- auto_delete: true - auto_delete: true
boot: true boot: true
initialize_params: initialize_params:
source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' source_image: projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts
machine_type: n1-standard-1 machine_type: n1-standard-1
network_interfaces: network_interfaces:
- network: "{{ network }}" - network: "{{ network }}"
access_configs: access_configs:
- name: 'test-config' - name: test-config
type: 'ONE_TO_ONE_NAT' type: ONE_TO_ONE_NAT
nat_ip: "{{ address }}" nat_ip: "{{ address }}"
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
@ -194,22 +190,18 @@
# Post-test teardown # Post-test teardown
- name: delete a address - name: delete a address
gcp_compute_address: gcp_compute_address:
name: 'address-instancetemplate' name: "address-instancetemplate"
region: 'us-west1' region: us-west1
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-instancetemplate' name: "network-instancetemplate"
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