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

Adding Azure MariaDB Resource #8498

Merged
merged 5 commits into from Apr 19, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions tools/c7n_azure/c7n_azure/resources/mariadb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0

from c7n_azure.provider import resources
from c7n_azure.resources.arm import ArmResourceManager


@resources.register('mariadb')
class MariaDB(ArmResourceManager):
"""Azure MariaDB Server Resource

:example:

Returns all MariaDB servers

.. code-block:: yaml

policies:
- name: basic-logic-app-for-mariadb
resource: azure.mariadb
filters:
- type: value
key: sku.name
op: equal
value: Basic

"""

class resource_type(ArmResourceManager.resource_type):
doc_groups = ['Databases']

service = 'azure.mgmt.rdbms.mariadb'
client = 'MariaDBManagementClient'
enum_spec = ('servers', 'list', None)
default_report_fields = (
'name',
'location',
'resourceGroup'
)
resource_type = 'Microsoft.DBforMariaDB/servers'
1 change: 1 addition & 0 deletions tools/c7n_azure/c7n_azure/resources/resource_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"azure.keyvault-keys": "c7n_azure.resources.key_vault_keys.KeyVaultKeys",
"azure.loadbalancer": "c7n_azure.resources.load_balancer.LoadBalancer",
"azure.logic-app-workflow": "c7n_azure.resources.logic_app.LogicAppWorkflow",
"azure.mariadb": "c7n_azure.resources.mariadb.MariaDB",
"azure.mysql": "c7n_azure.resources.mysql.MySQL",
"azure.mysql-flexibleserver": "c7n_azure.resources.mysql_flexibleserver.MySQLFlexibleServer",
"azure.networkinterface": "c7n_azure.resources.network_interface.NetworkInterface",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "GET",
"uri": "https://management.azure.com/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/providers/Microsoft.DBForMariaDB/servers?api-version=2018-06-01",
"body": null,
"headers": {}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"cache-control": [
"no-cache"
],
"date": [
"Tue, 18 Apr 2023 15:37:02 GMT"
],
"content-type": [
"application/json; charset=utf-8"
],
"content-length": [
"971"
]
},
"body": {
"data": {
"value": [
{
"sku": {
"name": "GP_Gen5_2",
"tier": "GeneralPurpose",
"family": "Gen5",
"capacity": 2
},
"properties": {
"administratorLogin": "custodian",
"storageProfile": {
"storageMB": 51200,
"backupRetentionDays": 7,
"geoRedundantBackup": "Disabled",
"storageAutogrow": "Disabled"
},
"version": "10.3",
"sslEnforcement": "Enabled",
"minimalTlsVersion": "TLS1_2",
"userVisibleState": "Ready",
"fullyQualifiedDomainName": "cctestmariadbserver76cp5dtr7sta4.mariadb.database.azure.com",
"earliestRestoreDate": "2023-04-18T15:33:05.367+00:00",
"replicationRole": "",
"masterServerId": "",
"byokEnforcement": "Disabled",
"infrastructureEncryption": "Disabled",
"privateEndpointConnections": [],
"publicNetworkAccess": "Enabled"
},
"location": "eastus",
"tags": {
"product_id": "13742"
},
"id": "/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/test_mariadb/providers/Microsoft.DBforMariaDB/servers/cctestmariadbserver76cp5dtr7sta4",
"name": "cctestmariadbserver76cp5dtr7sta4",
"type": "Microsoft.DBforMariaDB/servers"
}
]
}
}
}
}
]
}
68 changes: 68 additions & 0 deletions tools/c7n_azure/tests_azure/templates/mariadb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"servers_cctestmariadbserver_name": {
"defaultValue": "[concat('cctestmariadbserver', uniqueString(resourceGroup().id))]",
"type": "string"
}

},
"variables": {},
"resources": [
{
"type": "Microsoft.DBforMariaDB/servers",
"apiVersion": "2018-06-01",
"name": "[parameters('servers_cctestmariadbserver_name')]",
"location": "EastUs",
"sku": {
"name": "GP_Gen5_2",
"tier": "GeneralPurpose",
"capacity": "2",
"size": "51200",
"family": "Gen5"
},
"properties": {
"createMode": "Default",
"version": "10.3",
"administratorLogin": "custodian",
"administratorLoginPassword": "Cust0dianPassw0rd",
"storageProfile": {
"storageMB": "51200",
"backupRetentionDays": 7,
"geoRedundantBackup": "Disabled"
},
"sslEnforcement": "Enabled",
"minimalTlsVersion": "TLS1_2"
},
"resources": [
{
"type": "firewallrules",
"apiVersion": "2018-06-01",
"dependsOn": [
"[resourceId('Microsoft.DBforMariaDB/servers', parameters('servers_cctestmariadbserver_name'))]"
],
"location": "EastUs",
"name": "AllowAzureIPs",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
},
{
"name": "[parameters('servers_cctestmariadbserver_name')]",
"type": "databases",
"apiVersion": "2018-06-01",
"properties": {
"charset": "utf8mb4",
"collation": "utf8mb4_unicode_520_ci"
},
"dependsOn": [
"[resourceId('Microsoft.DBforMariaDB/servers/',parameters('servers_cctestmariadbserver_name'))]"
]
}
]
}
],
"outputs": {}
}
26 changes: 26 additions & 0 deletions tools/c7n_azure/tests_azure/tests_resources/test_mariadb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
from ..azure_common import BaseTest


class MariaDBTest(BaseTest):
def test_azure_mariadb_schema_validate(self):
p = self.load_policy({
'name': 'test-azure-mariadb-schema-validate',
'resource': 'azure.mariadb'
}, validate=True)
self.assertTrue(p)

def test_find_by_name(self):
p = self.load_policy({
'name': 'test-azure-mariadb',
'resource': 'azure.mariadb',
'filters': [
{'type': 'value',
'key': 'name',
'op': 'glob',
'value_type': 'normalize',
'value': 'cctestmariadbserver76cp5dtr7sta4'}],
})
resources = p.run()
self.assertEqual(len(resources), 1)