|
@@ -3,6 +3,18 @@ locals {
|
|
|
for account in var.account_list:
|
|
|
"arn:${var.aws_partition}:iam::${account}:root"
|
|
|
]
|
|
|
+
|
|
|
+ all_keys = concat([ "${module.shared_ami_key.key_arn}" ], var.vmimport_extra_keys)
|
|
|
+
|
|
|
+ buckets = [
|
|
|
+ for bucket in concat([ aws_s3_bucket.xdr-shared-amis.arn ], var.vmimport_extra_buckets):
|
|
|
+ "${bucket}"
|
|
|
+ ]
|
|
|
+ bucket_contents = [
|
|
|
+ for bucket in concat([ aws_s3_bucket.xdr-shared-amis.arn ], var.vmimport_extra_buckets):
|
|
|
+ "${bucket}/*"
|
|
|
+ ]
|
|
|
+ bucket_resources = concat(local.buckets, local.bucket_contents)
|
|
|
}
|
|
|
|
|
|
output other {
|
|
@@ -68,46 +80,30 @@ resource "aws_iam_role_policy" "vmimport" {
|
|
|
role = aws_iam_role.vmimport.id
|
|
|
policy = <<EOF
|
|
|
{
|
|
|
- "Version":"2012-10-17",
|
|
|
- "Statement":[
|
|
|
+ "Version":"2012-10-17",
|
|
|
+ "Statement": [
|
|
|
{
|
|
|
"Sid": "AllowAccesstoImportsBucket",
|
|
|
"Effect": "Allow",
|
|
|
"Action": [
|
|
|
"s3:GetBucketLocation",
|
|
|
"s3:GetObject",
|
|
|
- "s3:ListBucket"
|
|
|
+ "s3:GetBucketAcl",
|
|
|
+ "s3:ListBucket",
|
|
|
+ "s3:PutObject"
|
|
|
],
|
|
|
- "Resource": [
|
|
|
- "${aws_s3_bucket.xdr-shared-amis.arn}",
|
|
|
- "${aws_s3_bucket.xdr-shared-amis.arn}/*"
|
|
|
- ]
|
|
|
+ "Resource": ${jsonencode(local.bucket_resources)}
|
|
|
},
|
|
|
{
|
|
|
- "Sid": "AllowAccesstoExportsBucket",
|
|
|
- "Effect": "Allow",
|
|
|
- "Action": [
|
|
|
- "s3:GetBucketLocation",
|
|
|
- "s3:GetObject",
|
|
|
- "s3:ListBucket",
|
|
|
- "s3:PutObject",
|
|
|
- "s3:GetBucketAcl"
|
|
|
- ],
|
|
|
- "Resource": [
|
|
|
- "${aws_s3_bucket.xdr-shared-amis.arn}",
|
|
|
- "${aws_s3_bucket.xdr-shared-amis.arn}/*"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "Sid": "AllowAccesstodoImportExportActions",
|
|
|
- "Effect": "Allow",
|
|
|
- "Action": [
|
|
|
- "ec2:ModifySnapshotAttribute",
|
|
|
- "ec2:CopySnapshot",
|
|
|
- "ec2:RegisterImage",
|
|
|
- "ec2:Describe*"
|
|
|
- ],
|
|
|
- "Resource": "*"
|
|
|
+ "Sid": "AllowAccesstodoImportExportActions",
|
|
|
+ "Effect": "Allow",
|
|
|
+ "Action": [
|
|
|
+ "ec2:ModifySnapshotAttribute",
|
|
|
+ "ec2:CopySnapshot",
|
|
|
+ "ec2:RegisterImage",
|
|
|
+ "ec2:Describe*"
|
|
|
+ ],
|
|
|
+ "Resource": "*"
|
|
|
},
|
|
|
{
|
|
|
"Sid": "AllowAccesstotheKMSkey",
|
|
@@ -120,9 +116,9 @@ resource "aws_iam_role_policy" "vmimport" {
|
|
|
"kms:GenerateDataKey*",
|
|
|
"kms:ReEncrypt*"
|
|
|
],
|
|
|
- "Resource": "${module.shared_ami_key.key_arn}"
|
|
|
+ "Resource": ${jsonencode(local.all_keys)}
|
|
|
}
|
|
|
- ]
|
|
|
+ ]
|
|
|
}
|
|
|
EOF
|
|
|
}
|