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

policy - fix tag:custodian-policy not deployed #33

Merged
merged 5 commits into from
Mar 18, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ To avoid any unnecessary code conflict while merging upstream changes, we must f

- support org level vars in config file
- c7n-org supports the argument not-accounts
- c7n-org - fix NoCredentialsError when getting creds from instance profile too frequently

### c7n_gcp

Expand Down
4 changes: 2 additions & 2 deletions c7n/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ def provision(self):
lambda assume=False: self.policy.session_factory(assume))

# NOTE introduce tag:custodian-policy as version to avoid massive re-deployments
existing = manager.get(self.policy_lambda(self.policy).name)
if tags.get("custodian-policy") and tags.get("custodian-policy") == existing.get("Tags", {}).get("custodian-policy"):
deployed = manager.get(self.policy_lambda(self.policy).name)
if tags.get("custodian-policy") and deployed and tags.get("custodian-policy") == deployed.get("Tags", {}).get("custodian-policy"):
self.policy.log.info("Skipped due to no changes to tag:custodian-policy")
return

Expand Down
1 change: 1 addition & 0 deletions c7n/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class QueryResourceManager(ResourceManager, metaclass=QueryMeta):

retry = staticmethod(
get_retry((
'TooManyRequestsException',
'ThrottlingException',
'RequestLimitExceeded',
'Throttled',
Expand Down
1 change: 1 addition & 0 deletions tools/c7n_azure/c7n_azure/provisioning/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _provision(self, params):
# consumption app plan
if params['is_consumption_plan']:
functionapp_def.kind = 'functionapp,linux'
site_config.linux_fx_version = FUNCTION_DOCKER_VERSION
# dedicated app plan
else:
functionapp_def.kind = 'functionapp,linux,container'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ policies:
type: azure-event-grid
events: ['ResourceGroupWrite']
provision-options:
identity:
type: UserAssigned
id: ${identity_name}
servicePlan:
resourceGroupName: ${rg_name}-consumption
filters:
Expand All @@ -21,6 +24,9 @@ policies:
type: azure-event-grid
events: ['ResourceGroupWrite']
provision-options:
identity:
type: UserAssigned
id: ${identity_name}
servicePlan:
resourceGroupName: ${rg_name}-dedicated
skuName: S2
Expand All @@ -39,6 +45,9 @@ policies:
type: azure-periodic
schedule: '0 */5 * * * *'
provision-options:
identity:
type: UserAssigned
id: ${identity_name}
servicePlan:
resourceGroupName: ${rg_name}-consumption
filters:
Expand All @@ -55,6 +64,9 @@ policies:
type: azure-periodic
schedule: '0 */5 * * * *'
provision-options:
identity:
type: UserAssigned
id: ${identity_name}
servicePlan:
resourceGroupName: ${rg_name}-dedicated
skuName: S2
Expand Down
9 changes: 9 additions & 0 deletions tools/c7n_azure/tests_azure/azure-functions/test_functions.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
set -e

rg_name=cloud-custodian-test-functions-$RANDOM
rg_identity_name="${rg_name}-identity"
identity_name="c7n-identity"

function cleanup {
set +e
Expand All @@ -11,13 +13,20 @@ function cleanup {
$(az group delete -n ${rg_name} -y)
$(az group delete -n ${rg_name}-dedicated -y)
$(az group delete -n ${rg_name}-consumption -y)
$(az group delete -n ${rg_identity_name}-consumption -y)
}
trap cleanup EXIT

echo "Logging to Azure"
az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID -o none
az account set -s $AZURE_SUBSCRIPTION_ID -o none

echo "Creating user managed identity"
az group create -l westus -n ${rg_identity_name} -o none
identity_principal=$(az identity create -g ${rg_identity_name} --name ${identity_name} --query clientId -o tsv)
sleep 60
az role assignment create --assignee-object-id ${identity_principal} --assignee-principal-type "ServicePrincipal" --role "Owner" --scope "/subscriptions/${AZURE_SUBSCRIPTION_ID}" -o None

eval "echo \"$(cat templates/policies.yaml)\"" > policies.yaml

echo "Running Cloud Custodian"
Expand Down