diff --git a/cluster.tf b/cluster.tf index 68a0736..542ae11 100644 --- a/cluster.tf +++ b/cluster.tf @@ -130,3 +130,28 @@ resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSServicePolicy" { policy_arn = "${local.policy_arn_prefix}/AmazonEKSServicePolicy" role = local.cluster_iam_role_name } + +/* + Adding a policy to cluster IAM role that allow permissions + required to create AWSServiceRoleForElasticLoadBalancing service-linked role by EKS during ELB provisioning +*/ + +data "aws_iam_policy_document" "cluster_elb_sl_role_creation" { + count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 + + statement { + effect = "Allow" + actions = [ + "ec2:DescribeAccountAttributes", + "ec2:DescribeInternetGateways" + ] + resources = ["*"] + } +} + +resource "aws_iam_role_policy" "cluster_elb_sl_role_creation" { + count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 + name_prefix = "${var.cluster_name}-elb-sl-role-creation" + role = local.cluster_iam_role_name + policy = data.aws_iam_policy_document.cluster_elb_sl_role_creation[0].json +}