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

add-azure-resources-to-support-spring-apps #8558

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
2 changes: 2 additions & 0 deletions tools/c7n_azure/c7n_azure/resources/resource_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
"azure.servicebus-namespace": "c7n_azure.resources.servicebus_namespace.ServiceBusNamespace",
"azure.service-fabric-cluster": "c7n_azure.resources.service_fabric.ServiceFabricCluster",
"azure.service-fabric-cluster-managed": "c7n_azure.resources.service_fabric.ServiceFabricClusterManaged", # noqa
"azure.spring-app": "c7n_azure.resources.spring.SpringApp",
"azure.spring-service-instance": "c7n_azure.resources.spring.SpringServiceInstance",
"azure.sql-database": "c7n_azure.resources.sqldatabase.SqlDatabase",
"azure.sqldatabase": "c7n_azure.resources.sqldatabase.SqlDatabase",
"azure.sql-server": "c7n_azure.resources.sqlserver.SqlServer",
Expand Down
74 changes: 74 additions & 0 deletions tools/c7n_azure/c7n_azure/resources/spring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0

from c7n_azure.provider import resources
from c7n_azure.query import ChildResourceManager, ChildTypeInfo
from c7n_azure.utils import ResourceIdParser
from c7n_azure.resources.arm import ArmResourceManager


@resources.register('spring-app')
class SpringApp(ChildResourceManager):
"""Azure Spring Apps Resource

:example:

Returns Spring Apps resources

.. code-block:: yaml

policies:
- name: basic-spring-apps
resource: azure.spring-app

"""

class resource_type(ChildTypeInfo):
doc_groups = ['Compute']

service = 'azure.mgmt.appplatform'
client = 'AppPlatformManagementClient'
enum_spec = ('apps', 'list', None)
parent_manager_name = 'spring-service-instance'

default_report_fields = (
'name',
'location',
'resourceGroup'
)

@classmethod
def extra_args(cls, parent_resource):
return {'resource_group_name':
ResourceIdParser.get_resource_group(parent_resource['id']),
'service_name': parent_resource['name']}


@resources.register('spring-service-instance')
class SpringServiceInstance(ArmResourceManager):
"""Azure Spring Service Instance Resource

:example:

Returns Spring Service Instance resources

.. code-block:: yaml

policies:
- name: basic-spring-service-instance
resource: azure.spring-service-instance

"""

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

service = 'azure.mgmt.appplatform'
client = 'AppPlatformManagementClient'
enum_spec = ('services', 'list_by_subscription', None)
default_report_fields = (
'name',
'location',
'resourceGroup'
)
resource_type = 'Microsoft.AppPlatform/Spring'
20 changes: 19 additions & 1 deletion tools/c7n_azure/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/c7n_azure/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ azure-mgmt-trafficmanager = "^0.51.0"
azure-mgmt-frontdoor = "^1.0.0"
azure-mgmt-security = "^1.0.0"
azure-mgmt-servicebus = "^8.2.0"
azure-mgmt-appplatform = "^8.0.0"

