azure_rm_deployment: collect tags from existing Resource Group (#26104)
This commit is contained in:
parent
e364d717cb
commit
6741e98c04
1 changed files with 19 additions and 18 deletions
|
@ -416,6 +416,7 @@ class AzureRMDeploymentManager(AzureRMModuleBase):
|
|||
self.wait_for_deployment_completion = None
|
||||
self.wait_for_deployment_polling_period = None
|
||||
self.tags = None
|
||||
self.append_tags = None
|
||||
|
||||
self.results = dict(
|
||||
deployment=dict(),
|
||||
|
@ -429,7 +430,7 @@ class AzureRMDeploymentManager(AzureRMModuleBase):
|
|||
|
||||
def exec_module(self, **kwargs):
|
||||
|
||||
for key in list(self.module_arg_spec.keys()) + ['tags']:
|
||||
for key in list(self.module_arg_spec.keys()) + ['append_tags', 'tags']:
|
||||
setattr(self, key, kwargs[key])
|
||||
|
||||
if self.state == 'present':
|
||||
|
@ -454,10 +455,14 @@ class AzureRMDeploymentManager(AzureRMModuleBase):
|
|||
self.results['changed'] = True
|
||||
self.results['msg'] = 'deployment succeeded'
|
||||
else:
|
||||
if self.resource_group_exists(self.resource_group_name):
|
||||
self.destroy_resource_group()
|
||||
self.results['changed'] = True
|
||||
self.results['msg'] = "deployment deleted"
|
||||
try:
|
||||
if self.get_resource_group(self.resource_group_name):
|
||||
self.destroy_resource_group()
|
||||
self.results['changed'] = True
|
||||
self.results['msg'] = "deployment deleted"
|
||||
except CloudError:
|
||||
# resource group does not exist
|
||||
pass
|
||||
|
||||
return self.results
|
||||
|
||||
|
@ -484,6 +489,15 @@ class AzureRMDeploymentManager(AzureRMModuleBase):
|
|||
uri=self.template_link
|
||||
)
|
||||
|
||||
if self.append_tags and self.tags:
|
||||
try:
|
||||
rg = self.get_resource_group(self.resource_group_name)
|
||||
if rg.tags:
|
||||
self.tags = dict(self.tags, **rg.tags)
|
||||
except CloudError:
|
||||
# resource group does not exist
|
||||
pass
|
||||
|
||||
params = self.rm_models.ResourceGroup(location=self.location, tags=self.tags)
|
||||
|
||||
try:
|
||||
|
@ -531,19 +545,6 @@ class AzureRMDeploymentManager(AzureRMModuleBase):
|
|||
self.fail("Delete resource group and deploy failed with status code: %s and message: %s" %
|
||||
(e.status_code, e.message))
|
||||
|
||||
def resource_group_exists(self, resource_group):
|
||||
'''
|
||||
Return True/False based on existence of requested resource group.
|
||||
|
||||
:param resource_group: string. Name of a resource group.
|
||||
:return: boolean
|
||||
'''
|
||||
try:
|
||||
self.rm_client.resource_groups.get(resource_group)
|
||||
except CloudError:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _get_failed_nested_operations(self, current_operations):
|
||||
new_operations = []
|
||||
for operation in current_operations:
|
||||
|
|
Loading…
Reference in a new issue