-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add microsoft_network_applicationGateways_zones rule
- Loading branch information
1 parent
a160a92
commit 7a8e1cd
Showing
3 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...Resiliency-Library-v2/azapi/network/microsoft_network_applicationGateways_zones.mock.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{ | ||
"mock": { | ||
"3zones": { | ||
"resource_changes": [ | ||
{ | ||
"address": "azapi_resource.gw", | ||
"mode": "managed", | ||
"type": "azapi_resource", | ||
"name": "gw", | ||
"provider_name": "registry.terraform.io/azure/azapi", | ||
"change": { | ||
"actions": [ | ||
"create" | ||
], | ||
"after": { | ||
"body": { | ||
"zones": [ | ||
"1", | ||
"2", | ||
"3" | ||
] | ||
}, | ||
"name": "example-appgateway", | ||
"type": "Microsoft.Network/applicationGateways@2024-03-01" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"2zones": { | ||
"resource_changes": [ | ||
{ | ||
"address": "azapi_resource.gw", | ||
"mode": "managed", | ||
"type": "azapi_resource", | ||
"name": "gw", | ||
"provider_name": "registry.terraform.io/azure/azapi", | ||
"change": { | ||
"actions": [ | ||
"create" | ||
], | ||
"after": { | ||
"body": { | ||
"zones": [ | ||
"1", | ||
"2" | ||
] | ||
}, | ||
"name": "example-appgateway", | ||
"type": "Microsoft.Network/applicationGateways@2024-03-01" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"invalid_no_zones": { | ||
"resource_changes": [ | ||
{ | ||
"address": "azapi_resource.gw", | ||
"mode": "managed", | ||
"type": "azapi_resource", | ||
"name": "gw", | ||
"provider_name": "registry.terraform.io/azure/azapi", | ||
"change": { | ||
"actions": [ | ||
"create" | ||
], | ||
"after": { | ||
"body": { | ||
}, | ||
"name": "example-appgateway", | ||
"type": "Microsoft.Network/applicationGateways@2024-03-01" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"invalid_no_enough_zones":{ | ||
"resource_changes": [ | ||
{ | ||
"address": "azapi_resource.gw", | ||
"mode": "managed", | ||
"type": "azapi_resource", | ||
"name": "gw", | ||
"provider_name": "registry.terraform.io/azure/azapi", | ||
"change": { | ||
"actions": [ | ||
"create" | ||
], | ||
"after": { | ||
"body": { | ||
"zones": [ | ||
"1" | ||
] | ||
}, | ||
"name": "example-appgateway", | ||
"type": "Microsoft.Network/applicationGateways@2024-03-01" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...tive-Resiliency-Library-v2/azapi/network/microsoft_network_applicationGateways_zones.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package Azure_Proactive_Resiliency_Library_v2.Microsoft_Network_applicationGateways | ||
|
||
valid_zones(after) { | ||
after.body.zones | ||
count(after.body.zones) >= 2 | ||
} | ||
|
||
deny[reason] { | ||
tfplan := data.utils.tfplan(input) | ||
resource := tfplan.resource_changes[_] | ||
resource.mode == "managed" | ||
resource.type == "azapi_resource" | ||
regex.match(`^Microsoft.Network/applicationGateways@`, resource.change.after.type) | ||
data.utils.is_create_or_update(resource.change.actions) | ||
not valid_zones(resource.change.after) | ||
|
||
reason := sprintf("Azure-Proactive-Resiliency-Library-v2: '%s' `azapi_resource` must have must have configured to use at least 2 Availability Zones: https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/Network/applicationGateways/#deploy-application-gateway-in-a-zone-redundant-configuration", [resource.address]) | ||
} |