File tree Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 44
44
aws_role : ${{ inputs.environment == 'production'
45
45
&& 'arn:aws:iam::820242920762:role/GithubDeployDataReplicationInfrastructure'
46
46
|| 'arn:aws:iam::393416225559:role/GithubDeployDataReplicationInfrastructure' }}
47
+ db_snapshot_role : ${{ inputs.environment == 'production'
48
+ && 'arn:aws:iam::820242920762:role/DatabaseSnapshotRole'
49
+ || 'arn:aws:iam::393416225559:role/DatabaseSnapshotRole' }}
47
50
48
51
defaults :
49
52
run :
@@ -62,10 +65,11 @@ jobs:
62
65
steps :
63
66
- name : Checkout code
64
67
uses : actions/checkout@v5
65
- - name : Configure AWS Credentials
68
+ - name : Assume DB Snapshot role
69
+ if : inputs.take_db_snapshot
66
70
uses : aws-actions/configure-aws-credentials@v4
67
71
with :
68
- role-to-assume : ${{ env.aws_role }}
72
+ role-to-assume : ${{ env.db_snapshot_role }}
69
73
aws-region : eu-west-2
70
74
- name : Take DB snapshot
71
75
if : inputs.take_db_snapshot
76
80
echo "Waiting for snapshot to be available. This can take a while."
77
81
aws rds wait db-cluster-snapshot-available --db-cluster-snapshot-identifier $snapshot_identifier
78
82
echo "New snapshot is now available"
83
+ - name : Configure AWS Credentials
84
+ uses : aws-actions/configure-aws-credentials@v4
85
+ with :
86
+ role-to-assume : ${{ env.aws_role }}
87
+ aws-region : eu-west-2
79
88
- name : Get latest snapshot
80
89
id : get-latest-snapshot
81
90
run : |
Original file line number Diff line number Diff line change @@ -46,6 +46,28 @@ resource "aws_iam_role_policy_attachment" "data_replication" {
46
46
policy_arn = each. value
47
47
}
48
48
49
+ resource "aws_iam_role" "data_replication_snapshot" {
50
+ name = " DatabaseSnapshotRole"
51
+ description = " Role to be assumed by the data replication workflow for taking on-demand DB snapshots"
52
+ assume_role_policy = templatefile (" resources/iam_role_github_trust_policy_${ var . environment } .json.tftpl" , {
53
+ account_id = var.account_id
54
+ })
55
+ }
56
+
57
+ resource "aws_iam_policy" "db_snapshot_policy" {
58
+ name = " DatabaseSnapshotPolicy"
59
+ description = " Policy to take DB snapshots"
60
+ policy = file (" resources/iam_policy_DatabaseSnapshotPolicy.json" )
61
+ lifecycle {
62
+ ignore_changes = [description ]
63
+ }
64
+ }
65
+
66
+ resource "aws_iam_role_policy_attachment" "db_snapshot" {
67
+ role = aws_iam_role. data_replication_snapshot . name
68
+ policy_arn = aws_iam_policy. db_snapshot_policy . arn
69
+ }
70
+
49
71
# ################ Deploy Monitoring ################
50
72
51
73
resource "aws_iam_role" "monitoring_deploy" {
Original file line number Diff line number Diff line change
1
+ {
2
+ "Version" : " 2012-10-17" ,
3
+ "Statement" : [
4
+ {
5
+ "Sid" : " Statement1" ,
6
+ "Effect" : " Allow" ,
7
+ "Action" : [
8
+ " rds:CreateDBClusterSnapshot" ,
9
+ " rds:DescribeDBClusterSnapshots"
10
+ ],
11
+ "Resource" : [" *" ]
12
+ }
13
+ ]
14
+ }
You can’t perform that action at this time.
0 commit comments