Skip to content
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

new rule for public ip resource #16

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"mock": {
"default": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"body": {
"sku": {
"name": "Standard",
"tier": "Regional"
},
"zones": [
"2",
"1"
]
}
}
}
}
]
},
"invalid_basic": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"body": {
"sku": {
"name": "Basic"
}
},
"type": "Microsoft.Network/publicIPAddresses@2024-05-01"
}
}
}
]
},
"invalid_no_zones": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"body": {
"sku": {
"name": "Standard"
}
},
"type": "Microsoft.Network/publicIPAddresses@2024-05-01"
}
}
}
]
},
"invalid_empty_zones": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"body": {
"sku": {
"name": "Standard"
},
"zones": []
},
"type": "Microsoft.Network/publicIPAddresses@2024-05-01"
}
}
}
]
},
"invalid_single_zone": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"body": {
"sku": {
"name": "Standard"
},
"zones": ["1"]
},
"type": "Microsoft.Network/publicIPAddresses@2024-05-01"
}
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package Azure_Proactive_Resiliency_Library_v2.Microsoft_Network_publicIPAddresses

import rego.v1

valid(resource) if {
resource.values.body.sku.name == "Sandard"
count(resource.values.body.zones) >= 2
}

deny_use_standard_sku_and_zone_redundant_ip contains reason if {
resource := data.utils.resource(input, "azapi_resource")[_]
data.utils.is_azure_type(resource.values, "Microsoft.Network/publicIPAddresses")
not valid(resource)

reason := sprintf("Azure-Proactive-Resiliency-Library-v2: '%s' `azapi_resource` must have configured `sku.name` to `\"Standard\"` and a `zones` that cotnains at least 2 zones: https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/Network/publicIPAddresses/#use-standard-sku-and-zone-redundant-ips-when-applicable", [resource.address])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"mock": {
"default": {
"resource_changes": [
{
"address": "azurerm_public_ip.example",
"mode": "managed",
"type": "azurerm_public_ip",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"sku": "Standard",
"sku_tier": "Regional",
"zones": [
"1",
"2"
]
}
}
}
]
},
"invalid_basic_sku": {
"resource_changes": [
{
"address": "azurerm_public_ip.example",
"mode": "managed",
"type": "azurerm_public_ip",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"sku": "Basic"
},
"after_unknown": {
"fqdn": true,
"id": true,
"ip_address": true,
"resource_group_name": true,
"tags": {}
},
"before_sensitive": false,
"after_sensitive": {
"tags": {}
}
}
}
]
},
"invalid_null_zones": {
"resource_changes": [
{
"address": "azurerm_public_ip.example",
"mode": "managed",
"type": "azurerm_public_ip",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"sku": "Standard",
"zones": null
},
"after_unknown": {
"fqdn": true,
"id": true,
"ip_address": true,
"resource_group_name": true,
"tags": {}
},
"before_sensitive": false,
"after_sensitive": {
"tags": {}
}
}
}
]
},
"invalid_no_zones": {
"resource_changes": [
{
"address": "azurerm_public_ip.example",
"mode": "managed",
"type": "azurerm_public_ip",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"sku": "Standard"
},
"after_unknown": {
"fqdn": true,
"id": true,
"ip_address": true,
"resource_group_name": true,
"tags": {}
},
"before_sensitive": false,
"after_sensitive": {
"tags": {}
}
}
}
]
},
"invalid_empty_zones": {
"resource_changes": [
{
"address": "azurerm_public_ip.example",
"mode": "managed",
"type": "azurerm_public_ip",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"sku": "Standard",
"zones": []
},
"after_unknown": {
"fqdn": true,
"id": true,
"ip_address": true,
"resource_group_name": true,
"tags": {}
},
"before_sensitive": false,
"after_sensitive": {
"tags": {}
}
}
}
]
},
"invalid_single_zone": {
"resource_changes": [
{
"address": "azurerm_public_ip.example",
"mode": "managed",
"type": "azurerm_public_ip",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"sku": "Standard",
"zones": [
"1"
]
},
"after_unknown": {
"fqdn": true,
"id": true,
"ip_address": true,
"resource_group_name": true,
"tags": {}
},
"before_sensitive": false,
"after_sensitive": {
"tags": {}
}
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Azure_Proactive_Resiliency_Library_v2.azurerm_public_ip

import rego.v1

valid_ip(resource) if {
resource.values.sku == "Standard"
count(resource.values.zones) >= 2
}

deny_use_standard_sku_and_zone_redundant_ip contains reason if {
resource := data.utils.resource(input, "azurerm_public_ip")[_]
not valid_ip(resource)

reason := sprintf("Azure-Proactive-Resiliency-Library-v2: '%s' `azurerm_public_ip` must have configured `sku` to `\"Standard\"` and a `zones` that cotnains at least 2 zones: https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/Network/publicIPAddresses/#use-standard-sku-and-zone-redundant-ips-when-applicable", [resource.address])
}
17 changes: 0 additions & 17 deletions policy/common/avm.utils.rego

This file was deleted.

4 changes: 4 additions & 0 deletions policy/common/common.utils.rego
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package utils

import rego.v1

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

_resource(_input) := output if {
_input.plan.resource_changes == _input.plan.resource_changes
output := {
Expand Down
Loading
Loading