Skip to content

Commit

Permalink
Add cluster_name variable (#84)
Browse files Browse the repository at this point in the history
* Add cluster_name variable

* Edit variables default value

* Edit test/fixture/main.tf

* Edit README.md

* Edit variables. Edit tests

* Edit variables

* Edit test/fixture/main.tf
  • Loading branch information
bamaralf authored May 21, 2021
1 parent 1e7d9a3 commit cb3b833
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module "aks" {
kubernetes_version = "1.19.3"
orchestrator_version = "1.19.3"
prefix = "prefix"
cluster_name = "cluster-name"
network_plugin = "azure"
vnet_subnet_id = module.network.vnet_subnets[0]
os_disk_size_gb = 50
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module "ssh-key" {
}

resource "azurerm_kubernetes_cluster" "main" {
name = "${var.prefix}-aks"
name = var.cluster_name == null ? "${var.prefix}-aks" : var.cluster_name
kubernetes_version = var.kubernetes_version
location = data.azurerm_resource_group.main.location
resource_group_name = data.azurerm_resource_group.main.name
Expand Down Expand Up @@ -138,7 +138,7 @@ resource "azurerm_kubernetes_cluster" "main" {

resource "azurerm_log_analytics_workspace" "main" {
count = var.enable_log_analytics_workspace ? 1 : 0
name = "${var.prefix}-workspace"
name = var.cluster_log_analytics_workspace_name == null ? "${var.prefix}-workspace" : var.cluster_log_analytics_workspace_name
location = data.azurerm_resource_group.main.location
resource_group_name = var.resource_group_name
sku = var.log_analytics_workspace_sku
Expand Down
12 changes: 12 additions & 0 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,15 @@ module "aks_without_monitor" {
net_profile_pod_cidr = "10.1.0.0/16"
depends_on = [azurerm_resource_group.main]
}

module "aks_cluster_name" {
source = "../.."
cluster_name = "test-cluster"
prefix = "prefix"
resource_group_name = azurerm_resource_group.main.name
enable_log_analytics_workspace = true
cluster_log_analytics_workspace_name = "test-cluster"
enable_kube_dashboard = false
net_profile_pod_cidr = "10.1.0.0/16"
depends_on = [azurerm_resource_group.main]
}
14 changes: 13 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ variable "resource_group_name" {
type = string
}

variable "cluster_name" {
description = "(Optional) The name for the AKS resources created in the specified Azure Resource Group. This variable overwrites the 'prefix' var (The 'prefix' var will still be applied to the dns_prefix if it is set)"
type = string
default = null
}

variable "cluster_log_analytics_workspace_name" {
description = "(Optional) The name of the Analytics workspace"
type = string
default = null
}

variable "prefix" {
description = "The prefix for the resources created in the specified Azure Resource Group"
description = "(Required) The prefix for the resources created in the specified Azure Resource Group"
type = string
}

Expand Down

0 comments on commit cb3b833

Please sign in to comment.