Created
January 24, 2020 17:49
-
-
Save morganchristiansson/9220a94b4ba5af21107031c8cd783960 to your computer and use it in GitHub Desktop.
terraform iam_module.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource aws_iam_role_policy this { | |
name = var.name | |
role = aws_iam_role.this.name | |
policy = var.policy | |
} | |
resource aws_iam_role this { | |
name = var.name | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "", | |
"Effect": "Allow", | |
"Principal": { | |
"Service": "ec2.amazonaws.com" | |
}, | |
"Action": "sts:AssumeRole" | |
}, | |
{ | |
"Sid": "", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "${var.principal}" | |
}, | |
"Action": "sts:AssumeRole" | |
} | |
] | |
} | |
EOF | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable name {} | |
variable policy {} | |
variable principal {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module cluster_autoscaler { | |
source = "iam_module" | |
name = "k8s-cluster-autoscaler" | |
principal = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${module.eks.worker_iam_role_name}" | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"autoscaling:DescribeAutoScalingGroups", | |
"autoscaling:DescribeAutoScalingInstances", | |
"autoscaling:DescribeTags", | |
"autoscaling:DescribeLaunchConfigurations", | |
"autoscaling:SetDesiredCapacity", | |
"autoscaling:TerminateInstanceInAutoScalingGroup", | |
"ec2:DescribeLaunchTemplateVersions" | |
], | |
"Resource": "*" | |
} | |
] | |
} | |
EOF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment