mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-30 22:31:25 -07:00
Getting latest API version if not specified in azure_rm_resource (#54022)
This commit is contained in:
parent
0bf14d61d0
commit
5b79631380
3 changed files with 53 additions and 8 deletions
|
@ -30,7 +30,6 @@ options:
|
|||
api_version:
|
||||
description:
|
||||
- Specific API version to be used.
|
||||
required: yes
|
||||
provider:
|
||||
description:
|
||||
- Provider type.
|
||||
|
@ -163,8 +162,7 @@ class AzureRMResource(AzureRMModuleBase):
|
|||
default=[]
|
||||
),
|
||||
api_version=dict(
|
||||
type='str',
|
||||
required=True
|
||||
type='str'
|
||||
),
|
||||
method=dict(
|
||||
type='str',
|
||||
|
@ -260,6 +258,25 @@ class AzureRMResource(AzureRMModuleBase):
|
|||
|
||||
if orphan is not None:
|
||||
self.url += '/' + orphan
|
||||
|
||||
# if api_version was not specified, get latest one
|
||||
if not self.api_version:
|
||||
try:
|
||||
# extract provider and resource type
|
||||
if "/providers/" in self.url:
|
||||
provider = self.url.split("/providers/")[1].split("/")[0]
|
||||
resourceType = self.url.split(provider + "/")[1].split("/")[0]
|
||||
url = "/subscriptions/" + self.subscription_id + "/providers/" + provider
|
||||
api_versions = json.loads(self.mgmt_client.query(url, "GET", {'api-version': '2015-01-01'}, None, None, [200], 0, 0).text)
|
||||
for rt in api_versions['resourceTypes']:
|
||||
if rt['resourceType'].lower() == resourceType.lower():
|
||||
self.api_version = rt['apiVersions'][0]
|
||||
break
|
||||
if not self.api_version:
|
||||
self.fail("Couldn't find api version for {0}/{1}".format(provider, resourceType))
|
||||
except Exception as exc:
|
||||
self.fail("Failed to obtain API version: {0}".format(str(exc)))
|
||||
|
||||
query_parameters = {}
|
||||
query_parameters['api-version'] = self.api_version
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue