262 lines
15 KiB
Diff
262 lines
15 KiB
Diff
From 8c34aeb78229d7487cb326d32de43e34d6cc6948 Mon Sep 17 00:00:00 2001
|
|
From: Jeremy Cline <jeremycline@microsoft.com>
|
|
Date: Mon, 26 Feb 2024 14:51:04 -0500
|
|
Subject: [PATCH 1/3] Allow creating gallery image versions from storage
|
|
accounts
|
|
|
|
It's possible to upload a VHD into a container in a storage account and
|
|
then use that to import an image version. This adds a third way to
|
|
specify an `os_disk` in the galleryimageversion plugin to support that
|
|
approach.
|
|
---
|
|
.../modules/azure_rm_galleryimageversion.py | 41 ++++++++++++++++++-
|
|
.../targets/azure_rm_gallery/tasks/main.yml | 40 ++++++++++++++++++
|
|
2 files changed, 79 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/plugins/modules/azure_rm_galleryimageversion.py b/plugins/modules/azure_rm_galleryimageversion.py
|
|
index 66a4dea6b..93bf031f1 100644
|
|
--- a/plugins/modules/azure_rm_galleryimageversion.py
|
|
+++ b/plugins/modules/azure_rm_galleryimageversion.py
|
|
@@ -63,7 +63,10 @@
|
|
suboptions:
|
|
source:
|
|
description:
|
|
- - Reference to os disk snapshot. Could be resource ID or dictionary containing I(resource_group) and I(name)
|
|
+ - Reference to os disk snapshot.
|
|
+ - Could be resource ID.
|
|
+ - Could be a dictionary containing I(resource_group) and I(name).
|
|
+ - Could be a dictionary containing I(resource_group), I(storage_account), and I(uri) if the snapshot is stored as a PageBlob in a storage account container.
|
|
type: raw
|
|
host_caching:
|
|
description:
|
|
@@ -303,6 +306,28 @@
|
|
name: data_snapshot_vma
|
|
- lun: 1
|
|
source: "/subscriptions/mySub/resourceGroups/myGroup/providers/Microsoft.Compute/snapshots/data_snapshot_vmb"
|
|
+
|
|
+- name: Create gallery image by using a os disk snapshot stored in Storage Account container
|
|
+ azure_rm_galleryimageversion:
|
|
+ resource_group: myResourceGroup
|
|
+ gallery_name: myGallery
|
|
+ gallery_image_name: myGalleryImage
|
|
+ name: 3.4.0
|
|
+ location: East US
|
|
+ publishing_profile:
|
|
+ end_of_life_date: "2020-10-01t00:00:00+00:00"
|
|
+ exclude_from_latest: true
|
|
+ replica_count: 1
|
|
+ storage_account_type: Standard_LRS
|
|
+ target_regions:
|
|
+ - name: East US
|
|
+ regional_replica_count: 1
|
|
+ storage_account_type: Standard_LRS
|
|
+ storage_profile:
|
|
+ os_disk:
|
|
+ resource_group: myResourceGroup
|
|
+ storage_account: myStorageAccount
|
|
+ uri: "https://myStorageAccount.blob.core.windows.net/myContainer/myImage.vhd"
|
|
'''
|
|
|
|
RETURN = '''
|
|
@@ -561,7 +586,7 @@ def exec_module(self, **kwargs):
|
|
elif isinstance(kwargs[key]['os_disk']['source'], dict):
|
|
if kwargs[key]['os_disk']['source'].get('id') is not None:
|
|
self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = kwargs[key]['os_disk']['source'].get('id')
|
|
- if kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
|
|
+ elif kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
|
|
kwargs[key]['os_disk']['source'].get('name') is not None:
|
|
resource_group = kwargs[key]['os_disk']['source'].get('resource_group')
|
|
self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = ('/subscriptions/' +
|
|
@@ -570,6 +595,18 @@ def exec_module(self, **kwargs):
|
|
resource_group +
|
|
'/providers/Microsoft.Compute/snapshots/' +
|
|
kwargs[key]['os_disk']['source'].get('name'))
|
|
+ elif kwargs[key]['os_disk']['source'].get('uri') is not None and \
|
|
+ kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
|
|
+ kwargs[key]['os_disk']['source'].get('storage_account') is not None:
|
|
+ resource_group = kwargs[key]['os_disk']['source'].get('resource_group')
|
|
+ storage_account = kwargs[key]['os_disk']['source'].get('storage_account')
|
|
+ self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = ('/subscriptions/' +
|
|
+ self.subscription_id +
|
|
+ '/resourceGroups/' +
|
|
+ resource_group +
|
|
+ '/providers/Microsoft.Storage/storageAccounts/' +
|
|
+ storage_account)
|
|
+ self.body['properties']['storageProfile']['osDiskImage']['source']['uri'] = kwargs[key]['os_disk']['source'].get('uri')
|
|
else:
|
|
self.fail("The os_disk.source parameters config errors")
|
|
|
|
diff --git a/tests/integration/targets/azure_rm_gallery/tasks/main.yml b/tests/integration/targets/azure_rm_gallery/tasks/main.yml
|
|
index 8270b04ce..0ebbe439f 100644
|
|
--- a/tests/integration/targets/azure_rm_gallery/tasks/main.yml
|
|
+++ b/tests/integration/targets/azure_rm_gallery/tasks/main.yml
|
|
@@ -343,6 +343,46 @@
|
|
that:
|
|
- output.changed
|
|
|
|
+- name: Create or update a simple gallery Image Version.
|
|
+ azure_rm_galleryimageversion:
|
|
+ resource_group: "{{ resource_group }}"
|
|
+ gallery_name: myGallery{{ rpfx }}
|
|
+ gallery_image_name: myImage
|
|
+ name: 10.1.3
|
|
+ location: eastus
|
|
+ publishing_profile:
|
|
+ end_of_life_date: "2050-10-01t00:00:00+00:00"
|
|
+ exclude_from_latest: true
|
|
+ replica_count: 3
|
|
+ storage_account_type: Standard_LRS
|
|
+ target_regions:
|
|
+ - name: eastus
|
|
+ regional_replica_count: 1
|
|
+ encryption:
|
|
+ data_disk_images:
|
|
+ - disk_encryption_set_id: "{{ des_results.state.id }}"
|
|
+ os_disk_image:
|
|
+ disk_encryption_set_id: "{{ des_results.state.id }}"
|
|
+ - name: westus
|
|
+ regional_replica_count: 2
|
|
+ encryption:
|
|
+ data_disk_images:
|
|
+ - disk_encryption_set_id: "{{ des_results.state.id }}"
|
|
+ os_disk_image:
|
|
+ disk_encryption_set_id: "{{ des_results.state.id }}"
|
|
+ storage_account_type: Standard_ZRS
|
|
+ storage_profile:
|
|
+ source_image:
|
|
+ resource_group: "{{ resource_group }}"
|
|
+ storage_account: '{{ output.vms[0].storage_account_name }}'
|
|
+ uri: 'https://{{ output.vms[0].storage_account_name }}.blob.core.windows.net/{{ output.vms[0].storage_container_name }}/{{ output.vms[0].storage_blob_name }}'
|
|
+ register: output
|
|
+
|
|
+- name: Assert the gallery image version created
|
|
+ ansible.builtin.assert:
|
|
+ that:
|
|
+ - output.changed
|
|
+
|
|
- name: Create or update a simple gallery Image Version - idempotent
|
|
azure_rm_galleryimageversion:
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
From 611ab25a9c323ff31e3f904e7860cc94e0106313 Mon Sep 17 00:00:00 2001
|
|
From: Jeremy Cline <jeremycline@microsoft.com>
|
|
Date: Wed, 28 Feb 2024 09:35:11 -0500
|
|
Subject: [PATCH 2/3] Address PR comments for style
|
|
|
|
There's no functional change.
|
|
---
|
|
plugins/modules/azure_rm_galleryimageversion.py | 12 +++++++-----
|
|
1 file changed, 7 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/plugins/modules/azure_rm_galleryimageversion.py b/plugins/modules/azure_rm_galleryimageversion.py
|
|
index 93bf031f1..cebad20b3 100644
|
|
--- a/plugins/modules/azure_rm_galleryimageversion.py
|
|
+++ b/plugins/modules/azure_rm_galleryimageversion.py
|
|
@@ -66,7 +66,8 @@
|
|
- Reference to os disk snapshot.
|
|
- Could be resource ID.
|
|
- Could be a dictionary containing I(resource_group) and I(name).
|
|
- - Could be a dictionary containing I(resource_group), I(storage_account), and I(uri) if the snapshot is stored as a PageBlob in a storage account container.
|
|
+ - Could be a dictionary containing I(resource_group), I(storage_account), and I(uri)
|
|
+ if the snapshot is stored as a PageBlob in a storage account container.
|
|
type: raw
|
|
host_caching:
|
|
description:
|
|
@@ -587,7 +588,7 @@ def exec_module(self, **kwargs):
|
|
if kwargs[key]['os_disk']['source'].get('id') is not None:
|
|
self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = kwargs[key]['os_disk']['source'].get('id')
|
|
elif kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
|
|
- kwargs[key]['os_disk']['source'].get('name') is not None:
|
|
+ kwargs[key]['os_disk']['source'].get('name') is not None:
|
|
resource_group = kwargs[key]['os_disk']['source'].get('resource_group')
|
|
self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = ('/subscriptions/' +
|
|
self.subscription_id +
|
|
@@ -596,15 +597,16 @@ def exec_module(self, **kwargs):
|
|
'/providers/Microsoft.Compute/snapshots/' +
|
|
kwargs[key]['os_disk']['source'].get('name'))
|
|
elif kwargs[key]['os_disk']['source'].get('uri') is not None and \
|
|
- kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
|
|
- kwargs[key]['os_disk']['source'].get('storage_account') is not None:
|
|
+ kwargs[key]['os_disk']['source'].get('resource_group') is not None and \
|
|
+ kwargs[key]['os_disk']['source'].get('storage_account') is not None:
|
|
resource_group = kwargs[key]['os_disk']['source'].get('resource_group')
|
|
storage_account = kwargs[key]['os_disk']['source'].get('storage_account')
|
|
self.body['properties']['storageProfile']['osDiskImage']['source']['id'] = ('/subscriptions/' +
|
|
self.subscription_id +
|
|
'/resourceGroups/' +
|
|
resource_group +
|
|
- '/providers/Microsoft.Storage/storageAccounts/' +
|
|
+ '/providers/Microsoft.Storage' +
|
|
+ '/storageAccounts/' +
|
|
storage_account)
|
|
self.body['properties']['storageProfile']['osDiskImage']['source']['uri'] = kwargs[key]['os_disk']['source'].get('uri')
|
|
else:
|
|
|
|
From 69afaab20550b0659dd6cad58edadbb8c081e8bd Mon Sep 17 00:00:00 2001
|
|
From: Jeremy Cline <jeremycline@microsoft.com>
|
|
Date: Fri, 1 Mar 2024 09:16:07 -0500
|
|
Subject: [PATCH 3/3] Fix example and tests based on review comments
|
|
|
|
Add the missing "source" intermediate key in the example and test case,
|
|
and ensure the VM information isn't shadowed by later steps.
|
|
---
|
|
plugins/modules/azure_rm_galleryimageversion.py | 7 ++++---
|
|
.../targets/azure_rm_gallery/tasks/main.yml | 13 +++++++------
|
|
2 files changed, 11 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/plugins/modules/azure_rm_galleryimageversion.py b/plugins/modules/azure_rm_galleryimageversion.py
|
|
index cebad20b3..4befec9c3 100644
|
|
--- a/plugins/modules/azure_rm_galleryimageversion.py
|
|
+++ b/plugins/modules/azure_rm_galleryimageversion.py
|
|
@@ -326,9 +326,10 @@
|
|
storage_account_type: Standard_LRS
|
|
storage_profile:
|
|
os_disk:
|
|
- resource_group: myResourceGroup
|
|
- storage_account: myStorageAccount
|
|
- uri: "https://myStorageAccount.blob.core.windows.net/myContainer/myImage.vhd"
|
|
+ source:
|
|
+ resource_group: myResourceGroup
|
|
+ storage_account: myStorageAccount
|
|
+ uri: "https://myStorageAccount.blob.core.windows.net/myContainer/myImage.vhd"
|
|
'''
|
|
|
|
RETURN = '''
|
|
diff --git a/tests/integration/targets/azure_rm_gallery/tasks/main.yml b/tests/integration/targets/azure_rm_gallery/tasks/main.yml
|
|
index 0ebbe439f..ee1cbd9ed 100644
|
|
--- a/tests/integration/targets/azure_rm_gallery/tasks/main.yml
|
|
+++ b/tests/integration/targets/azure_rm_gallery/tasks/main.yml
|
|
@@ -109,7 +109,7 @@
|
|
azure_rm_virtualmachine_info:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "vmforimage{{ rpfx }}"
|
|
- register: output
|
|
+ register: vm_output
|
|
|
|
- name: Create a snapshot by importing an unmanaged blob from the same subscription.
|
|
azure_rm_snapshot:
|
|
@@ -118,7 +118,7 @@
|
|
location: eastus
|
|
creation_data:
|
|
create_option: Import
|
|
- source_uri: 'https://{{ output.vms[0].storage_account_name }}.blob.core.windows.net/{{ output.vms[0].storage_container_name }}/{{ output.vms[0].storage_blob_name }}'
|
|
+ source_uri: 'https://{{ vm_output.vms[0].storage_account_name }}.blob.core.windows.net/{{ vm_output.vms[0].storage_container_name }}/{{ vm_output.vms[0].storage_blob_name }}'
|
|
register: output
|
|
|
|
- name: Assert the snapshot created
|
|
@@ -372,10 +372,11 @@
|
|
disk_encryption_set_id: "{{ des_results.state.id }}"
|
|
storage_account_type: Standard_ZRS
|
|
storage_profile:
|
|
- source_image:
|
|
- resource_group: "{{ resource_group }}"
|
|
- storage_account: '{{ output.vms[0].storage_account_name }}'
|
|
- uri: 'https://{{ output.vms[0].storage_account_name }}.blob.core.windows.net/{{ output.vms[0].storage_container_name }}/{{ output.vms[0].storage_blob_name }}'
|
|
+ os_disk:
|
|
+ source:
|
|
+ resource_group: "{{ resource_group }}"
|
|
+ storage_account: '{{ vm_output.vms[0].storage_account_name }}'
|
|
+ uri: 'https://{{ vm_output.vms[0].storage_account_name }}.blob.core.windows.net/{{ vm_output.vms[0].storage_container_name }}/{{ vm_output.vms[0].storage_blob_name }}'
|
|
register: output
|
|
|
|
- name: Assert the gallery image version created
|