-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add firewall steps #1198
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
base: v2
Are you sure you want to change the base?
feat: add firewall steps #1198
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| script = """ | ||
| az extension add --name azure-firewall | ||
|
|
||
| az network public-ip create \\ | ||
| --resource-group "${resourceGroup}" \\ | ||
| --name "${publicIpName}" \\ | ||
| --sku Standard \\ | ||
| --location "${location}" \\ | ||
| --subscription "${subscription}" | ||
|
|
||
| az network firewall create \\ | ||
| --resource-group "${resourceGroup}" \\ | ||
| --name "${name}" \\ | ||
| --location "${location}" \\ | ||
| --enable-dns-proxy true \\ | ||
| --subscription "${subscription}" | ||
|
|
||
| az network firewall ip-config create \\ | ||
| --resource-group "${resourceGroup}" \\ | ||
| --firewall-name "${name}" \\ | ||
| --name "${name}-ipconfig" \\ | ||
| --public-ip-address "${publicIpName}" \\ | ||
| --vnet-name "${vnetName}" \\ | ||
| --subscription "${subscription}" | ||
|
|
||
| FWPRIVATE_IP=$(az network firewall show \\ | ||
| --resource-group "${resourceGroup}" \\ | ||
| --name "${name}" \\ | ||
| --subscription "${subscription}" \\ | ||
| --query "ipConfigurations[0].privateIPAddress" -o tsv) | ||
| echo "##vso[task.setvariable variable=${exportVar}]$FWPRIVATE_IP" | ||
| """ | ||
| AzCli(serviceConnection, "Create firewall ${name}", script) | ||
| } | ||
|
|
||
| UpdateFirewallPolicy = lambda serviceConnection: str, subscription: str, resourceGroup: str, name: str, policyPath: str, location: str -> steps.Step { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do you use this funciton?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| script = """ | ||
| POLICY_TMP=$(mktemp) | ||
| 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=2025-05-01" \\ | ||
| --headers "Content-Type=application/json" \\ | ||
| --body "@$POLICY_TMP" | ||
| rm -f "$POLICY_TMP" | ||
| """ | ||
| AzCli(serviceConnection, "Update firewall policy ${name}", script) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWPRIVATE_IPplease avoid using abbr.FWto make it easier to read.