# The Azure deny rule that never wins

Two real outbound rules overlap: an allow for TCP 443 to any destination and
a deny for the documentation-only network `198.51.100.0/24`. The allow's
lower priority number makes it win first. Reorder the allow while preserving
both rules: the deny should be priority 200 and the allow priority 300.

## Before you begin

This exercise creates a uniquely named resource group and an **unattached**
Azure network security group. Never attach it to a VM, network interface or
subnet. It creates no VM, public IP or data and does not send network traffic.
An unattached NSG and empty resource group normally have no direct usage
charge, but Azure pricing and policies vary; check costs and remove resources
promptly. Use an isolated subscription with known safe guardrails.

Install Azure CLI, Terraform 1.5+, Python 3 and Bash on Linux. Log in and select
the intended subscription. `Microsoft.Resources` and `Microsoft.Network` must
already be registered. Use a private local Linux filesystem for Terraform
state. The provided IP range is an example, not a production policy.

```sh
export AZURE_SUBSCRIPTION_ID="your-subscription-id"
./setup.sh "$AZURE_SUBSCRIPTION_ID" northeurope --accept-costs
```

Inspect the lab NSG and its rules in Azure. Change the allow priority through
`.lab-state/access.auto.tfvars.json`, inspect the Terraform plan in
`.lab-state`, and apply only the intended in-place update:

```sh
terraform -chdir=.lab-state plan -out=repair.tfplan
terraform -chdir=.lab-state show repair.tfplan
# Apply the saved plan only if it updates the lab NSG in place.
terraform -chdir=.lab-state apply repair.tfplan
./verify.sh
```

`./verify.sh` reads the Azure rules and checks Terraform for drift; it does not
test actual packet flow or other NSGs, routes or firewalls.

Run `./teardown.sh` when finished. Teardown refuses unexpected group contents
or an attached NSG and retains private state on failure. Confirm that the lab
resource group is gone before removing `.lab-state`.
