diff --git a/README.md b/README.md index 22f4d71..a293d6b 100644 --- a/README.md +++ b/README.md @@ -145,13 +145,85 @@ Module usage examples: subnet_ids = module.subnets.public_subnet_ids kubernetes_version = var.kubernetes_version + kubeconfig_path = var.kubeconfig_path - # `workers_security_group_count` is needed to prevent `count can't be computed` errors workers_security_group_ids = [module.eks_workers.security_group_id] - workers_security_group_count = 1 + workers_role_arns = [module.eks_workers.workers_role_arn] + } +``` + +Module usage with two worker groups: + +```hcl + { + ... + + module "eks_workers" { + source = "git::https://github.com/cloudposse/terraform-aws-eks-workers.git?ref=master" + namespace = var.namespace + stage = var.stage + name = "small" + attributes = var.attributes + tags = var.tags + instance_type = "t3.small" + vpc_id = module.vpc.vpc_id + subnet_ids = module.subnets.public_subnet_ids + health_check_type = var.health_check_type + min_size = var.min_size + max_size = var.max_size + wait_for_capacity_timeout = var.wait_for_capacity_timeout + cluster_name = module.label.id + cluster_endpoint = module.eks_cluster.eks_cluster_endpoint + cluster_certificate_authority_data = module.eks_cluster.eks_cluster_certificate_authority_data + cluster_security_group_id = module.eks_cluster.security_group_id + + # Auto-scaling policies and CloudWatch metric alarms + autoscaling_policies_enabled = var.autoscaling_policies_enabled + cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent + cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent + } + + module "eks_workers_2" { + source = "git::https://github.com/cloudposse/terraform-aws-eks-workers.git?ref=master" + namespace = var.namespace + stage = var.stage + name = "medium" + attributes = var.attributes + tags = var.tags + instance_type = "t3.medium" + vpc_id = module.vpc.vpc_id + subnet_ids = module.subnets.public_subnet_ids + health_check_type = var.health_check_type + min_size = var.min_size + max_size = var.max_size + wait_for_capacity_timeout = var.wait_for_capacity_timeout + cluster_name = module.label.id + cluster_endpoint = module.eks_cluster.eks_cluster_endpoint + cluster_certificate_authority_data = module.eks_cluster.eks_cluster_certificate_authority_data + cluster_security_group_id = module.eks_cluster.security_group_id + + # Auto-scaling policies and CloudWatch metric alarms + autoscaling_policies_enabled = var.autoscaling_policies_enabled + cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent + cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent + } + + module "eks_cluster" { + source = "git::https://github.com/cloudposse/terraform-aws-eks-cluster.git?ref=master" + namespace = var.namespace + stage = var.stage + name = var.name + attributes = var.attributes + tags = var.tags + vpc_id = module.vpc.vpc_id + subnet_ids = module.subnets.public_subnet_ids + + kubernetes_version = var.kubernetes_version + kubeconfig_path = var.kubeconfig_path - workers_role_arns = [module.eks_workers.workers_role_arn] - kubeconfig_path = var.kubeconfig_path + workers_role_arns = [module.eks_workers.workers_role_arn, module.eks_workers_2.workers_role_arn] + workers_security_group_ids = [module.eks_workers.security_group_id, module.eks_workers_2.security_group_id] + } ``` @@ -197,7 +269,6 @@ Available targets: | tags | Additional tags (e.g. `map('BusinessUnit`,`XYZ`) | map(string) | `` | no | | vpc_id | VPC ID for the EKS cluster | string | - | yes | | workers_role_arns | List of Role ARNs of the worker nodes | list(string) | - | yes | -| workers_security_group_count | Count of the worker Security Groups. Needed to prevent Terraform error `count can't be computed` | number | - | yes | | workers_security_group_ids | Security Group IDs of the worker nodes | list(string) | - | yes | ## Outputs diff --git a/README.yaml b/README.yaml index 122b582..6eb58b6 100644 --- a/README.yaml +++ b/README.yaml @@ -164,13 +164,85 @@ usage: |- subnet_ids = module.subnets.public_subnet_ids kubernetes_version = var.kubernetes_version + kubeconfig_path = var.kubeconfig_path - # `workers_security_group_count` is needed to prevent `count can't be computed` errors workers_security_group_ids = [module.eks_workers.security_group_id] - workers_security_group_count = 1 + workers_role_arns = [module.eks_workers.workers_role_arn] + } + ``` + + Module usage with two worker groups: + + ```hcl + { + ... + + module "eks_workers" { + source = "git::https://github.com/cloudposse/terraform-aws-eks-workers.git?ref=master" + namespace = var.namespace + stage = var.stage + name = "small" + attributes = var.attributes + tags = var.tags + instance_type = "t3.small" + vpc_id = module.vpc.vpc_id + subnet_ids = module.subnets.public_subnet_ids + health_check_type = var.health_check_type + min_size = var.min_size + max_size = var.max_size + wait_for_capacity_timeout = var.wait_for_capacity_timeout + cluster_name = module.label.id + cluster_endpoint = module.eks_cluster.eks_cluster_endpoint + cluster_certificate_authority_data = module.eks_cluster.eks_cluster_certificate_authority_data + cluster_security_group_id = module.eks_cluster.security_group_id + + # Auto-scaling policies and CloudWatch metric alarms + autoscaling_policies_enabled = var.autoscaling_policies_enabled + cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent + cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent + } + + module "eks_workers_2" { + source = "git::https://github.com/cloudposse/terraform-aws-eks-workers.git?ref=master" + namespace = var.namespace + stage = var.stage + name = "medium" + attributes = var.attributes + tags = var.tags + instance_type = "t3.medium" + vpc_id = module.vpc.vpc_id + subnet_ids = module.subnets.public_subnet_ids + health_check_type = var.health_check_type + min_size = var.min_size + max_size = var.max_size + wait_for_capacity_timeout = var.wait_for_capacity_timeout + cluster_name = module.label.id + cluster_endpoint = module.eks_cluster.eks_cluster_endpoint + cluster_certificate_authority_data = module.eks_cluster.eks_cluster_certificate_authority_data + cluster_security_group_id = module.eks_cluster.security_group_id + + # Auto-scaling policies and CloudWatch metric alarms + autoscaling_policies_enabled = var.autoscaling_policies_enabled + cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent + cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent + } + + module "eks_cluster" { + source = "git::https://github.com/cloudposse/terraform-aws-eks-cluster.git?ref=master" + namespace = var.namespace + stage = var.stage + name = var.name + attributes = var.attributes + tags = var.tags + vpc_id = module.vpc.vpc_id + subnet_ids = module.subnets.public_subnet_ids + + kubernetes_version = var.kubernetes_version + kubeconfig_path = var.kubeconfig_path - workers_role_arns = [module.eks_workers.workers_role_arn] - kubeconfig_path = var.kubeconfig_path + workers_role_arns = [module.eks_workers.workers_role_arn, module.eks_workers_2.workers_role_arn] + workers_security_group_ids = [module.eks_workers.security_group_id, module.eks_workers_2.security_group_id] + } ``` diff --git a/docs/terraform.md b/docs/terraform.md index dcb1f20..c56fbb2 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -25,7 +25,6 @@ | tags | Additional tags (e.g. `map('BusinessUnit`,`XYZ`) | map(string) | `` | no | | vpc_id | VPC ID for the EKS cluster | string | - | yes | | workers_role_arns | List of Role ARNs of the worker nodes | list(string) | - | yes | -| workers_security_group_count | Count of the worker Security Groups. Needed to prevent Terraform error `count can't be computed` | number | - | yes | | workers_security_group_ids | Security Group IDs of the worker nodes | list(string) | - | yes | ## Outputs diff --git a/examples/complete/main.tf b/examples/complete/main.tf index fb4a013..a23bafd 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -81,11 +81,8 @@ module "eks_cluster" { vpc_id = module.vpc.vpc_id subnet_ids = module.subnets.public_subnet_ids kubernetes_version = var.kubernetes_version + kubeconfig_path = var.kubeconfig_path - # `workers_security_group_count` is needed to prevent `count can't be computed` errors - workers_security_group_ids = [module.eks_workers.security_group_id] - workers_security_group_count = 1 - - workers_role_arns = [module.eks_workers.workers_role_arn] - kubeconfig_path = var.kubeconfig_path + workers_role_arns = [module.eks_workers.workers_role_arn] + workers_security_group_ids = [module.eks_workers.security_group_id] } diff --git a/main.tf b/main.tf index 801d301..15a9428 100644 --- a/main.tf +++ b/main.tf @@ -62,7 +62,7 @@ resource "aws_security_group_rule" "egress" { } resource "aws_security_group_rule" "ingress_workers" { - count = var.enabled ? var.workers_security_group_count : 0 + count = var.enabled ? length(var.workers_security_group_ids) : 0 description = "Allow the cluster to receive communication from the worker nodes" from_port = 0 to_port = 65535 diff --git a/variables.tf b/variables.tf index a1ca3c2..a9043bb 100644 --- a/variables.tf +++ b/variables.tf @@ -82,11 +82,6 @@ variable "workers_security_group_ids" { description = "Security Group IDs of the worker nodes" } -variable "workers_security_group_count" { - type = number - description = "Count of the worker Security Groups. Needed to prevent Terraform error `count can't be computed`" -} - variable "kubernetes_version" { type = string default = "1.14"