Skip to content

Commit

Permalink
azure - app service environment resource (cloud-custodian#9820)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-afanasiev authored Nov 12, 2024
1 parent 4a6f80f commit 5485b53
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tools/c7n_azure/c7n_azure/resources/app_service_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from c7n_azure.provider import resources
from c7n_azure.resources.arm import ArmResourceManager


@resources.register("app-service-environment")
class AppServiceEnvironment(ArmResourceManager):
"""App Service Environment
:example:
This policy will find all App Service Environment that are still not ready
.. code-block:: yaml
policies:
- name: app-service-environment-not-ready
resource: azure.app-service-environment
filters:
- type: value
key: properties.provisioningState
value: InProgress
"""

class resource_type(ArmResourceManager.resource_type):
doc_groups = ["Compute", "Web"]
service = "azure.mgmt.web"
client = "WebSiteManagementClient"
enum_spec = ("app_service_environments", "list", None)
default_report_fields = (
"name",
"location",
"resourceGroup",
"kind",
"properties.dnsSuffix"
)
resource_type = "Microsoft.Web/hostingEnvironments"
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 @@ -4,6 +4,7 @@
"azure.advisor-recommendation": "c7n_azure.resources.advisor.AdvisorRecommendation",
"azure.aks": "c7n_azure.resources.k8s_service.KubernetesService",
"azure.app-insights": "c7n_azure.resources.appinsights.AzureAppInsights",
"azure.app-service-environment": "c7n_azure.resources.app_service_environment.AppServiceEnvironment", # noqa
"azure.automation-account": "c7n_azure.resources.automation_account.AutomationAccount",
"azure.open-shift": "c7n_azure.resources.open_shift.OpenShiftService",
"azure.api-management": "c7n_azure.resources.apimanagement.ApiManagement",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "GET",
"uri": "https://management.azure.com/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/providers/Microsoft.Web/hostingEnvironments?api-version=2018-11-01",
"body": null,
"headers": {}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"cache-control": [
"no-cache"
],
"etag": [
"\"1D56A6327B0767F\""
],
"content-type": [
"application/json"
],
"date": [
"Fri, 13 Sep 2019 18:43:59 GMT"
],
"content-length": [
"3205"
]
},
"body": {
"data": {
"value": [
{
"id": "/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/test_ase/providers/Microsoft.Web/hostingEnvironments/example-ase",
"name": "example-ase",
"kind": "ASEV3",
"location": "East US",
"type": "Microsoft.Web/hostingEnvironments",
"tags": {
"ComplianceStatus": "Green",
"CustodianRule": "ecc-azure-433-dep_app_latest_env"
},
"properties": {
"provisioningState": "InProgress",
"status": "Preparing",
"virtualNetwork": {
"id": "/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/test_ase/providers/Microsoft.Network/virtualNetworks/this-green-vnet/subnets/this-green-subnet",
"name": "this-green-subnet",
"type": "Microsoft.Network/virtualNetworks/subnets",
"subnet": ""
},
"internalLoadBalancingMode": "Web, Publishing",
"multiSize": "Standard_D2d_v4",
"ipsslAddressCount": 0,
"dnsSuffix": "example-ase.appserviceenvironment.net",
"maximumNumberOfMachines": 250,
"suspended": false,
"clusterSettings": [
{
"name": "DisableTls1.0",
"value": "1"
},
{
"name": "InternalEncryption",
"value": "true"
},
{
"name": "FrontEndSSLCipherSuiteOrder",
"value": "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
}
],
"hasLinuxWorkers": true,
"dedicatedHostCount": 0
},
"resourceGroup": "test_ase"
}
],
"nextLink": null,
"id": null
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
from ..azure_common import BaseTest


class AppServiceEnvironmentTest(BaseTest):

def test_validate_ase_schema(self):
with self.sign_out_patch():
p = self.load_policy({
"name": "test-azure-ase",
"resource": "azure.app-service-environment"
}, validate=True)

self.assertTrue(p)

def test_find_ase_in_pending_state(self):
p = self.load_policy({
"name": "test-azure-ase",
"resource": "azure.app-service-environment",
"filters": [
{"type": "value",
"key": "properties.provisioningState",
"value": "InProgress"}
],
})
resources = p.run()
self.assertEqual(len(resources), 1)
self.assertEqual(resources[0]["name"], "example-ase")

0 comments on commit 5485b53

Please sign in to comment.