Skip to content

Commit

Permalink
extract regex match into funcion is_azure_type
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Jan 26, 2025
1 parent 7a8e1cd commit f90720e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ deny[reason] {
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)
data.utils.is_azure_type(resource.change.after, "Microsoft.Network/applicationGateways")
not valid_sku(resource)

reason := sprintf("Azure-Proactive-Resiliency-Library-v2: '%s' `azapi_resource` must have 'body.properties.sku.name' set to 'Standard_v2' or 'WAF_v2': https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/Network/applicationGateways/#migrate-to-application-gateway-v2", [resource.address])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deny[reason] {
resource := tfplan.resource_changes[_]
resource.mode == "managed"
resource.type == "azapi_resource"
regex.match(`^Microsoft.Network/applicationGateways@`, resource.change.after.type)
data.utils.is_azure_type(resource.change.after, "Microsoft.Network/applicationGateways")
data.utils.is_create_or_update(resource.change.actions)
not valid_zones(resource.change.after)

Expand Down
4 changes: 4 additions & 0 deletions policy/common/avm.utils.rego
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ tfplan(d) = output {
tfplan(d) = output {
not d.plan.resource_changes
output := d
}

is_azure_type(resource, azure_type) {
regex.match(sprintf("^%s@", [azure_type]), resource.type)
}

0 comments on commit f90720e

Please sign in to comment.