Skip to content

Commit 02a01c5

Browse files
authored
Merge pull request #1 from truefoundry/aks-module
Added aks module for k8s
2 parents 360c8a5 + 6442035 commit 02a01c5

File tree

5 files changed

+262
-33
lines changed

5 files changed

+262
-33
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
11
# terraform-azure-truefoundry-cluster
22
Truefoundry Azure Cluster Module
3+
4+
<!-- BEGIN_TF_DOCS -->
5+
## Requirements
6+
7+
No requirements.
8+
9+
## Providers
10+
11+
| Name | Version |
12+
|------|---------|
13+
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | n/a |
14+
15+
## Modules
16+
17+
| Name | Source | Version |
18+
|------|--------|---------|
19+
| <a name="module_aks"></a> [aks](#module\_aks) | Azure/aks/azurerm | 7.2.0 |
20+
21+
## Resources
22+
23+
| Name | Type |
24+
|------|------|
25+
| [azurerm_role_assignment.network_contributor_cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) | resource |
26+
| [azurerm_user_assigned_identity.cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity) | resource |
27+
28+
## Inputs
29+
30+
| Name | Description | Type | Default | Required |
31+
|------|-------------|------|---------|:--------:|
32+
| <a name="input_allowed_ip_ranges"></a> [allowed\_ip\_ranges](#input\_allowed\_ip\_ranges) | allowed IP ranges to connect to the cluster | `list(string)` | <pre>[<br> "0.0.0.0/0"<br>]</pre> | no |
33+
| <a name="input_control_plane"></a> [control\_plane](#input\_control\_plane) | whether the cluster is control plane | `bool` | n/a | yes |
34+
| <a name="input_disk_size"></a> [disk\_size](#input\_disk\_size) | disk size of the initial node pool in GB | `string` | `"100"` | no |
35+
| <a name="input_dns_ip"></a> [dns\_ip](#input\_dns\_ip) | IP from service CIDR used for internal DNS | `string` | `"10.0.0.10"` | no |
36+
| <a name="input_intial_node_pool_instance_type"></a> [intial\_node\_pool\_instance\_type](#input\_intial\_node\_pool\_instance\_type) | Instance size of the initial node pool | `string` | `"Standard_D2s_v5"` | no |
37+
| <a name="input_intial_node_pool_spot_instance_type"></a> [intial\_node\_pool\_spot\_instance\_type](#input\_intial\_node\_pool\_spot\_instance\_type) | Instance size of the initial node pool | `string` | `"Standard_D4s_v5"` | no |
38+
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | version of the kubernetes engine | `string` | `"1.26"` | no |
39+
| <a name="input_location"></a> [location](#input\_location) | Location of the resource group | `string` | n/a | yes |
40+
| <a name="input_name"></a> [name](#input\_name) | Name of the cluster | `string` | n/a | yes |
41+
| <a name="input_network_plugin"></a> [network\_plugin](#input\_network\_plugin) | network plugin to use for cluster | `string` | `"kubenet"` | no |
42+
| <a name="input_oidc_issuer_enabled"></a> [oidc\_issuer\_enabled](#input\_oidc\_issuer\_enabled) | enable OIDC for the cluster | `bool` | `true` | no |
43+
| <a name="input_pod_cidr"></a> [pod\_cidr](#input\_pod\_cidr) | CIDR of the pod | `string` | `"10.244.0.0/16"` | no |
44+
| <a name="input_private_cluster_enabled"></a> [private\_cluster\_enabled](#input\_private\_cluster\_enabled) | Private cluster | `bool` | `false` | no |
45+
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Name of the resource group | `string` | n/a | yes |
46+
| <a name="input_server_cidr"></a> [server\_cidr](#input\_server\_cidr) | service CIDR | `string` | `"10.0.0.0/16"` | no |
47+
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | Subnet Id for the cluster. | `string` | n/a | yes |
48+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
49+
| <a name="input_vnet_id"></a> [vnet\_id](#input\_vnet\_id) | Vnet ID for the cluster | `string` | n/a | yes |
50+
| <a name="input_workload_identity_enabled"></a> [workload\_identity\_enabled](#input\_workload\_identity\_enabled) | enable workload identity in the cluster | `bool` | `true` | no |
51+
52+
## Outputs
53+
54+
| Name | Description |
55+
|------|-------------|
56+
| <a name="output_cluster_endpoint"></a> [cluster\_endpoint](#output\_cluster\_endpoint) | Endpoint for your Kubernetes API server |
57+
| <a name="output_cluster_host"></a> [cluster\_host](#output\_cluster\_host) | The `host` in the `azurerm_kubernetes_cluster`'s `kube_config` block. The Kubernetes cluster server host. |
58+
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | The name/id of the EKS cluster. Will block on cluster creation until the cluster is really ready |
59+
| <a name="output_cluster_identity"></a> [cluster\_identity](#output\_cluster\_identity) | The `azurerm_kubernetes_cluster`'s `identity` block. |
60+
| <a name="output_cluster_name"></a> [cluster\_name](#output\_cluster\_name) | Name of the cluster |
61+
| <a name="output_cluster_networking_profile"></a> [cluster\_networking\_profile](#output\_cluster\_networking\_profile) | Networking profile of the cluster |
62+
| <a name="output_cluster_oidc_issuer_url"></a> [cluster\_oidc\_issuer\_url](#output\_cluster\_oidc\_issuer\_url) | OIDC issuer url of the cluster |
63+
<!-- END_TF_DOCS -->

aks.tf

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,69 @@ resource "azurerm_role_assignment" "network_contributor_cluster" {
1111
principal_id = azurerm_user_assigned_identity.cluster.principal_id
1212
}
1313

14-
resource "azurerm_kubernetes_cluster" "cluster" {
15-
name = var.name
16-
location = var.location
17-
resource_group_name = var.resource_group_name
18-
private_cluster_enabled = var.private_cluster_enabled
19-
# Additional node pools can be added separately - https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster_node_pool
20-
default_node_pool {
21-
name = "default"
22-
vm_size = "Standard_D2_v2"
23-
enable_auto_scaling = true
24-
max_count = 10
25-
min_count = 2
26-
os_disk_size_gb = 40
27-
vnet_subnet_id = var.subnet_id
28-
}
29-
oidc_issuer_enabled = true
30-
local_account_disabled = false
31-
dns_prefix = var.name
32-
identity {
33-
type = "UserAssigned"
34-
identity_ids = [azurerm_user_assigned_identity.cluster.id]
35-
}
36-
network_profile {
37-
network_plugin = "kubenet"
14+
module "aks" {
15+
source = "Azure/aks/azurerm"
16+
version = "7.2.0"
17+
resource_group_name = var.resource_group_name
18+
cluster_name = var.name
19+
location = var.location
20+
prefix = "tfy"
21+
workload_identity_enabled = var.workload_identity_enabled
22+
23+
# agent configuration
24+
# agents_availability_zones = []
25+
agents_labels = {
26+
"truefoundry" : "essential"
3827
}
39-
}
28+
agents_count = local.intial_node_pool_instance_count
29+
agents_max_count = local.intial_node_pool_instance_count
30+
agents_min_count = local.intial_node_pool_instance_count
31+
agents_pool_name = "initial"
32+
agents_size = var.intial_node_pool_instance_type
33+
agents_tags = local.tags
34+
35+
# autoscaler configuration
36+
auto_scaler_profile_enabled = true
37+
auto_scaler_profile_expander = "random"
38+
auto_scaler_profile_max_node_provisioning_time = "5m"
39+
auto_scaler_profile_max_unready_nodes = 0
40+
auto_scaler_profile_scale_down_delay_after_add = "5m"
41+
auto_scaler_profile_scale_down_delay_after_delete = "30s"
42+
auto_scaler_profile_scale_down_unneeded = "1m"
43+
auto_scaler_profile_scale_down_unready = "5m"
44+
auto_scaler_profile_scale_down_utilization_threshold = "0.3"
45+
46+
# cluster level configurations
47+
api_server_authorized_ip_ranges = var.allowed_ip_ranges
48+
create_role_assignment_network_contributor = false
49+
enable_auto_scaling = true
50+
enable_host_encryption = true
51+
identity_ids = [azurerm_user_assigned_identity.cluster.id]
52+
identity_type = "UserAssigned"
53+
kubernetes_version = var.kubernetes_version
54+
55+
# network configuration
56+
network_plugin = var.network_plugin
57+
vnet_subnet_id = var.subnet_id
58+
net_profile_dns_service_ip = var.dns_ip
59+
net_profile_service_cidr = var.server_cidr
60+
net_profile_pod_cidr = var.pod_cidr
61+
# net_profile_docker_bridge_cidr = "10.244.0.10"
62+
63+
node_pools = local.node_pools
64+
65+
oidc_issuer_enabled = var.oidc_issuer_enabled
66+
os_disk_size_gb = var.disk_size
67+
68+
# makes the initial node pool have a taint `CriticalAddonsOnly=true:NoSchedule`
69+
# helpful in scheduling important workloads
70+
only_critical_addons_enabled = true
71+
72+
private_cluster_enabled = var.private_cluster_enabled
73+
74+
# rbac
75+
rbac_aad = false
76+
role_based_access_control_enabled = false
77+
78+
tags = local.tags
79+
}

locals.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
locals {
2+
tags = merge(
3+
{
4+
"terraform-module" = "terraform-azure-truefoundry-cluster"
5+
"terraform" = "true"
6+
"cluster-name" = var.name
7+
},
8+
var.tags
9+
)
10+
intial_node_pool_instance_count = var.control_plane ? 2 : 1
11+
node_pools = {
12+
spot = {
13+
name = "spotpool"
14+
node_count = 1
15+
max_count = 20
16+
min_count = 1
17+
os_disk_size_gb = 100
18+
priority = "Spot"
19+
vm_size = var.intial_node_pool_spot_instance_type
20+
21+
# mandatory to pass otherwise node pool will be recreated
22+
enable_auto_scaling = true
23+
custom_ca_trust_enabled = false
24+
enable_host_encryption = false
25+
enable_node_public_ip = false
26+
eviction_policy = "Delete"
27+
node_taints = [
28+
"kubernetes.azure.com/scalesetpriority=spot:NoSchedule"
29+
]
30+
tags = local.tags
31+
zones = []
32+
vnet_subnet_id = var.subnet_id
33+
}
34+
}
35+
}

output.tf

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,36 @@
66

77
output "cluster_endpoint" {
88
description = "Endpoint for your Kubernetes API server"
9-
value = azurerm_kubernetes_cluster.cluster.fqdn
9+
value = module.aks.cluster_fqdn
1010
}
1111

1212
output "cluster_id" {
1313
description = "The name/id of the EKS cluster. Will block on cluster creation until the cluster is really ready"
14-
value = azurerm_kubernetes_cluster.cluster.id
14+
value = module.aks.aks_id
1515
}
1616

17-
output "oidc_issuer_url" {
18-
description = "The OIDC issuer URL that is associated with the cluster."
19-
value = azurerm_kubernetes_cluster.cluster.oidc_issuer_url
17+
output "cluster_name" {
18+
description = "Name of the cluster"
19+
value = module.aks.aks_name
20+
}
21+
22+
output "cluster_identity" {
23+
description = "The `azurerm_kubernetes_cluster`'s `identity` block."
24+
value = module.aks.cluster_identity
25+
}
26+
27+
output "cluster_host" {
28+
description = "The `host` in the `azurerm_kubernetes_cluster`'s `kube_config` block. The Kubernetes cluster server host."
29+
value = module.aks.host
30+
sensitive = true
31+
}
32+
33+
output "cluster_networking_profile" {
34+
description = "Networking profile of the cluster"
35+
value = module.aks.network_profile
36+
}
37+
38+
output "cluster_oidc_issuer_url" {
39+
description = "OIDC issuer url of the cluster"
40+
value = module.aks.oidc_issuer_url
2041
}

variables.tf

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,95 @@ variable "name" {
66
description = "Name of the cluster"
77
type = string
88
}
9+
variable "kubernetes_version" {
10+
description = "version of the kubernetes engine"
11+
default = "1.26"
12+
type = string
13+
}
914

10-
variable "private_cluster_enabled" {
11-
description = "Private cluster"
12-
default = false
15+
variable "oidc_issuer_enabled" {
16+
description = "enable OIDC for the cluster"
17+
default = true
1318
type = bool
1419
}
1520

21+
variable "disk_size" {
22+
description = "disk size of the initial node pool in GB"
23+
default = "100"
24+
type = string
25+
}
1626

27+
variable "intial_node_pool_instance_type" {
28+
description = "Instance size of the initial node pool"
29+
default = "Standard_D2s_v5"
30+
type = string
31+
}
32+
33+
variable "intial_node_pool_spot_instance_type" {
34+
description = "Instance size of the initial node pool"
35+
default = "Standard_D4s_v5"
36+
type = string
37+
}
38+
39+
variable "workload_identity_enabled" {
40+
description = "enable workload identity in the cluster"
41+
default = true
42+
type = bool
43+
}
44+
45+
variable "control_plane" {
46+
description = "whether the cluster is control plane"
47+
type = bool
48+
49+
}
1750
################################################################################
1851
# Network
1952
################################################################################
2053

2154
variable "vnet_id" {
2255
description = "Vnet ID for the cluster"
56+
type = string
2357
}
58+
2459
variable "subnet_id" {
2560
description = "Subnet Id for the cluster."
61+
type = string
62+
}
63+
64+
variable "network_plugin" {
65+
description = "network plugin to use for cluster"
66+
type = string
67+
default = "kubenet"
68+
}
69+
70+
variable "pod_cidr" {
71+
description = "CIDR of the pod"
72+
default = "10.244.0.0/16"
73+
type = string
74+
}
75+
76+
variable "server_cidr" {
77+
description = "service CIDR"
78+
default = "10.0.0.0/16"
79+
type = string
80+
}
81+
82+
variable "dns_ip" {
83+
description = "IP from service CIDR used for internal DNS"
84+
default = "10.0.0.10"
85+
type = string
86+
}
87+
88+
variable "allowed_ip_ranges" {
89+
description = "allowed IP ranges to connect to the cluster"
90+
default = ["0.0.0.0/0"]
91+
type = list(string)
92+
}
93+
94+
variable "private_cluster_enabled" {
95+
description = "Private cluster"
96+
default = false
97+
type = bool
2698
}
2799

28100
################################################################################

0 commit comments

Comments
 (0)