Skip to content

Add infrastructure tags#46

Merged
simonkurtz-MSFT merged 3 commits into
mainfrom
feature/tag-and-identify-infrastructure-resource-groups
Jun 9, 2025
Merged

Add infrastructure tags#46
simonkurtz-MSFT merged 3 commits into
mainfrom
feature/tag-and-identify-infrastructure-resource-groups

Conversation

@simonkurtz-MSFT

Copy link
Copy Markdown
Member

Resolves #45

In draft now as it still requires unit tests to be added. Will be added early next week before changing draft to full PR.

@simonkurtz-MSFT simonkurtz-MSFT self-assigned this Jun 7, 2025
@simonkurtz-MSFT simonkurtz-MSFT added the enhancement New feature or request label Jun 7, 2025
@github-actions

github-actions Bot commented Jun 7, 2025

Copy link
Copy Markdown

Python 3.13 Test Results

142 tests  +16   142 ✅ +16   1s ⏱️ ±0s
  1 suites ± 0     0 💤 ± 0 
  1 files   ± 0     0 ❌ ± 0 

Results for commit cfb7e38. ± Comparison against base commit 0c96d6f.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Jun 7, 2025

Copy link
Copy Markdown

Python 3.12 Test Results

142 tests  +16   142 ✅ +16   1s ⏱️ ±0s
  1 suites ± 0     0 💤 ± 0 
  1 files   ± 0     0 ❌ ± 0 

Results for commit cfb7e38. ± Comparison against base commit 0c96d6f.

♻️ This comment has been updated with latest results.

@simonkurtz-MSFT simonkurtz-MSFT requested a review from Copilot June 9, 2025 13:22
@simonkurtz-MSFT simonkurtz-MSFT marked this pull request as ready for review June 9, 2025 13:22

This comment was marked as outdated.

@simonkurtz-MSFT simonkurtz-MSFT requested a review from Copilot June 9, 2025 13:47
@simonkurtz-MSFT simonkurtz-MSFT merged commit 761447b into main Jun 9, 2025
7 checks passed
@simonkurtz-MSFT simonkurtz-MSFT deleted the feature/tag-and-identify-infrastructure-resource-groups branch June 9, 2025 13:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces support for applying custom tags to Azure resource groups and Bicep deployments.

  • Adds build_infrastructure_tags helper to generate standard and custom tags.
  • Extends create_resource_group and create_bicep_deployment_group to accept and apply tags.
  • Updates sample notebooks to generate and pass rg_tags when invoking deployments.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

File Description
shared/python/utils.py Added tag-building helper; updated RG and Bicep deployment APIs to support tags.
tests/python/test_utils.py Added unit tests covering infrastructure tag generation and RG creation with tags.
infrastructure/*/create.ipynb Updated notebooks to call build_infrastructure_tags and pass rg_tags to deployments.
Comments suppressed due to low confidence (1)

shared/python/utils.py:41

  • [nitpick] The docstring refers to "infrastructure name tags" plural but only a single infrastructure tag is produced; consider clarifying this description.
"""

Comment thread shared/python/utils.py
"""

# Convert infrastructure enum to string value if needed
if hasattr(infrastructure, 'value'):

Copilot AI Jun 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Instead of using hasattr to detect an enum, consider using isinstance(infrastructure, INFRASTRUCTURE) for clearer intent and to avoid false positives on objects with a value attribute.

Suggested change
if hasattr(infrastructure, 'value'):
if isinstance(infrastructure, INFRASTRUCTURE):

Copilot uses AI. Check for mistakes.
Comment thread shared/python/utils.py

run(f"az group create --name {rg_name} --location {resource_group_location} --tags source=apim-sample",
# Build the tags string for the Azure CLI command
tag_string = "source=apim-sample"

Copilot AI Jun 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Wrap the default source tag value in quotes (e.g. source="apim-sample") for consistency with how custom tag values are quoted, and to prevent issues if the value ever contains special characters.

Suggested change
tag_string = "source=apim-sample"
tag_string = "source=\"apim-sample\""

Copilot uses AI. Check for mistakes.
Comment thread shared/python/utils.py
# Build the tags string for the Azure CLI command
tag_string = "source=apim-sample"
if tags:
for key, value in tags.items():

Copilot AI Jun 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Iterating tags.items() can produce a non-deterministic order; consider iterating over sorted(tags) to keep the CLI command consistent across runs and easier to test.

Suggested change
for key, value in tags.items():
for key, value in sorted(tags.items()):

Copilot uses AI. Check for mistakes.
Comment thread shared/python/utils.py
Comment on lines +370 to +371
escaped_value = value.replace('"', '\\"') if isinstance(value, str) else str(value)
tag_string += f" {key}=\"{escaped_value}\""

Copilot AI Jun 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual string escaping may miss other shell metacharacters; using shlex.quote(value) would more robustly escape any special characters for the shell.

Suggested change
escaped_value = value.replace('"', '\\"') if isinstance(value, str) else str(value)
tag_string += f" {key}=\"{escaped_value}\""
escaped_value = shlex.quote(value) if isinstance(value, str) else shlex.quote(str(value))
tag_string += f" {key}={escaped_value}"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Set Infrastructure Tags

2 participants