[tool.poetry.dev-dependencies]
# setup custodian as a dev dependency
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "GET",
"uri": "https://management.azure.com/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/providers/Microsoft.AppPlatform/Spring?api-version=2022-12-01",
"body": null,
"headers": {}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"cache-control": [
"no-cache"
],
"content-type": [
"application/json; charset=utf-8"
],
"date": [
"Wed, 10 May 2023 22:52:48 GMT"
],
"x-ms-ratelimit-remaining-subscription-resource-requests": [
"11999"
],
"content-length": [
"921"
]
},
"body": {
"data": {
"value": [
{
"properties": {
"provisioningState": "Succeeded",
"zoneRedundant": false,
"version": 3,
"serviceId": "3678cebb6e5b4b43a2c79d9a257f9009",
"networkProfile": {
"outboundIPs": {
"publicIPs": [
"20.221.83.90"
]
},
"outboundType": "loadBalancer"
},
"powerState": "Running",
"fqdn": "test-spring-service2.azuremicroservices.io"
},
"type": "Microsoft.AppPlatform/Spring",
"sku": {
"name": "B0",
"tier": "Basic"
},
"location": "centralus",
"tags": {
"product_id": "13742",
"created_by": "abc@def.com"
},
"id": "/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/temp-test-spring-apps/providers/Microsoft.AppPlatform/Spring/test-spring-service2",
"name": "test-spring-service2",
"systemData": {
"createdBy": "abc@def.com",
"createdByType": "User",
"createdAt": "2023-05-10T21:14:40.0760641Z",
"lastModifiedBy": "5248d4c8-2530-4bc3-98d3-a01744561df5",
"lastModifiedByType": "Application",
"lastModifiedAt": "2023-05-10T22:15:18.0213302Z"
}
}
]
}
}
}
},
{
"request": {
"method": "GET",
"uri": "https://management.azure.com/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/temp-test-spring-apps/providers/Microsoft.AppPlatform/Spring/test-spring-service2/apps?api-version=2022-12-01",
"body": null,
"headers": {}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"cache-control": [
"no-cache"
],
"x-rp-server-mvid": [
"3f0be3de-b54c-4127-959a-365fde51af69"
],
"content-type": [
"application/json"
],
"request-context": [
"appId=cid-v1:797d7e4e-8180-497e-a254-780fbd39ba4d"
],
"date": [
"Wed, 10 May 2023 22:52:48 GMT"
],
"x-ms-ratelimit-remaining-subscription-resource-requests": [
"11999"
],
"content-length": [
"1152"
]
},
"body": {
"data": {
"value": [
{
"properties": {
"addonConfigs": {
"applicationConfigurationService": {},
"serviceRegistry": {}
},
"public": false,
"provisioningState": "Succeeded",
"fqdn": "test-spring-service2.azuremicroservices.io",
"httpsOnly": false,
"temporaryDisk": {
"sizeInGB": 5,
"mountPath": "/tmp"
},
"persistentDisk": {
"sizeInGB": 0,
"mountPath": "/persistent"
},
"enableEndToEndTLS": false,
"ingressSettings": {
"readTimeoutInSeconds": 300,
"sendTimeoutInSeconds": 60,
"sessionCookieMaxAge": 0,
"sessionAffinity": "None",
"backendProtocol": "Default"
}
},
"type": "Microsoft.AppPlatform/Spring/apps",
"identity": {
"type": "SystemAssigned",
"principalId": "55e8d01b-e5f8-4d81-9f6d-483cc8700abd",
"tenantId": "00000000-0000-0000-0000-000000000003"
},
"location": "centralus",
"id": "/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/temp-test-spring-apps/providers/Microsoft.AppPlatform/Spring/test-spring-service2/apps/test-spring-app",
"name": "test-spring-app",
"systemData": {
"createdBy": "abc@def.com",
"createdByType": "User",
"createdAt": "2023-05-10T21:20:39.5498364Z",
"lastModifiedBy": "abc@def.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2023-05-10T21:21:34.9400574Z"
}
}
]
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "GET",
"uri": "https://management.azure.com/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/providers/Microsoft.AppPlatform/Spring?api-version=2022-12-01",
"body": null,
"headers": {}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"content-type": [
"application/json; charset=utf-8"
],
"date": [
"Wed, 10 May 2023 22:49:12 GMT"
],
"x-ms-ratelimit-remaining-subscription-resource-requests": [
"11999"
],
"cache-control": [
"no-cache"
],
"content-length": [
"921"
]
},
"body": {
"data": {
"value": [
{
"properties": {
"provisioningState": "Succeeded",
"zoneRedundant": false,
"version": 3,
"serviceId": "3678cebb6e5b4b43a2c79d9a257f9009",
"networkProfile": {
"outboundIPs": {
"publicIPs": [
"20.221.83.90"
]
},
"outboundType": "loadBalancer"
},
"powerState": "Running",
"fqdn": "test-spring-service2.azuremicroservices.io"
},
"type": "Microsoft.AppPlatform/Spring",
"sku": {
"name": "B0",
"tier": "Basic"
},
"location": "centralus",
"tags": {
"product_id": "13742",
"created_by": "abc@def.com"
},
"id": "/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/temp-test-spring-apps/providers/Microsoft.AppPlatform/Spring/test-spring-service2",
"name": "test-spring-service2",
"systemData": {
"createdBy": "abc@def.com",
"createdByType": "User",
"createdAt": "2023-05-10T21:14:40.0760641Z",
"lastModifiedBy": "5248d4c8-2530-4bc3-98d3-a01744561df5",
"lastModifiedByType": "Application",
"lastModifiedAt": "2023-05-10T22:15:18.0213302Z"
}
}
]
}
}
}
}
]
}
24 changes: 24 additions & 0 deletions tools/c7n_azure/tests_azure/tests_resources/test_spring_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
from ..azure_common import BaseTest


class SpringAppsTest(BaseTest):
def test_azure_springapps_schema_validate(self):
p = self.load_policy({
'name': 'test-azure-springapps-schema-validate',
'resource': 'azure.spring-app'
}, validate=True)
self.assertTrue(p)

def test_find_by_name(self):
p = self.load_policy({
'name': 'test-azure-azure-springapps',
'resource': 'azure.spring-app',
'filters': [
{'type': 'value',
'key': 'name',
'value': 'test-spring-app'}]
})
resources = p.run()
self.assertEqual(len(resources), 1)