Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit 976485a

Browse files
matej5Matej Stajduhar
andauthored
Updating-aws-iam-tasks (#2727)
* Updating-aws-iam-tasks * Updating-aws-backup-defaults * Adding-profile-to-task * Changing-when-statements --------- Co-authored-by: Matej Stajduhar <[email protected]>
1 parent 6a4b3a5 commit 976485a

File tree

8 files changed

+41
-24
lines changed

8 files changed

+41
-24
lines changed

roles/aws/aws_admin_tools/tasks/create_schedule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
region: "{{ _aws_region }}"
77
targets:
88
- id: "{{ 'schedule_' + item.name }}"
9-
arn: "{{ (aws_lambda._result['schedule_' + item.name].configuration.function_arn.split(':') | map('trim'))[:-1] | join(':') }}" # Remove the version number from ARN
9+
arn: "arn:aws:lambda:{{ _aws_region }}:{{ _acc_id }}:function:{{ item.name }}"
1010
register: _schedule_result
1111

1212
- name: Update Lambda policy.

roles/aws/aws_admin_tools/tasks/lambda_iam.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@
1212
managed_policies: "{{ _policies }}"
1313
inline_policies: "{{ item.inline_policies | default(omit) }}"
1414
policy_document: "{{ lookup('template', 'trust_lambda.j2') }}"
15+
16+
- name: Wait for 6 seconds for IAM to be ready.
17+
ansible.builtin.wait_for:
18+
timeout: 6

roles/aws/aws_admin_tools/tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
- "s3:GetObject"
9393
policy_document: "{{ lookup('template', 'trust_apigateway.j2') }}"
9494

95+
- name: Wait for 6 seconds for IAM to be ready.
96+
ansible.builtin.wait_for:
97+
timeout: 6
98+
9599
- name: Configure Lambda IAM policies.
96100
ansible.builtin.include_tasks: lambda_iam.yml
97101
loop: "{{ _api_without_s3 }}"

roles/aws/aws_backup/tasks/resource.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
policy_document: backup
3737
when: aws_backup.backup.iam_role_arn == "Default"
3838

39+
- name: Wait for 6 seconds for IAM to be ready.
40+
ansible.builtin.wait_for:
41+
timeout: 6
42+
3943
- name: Set IAM role ARN for backups.
4044
ansible.builtin.set_fact:
4145
_iam_role_arn: "{{ _aws_iam_role_result.iam_role.arn }}"

roles/aws/aws_backup_validation/defaults/main.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
aws_backup_validation:
33
s3_bucket: "{{ _general_bucket }}"
44
s3_bucket_prefix: "backup-validation" # Prefix used for storing backup validation info
5-
name: "RestoreValidation"
65
description: "Restore validation is running every Sunday at 00:00AM, and validation reporting is triggered on Monday 00:00AM"
76
timeout: 60
87
runtime: "python3.12"
8+
main_file: "app"
99
handler: "lambda_handler"
10+
git_url: example.git-url.codeenigma.com # Can be overwritten by git_url in item
1011
resources:
1112
- name: ec2_test_instance
12-
git_url: true
13+
git: true # if true, it will build git url to download repo
1314
type: EC2
1415
lambda_policy:
1516
- "backup:PutRestoreValidationResult"
@@ -18,7 +19,7 @@ aws_backup_validation:
1819
- "ssm:SendCommand"
1920
- "ec2:DescribeInstances"
2021
- name: rds_test_instance
21-
git_url: true
22+
git: true
2223
type: RDS
2324
lambda_policy:
2425
- "backup:PutRestoreValidationResult"
@@ -27,12 +28,14 @@ aws_backup_validation:
2728
- "ec2:DescribeInstances"
2829
- "rds:DescribeDBInstances"
2930
- name: aurora_create_instance
30-
git_url: true
31+
git: true
3132
type: Aurora
3233
lambda_policy:
33-
- "lambda:InvokeFunction"
34+
- "rds:DescribeDbClusters"
35+
- "rds:CreateDbInstance"
36+
- "rds:AddTagsToResource"
3437
- name: aurora_test_instance
35-
git_url: true
38+
git: true
3639
type: Aurora
3740
event_pattern: '{ "source": ["aws.rds"], "detail-type": ["RDS DB Instance Event"], "resources": [{ "prefix": "arn:aws:rds:eu-west-1:{{ _acc_id }}:db:restoretest" }], "detail": { "EventID": ["RDS-EVENT-0005"] } }'
3841
lambda_policy:
@@ -42,7 +45,7 @@ aws_backup_validation:
4245
- "rds:DescribeDBClusters"
4346
- "rds:DeleteDBInstance"
4447
- name: validation_report
45-
git_url: true
48+
git: true
4649
type: Schedule
4750
schedule: "cron(0 0 ? * MON *)"
4851
lambda_policy:

roles/aws/aws_backup_validation/tasks/main.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
- name: Setting previous command output into variable.
1010
ansible.builtin.set_fact:
11-
_acc_id: "{{ _acc_id.stdout | from_json }}"
11+
_acc_id: "{{ _acc_id.stdout }}"
1212

1313
- name: Create a role and attach policies for events.
1414
ansible.builtin.include_role:
1515
name: aws/aws_iam_role
1616
vars:
1717
aws_iam_role:
1818
name: "{{ item.name }}_event"
19-
source: "{{ item.name}}"
19+
source: "{{ item.name }}"
2020
aws_profile: "{{ _aws_profile }}"
2121
inline_policies:
2222
name: "{{ item.name }}_event"
@@ -25,17 +25,14 @@
2525
- "lambda:InvokeFunction"
2626
policy_document: "{{ lookup('template', 'event_document_policy.json.j2') }}"
2727
loop: "{{ aws_backup_validation.resources }}"
28-
loop_control:
29-
extended: true
30-
extended_allitems: false
3128

3229
- name: Create a role and attach policies for Lambda functions.
3330
ansible.builtin.include_role:
3431
name: aws/aws_iam_role
3532
vars:
3633
aws_iam_role:
3734
name: "{{ item.name}}_lambda"
38-
source: "{{ item.name}}"
35+
source: "{{ item.name }}"
3936
aws_profile: "{{ _aws_profile }}"
4037
managed_policies:
4138
- arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
@@ -45,9 +42,10 @@
4542
action: "{{ item.lambda_policy }}"
4643
policy_document: "{{ lookup('template', 'trusted_entitites.json.j2') }}"
4744
loop: "{{ aws_backup_validation.resources }}"
48-
loop_control:
49-
extended: true
50-
extended_allitems: false
45+
46+
- name: Wait for 6 seconds for IAM to be ready.
47+
ansible.builtin.wait_for:
48+
timeout: 6
5149

5250
- name: Get info about newly created restore testing plan.
5351
ansible.builtin.command: >
@@ -70,7 +68,7 @@
7068
tags:
7169
Name: "{{ item.name }}"
7270
loop: "{{ aws_backup_validation.resources }}"
73-
when: item.git_url is not defined
71+
when: item.git is not defined
7472

7573
- name: Create Lambda functions from git url.
7674
ansible.builtin.include_role:
@@ -88,7 +86,7 @@
8886
tags:
8987
Name: "{{ item.name }}"
9088
loop: "{{ aws_backup_validation.resources }}"
91-
when: item.git_url is defined
89+
when: item.git is defined and item.git
9290

9391
- name: Create an IAM Managed Policy for passing roles and setup IAM role.
9492
ansible.builtin.include_role:
@@ -107,6 +105,10 @@
107105
- arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup
108106
- arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestores
109107

108+
- name: Wait for 6 seconds for IAM to be ready.
109+
ansible.builtin.wait_for:
110+
timeout: 6
111+
110112
# TODO: Not all clients have verified identity
111113
#- name: Get verified domain.
112114
# ansible.builtin.include_tasks: get_valid_email.yml

roles/aws/aws_cloudfront_distribution/tasks/create_lambda_function.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
- "lambda:GetFunction"
1515
policy_document: "{{ lookup('template', 'lambda_policy.json') }}"
1616

17+
- name: Wait for 6 seconds for IAM to be ready.
18+
ansible.builtin.wait_for:
19+
timeout: 6
20+
1721
- name: Create Lambda function.
1822
ansible.builtin.include_role:
1923
name: aws/aws_lambda

roles/aws/aws_iam_role/tasks/main.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- name: Create an inline IAM Managed Policy if defined.
22
amazon.aws.iam_managed_policy:
3+
profile: "{{ aws_iam_role.aws_profile }}"
34
policy_name: "inline_{{ aws_iam_role.inline_policies.name }}_policy"
45
policy:
56
Version: "2012-10-17"
@@ -47,11 +48,6 @@
4748
wait: true
4849
register: _aws_iam_role_result
4950

50-
- name: Wait for 6 seconds for IAM to be ready.
51-
ansible.builtin.wait_for:
52-
timeout: 6
53-
when: ansible_loop.last is defined and ansible_loop.last
54-
5551
- name: Register aws_iam_role results.
5652
ansible.builtin.set_fact:
5753
aws_iam_role: "{{ aws_iam_role | combine({'_result': {aws_iam_role.name: _aws_iam_role_result}}, recursive=True) }}"

0 commit comments

Comments
 (0)