Skip to content

feat: add firewall steps#1198

Open
xinWeiWei24 wants to merge 2 commits into
v2from
xinwei/lib-firewall
Open

feat: add firewall steps#1198
xinWeiWei24 wants to merge 2 commits into
v2from
xinwei/lib-firewall

Conversation

@xinWeiWei24
Copy link
Copy Markdown
Collaborator

Add CreateFirewall (public IP + firewall + IP config, exports FWPRIVATE_IP) and UpdateFirewallPolicy (applies rule JSON via az rest PUT with dynamic location substitution) to lib/steps/azure.

Add CreateFirewall (public IP + firewall + IP config, exports FWPRIVATE_IP)
and UpdateFirewallPolicy (applies rule JSON via az rest PUT with dynamic
location substitution) to lib/steps/azure.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Comment thread kcl/lib/steps/azure/firewall.k Outdated
AzCli(serviceConnection, "Create firewall ${name}", script)
}

UpdateFirewallPolicy = lambda serviceConnection: str, resourceGroup: str, name: str, subscription: str, policyPath: str, location: str -> steps.Step {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: prefer subscription to come before resourceGroup in param order
resourceGroup: str, name: str, subscription

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! changed

Comment thread kcl/lib/steps/azure/firewall.k Outdated
sed 's|"location": "[^"]*"|"location": "${location}"|g' "${policyPath}" > "$POLICY_TMP"
az rest \\
--method put \\
--uri "https://management.azure.com/subscriptions/${subscription}/resourceGroups/${resourceGroup}/providers/Microsoft.Network/azureFirewalls/${name}?api-version=2023-09-01" \\
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

api-version seems pretty old, do we want to pin to this version?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

change to AI suggested newer and stable version: 2025-01-01

Comment thread kcl/lib/steps/azure/firewall.k Outdated
--name "${name}" \\
--subscription "${subscription}" \\
--query "ipConfigurations[0].privateIPAddress" -o tsv)
echo "##vso[task.setvariable variable=FWPRIVATE_IP]$FWPRIVATE_IP"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit (as in another PR): would it be better let user to specify name

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added exportVar to specify the export parameter name

AzCli(serviceConnection, "Create firewall ${name}", script)
}

UpdateFirewallPolicy = lambda serviceConnection: str, subscription: str, resourceGroup: str, name: str, policyPath: str, location: str -> steps.Step {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

how do you use this funciton?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It’s called in pipelines with a firewall policy json file path input

@@ -0,0 +1,51 @@
import azure_pipelines.ap.steps

CreateFirewall = lambda serviceConnection: str, subscription: str, resourceGroup: str, name: str, location: str, vnetName: str, publicIpName: str, exportVar: str = "FWPRIVATE_IP" -> steps.Step {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FWPRIVATE_IP please avoid using abbr. FW to make it easier to read.

@@ -0,0 +1,51 @@
import azure_pipelines.ap.steps

CreateFirewall = lambda serviceConnection: str, subscription: str, resourceGroup: str, name: str, location: str, vnetName: str, publicIpName: str, exportVar: str = "FWPRIVATE_IP" -> steps.Step {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a great example that you encapsulate a few steps into one function and only expose a small interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants