Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to set boot diagnostics storage account to managed #1206

Merged
29 changes: 23 additions & 6 deletions plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,23 @@
- Flag indicating if boot diagnostics are enabled.
required: true
type: bool
type:
description:
- Should the storage account be managed by azure or a custom storage account
required: false
type: str
choices:
- managed
storage_account:
Klaas- marked this conversation as resolved.
Show resolved Hide resolved
description:
- Only used if I(type) is not set
- The name of an existing storage account to use for boot diagnostics.
- If not specified, uses I(storage_account_name) defined one level up.
- If storage account is not specified anywhere, and C(enabled) is C(true), a default storage account is created for boot diagnostics data.
required: false
resource_group:
description:
- Only used if I(type) is not set
- Resource group where the storage account is located.
type: str
linux_config:
Expand Down Expand Up @@ -603,6 +612,7 @@
storage_blob: osdisk.vhd
boot_diagnostics:
enabled: yes
type: managed
image:
offer: 0001-com-ubuntu-server-focal
publisher: canonical
Expand Down Expand Up @@ -1477,9 +1487,12 @@ def exec_module(self, **kwargs):
current_boot_diagnostics['enabled'] = self.boot_diagnostics['enabled']
boot_diagnostics_changed = True

boot_diagnostics_storage_account = self.get_boot_diagnostics_storage_account(
limited=not self.boot_diagnostics['enabled'], vm_dict=vm_dict)
boot_diagnostics_blob = boot_diagnostics_storage_account.primary_endpoints.blob if boot_diagnostics_storage_account else None
if 'type' in self.boot_diagnostics and self.boot_diagnostics['type'] == 'managed':
boot_diagnostics_blob = None
else:
boot_diagnostics_storage_account = self.get_boot_diagnostics_storage_account(
limited=not self.boot_diagnostics['enabled'], vm_dict=vm_dict)
boot_diagnostics_blob = boot_diagnostics_storage_account.primary_endpoints.blob if boot_diagnostics_storage_account else None
if current_boot_diagnostics.get('storageUri') != boot_diagnostics_blob:
current_boot_diagnostics['storageUri'] = boot_diagnostics_blob
boot_diagnostics_changed = True
Expand Down Expand Up @@ -1606,7 +1619,7 @@ def exec_module(self, **kwargs):
promotion_code=self.plan.get('promotion_code'))

# do this before creating vm_resource as it can modify tags
if self.boot_diagnostics_present and self.boot_diagnostics['enabled']:
if self.boot_diagnostics_present and self.boot_diagnostics['enabled'] and self.boot_diagnostics.get('type') != 'managed':
boot_diag_storage_account = self.get_boot_diagnostics_storage_account()

vm_resource = self.compute_models.VirtualMachine(
Expand Down Expand Up @@ -1703,7 +1716,7 @@ def exec_module(self, **kwargs):
)

if self.boot_diagnostics_present:
if self.boot_diagnostics['enabled']:
if self.boot_diagnostics['enabled'] and self.boot_diagnostics.get('type') != 'managed':
storage_uri = boot_diag_storage_account.primary_endpoints.blob
else:
storage_uri = None
Expand Down Expand Up @@ -1950,10 +1963,14 @@ def exec_module(self, **kwargs):
)

if self.boot_diagnostics is not None:
storage_uri = None
# storageUri is undefined if boot diagnostics is disabled
if 'storageUri' in vm_dict['properties']['diagnosticsProfile']['bootDiagnostics']:
storage_uri = vm_dict['properties']['diagnosticsProfile']['bootDiagnostics']['storageUri']
vm_resource.diagnostics_profile = self.compute_models.DiagnosticsProfile(
boot_diagnostics=self.compute_models.BootDiagnostics(
enabled=vm_dict['properties']['diagnosticsProfile']['bootDiagnostics']['enabled'],
storage_uri=vm_dict['properties']['diagnosticsProfile']['bootDiagnostics']['storageUri']))
storage_uri=storage_uri))

if vm_dict.get('tags'):
vm_resource.tags = vm_dict['tags']
Expand Down