-
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 rule for postgresql_flexible_server_high_availability_mode_zone_r…
…edundant
- Loading branch information
1 parent
758c8e3
commit 60bfc61
Showing
4 changed files
with
107 additions
and
2 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
87 changes: 87 additions & 0 deletions
87
...y-v2/azurerm/postgres/azurerm_postgresql_flexible_server_high_availability_mode.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,87 @@ | ||
{ | ||
"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": { | ||
"high_availability": [ | ||
{ | ||
"mode": "ZoneRedundant" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"invalid_same_zone": { | ||
"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": { | ||
"high_availability": [ | ||
{ | ||
"mode": "SameZone" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"invalid_empty_availability": { | ||
"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": { | ||
"high_availability": [ | ||
] | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"invalid_no_high_availability": { | ||
"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": {} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ibrary-v2/azurerm/postgres/azurerm_postgresql_flexible_server_high_availability_mode.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,16 @@ | ||
package Azure_Proactive_Resiliency_Library_v2.azurerm_postgresql_flexible_server | ||
|
||
valid_high_availability_mode(resource) { | ||
resource.change.after.high_availability[_].mode == "ZoneRedundant" | ||
} | ||
|
||
deny_postgresql_flexible_server_high_availability_mode_zone_redundant[reason] { | ||
tfplan := data.utils.tfplan(input) | ||
resource := tfplan.resource_changes[_] | ||
resource.mode == "managed" | ||
resource.type == "azurerm_postgresql_flexible_server" | ||
data.utils.is_create_or_update(resource.change.actions) | ||
not valid_high_availability_mode(resource) | ||
|
||
reason := sprintf("Azure-Proactive-Resiliency-Library-v2: '%s' `azurerm_postgresql_flexible_server` must have 'high_availability.mode' set to 'ZoneRedundant': https://azure.github.io/Azure-Proactive-Resiliency-Library-v2/azure-resources/DBforPostgreSQL/flexibleServers/#enable-ha-with-zone-redundancy", [resource.address]) | ||
} |
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