Skip to content

Commit

Permalink
feat: support for IPv6 policy (#16)
Browse files Browse the repository at this point in the history
* feat: support for IPv6 policy

* name of the policy should be dynamic
  • Loading branch information
aldor007 authored Dec 19, 2024
1 parent 5d39d66 commit 858ed7c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
25 changes: 25 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ locals {
iam_role_policy_name = "castai-user-policy-${substr(local.resource_name_postfix, 0, 45)}"
instance_profile_role_name = "castai-eks-instance-${substr(local.resource_name_postfix, 0, 44)}"
iam_policy_prefix = "arn:${data.aws_partition.current.partition}:iam::aws:policy"
ipv6_policy_name = "CastEC2AssignIPv6Policy-${local.resource_name_postfix}"

castai_instance_profile_policy_list = flatten([
"${local.iam_policy_prefix}/AmazonEKSWorkerNodePolicy",
Expand Down Expand Up @@ -90,6 +91,30 @@ resource "aws_iam_role_policy_attachment" "castai_instance_profile_policy" {
policy_arn = each.value
}

# Create the IAM Policy for IPv6 assignment
resource "aws_iam_policy" "ec2_assign_ipv6" {
count = var.enable_ipv6 ? 1 : 0
name = local.ipv6_policy_name
description = "Policy to allow EC2 to assign IPv6 addresses"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = "ec2:AssignIpv6Addresses",
Resource = "*"
}
]
})
}

# Attach the policy to the role associated with the instance profile
resource "aws_iam_role_policy_attachment" "attach_ec2_assign_ipv6" {
count = var.enable_ipv6 ? 1 : 0
role = aws_iam_instance_profile.instance_profile.role
policy_arn = aws_iam_policy.ec2_assign_ipv6[0].arn
}

data "aws_iam_policy_document" "cast_assume_role_policy" {
statement {
sid = ""
Expand Down
6 changes: 5 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ variable "attach_worker_cni_policy" {
default = true
}


variable "enable_ipv6" {
type = bool
description = "Whether to enable IPv6 CNI policy for the cluster."
default = true
}

0 comments on commit 858ed7c

Please sign in to comment.