-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
63 lines (60 loc) · 1.55 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
63
# IAM Role Required for VM Import
# https://docs.aws.amazon.com/vm-import/latest/userguide/required-permissions.html
# https://github.com/StratusGrid/terraform-aws-iam-role-vmimport/blob/main/iam-role-vmimport.tf
resource "aws_iam_role" "vmimport" {
name = "vmimport"
assume_role_policy = data.aws_iam_policy_document.vmimport-trust-policy.json
}
data "aws_iam_policy_document" "vmimport-trust-policy" {
version = "2012-10-17"
statement {
sid = ""
effect = "Allow"
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = [
"vmie.amazonaws.com"
]
}
}
}
resource "aws_iam_policy" "vmimport-policy" {
name = "vmimport-policy-nixos-vm"
policy = jsonencode({
"Version" = "2012-10-17",
"Statement" = [
{
"Effect" = "Allow",
"Action" = [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
"s3:GetBucketAcl"
],
"Resource" = [
"${aws_s3_bucket.this.arn}",
"${aws_s3_bucket.this.arn}/*"
]
},
{
"Effect" = "Allow",
"Action" = [
"ec2:ModifySnapshotAttribute",
"ec2:CopySnapshot",
"ec2:RegisterImage",
"ec2:Describe*"
],
"Resource" = "*"
}
]
})
}
# Attach the policy to the role
resource "aws_iam_role_policy_attachment" "vmimport_policy_attachment" {
role = aws_iam_role.vmimport.name
policy_arn = aws_iam_policy.vmimport-policy.arn
}