-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(control_plane): Move control plane related resources to their ow…
…n submodule
- Loading branch information
1 parent
f2a4434
commit f1ca63c
Showing
18 changed files
with
938 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_version = ">= 0.12.9" | ||
|
||
required_providers { | ||
aws = ">= 2.44.0" | ||
local = ">= 1.2" | ||
null = ">= 2.1" | ||
template = ">= 2.1" | ||
random = ">= 2.1" | ||
kubernetes = ">= 1.6.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,65 @@ | ||
# eks `control_plane` submodule | ||
|
||
This submodule is designed for use by both the parent `eks` module and by the user. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Providers | ||
|
||
No provider. | ||
| Name | Version | | ||
|------|---------| | ||
| aws | >= 2.44.0 | | ||
| local | >= 1.2 | | ||
| template | >= 2.1 | | ||
|
||
## Inputs | ||
|
||
No input. | ||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:-----:| | ||
| cluster\_create\_security\_group | Whether to create a security group for the cluster or attach the cluster to `cluster_security_group_id`. | `bool` | `true` | no | | ||
| cluster\_create\_timeout | Timeout value when creating the EKS cluster. | `string` | `"30m"` | no | | ||
| cluster\_delete\_timeout | Timeout value when deleting the EKS cluster. | `string` | `"15m"` | no | | ||
| cluster\_enabled\_log\_types | A list of the desired control plane logging to enable. For more information, see Amazon EKS Control Plane Logging documentation (https://docs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html) | `list(string)` | `[]` | no | | ||
| cluster\_endpoint\_private\_access | Indicates whether or not the Amazon EKS private API server endpoint is enabled. | `bool` | `false` | no | | ||
| cluster\_endpoint\_public\_access | Indicates whether or not the Amazon EKS public API server endpoint is enabled. | `bool` | `true` | no | | ||
| cluster\_endpoint\_public\_access\_cidrs | List of CIDR blocks which can access the Amazon EKS public API server endpoint. | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no | | ||
| cluster\_iam\_role\_name | IAM role name for the cluster. Only applicable if manage\_cluster\_iam\_resources is set to false. | `string` | `""` | no | | ||
| cluster\_log\_kms\_key\_id | If a KMS Key ARN is set, this key will be used to encrypt the corresponding log group. Please be sure that the KMS Key has an appropriate key policy (https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html) | `string` | `""` | no | | ||
| cluster\_log\_retention\_in\_days | Number of days to retain log events. Default retention - 90 days. | `number` | `90` | no | | ||
| cluster\_name | Name of the EKS cluster. Also used as a prefix in names of related resources. | `string` | n/a | yes | | ||
| cluster\_security\_group\_id | If provided, the EKS cluster will be attached to this security group. If not given, a security group will be created with necessary ingress/egress to work with the workers | `string` | `""` | no | | ||
| cluster\_version | Kubernetes version to use for the EKS cluster. | `string` | `"1.14"` | no | | ||
| config\_output\_path | Where to save the Kubectl config file (if `write_kubeconfig = true`). Assumed to be a directory if the value ends with a forward slash `/`. | `string` | `"./"` | no | | ||
| create\_eks | Controls if EKS resources should be created (it affects almost all resources) | `bool` | `true` | no | | ||
| eks\_oidc\_root\_ca\_thumbprint | Thumbprint of Root CA for EKS OIDC, Valid until 2037 | `string` | `"9e99a48a9960b14926bb7f3b02e22da2b0ab7280"` | no | | ||
| enable\_irsa | Whether to create OpenID Connect Provider for EKS to enable IRSA | `bool` | `false` | no | | ||
| iam\_path | If provided, all IAM roles will be created on this path. | `string` | `"/"` | no | | ||
| kubeconfig\_aws\_authenticator\_additional\_args | Any additional arguments to pass to the authenticator such as the role to assume. e.g. ["-r", "MyEksRole"]. | `list(string)` | `[]` | no | | ||
| kubeconfig\_aws\_authenticator\_command | Command to use to fetch AWS EKS credentials. | `string` | `"aws-iam-authenticator"` | no | | ||
| kubeconfig\_aws\_authenticator\_command\_args | Default arguments passed to the authenticator command. Defaults to [token -i $cluster\_name]. | `list(string)` | `[]` | no | | ||
| kubeconfig\_aws\_authenticator\_env\_variables | Environment variables that should be used when executing the authenticator. e.g. { AWS\_PROFILE = "eks"}. | `map(string)` | `{}` | no | | ||
| kubeconfig\_name | Override the default name used for items kubeconfig. | `string` | `""` | no | | ||
| manage\_cluster\_iam\_resources | Whether to let the module manage cluster IAM resources. If set to false, cluster\_iam\_role\_name must be specified. | `bool` | `true` | no | | ||
| permissions\_boundary | If provided, all IAM roles will be created with this permissions boundary attached. | `string` | n/a | yes | | ||
| subnets | A list of subnets to place the EKS cluster and workers within. | `list(string)` | n/a | yes | | ||
| tags | A map of tags to add to all resources. | `map(string)` | `{}` | no | | ||
| vpc\_id | VPC where the cluster and workers will be deployed. | `string` | n/a | yes | | ||
| write\_kubeconfig | Whether to write a Kubectl config file containing the cluster configuration. Saved to `config_output_path`. | `bool` | `true` | no | | ||
|
||
## Outputs | ||
|
||
No output. | ||
| Name | Description | | ||
|------|-------------| | ||
| cloudwatch\_log\_group\_name | Name of cloudwatch log group created | | ||
| cluster\_arn | The Amazon Resource Name (ARN) of the cluster. | | ||
| cluster\_certificate\_authority\_data | Nested attribute containing certificate-authority-data for your cluster. This is the base64 encoded certificate data required to communicate with your cluster. | | ||
| cluster\_endpoint | The endpoint for your EKS Kubernetes API. | | ||
| cluster\_iam\_role\_arn | IAM role ARN of the EKS cluster. | | ||
| cluster\_id | The name/id of the EKS cluster. | | ||
| cluster\_oidc\_issuer\_url | The URL on the EKS cluster OIDC Issuer | | ||
| cluster\_security\_group\_id | Security group ID attached to the EKS cluster. | | ||
| cluster\_version | The Kubernetes server version for the EKS cluster. | | ||
| kubeconfig | kubectl config file contents for this EKS cluster. | | ||
| kubeconfig\_filename | The filename of the generated kubectl config. | | ||
| oidc\_provider\_arn | The ARN of the OIDC Provider if `enable_irsa = true`. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
resource "aws_cloudwatch_log_group" "this" { | ||
count = length(var.cluster_enabled_log_types) > 0 && var.create_eks ? 1 : 0 | ||
name = "/aws/eks/${var.cluster_name}/cluster" | ||
retention_in_days = var.cluster_log_retention_in_days | ||
kms_key_id = var.cluster_log_kms_key_id | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_eks_cluster" "this" { | ||
count = var.create_eks ? 1 : 0 | ||
name = var.cluster_name | ||
enabled_cluster_log_types = var.cluster_enabled_log_types | ||
role_arn = local.cluster_iam_role_arn | ||
version = var.cluster_version | ||
tags = var.tags | ||
|
||
vpc_config { | ||
security_group_ids = [local.cluster_security_group_id] | ||
subnet_ids = var.subnets | ||
endpoint_private_access = var.cluster_endpoint_private_access | ||
endpoint_public_access = var.cluster_endpoint_public_access | ||
public_access_cidrs = var.cluster_endpoint_public_access_cidrs | ||
} | ||
|
||
timeouts { | ||
create = var.cluster_create_timeout | ||
delete = var.cluster_delete_timeout | ||
} | ||
|
||
depends_on = [ | ||
aws_iam_role_policy_attachment.cluster_AmazonEKSClusterPolicy, | ||
aws_iam_role_policy_attachment.cluster_AmazonEKSServicePolicy, | ||
aws_cloudwatch_log_group.this | ||
] | ||
} | ||
|
||
resource "aws_security_group" "cluster" { | ||
count = var.cluster_create_security_group && var.create_eks ? 1 : 0 | ||
name_prefix = var.cluster_name | ||
description = "EKS cluster security group." | ||
vpc_id = var.vpc_id | ||
tags = merge( | ||
var.tags, | ||
{ | ||
"Name" = "${var.cluster_name}-eks_cluster_sg" | ||
}, | ||
) | ||
} | ||
|
||
resource "aws_security_group_rule" "cluster_egress_internet" { | ||
count = var.cluster_create_security_group && var.create_eks ? 1 : 0 | ||
description = "Allow cluster egress access to the Internet." | ||
protocol = "-1" | ||
security_group_id = local.cluster_security_group_id | ||
cidr_blocks = ["0.0.0.0/0"] | ||
from_port = 0 | ||
to_port = 0 | ||
type = "egress" | ||
} | ||
|
||
resource "aws_iam_role" "cluster" { | ||
count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 | ||
name_prefix = var.cluster_name | ||
assume_role_policy = data.aws_iam_policy_document.cluster_assume_role_policy.json | ||
permissions_boundary = var.permissions_boundary | ||
path = var.iam_path | ||
force_detach_policies = true | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSClusterPolicy" { | ||
count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 | ||
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy" | ||
role = local.cluster_iam_role_name | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSServicePolicy" { | ||
count = var.manage_cluster_iam_resources && var.create_eks ? 1 : 0 | ||
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy" | ||
role = local.cluster_iam_role_name | ||
} |
Oops, something went wrong.