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

fix: add missing schedule to backup policy #525

Merged
merged 4 commits into from
Jul 3, 2024
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
3 changes: 3 additions & 0 deletions cdk/src/stacks/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ export class BackupStack extends NestedStack {
},
rules: {
'backup-daily': {
schedule_expression: {
'@@assign': 'cron(0 5 ? * * *)',
},
lifecycle: {
delete_after_days: { '@@assign': 30 },
},
Expand Down
50 changes: 48 additions & 2 deletions tests/backup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from retrying import retry
import warnings
import pytest
import json

sts = boto3.client('sts')
ssm = boto3.client('ssm')
Expand Down Expand Up @@ -147,7 +148,7 @@ def test_check_tag_policy():
tag_policy_id = tag_policies[0]['Id']
tag_policy=organizations.describe_policy(PolicyId=tag_policy_id)
assert tag_policy['Policy']['PolicySummary']['Description'] == 'superwerker - TagPolicy'
assert ''.join(tag_policy['Policy']['Content'].split()) == ''.join('''{
assert json.loads(tag_policy['Policy']['Content']) == json.loads('''{
"tags": {
"superwerker:backup": {
"tag_value": {
Expand All @@ -164,7 +165,7 @@ def test_check_tag_policy():
}
}
}
}'''.split()), 'Policy content does not match expected content'
}'''), 'Policy content does not match expected content'

def test_check_backup_policy():
root_id = organizations.list_roots()['Roots'][0]['Id']
Expand All @@ -173,6 +174,51 @@ def test_check_backup_policy():
backup_policy_id = backup_policies[0]['Id']
backup_policy=organizations.describe_policy(PolicyId=backup_policy_id)
assert backup_policy['Policy']['PolicySummary']['Description'] == 'superwerker - BackupPolicy'
assert json.loads(backup_policy['Policy']['Content']) == json.loads('''{
"plans": {
"superwerker-backup": {
"regions":{
"@@assign":
[
"eu-central-1"
]
},
"rules": {
"backup-daily": {
"lifecycle": {
"delete_after_days": {
"@@assign": 30
}
},
"schedule_expression": {
"@@assign": "cron(0 5 ? * * *)"
},
"target_backup_vault_name": {
"@@assign": "Default"
}
}
},
"selections": {
"tags": {
"backup-daily": {
"iam_role_arn": {
"@@assign": "arn:aws:iam::$account:role/service-role/AWSBackupDefaultServiceRole"
},
"tag_key": {
"@@assign": "superwerker:backup"
},
"tag_value": {
"@@assign":
[
"daily"
]
}
}
}
}
}
}
}'''), 'Policy content does not match expected content'

# sometimes it can take some time before the attached tap policy takes effect, therefore we retry this test
@pytest.mark.flaky(retries=3, delay=1)
Expand Down
Loading