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 2 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 _validate_resource_group_exists(self, config, command_context):
jordlay marked this conversation as resolved.
Show resolved Hide resolved
"""Ensure resource group exists.
jordlay marked this conversation as resolved.
Show resolved Hide resolved

Using ResourceManagementClient:
- Check for existence of resource group from allDeployParameters.json.
jordlay marked this conversation as resolved.
Show resolved Hide resolved
- Create resource group if doesn't exist.
"""
resource_client = command_context.resources_client
jordlay marked this conversation as resolved.
Show resolved Hide resolved
if not resource_client.resource_groups.check_existence(config.publisherResourceGroupName):
rg_params = ResourceGroup(location=config.location)
jordlay marked this conversation as resolved.
Show resolved Hide resolved
resource_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._validate_resource_group_exists(config, command_context)
for element in self.elements:
logger.debug(
"Deploying definition element %s of type %s",
Expand Down