2018-12-17 17:40:09 +00:00
|
|
|
resource "aws_iam_instance_profile" "instance_profile" {
|
2019-10-14 15:27:08 +00:00
|
|
|
name_prefix = local.random_name
|
|
|
|
role = aws_iam_role.instance_role.name
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_iam_role" "instance_role" {
|
2019-10-14 15:27:08 +00:00
|
|
|
name_prefix = local.random_name
|
|
|
|
assume_role_policy = data.aws_iam_policy_document.instance_role.json
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data "aws_iam_policy_document" "instance_role" {
|
|
|
|
statement {
|
|
|
|
effect = "Allow"
|
|
|
|
actions = ["sts:AssumeRole"]
|
|
|
|
|
|
|
|
principals {
|
|
|
|
type = "Service"
|
|
|
|
identifiers = ["ec2.amazonaws.com"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_iam_role_policy" "auto_discover_cluster" {
|
|
|
|
name = "auto-discover-cluster"
|
2019-10-14 15:27:08 +00:00
|
|
|
role = aws_iam_role.instance_role.id
|
|
|
|
policy = data.aws_iam_policy_document.auto_discover_cluster.json
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Note: Overloading this instance profile to access
|
|
|
|
# test binaries, should be renamed.
|
|
|
|
data "aws_iam_policy_document" "auto_discover_cluster" {
|
|
|
|
statement {
|
|
|
|
effect = "Allow"
|
|
|
|
|
|
|
|
actions = [
|
|
|
|
"ec2:DescribeInstances",
|
|
|
|
"ec2:DescribeTags",
|
|
|
|
"autoscaling:DescribeAutoScalingGroups",
|
|
|
|
]
|
|
|
|
resources = ["*"]
|
|
|
|
}
|
|
|
|
|
|
|
|
statement {
|
|
|
|
effect = "Allow"
|
|
|
|
|
|
|
|
actions = [
|
|
|
|
"ec2:DescribeInstances",
|
|
|
|
"ec2:DescribeTags",
|
2020-03-04 15:44:51 +00:00
|
|
|
"ec2:DescribeVolume*",
|
|
|
|
"ec2:AttachVolume",
|
2020-03-16 12:53:04 +00:00
|
|
|
"ec2:DetachVolume",
|
2018-12-17 17:40:09 +00:00
|
|
|
"autoscaling:DescribeAutoScalingGroups",
|
|
|
|
]
|
|
|
|
resources = ["*"]
|
|
|
|
}
|
|
|
|
|
|
|
|
statement {
|
|
|
|
effect = "Allow"
|
|
|
|
|
|
|
|
actions = [
|
2019-10-14 15:27:08 +00:00
|
|
|
"s3:PutObject",
|
|
|
|
"s3:GetObject",
|
|
|
|
"s3:DeleteObject",
|
2018-12-17 17:40:09 +00:00
|
|
|
]
|
|
|
|
resources = ["arn:aws:s3:::nomad-team-test-binary/*"]
|
|
|
|
}
|
|
|
|
}
|