diff --git a/src/aosm/azext_aosm/definition_folder/reader/definition_folder.py b/src/aosm/azext_aosm/definition_folder/reader/definition_folder.py index 7dfc61c70dc..95cf98813e7 100644 --- a/src/aosm/azext_aosm/definition_folder/reader/definition_folder.py +++ b/src/aosm/azext_aosm/definition_folder/reader/definition_folder.py @@ -7,7 +7,7 @@ from typing import Any, Dict, List from knack.log import get_logger - +from azure.mgmt.resource.resources.models import ResourceGroup from azext_aosm.common.command_context import CommandContext from azext_aosm.configuration_models.common_parameters_config import ( BaseCommonParametersConfig, @@ -71,10 +71,26 @@ def _parse_index_file(self, file_content: str) -> List[Dict[str, Any]]: ) return parsed_elements + def _create_or_confirm_existence_of_resource_group(self, config, command_context): + """Ensure resource group exists before deploying of elements begins. + + Using ResourceManagementClient: + - Check for existence of resource group specified in allDeployParameters.json. + - Create resource group if doesn't exist. + """ + resources_client = command_context.resources_client + if not resources_client.resource_groups.check_existence(config.publisherResourceGroupName): + rg_params = ResourceGroup(location=config.location) + resources_client.resource_groups.create_or_update( + resource_group_name=config.publisherResourceGroupName, + parameters=rg_params + ) + def deploy( self, config: BaseCommonParametersConfig, command_context: CommandContext ): """Deploy the resources defined in the folder.""" + self._create_or_confirm_existence_of_resource_group(config, command_context) for element in self.elements: logger.debug( "Deploying definition element %s of type %s",