Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform AWS EKS security group issue

I am deploying AWS EKS Cluster using a terraform script. Everything is deploying fine. But I am stuck in an issue with the security group. I have added two ports to allow ingress traffic to my application URL.

But the issue is that, after complete deployment of EKS cluster there is two security group created, one which I have created and other is created by EKS itself.

So here I have to manually add the port in EKS created security group to access my application's URL on the browser.

Here how I can add my specific ports in EKS created security group.

like image 855
Albus Avatar asked Sep 12 '25 17:09

Albus


1 Answers

Here is the appropriate answer. If you scroll down the page in the terraform docs, it gives a list of attributes (which are exportable): https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_cluster. You will notice vpc_config attributes has a member cluster_security_group_id:

vpc_config Attributes cluster_security_group_id - Cluster security group that was created by Amazon EKS for the cluster. Managed node groups use this security group for control-plane-to-data-plane communication.

To actually gain access to this property, given that vpc_config is a list, you will need to access it as so:

 aws_eks_cluster.cluster.vpc_config[0].cluster_security_group_id

If you do not specify a cluster security group, then AWS will autogenerate a cluster security group which contains the rules to allow the cluster and the cluster node group to communicate. Consequently, it is a common pattern to export this property like so:

output "cluster_security_group_id" {
    value   = aws_eks_cluster.cluster.vpc_config[0].cluster_security_group_id
}
like image 85
Daniel Viglione Avatar answered Sep 14 '25 08:09

Daniel Viglione