Skip to content

Commit 73dd9a3

Browse files
authored
Support oidc-idp for eks-cluster module (#13)
1 parent fb7e122 commit 73dd9a3

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

modules/eks-cluster/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This module creates following resources.
4646
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
4747
| [aws_eks_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_cluster) | resource |
4848
| [aws_eks_fargate_profile.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_fargate_profile) | resource |
49+
| [aws_eks_identity_provider_config.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_identity_provider_config) | resource |
4950
| [aws_iam_openid_connect_provider.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_openid_connect_provider) | resource |
5051
| [aws_resourcegroups_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/resourcegroups_group) | resource |
5152
| [aws_security_group_rule.node](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
@@ -75,6 +76,7 @@ This module creates following resources.
7576
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | (Optional) Number of days to retain log events. Default retention - 90 days. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0. If you select 0, the events in the log group are always retained and never expire. | `number` | `90` | no |
7677
| <a name="input_log_types"></a> [log\_types](#input\_log\_types) | (Optional) A list of the desired control plane logging to enable. | `list(string)` | <pre>[<br> "api",<br> "audit",<br> "authenticator",<br> "controllerManager",<br> "scheduler"<br>]</pre> | no |
7778
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
79+
| <a name="input_oidc_identity_providers"></a> [oidc\_identity\_providers](#input\_oidc\_identity\_providers) | (Optional) A list of OIDC Identity Providers to associate as an additional method for user authentication to your Kubernetes cluster. Each item of `oidc_identity_providers` block as defined below.<br> (Required) `name` - A unique name for the Identity Provider Configuration.<br> (Required) `issuer_url` - The OIDC Identity Provider issuer URL.<br> (Required) `client_id` - The OIDC Identity Provider client ID.<br> (Optional) `required_claims` - The key value pairs that describe required claims in the identity token.<br> (Optional) `username_claim` - The JWT claim that the provider will use as the username.<br> (Optional) `username_prefix` - A prefix that is prepended to username claims.<br> (Optional) `groups_claim` - The JWT claim that the provider will use to return groups.<br> (Optional) `groups_prefix` - A prefix that is prepended to group claims e.g., `oidc:`. | `any` | `[]` | no |
7880
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
7981
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
8082
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | (Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
@@ -94,6 +96,7 @@ This module creates following resources.
9496
| <a name="output_ip_family"></a> [ip\_family](#output\_ip\_family) | The IP family used to assign Kubernetes pod and service addresses. |
9597
| <a name="output_logging"></a> [logging](#output\_logging) | The configurations of the control plane logging. |
9698
| <a name="output_name"></a> [name](#output\_name) | The name of the cluster. |
99+
| <a name="output_oidc_identity_providers"></a> [oidc\_identity\_providers](#output\_oidc\_identity\_providers) | A map of all associated OIDC Identity Providers to the cluster. |
97100
| <a name="output_oidc_provider_arn"></a> [oidc\_provider\_arn](#output\_oidc\_provider\_arn) | The Amazon Resource Name (ARN) for the OpenID Connect identity provider. |
98101
| <a name="output_oidc_provider_url"></a> [oidc\_provider\_url](#output\_oidc\_provider\_url) | Issuer URL for the OpenID Connect identity provider. |
99102
| <a name="output_oidc_provider_urn"></a> [oidc\_provider\_urn](#output\_oidc\_provider\_urn) | Issuer URN for the OpenID Connect identity provider. |
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
###################################################
2+
# Associations of OIDC Identity Provider
3+
###################################################
4+
5+
resource "aws_eks_identity_provider_config" "this" {
6+
for_each = {
7+
for provider in var.oidc_identity_providers :
8+
provider.name => provider
9+
}
10+
11+
cluster_name = aws_eks_cluster.this.name
12+
13+
oidc {
14+
identity_provider_config_name = each.key
15+
16+
issuer_url = each.value.issuer_url
17+
client_id = each.value.client_id
18+
19+
required_claims = try(each.value.required_claims, null)
20+
username_claim = try(each.value.username_claim, null)
21+
username_prefix = try(each.value.username_prefix, null)
22+
groups_claim = try(each.value.groups_claim, null)
23+
groups_prefix = try(each.value.groups_prefix, null)
24+
}
25+
26+
tags = merge(
27+
{
28+
"Name" = "${local.metadata.name}/${each.key}"
29+
},
30+
local.module_tags,
31+
var.tags,
32+
)
33+
}

modules/eks-cluster/outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,22 @@ output "fargate_profiles" {
112112
}
113113
}
114114
}
115+
116+
output "oidc_identity_providers" {
117+
description = "A map of all associated OIDC Identity Providers to the cluster."
118+
value = {
119+
for name, provider in aws_eks_identity_provider_config.this :
120+
name => {
121+
arn = provider.arn
122+
status = provider.status
123+
name = provider.oidc[0].identity_provider_config_name
124+
issuer_url = provider.oidc[0].issuer_url
125+
126+
required_claims = provider.oidc[0].required_claims
127+
username_claim = provider.oidc[0].username_claim
128+
username_prefix = provider.oidc[0].username_prefix
129+
groups_claim = provider.oidc[0].groups_claim
130+
groups_prefix = provider.oidc[0].groups_prefix
131+
}
132+
}
133+
}

modules/eks-cluster/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ variable "fargate_profiles" {
131131
default = []
132132
}
133133

134+
variable "oidc_identity_providers" {
135+
description = <<EOF
136+
(Optional) A list of OIDC Identity Providers to associate as an additional method for user authentication to your Kubernetes cluster. Each item of `oidc_identity_providers` block as defined below.
137+
(Required) `name` - A unique name for the Identity Provider Configuration.
138+
(Required) `issuer_url` - The OIDC Identity Provider issuer URL.
139+
(Required) `client_id` - The OIDC Identity Provider client ID.
140+
(Optional) `required_claims` - The key value pairs that describe required claims in the identity token.
141+
(Optional) `username_claim` - The JWT claim that the provider will use as the username.
142+
(Optional) `username_prefix` - A prefix that is prepended to username claims.
143+
(Optional) `groups_claim` - The JWT claim that the provider will use to return groups.
144+
(Optional) `groups_prefix` - A prefix that is prepended to group claims e.g., `oidc:`.
145+
EOF
146+
type = any
147+
default = []
148+
}
149+
134150
variable "tags" {
135151
description = "(Optional) A map of tags to add to all resources."
136152
type = map(string)

0 commit comments

Comments
 (0)