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

Create RG if it doesn't exist #150

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
jordlay marked this conversation as resolved.
Show resolved Hide resolved
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",
Expand Down