-
Notifications
You must be signed in to change notification settings - Fork 7
/
iam.tf
62 lines (52 loc) · 2.17 KB
/
iam.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Assume Role Policy for Backups */
data "aws_iam_policy_document" "example-aws-backup-service-assume-role-policy-doc" {
statement {
sid = "AssumeServiceRole"
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = "Service"
identifiers = ["backup.amazonaws.com"]
}
}
}
/* The policies that allow the backup service to take backups and restores */
data "aws_iam_policy" "aws-backup-service-policy" {
arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup"
}
data "aws_iam_policy" "aws-restore-service-policy" {
arn = "arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForRestores"
}
data "aws_caller_identity" "current_account" {}
/* Needed to allow the backup service to restore from a snapshot to an EC2 instance
See https://stackoverflow.com/questions/61802628/aws-backup-missing-permission-iampassrole */
data "aws_iam_policy_document" "example-pass-role-policy-doc" {
statement {
sid = "ExamplePassRole"
actions = ["iam:PassRole"]
effect = "Allow"
resources = ["arn:aws:iam::${data.aws_caller_identity.current_account.account_id}:role/*"]
}
}
/* Roles for taking AWS Backups */
resource "aws_iam_role" "example-aws-backup-service-role" {
name = "ExampleAWSBackupServiceRole"
description = "Allows the AWS Backup Service to take scheduled backups"
assume_role_policy = data.aws_iam_policy_document.example-aws-backup-service-assume-role-policy-doc.json
tags = {
Project = var.project
Role = "iam"
}
}
resource "aws_iam_role_policy" "example-backup-service-aws-backup-role-policy" {
policy = data.aws_iam_policy.aws-backup-service-policy.policy
role = aws_iam_role.example-aws-backup-service-role.name
}
resource "aws_iam_role_policy" "example-restore-service-aws-backup-role-policy" {
policy = data.aws_iam_policy.aws-restore-service-policy.policy
role = aws_iam_role.example-aws-backup-service-role.name
}
resource "aws_iam_role_policy" "example-backup-service-pass-role-policy" {
policy = data.aws_iam_policy_document.example-pass-role-policy-doc.json
role = aws_iam_role.example-aws-backup-service-role.name
}