Initial addition of generated Image to Terraform. (#151)

This commit is contained in:
The Magician 2019-01-02 16:05:31 -08:00 committed by Alex Stephen
parent a6107610d7
commit 9a8b1ff291
2 changed files with 51 additions and 9 deletions

View file

@ -111,6 +111,11 @@ options:
- The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption - The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption
key that protects this resource. key that protects this resource.
required: false required: false
labels:
description:
- Labels to apply to this Image.
required: false
version_added: 2.8
licenses: licenses:
description: description:
- Any applicable license URI. - Any applicable license URI.
@ -146,7 +151,7 @@ options:
description: description:
- The full Google Cloud Storage URL where disk storage is stored You must - The full Google Cloud Storage URL where disk storage is stored You must
provide either this property or the sourceDisk property but not both. provide either this property or the sourceDisk property but not both.
required: false required: true
source_disk: source_disk:
description: description:
- Refers to a gcompute_disk object You must provide either this property or the - Refers to a gcompute_disk object You must provide either this property or the
@ -187,7 +192,7 @@ options:
- RAW - RAW
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
notes: notes:
- 'API Reference: U(https://cloud.google.com/compute/docs/reference/v1/images)' - 'API Reference: U(https://cloud.google.com/compute/docs/reference/latest/images)'
- 'Official Documentation: U(https://cloud.google.com/compute/docs/images)' - 'Official Documentation: U(https://cloud.google.com/compute/docs/images)'
''' '''
@ -331,6 +336,17 @@ imageEncryptionKey:
key that protects this resource. key that protects this resource.
returned: success returned: success
type: str type: str
labels:
description:
- Labels to apply to this Image.
returned: success
type: dict
labelFingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally
during updates.
returned: success
type: str
licenses: licenses:
description: description:
- Any applicable license URI. - Any applicable license URI.
@ -434,15 +450,20 @@ def main():
description=dict(type='str'), description=dict(type='str'),
disk_size_gb=dict(type='int'), disk_size_gb=dict(type='int'),
family=dict(type='str'), family=dict(type='str'),
guest_os_features=dict(type='list', elements='dict', options=dict(type=dict(type='str', choices=['VIRTIO_SCSI_MULTIQUEUE']))), guest_os_features=dict(type='list', elements='dict', options=dict(
image_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'))), type=dict(type='str', choices=['VIRTIO_SCSI_MULTIQUEUE'])
)),
image_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
)),
labels=dict(type='dict'), labels=dict(type='dict'),
licenses=dict(type='list', elements='str'), licenses=dict(type='list', elements='str'),
name=dict(required=True, type='str'), name=dict(required=True, type='str'),
raw_disk=dict(type='dict', options=dict( raw_disk=dict(type='dict', options=dict(
container_type=dict(type='str', choices=['TAR']), container_type=dict(type='str', choices=['TAR']),
sha1_checksum=dict(type='str'), sha1_checksum=dict(type='str'),
source=dict(type='str') source=dict(required=True, type='str')
)), )),
source_disk=dict(), source_disk=dict(),
source_disk_encryption_key=dict(type='dict', options=dict( source_disk_encryption_key=dict(type='dict', options=dict(
@ -466,7 +487,7 @@ def main():
if fetch: if fetch:
if state == 'present': if state == 'present':
if is_different(module, fetch): if is_different(module, fetch):
update(module, self_link(module), kind) update(module, self_link(module), kind, fetch)
fetch = fetch_resource(module, self_link(module), kind) fetch = fetch_resource(module, self_link(module), kind)
changed = True changed = True
else: else:
@ -491,7 +512,8 @@ def create(module, link, kind):
def update(module, link, kind, fetch): def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module), response_to_hash(module, fetch)) update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind) return fetch_resource(module, self_link(module), kind)
@ -503,8 +525,14 @@ def update_fields(module, request, response):
def labels_update(module, request, response): def labels_update(module, request, response):
auth = GcpSession(module, 'compute') auth = GcpSession(module, 'compute')
auth.post( auth.post(
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/images/{name}/setLabels"]).format(**module.params), ''.join([
{u'labels': module.params.get('labels'), u'labelFingerprint': response.get('labelFingerprint')}, "https://www.googleapis.com/compute/v1/",
"projects/{project}/global/images/{name}/setLabels"
]).format(**module.params),
{
u'labels': module.params.get('labels'),
u'labelFingerprint': response.get('labelFingerprint')
}
) )
@ -521,6 +549,7 @@ def resource_to_request(module):
u'family': module.params.get('family'), u'family': module.params.get('family'),
u'guestOsFeatures': ImageGuestosfeaturesArray(module.params.get('guest_os_features', []), module).to_request(), u'guestOsFeatures': ImageGuestosfeaturesArray(module.params.get('guest_os_features', []), module).to_request(),
u'imageEncryptionKey': ImageImageencryptionkey(module.params.get('image_encryption_key', {}), module).to_request(), u'imageEncryptionKey': ImageImageencryptionkey(module.params.get('image_encryption_key', {}), module).to_request(),
u'labels': module.params.get('labels'),
u'licenses': module.params.get('licenses'), u'licenses': module.params.get('licenses'),
u'name': module.params.get('name'), u'name': module.params.get('name'),
u'rawDisk': ImageRawdisk(module.params.get('raw_disk', {}), module).to_request(), u'rawDisk': ImageRawdisk(module.params.get('raw_disk', {}), module).to_request(),
@ -602,6 +631,8 @@ def response_to_hash(module, response):
u'guestOsFeatures': ImageGuestosfeaturesArray(response.get(u'guestOsFeatures', []), module).from_response(), u'guestOsFeatures': ImageGuestosfeaturesArray(response.get(u'guestOsFeatures', []), module).from_response(),
u'id': response.get(u'id'), u'id': response.get(u'id'),
u'imageEncryptionKey': ImageImageencryptionkey(response.get(u'imageEncryptionKey', {}), module).from_response(), u'imageEncryptionKey': ImageImageencryptionkey(response.get(u'imageEncryptionKey', {}), module).from_response(),
u'labels': response.get(u'labels'),
u'labelFingerprint': response.get(u'labelFingerprint'),
u'licenses': response.get(u'licenses'), u'licenses': response.get(u'licenses'),
u'name': response.get(u'name'), u'name': response.get(u'name'),
u'rawDisk': ImageRawdisk(response.get(u'rawDisk', {}), module).from_response(), u'rawDisk': ImageRawdisk(response.get(u'rawDisk', {}), module).from_response(),

View file

@ -186,6 +186,17 @@ items:
key that protects this resource. key that protects this resource.
returned: success returned: success
type: str type: str
labels:
description:
- Labels to apply to this Image.
returned: success
type: dict
labelFingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally
during updates.
returned: success
type: str
licenses: licenses:
description: description:
- Any applicable license URI. - Any applicable license URI.