From d8f256aba9df2d764e97e503ec12dcdfe2945a68 Mon Sep 17 00:00:00 2001 From: David van der Spek Date: Wed, 6 Sep 2023 14:21:00 +0200 Subject: [PATCH] cleanup old azure tf Signed-off-by: David van der Spek --- .../azure-bootstrap-cluster-api/deps.yaml | 23 - .../azure-bootstrap-cluster-api/locals.tf | 3 - .../azure-bootstrap-cluster-api/main.tf | 214 ------ .../azure-bootstrap-cluster-api/moved.tf | 34 - .../azure-bootstrap-cluster-api/outputs.tf | 33 - .../terraform.tfvars | 31 - .../azure-bootstrap-cluster-api/variables.tf | 635 ------------------ 7 files changed, 973 deletions(-) delete mode 100644 bootstrap/terraform/azure-bootstrap-cluster-api/deps.yaml delete mode 100644 bootstrap/terraform/azure-bootstrap-cluster-api/locals.tf delete mode 100644 bootstrap/terraform/azure-bootstrap-cluster-api/main.tf delete mode 100644 bootstrap/terraform/azure-bootstrap-cluster-api/moved.tf delete mode 100644 bootstrap/terraform/azure-bootstrap-cluster-api/outputs.tf delete mode 100644 bootstrap/terraform/azure-bootstrap-cluster-api/terraform.tfvars delete mode 100644 bootstrap/terraform/azure-bootstrap-cluster-api/variables.tf diff --git a/bootstrap/terraform/azure-bootstrap-cluster-api/deps.yaml b/bootstrap/terraform/azure-bootstrap-cluster-api/deps.yaml deleted file mode 100644 index 8e5ac81ad..000000000 --- a/bootstrap/terraform/azure-bootstrap-cluster-api/deps.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: plural.sh/v1alpha1 -kind: Dependencies -metadata: - description: Creates an AKS cluster and prepares it for bootstrapping - version: 0.3.4 -spec: - breaking: true - dependencies: [] - providers: - - azure - secrets: - - /private_ssh_key - outputs: - cluster_name: cluster_name - resource_group_name: resource_group_name - cluster: cluster - network: network - kubelet_msi_id: kubelet_msi_id - node_resource_group: node_resource_group - capz_assigned_identity_client_id: capz_assigned_identity_client_id - provider_wirings: - cluster: module.azure-bootstrap-cluster-api.cluster - provider_vsn: "0.1.3" diff --git a/bootstrap/terraform/azure-bootstrap-cluster-api/locals.tf b/bootstrap/terraform/azure-bootstrap-cluster-api/locals.tf deleted file mode 100644 index a59018e3d..000000000 --- a/bootstrap/terraform/azure-bootstrap-cluster-api/locals.tf +++ /dev/null @@ -1,3 +0,0 @@ -locals { - node_pool_name = substr(replace("${var.name}nodes", "-", ""), 0, 12) -} \ No newline at end of file diff --git a/bootstrap/terraform/azure-bootstrap-cluster-api/main.tf b/bootstrap/terraform/azure-bootstrap-cluster-api/main.tf deleted file mode 100644 index 042545576..000000000 --- a/bootstrap/terraform/azure-bootstrap-cluster-api/main.tf +++ /dev/null @@ -1,214 +0,0 @@ -data "azurerm_resource_group" "group" { - name = var.resource_group -} - -data "azurerm_resource_group" "node_group" { - name = var.cluster_api ? one(data.azurerm_kubernetes_cluster.cluster[*].node_resource_group) : one(module.aks[*].node_resource_group) -} - -data "azurerm_kubernetes_cluster" "cluster" { - count = var.cluster_api ? 1: 0 - - name = var.name - resource_group_name = var.resource_group -} - -data "azurerm_virtual_network" "vnet" { - count = var.cluster_api ? 1: 0 - - name = var.network_name - resource_group_name = var.resource_group -} - -module "network" { - count = var.cluster_api ? 0 : 1 - - source = "github.com/pluralsh/terraform-azurerm-network?ref=plural" - - vnet_name = var.network_name - resource_group_name = data.azurerm_resource_group.group.name - address_space = var.address_space - subnet_prefixes = var.subnet_prefixes - subnet_names = [var.subnet_name] - tags = var.tags -} - -module "aks" { - count = var.cluster_api ? 0 : 1 - - source = "github.com/pluralsh/terraform-azurerm-aks?ref=ea5c22775e0352ef6fe7a9abe2d94306029b6a6e" # branch auto-scaler-profile - - resource_group_name = data.azurerm_resource_group.group.name - kubernetes_version = var.kubernetes_version - orchestrator_version = var.kubernetes_version - prefix = var.name - cluster_name = var.name - network_plugin = var.network_plugin - vnet_subnet_id = one(module.network[*].vnet_subnets[0]) - os_disk_size_gb = var.node_groups[0].os_disk_size_gb - os_disk_type = var.node_groups[0].os_disk_type - enable_role_based_access_control = true - rbac_aad_enabled = false - rbac_aad_managed = false - oidc_issuer_enabled = true - location = data.azurerm_resource_group.group.location - sku_tier = "Paid" - private_cluster_enabled = var.private_cluster - enable_http_application_routing = false - azure_policy_enabled = false - admin_username = var.admin_username - enable_auto_scaling = var.node_groups[0].enable_auto_scaling - agents_min_count = var.node_groups[0].min_count - agents_max_count = var.node_groups[0].max_count - agents_count = var.node_groups[0].node_count # Please set `agents_count` `null` while `enable_auto_scaling` is `true` to avoid possible `agents_count` changes. - agents_max_pods = var.node_groups[0].max_pods - agents_pool_name = var.node_groups[0].name - agents_availability_zones = var.node_groups[0].availability_zones - agents_type = "VirtualMachineScaleSets" - agents_size = var.node_groups[0].vm_size - - agents_labels = var.node_groups[0].node_labels - - agents_tags = merge(var.node_groups[0].tags, var.tags) - - network_policy = var.network_policy - net_profile_dns_service_ip = "10.0.0.10" - net_profile_docker_bridge_cidr = "170.10.0.1/16" - net_profile_service_cidr = "10.0.0.0/16" - - auto_scaler_profile_balance_similar_node_groups = var.auto_scaler_profile_balance_similar_node_groups - auto_scaler_profile_skip_nodes_with_local_storage = var.auto_scaler_profile_skip_nodes_with_local_storage - auto_scaler_profile_scale_down_utilization_threshold = var.auto_scaler_profile_scale_down_utilization_threshold - - enable_log_analytics_workspace = var.enable_aks_insights - tags = var.tags - - depends_on = [module.network] -} - -resource "azurerm_kubernetes_cluster_node_pool" "main" { - for_each = var.cluster_api ? {} : {for idx, val in var.node_groups : val.name => val if idx != 0} - - kubernetes_cluster_id = one(module.aks[*].aks_id) - - name = each.value.name - priority = each.value.priority - enable_auto_scaling = each.value.enable_auto_scaling - zones = each.value.availability_zones - mode = each.value.mode - orchestrator_version = var.kubernetes_version - node_count = each.value.node_count - min_count = each.value.min_count - max_count = each.value.max_count - spot_max_price = each.value.spot_max_price - eviction_policy = each.value.eviction_policy - vnet_subnet_id = one(module.network[*].vnet_subnets[0]) - vm_size = each.value.vm_size - os_disk_type = each.value.os_disk_type - os_disk_size_gb = each.value.os_disk_size_gb - max_pods = each.value.max_pods - - node_labels = each.value.node_labels - node_taints = each.value.node_taints - tags = merge(each.value.tags, var.tags) -} - -resource "azurerm_role_assignment" "aks-network-identity-ssi" { - scope = var.cluster_api ? one(data.azurerm_virtual_network.vnet[*].id) : one(module.network[*].vnet_id) - role_definition_name = "Network Contributor" - principal_id = var.cluster_api ? one(data.azurerm_kubernetes_cluster.cluster[*].identity[0].principal_id) : one(module.aks[*].system_assigned_identity[0].principal_id) - - depends_on = [data.azurerm_virtual_network.vnet, data.azurerm_kubernetes_cluster.cluster, module.aks, module.network] -} - -resource "azurerm_role_assignment" "aks-managed-identity" { - count = var.cluster_api ? 0 : 1 - - scope = data.azurerm_resource_group.group.id - role_definition_name = "Managed Identity Operator" - principal_id = one(module.aks[*].kubelet_identity[0].object_id) - - depends_on = [module.aks] -} - -resource "azurerm_role_assignment" "aks-network-identity-kubelet" { - count = var.cluster_api ? 0 : 1 - - scope = one(module.network[*].vnet_id) - role_definition_name = "Network Contributor" - principal_id = one(module.aks[*].kubelet_identity[0].object_id) - - depends_on = [module.aks, module.network] -} - -resource "azurerm_role_assignment" "aks-vm-contributor" { - count = var.cluster_api ? 0 : 1 - - scope = data.azurerm_resource_group.group.id - role_definition_name = "Virtual Machine Contributor" - principal_id = one(module.aks[*].kubelet_identity[0].object_id) - - depends_on = [module.aks] -} - -resource "azurerm_role_assignment" "aks-node-managed-identity" { - count = var.cluster_api ? 0 : 1 - - scope = data.azurerm_resource_group.node_group.id - role_definition_name = "Managed Identity Operator" - principal_id = one(module.aks[*].kubelet_identity[0].object_id) - - depends_on = [module.aks] -} - -resource "azurerm_role_assignment" "aks-node-vm-contributor" { - count = var.cluster_api ? 0 : 1 - - scope = data.azurerm_resource_group.node_group.id - role_definition_name = "Virtual Machine Contributor" - principal_id = one(module.aks[*].kubelet_identity[0].object_id) - - depends_on = [module.aks] -} - -resource "azurerm_user_assigned_identity" "capz" { - location = data.azurerm_resource_group.group.location - name = "${var.name}-capz" - resource_group_name = data.azurerm_resource_group.group.name -} - -resource "azurerm_role_assignment" "rg-contributor" { - scope = data.azurerm_resource_group.group.id - role_definition_name = "Contributor" - principal_id = azurerm_user_assigned_identity.capz.principal_id -} - -resource "azurerm_role_assignment" "node-rg-contributor" { - scope = data.azurerm_resource_group.node_group.id - role_definition_name = "Contributor" - principal_id = azurerm_user_assigned_identity.capz.principal_id -} - -resource "azurerm_federated_identity_credential" "capz" { - name = "${var.name}-capz-federated-identity" - resource_group_name = data.azurerm_resource_group.group.name - audience = ["api://AzureADTokenExchange"] - issuer = var.cluster_api ? one(data.azurerm_kubernetes_cluster.cluster[*].oidc_issuer_url) : one(module.aks[*].oidc_issuer_url) - parent_id = azurerm_user_assigned_identity.capz.id - subject = "system:serviceaccount:${var.namespace}:bootstrap-cluster-api-provider-azure" -} - -resource "kubernetes_namespace" "bootstrap" { - count = var.cluster_api ? 0 : 1 - - metadata { - name = var.namespace - - labels = { - "app.kubernetes.io/managed-by" = "plural" - "app.plural.sh/name" = "bootstrap" - } - } - - depends_on = [module.aks.host] -} diff --git a/bootstrap/terraform/azure-bootstrap-cluster-api/moved.tf b/bootstrap/terraform/azure-bootstrap-cluster-api/moved.tf deleted file mode 100644 index 09f41d181..000000000 --- a/bootstrap/terraform/azure-bootstrap-cluster-api/moved.tf +++ /dev/null @@ -1,34 +0,0 @@ -moved { - from = module.network - to = module.network[0] -} - -moved { - from = module.aks - to = module.aks[0] -} - -moved { - from = azurerm_role_assignment.aks-managed-identity - to = azurerm_role_assignment.aks-managed-identity[0] -} - -moved { - from = azurerm_role_assignment.aks-network-identity-kubelet - to = azurerm_role_assignment.aks-network-identity-kubelet[0] -} - -moved { - from = azurerm_role_assignment.aks-vm-contributor - to = azurerm_role_assignment.aks-vm-contributor[0] -} - -moved { - from = azurerm_role_assignment.aks-node-vm-contributor - to = azurerm_role_assignment.aks-node-vm-contributor[0] -} - -moved { - from = kubernetes_namespace.bootstrap - to = kubernetes_namespace.bootstrap[0] -} diff --git a/bootstrap/terraform/azure-bootstrap-cluster-api/outputs.tf b/bootstrap/terraform/azure-bootstrap-cluster-api/outputs.tf deleted file mode 100644 index efe752e56..000000000 --- a/bootstrap/terraform/azure-bootstrap-cluster-api/outputs.tf +++ /dev/null @@ -1,33 +0,0 @@ -output "cluster" { - value = var.cluster_api ? merge(one(data.azurerm_kubernetes_cluster.cluster[*]), { - host=one(data.azurerm_kubernetes_cluster.cluster[*]).kube_config.0.host, - client_certificate=one(data.azurerm_kubernetes_cluster.cluster[*]).kube_config.0.client_certificate, - client_key=one(data.azurerm_kubernetes_cluster.cluster[*]).kube_config.0.client_key, - cluster_ca_certificate=one(data.azurerm_kubernetes_cluster.cluster[*]).kube_config.0.cluster_ca_certificate - }) : one(module.aks[*]) - sensitive = true -} - -output "kubelet_msi_id" { - value = var.cluster_api ? one(data.azurerm_kubernetes_cluster.cluster[*].kubelet_identity.0.client_id) : one(module.aks[*].kubelet_identity[0].client_id) -} - -output "node_resource_group" { - value = data.azurerm_resource_group.node_group.name -} - -output "cluster_name" { - value = var.cluster_api ? one(data.azurerm_kubernetes_cluster.cluster[*].name) : one(module.aks[*].cluster_name) -} - -output "resource_group_name" { - value = data.azurerm_resource_group.group.name -} - -output "network" { - value = var.cluster_api ? one(data.azurerm_virtual_network.vnet[*]) : one(module.network[*]) -} - -output "capz_assigned_identity_client_id" { - value = azurerm_user_assigned_identity.capz.client_id -} diff --git a/bootstrap/terraform/azure-bootstrap-cluster-api/terraform.tfvars b/bootstrap/terraform/azure-bootstrap-cluster-api/terraform.tfvars deleted file mode 100644 index 517bf31ae..000000000 --- a/bootstrap/terraform/azure-bootstrap-cluster-api/terraform.tfvars +++ /dev/null @@ -1,31 +0,0 @@ -{{- $tfOutput := pathJoin repoRoot "bootstrap" "output.yaml" }} -resource_group = {{ .Project | quote }} -name = {{ .Cluster | quote }} -namespace = {{ .Namespace | quote }} -cluster_api = {{ .ClusterAPI }} - -{{- if fileExists $tfOutput }} -{{- $bootstrapOutputs := .Applications.TerraformValues "bootstrap" }} -{{- if and $bootstrapOutputs (not .ClusterAPI) }} - -network_name = {{ $bootstrapOutputs.network.vnet_name | quote }} -subnet_prefixes = yamldecode(<