Skip to content

Commit

Permalink
begin working on walkthrough for existing AKS clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Apr 20, 2024
1 parent 584ea6f commit d2f925e
Show file tree
Hide file tree
Showing 16 changed files with 358 additions and 62 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ test/helm-values

# IDE
.idea/

**/values.secret.yaml
2 changes: 1 addition & 1 deletion charts/runtime/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: runtime
description: Sets up the basic dependencies needed to get a network stack running
type: application
version: 0.1.19
version: 0.1.20
appVersion: "0.1.0"
dependencies:
- name: external-dns
Expand Down
2 changes: 2 additions & 0 deletions charts/runtime/templates/helmrepositories.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ if .Values.flux.enabled }}
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
Expand All @@ -21,3 +22,4 @@ metadata:
spec:
interval: 5m0s
url: https://fluxcd-community.github.io/helm-charts
{{ end }}
27 changes: 27 additions & 0 deletions existing/terraform/azure/externaldns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
data "azurerm_resource_group" "group" {
name = var.resource_group
}

data "azurerm_dns_zone" "zone" {
name = var.dns_zone_name
resource_group_name = data.azurerm_resource_group.group.name
}

resource "azurerm_user_assigned_identity" "externaldns" {
resource_group_name = data.azurerm_resource_group.group.name
location = data.azurerm_resource_group.group.location

name = "${var.cluster_name}-externaldns"
}

resource "azurerm_role_assignment" "rg-reader" {
scope = data.azurerm_resource_group.group.id
role_definition_name = "Reader"
principal_id = azurerm_user_assigned_identity.externaldns.principal_id
}

resource "azurerm_role_assignment" "dns-contributor" {
scope = data.azurerm_dns_zone.zone.id
role_definition_name = "Contributor"
principal_id = azurerm_user_assigned_identity.externaldns.principal_id
}
3 changes: 3 additions & 0 deletions existing/terraform/azure/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "externaldns_client_id" {
value = azurerm_user_assigned_identity.externaldns.client_id
}
4 changes: 4 additions & 0 deletions existing/terraform/azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ variable "cluster_name" {

variable "resource_group" {
type = string
}

variable "dns_zone_name" {
type = string
}
55 changes: 0 additions & 55 deletions existing/terraform/azure/versions.tf

This file was deleted.

22 changes: 22 additions & 0 deletions existing/terraform/azure/workload_identity.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data "azurerm_kubernetes_cluster" "cluster" {
name = var.cluster_name
resource_group_name = var.resource_group
}

resource "azurerm_federated_identity_credential" "externaldns" {
name = "fc-externaldns"
resource_group_name = var.resource_group
audience = ["api://AzureADTokenExchange"]
issuer = data.azurerm_kubernetes_cluster.cluster.oidc_issuer_url
parent_id = azurerm_user_assigned_identity.externaldns.id
subject = "system:serviceaccount:externaldns:externaldns"
}

resource "azurerm_federated_identity_credential" "certmanager" {
name = "fc-cert-manager"
resource_group_name = var.resource_group
audience = ["api://AzureADTokenExchange"]
issuer = data.azurerm_kubernetes_cluster.cluster.oidc_issuer_url
parent_id = azurerm_user_assigned_identity.externaldns.id
subject = "system:serviceaccount:cert-manager:cert-manager"
}
184 changes: 184 additions & 0 deletions existing/test/azure/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions existing/test/azure/cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "mgmt" {
source = "../../../terraform/clouds/azure"

cluster_name = "plural-existing-test"
network_name = "plural-existing-test"
location = "eastus"
db_name = "plural-existing-test"

postgres_dns_zone = "plrl-test.postgres.database.azure.com"
network_link_name = "plrl-test.postgres.com"

workload_identity_enabled = true
}
8 changes: 8 additions & 0 deletions existing/test/azure/externaldns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "externaldns" {
source = "../../terraform/azure"
cluster_name = module.mgmt.cluster.aks_name
resource_group = "plural"
dns_zone_name = "az.plural.sh"

depends_on = [ module.mgmt.cluster, module.mgmt.db_url ]
}
8 changes: 8 additions & 0 deletions existing/test/azure/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output "identity_client_id" {
value = module.externaldns.externaldns_client_id
}

output "db_url" {
value = module.mgmt.db_url
sensitive = true
}
Loading

0 comments on commit d2f925e

Please sign in to comment.