-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmimportexportaccess_policy.tf
144 lines (134 loc) · 4.07 KB
/
vmimportexportaccess_policy.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# ------------------------------------------------------------------------------
# Create the IAM policies that give sufficient permissions to manage VM
# Import/Export tasks in the Images (Production) and Images (Staging) accounts
# using the AWS CLI.
# ------------------------------------------------------------------------------
# These policy documents are based on the permissions required to use the VM
# Import/Export feature as described in
# https://docs.aws.amazon.com/vm-import/latest/userguide/vmie_prereqs.html#iam-permissions-image
# The CreateBucket and DeleteBucket permissions have been omitted as management
# of the buckets is handled by the cisagov/cool-images-assessment-images project.
data "aws_iam_policy_document" "vmimportexportaccess_production" {
statement {
actions = [
"s3:ListAllMyBuckets"
]
resources = [
"*"
]
}
statement {
actions = [
"s3:DeleteObject",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
]
resources = [
data.terraform_remote_state.assessment_images.outputs.assessment_images_bucket_production.arn,
"${data.terraform_remote_state.assessment_images.outputs.assessment_images_bucket_production.arn}/*"
]
}
statement {
actions = [
"ec2:CancelConversionTask",
"ec2:CancelExportTask",
"ec2:CancelImportTask",
"ec2:CreateImage",
"ec2:CreateInstanceExportTask",
"ec2:CreateTags",
"ec2:DeleteTags",
"ec2:DescribeConversionTasks",
"ec2:DescribeExportImageTasks",
"ec2:DescribeExportTasks",
"ec2:DescribeImages",
"ec2:DescribeImportImageTasks",
"ec2:DescribeImportSnapshotTasks",
"ec2:DescribeInstanceAttribute",
"ec2:DescribeInstances",
"ec2:DescribeInstanceStatus",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:ExportImage",
"ec2:ImportImage",
"ec2:ImportInstance",
"ec2:ImportSnapshot",
"ec2:ImportVolume",
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:TerminateInstances",
]
resources = [
"*"
]
}
}
data "aws_iam_policy_document" "vmimportexportaccess_staging" {
statement {
actions = [
"s3:ListAllMyBuckets"
]
resources = [
"*"
]
}
statement {
actions = [
"s3:DeleteObject",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject",
]
resources = [
data.terraform_remote_state.assessment_images.outputs.assessment_images_bucket_staging.arn,
"${data.terraform_remote_state.assessment_images.outputs.assessment_images_bucket_staging.arn}/*"
]
}
statement {
actions = [
"ec2:CancelConversionTask",
"ec2:CancelExportTask",
"ec2:CancelImportTask",
"ec2:CreateImage",
"ec2:CreateInstanceExportTask",
"ec2:CreateTags",
"ec2:DeleteTags",
"ec2:DescribeConversionTasks",
"ec2:DescribeExportImageTasks",
"ec2:DescribeExportTasks",
"ec2:DescribeImages",
"ec2:DescribeImportImageTasks",
"ec2:DescribeImportSnapshotTasks",
"ec2:DescribeInstanceAttribute",
"ec2:DescribeInstances",
"ec2:DescribeInstanceStatus",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:ExportImage",
"ec2:ImportImage",
"ec2:ImportInstance",
"ec2:ImportSnapshot",
"ec2:ImportVolume",
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:TerminateInstances",
]
resources = [
"*"
]
}
}
resource "aws_iam_policy" "vmimportexportaccess_production" {
provider = aws.images_production
description = var.vmimportexportaccess_role_description
name = var.vmimportexportaccess_role_name
policy = data.aws_iam_policy_document.vmimportexportaccess_production.json
}
resource "aws_iam_policy" "vmimportexportaccess_staging" {
provider = aws.images_staging
description = var.vmimportexportaccess_role_description
name = var.vmimportexportaccess_role_name
policy = data.aws_iam_policy_document.vmimportexportaccess_staging.json
}