Skip to content

Instantly share code, notes, and snippets.

@timoguin
Created December 28, 2016 16:38
Show Gist options
  • Save timoguin/6ef7c4c0da82c30496e9ea044e79ee47 to your computer and use it in GitHub Desktop.
Save timoguin/6ef7c4c0da82c30496e9ea044e79ee47 to your computer and use it in GitHub Desktop.
IAM policy for the Packer Builder
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "NonResourceBasedReadOnlyPermissions",
"Effect": "Allow",
"Action": [
"ec2:DescribeVolumes",
"ec2:DescribeKeyPairs",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeSnapshots",
"ec2:DescribeInstances",
"ec2:DescribeImages"
],
"Resource": "*"
},
{
"Sid": "NonResourceBasedReadOnlyPermissionsForSpotInstanceUsage",
"Effect": "Allow",
"Action": [
"ec2:DescribeSpotPriceHistory",
"ec2:DescribeSpotInstanceRequests"
],
"Resource": "*"
},
{
"Sid": "NonResourceBasedWritePermissions",
"Effect": "Allow",
"Action": [
"ec2:RegisterImage",
"ec2:ModifyInstanceAttribute",
"ec2:ModifyImageAttribute",
"ec2:DeleteSnapshot",
"ec2:DeleteKeyPair",
"ec2:CreateVolume",
"ec2:CreateTags",
"ec2:CreateSnapshot",
"ec2:CreateSecurityGroup",
"ec2:CreateKeyPair",
"ec2:CreateImage",
"ec2:CopyImage"
],
"Resource": "*"
},
{
"Sid": "NonResourceBasedWritePermissionsForSpotInstanceUsage",
"Effect": "Allow",
"Action": [
"ec2:RequestSpotInstances",
"ec2:CancelSpotInstanceRequests"
],
"Resource": "*"
},
{
"Sid": "IAMPassroleToInstance",
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::111111111111:role/PackerBuilder"
},
{
"Sid": "AllowInstanceActions",
"Effect": "Allow",
"Action": [
"ec2:TerminateInstances",
"ec2:StopInstances",
"ec2:DetachVolume",
"ec2:AttachVolume"
],
"Resource": "arn:aws:ec2:us-east-1:111111111111:instance/*",
"Condition": {
"StringEquals": {
"ec2:InstanceProfile": "arn:aws:iam::111111111111:instance-profile/packer_builder"
}
}
},
{
"Sid": "EC2RunInstances",
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": "arn:aws:ec2:us-east-1:111111111111:instance/*",
"Condition": {
"StringEquals": {
"ec2:InstanceProfile": "arn:aws:iam::111111111111:instance-profile/packer_builder"
}
}
},
{
"Sid": "EC2RunInstancesSubnet",
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": "arn:aws:ec2:us-east-1:111111111111:subnet/*",
"Condition": {
"StringEquals": {
"ec2:vpc": "arn:aws:ec2:us-east-1:111111111111:vpc/vpc-11111111"
}
}
},
{
"Sid": "RemainingRunInstancePermissions",
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": [
"arn:aws:ec2:us-east-1::snapshot/*",
"arn:aws:ec2:us-east-1::image/*",
"arn:aws:ec2:us-east-1:111111111111:volume/*",
"arn:aws:ec2:us-east-1:111111111111:subnet/*",
"arn:aws:ec2:us-east-1:111111111111:security-group/*",
"arn:aws:ec2:us-east-1:111111111111:network-interface/*",
"arn:aws:ec2:us-east-1:111111111111:key-pair/*"
]
},
{
"Sid": "EC2VpcNonresourceSpecificActions",
"Effect": "Allow",
"Action": [
"ec2:DeleteSecurityGroup",
"ec2:AuthorizeSecurityGroupIngress"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"ec2:vpc": "arn:aws:ec2:us-east-1:111111111111:vpc/vpc-11111111"
}
}
}
]
}
@timoguin
Copy link
Author

This allows Packer to launch instances in a specific VPC with a specific instance profile, and only terminate those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment