Skip to content

Instantly share code, notes, and snippets.

@mailman-2097
Last active August 18, 2020 07:03
Show Gist options
  • Select an option

  • Save mailman-2097/95dfb93cb9e2757633b41d3ad07bcc84 to your computer and use it in GitHub Desktop.

Select an option

Save mailman-2097/95dfb93cb9e2757633b41d3ad07bcc84 to your computer and use it in GitHub Desktop.
Sample IAM Policy Document
# -----------------------
# Inline Policy
# -----------------------
resource "aws_iam_role" "iam_ser" {
name_prefix = "svc-${var.workload_name}-bake"
permissions_boundary = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/WorkloadPermissionsBoundary"
assume_role_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Action" : "sts:AssumeRole",
"Principal" : {
"Service" : "ec2.amazonaws.com"
},
"Effect" : "Allow",
"Sid" : ""
}
]
})
}
resource "aws_iam_instance_profile" "core_services_bake" {
name_prefix = "svc-${var.workload_name}-bake"
role = aws_iam_role.core_services_bake.name
}
resource "aws_iam_role_policy" "core_services_bake" {
name = "allow_packer_permissions"
role = aws_iam_role.core_services_bake.id
policy = data.aws_iam_policy_document.sample_policy_document.json
}
data "aws_iam_policy_document" "sample_policy_document" {
statement {
sid = "sid1"
effect = "Allow"
actions = [
"ssm:ListInstance*",
"ssm:UpdateInstance*",
]
resources = [
"*"
]
}
statement {
sid = "sid2"
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
]
resources = [
"*"
]
}
statement {
sid = "sid3"
effect = "Allow"
actions = [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
]
resources = [
"*"
]
}
statement {
sid = "sid4"
effect = "Allow"
actions = [
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply",
"ec2:Describe*",
]
resources = [
"*"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment