Skip to content

Commit

Permalink
PLAT-4497: Allow a resource group id (#26)
Browse files Browse the repository at this point in the history
Allow the resource group id to be provided to create an implicit dependency on the
module.
  • Loading branch information
Michael Fraenkel authored Apr 15, 2022
1 parent 335e180 commit fc9eb89
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
docker:
- image: mcr.microsoft.com/azure-cli
environment:
TERRAFORM_VERSION: 1.0.6
TERRAFORM_VERSION: 1.1.8

steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion acr.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "azurerm_container_registry" "domino" {
name = replace("${var.resource_group}domino", "/[^a-zA-Z0-9]/", "")
name = replace("${data.azurerm_resource_group.aks.name}domino", "/[^a-zA-Z0-9]/", "")
resource_group_name = data.azurerm_resource_group.aks.name
location = data.azurerm_resource_group.aks.location

Expand Down
16 changes: 5 additions & 11 deletions aks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ resource "azurerm_kubernetes_cluster" "aks" {
node_count = local.node_pools.platform.initial_count
node_labels = local.node_pools.platform.node_labels
vm_size = local.node_pools.platform.vm_size
availability_zones = local.node_pools.platform.zones
zones = local.node_pools.platform.zones
os_disk_size_gb = local.node_pools.platform.os_disk_size_gb
node_taints = local.node_pools.platform.node_taints
enable_auto_scaling = local.node_pools.platform.enable_auto_scaling
Expand All @@ -53,19 +53,13 @@ resource "azurerm_kubernetes_cluster" "aks" {
type = "SystemAssigned"
}

addon_profile {
kube_dashboard {
enabled = false
}

oms_agent {
enabled = true
log_analytics_workspace_id = azurerm_log_analytics_workspace.logs.id
}
oms_agent {
log_analytics_workspace_id = azurerm_log_analytics_workspace.logs.id
}

network_profile {
load_balancer_sku = "Standard"
load_balancer_sku = "standard"
network_plugin = "azure"
network_policy = "calico"
}
Expand Down Expand Up @@ -100,7 +94,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "aks" {
name = each.key
node_count = each.value.initial_count
vm_size = each.value.vm_size
availability_zones = each.value.zones
zones = each.value.zones
os_disk_size_gb = each.value.os_disk_size_gb
os_type = each.value.node_os
node_labels = each.value.node_labels
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data "azurerm_subscription" "current" {
}

data "azurerm_resource_group" "aks" {
name = var.resource_group
name = reverse(split("/", var.resource_group))[0]
}

resource "azurerm_role_assignment" "aks_network" {
Expand Down
2 changes: 1 addition & 1 deletion monitoring.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resource "random_id" "log_analytics_workspace_name_suffix" {

resource "azurerm_log_analytics_workspace" "logs" {
# The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant.
name = "${var.resource_group}-${random_id.log_analytics_workspace_name_suffix.dec}"
name = "${data.azurerm_resource_group.aks.name}-${random_id.log_analytics_workspace_name_suffix.dec}"
location = data.azurerm_resource_group.aks.location
resource_group_name = data.azurerm_resource_group.aks.name
sku = var.log_analytics_workspace_sku
Expand Down
12 changes: 2 additions & 10 deletions tests/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.46"
}

random = {
source = "hashicorp/random"
version = "~> 2.1"
version = "~> 3.0"
}
}

Expand All @@ -20,7 +15,6 @@ terraform {
}

provider "azurerm" {
partner_id = "31912fbf-f6dd-5176-bffb-0a01e8ac71f2"
features {}
}

Expand All @@ -42,10 +36,8 @@ module "aks" {
source = "./.."

cluster_name = terraform.workspace
resource_group = azurerm_resource_group.ci.name
resource_group = azurerm_resource_group.ci.id
api_server_authorized_ip_ranges = var.api_server_authorized_ip_ranges
tags = var.tags
kubeconfig_output_path = "${path.cwd}/kubeconfig"

depends_on = [azurerm_resource_group.ci]
}
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ variable "api_server_authorized_ip_ranges" {

variable "resource_group" {
type = string
description = "Name of optional pre-existing resource group to install AKS in"
description = "Name or id of optional pre-existing resource group to install AKS in"
}

variable "cluster_name" {
Expand Down
20 changes: 20 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_version = ">= 1.1.0"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}

random = {
source = "hashicorp/random"
version = "~> 3.1"
}
}
}

provider "azurerm" {
partner_id = "31912fbf-f6dd-5176-bffb-0a01e8ac71f2"
features {}
}

0 comments on commit fc9eb89

Please sign in to comment.