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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With