Skip to content

Commit

Permalink
add rule for postgresql azapi
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Feb 20, 2025
1 parent 52a2f44 commit 7f835a1
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"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": {
"properties": {
"backup": {
"geoRedundantBackup": "Enabled"
}
}
},
"type": "Microsoft.DBforPostgreSQL/flexibleServers@2024-11-01-preview"
}
}
}
]
},
"invalid_geo_redundant_backup_disabled": {
"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": {
"properties": {
"backup": {
"geoRedundantBackup": "Disabled"
}
}
},
"type": "Microsoft.DBforPostgreSQL/flexibleServers@2024-11-01-preview"
}
}
}
]
},
"invalid_geo_redundant_backup_omitted": {
"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": {
"properties": {
"backup": {}
}
},
"type": "Microsoft.DBforPostgreSQL/flexibleServers@2024-11-01-preview"
}
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Azure_Proactive_Resiliency_Library_v2

import rego.v1

valid_azapi_postgres_flexible_server_geo_redundant_backup_enabled(resource) if {
resource.values.body.properties.backup.geoRedundantBackup == "Enabled"
}

deny_postgresql_flexible_server_geo_redundant_backup_enabled contains reason if {
resource := data.utils.resource(input, "azapi_resource")[_]
data.utils.is_azure_type(resource.values, "Microsoft.DBforPostgreSQL/flexibleServers")
not valid_azapi_postgres_flexible_server_geo_redundant_backup_enabled(resource)

reason := sprintf("Azure-Proactive-Resiliency-Library-v2/postgresql_flexible_server_geo_redundant_backup_enabled: '%s' `azapi_resource` must have 'backup.geoRedundantBackup' set to '\"Enabled\"': https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforMySQL/flexibleServers/#configure-geo-redundant-backup-storage", [resource.address])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"mock": {
"valid_zone_redundant": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"after": {
"body": {
"properties": {
"highAvailability": {
"mode": "ZoneRedundant"
}
}
},
"type": "Microsoft.DBforPostgreSQL/flexibleServers@2024-11-01-preview"
}
}
}
]
},
"invalid_same_zone": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"after": {
"body": {
"properties": {
"highAvailability": {
"mode": "SameZone"
}
}
},
"type": "Microsoft.DBforPostgreSQL/flexibleServers@2024-11-01-preview"
}
}
}
]
},
"invalid_no_high_availability": {
"resource_changes": [
{
"address": "azapi_resource.res",
"mode": "managed",
"type": "azapi_resource",
"name": "res",
"provider_name": "registry.terraform.io/azure/azapi",
"change": {
"actions": [
"create"
],
"after": {
"body": {
"properties": {
}
},
"type": "Microsoft.DBforPostgreSQL/flexibleServers@2024-11-01-preview"
}
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Azure_Proactive_Resiliency_Library_v2

import rego.v1

valid_azapi_postgres_flexible_server_high_availability_zone_redundant(resource) if {
resource.values.body.properties.highAvailability.mode == "ZoneRedundant"
}

deny_postgresql_flexible_server_high_availability_zone_redundant contains reason if {
resource := data.utils.resource(input, "azapi_resource")[_]
data.utils.is_azure_type(resource.values, "Microsoft.DBforPostgreSQL/flexibleServers")
not valid_azapi_postgres_flexible_server_high_availability_zone_redundant(resource)

reason := sprintf("Azure-Proactive-Resiliency-Library-v2/postgresql_flexible_server_high_availability_zone_redundant: '%s' `azapi_resource` must have 'highAvailability.mode' set to 'ZoneRedundant': https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforPostgreSQL/flexibleServers/#enable-ha-with-zone-redundancy", [resource.address])
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ deny_mysql_flexible_server_geo_redundant_backup_enabled contains reason if {
resource := data.utils.resource(input, "azurerm_mysql_flexible_server")[_]
not valid_mysql_flexible_server_geo_redundant_backup_enabled(resource)

reason := sprintf("Azure-Proactive-Resiliency-Library-v2/mysql_flexible_server_geo_redundant_backup_enabled: '%s' `azurerm_mysql_flexible_server` must have 'geo_redundant_backup_enabled.mode' set to 'true': https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforMySQL/flexibleServers/#configure-geo-redundant-backup-storage", [resource.address])
reason := sprintf("Azure-Proactive-Resiliency-Library-v2/mysql_flexible_server_geo_redundant_backup_enabled: '%s' `azurerm_mysql_flexible_server` must have 'geo_redundant_backup_enabled' set to 'true': https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforMySQL/flexibleServers/#configure-geo-redundant-backup-storage", [resource.address])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"mock": {
"default": {
"resource_changes": [
{
"address": "azurerm_postgresql_flexible_server.example",
"mode": "managed",
"type": "azurerm_postgresql_flexible_server",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"geo_redundant_backup_enabled": true
}
}
}
]
},
"invalid_geo_redundant_backup_disabled": {
"resource_changes": [
{
"address": "azurerm_postgresql_flexible_server.example",
"mode": "managed",
"type": "azurerm_postgresql_flexible_server",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {
"geo_redundant_backup_enabled": false
}
}
}
]
},
"invalid_geo_redundant_backup_omitted": {
"resource_changes": [
{
"address": "azurerm_postgresql_flexible_server.example",
"mode": "managed",
"type": "azurerm_postgresql_flexible_server",
"name": "example",
"provider_name": "registry.terraform.io/hashicorp/azurerm",
"change": {
"actions": [
"create"
],
"after": {}
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package Azure_Proactive_Resiliency_Library_v2

import rego.v1

valid_postgresql_flexible_server_geo_redundant_backup_enabled(resource) if {
resource.values.geo_redundant_backup_enabled == true
}

deny_postgresql_flexible_server_geo_redundant_backup_enabled contains reason if {
resource := data.utils.resource(input, "azurerm_postgresql_flexible_server")[_]
not valid_postgresql_flexible_server_geo_redundant_backup_enabled(resource)

reason := sprintf("Azure-Proactive-Resiliency-Library-v2/postgresql_flexible_server_geo_redundant_backup_enabled: '%s' `azurerm_postgresql_flexible_server` must have 'geo_redundant_backup_enabled' set to 'true': https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforPostgreSQL/flexibleServers/#configure-geo-redundant-backup-storage", [resource.address])
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ conftest test --all-namespaces --update git::https://github.com/lonegunmanb/poli

* `Microsoft.DBforPostgreSQL/flexibleServers`

[`postgresql_flexible_server_geo_redundant_backup_enabled`](https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforMySQL/flexibleServers/#configure-geo-redundant-backup-storage)
[`postgresql_flexible_server_high_availability_mode_zone_redundant`](https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforPostgreSQL/flexibleServers/#enable-ha-with-zone-redundancy)

* `Microsoft.Storage/storageAccounts`
Expand Down

0 comments on commit 7f835a1

Please sign in to comment.