Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth for ACR to aks_applications #351

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 32 additions & 11 deletions caf_solution/add-ons/aks_applications/app/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,42 @@ resource "kubernetes_namespace" "namespaces" {

}

# https://docs.microsoft.com/en-us/azure/container-registry/container-registry-helm-repos#authenticate-with-the-registry
data "external" "password" {
for_each = {
for key, value in var.helm_charts : key => value
if try(value.azure_container_registry, null) != null
}

program = [
"bash", "-cx",
format(
"az acr login --name %s --expose-token --output json --query '{value: accessToken}'",
var.azure_container_registries[each.value.azure_container_registry.lz_key][each.value.azure_container_registry.key].name
)
]
}

# https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release
resource "helm_release" "charts" {
for_each = var.helm_charts

name = each.value.name
repository = each.value.repository
chart = each.value.chart

namespace = each.value.namespace
wait = try(each.value.wait, true)
timeout = try(each.value.timeout, 900)
skip_crds = try(each.value.skip_crds, false)
create_namespace = try(each.value.create_namespace, false)
values = try(each.value.values, null)
version = try(each.value.version, null)
name = each.value.name
chart = each.value.chart
namespace = each.value.namespace
wait = try(each.value.wait, true)
timeout = try(each.value.timeout, 900)
skip_crds = try(each.value.skip_crds, false)
create_namespace = try(each.value.create_namespace, false)
values = try(each.value.values, null)
version = try(each.value.version, null)
repository_username = try(each.value.azure_container_registry.username, null)
repository_password = try(data.external.password[each.key].result.value, null)
repository = try(
each.value.repository,
format("oci://%s", var.azure_container_registries[each.value.azure_container_registry.lz_key][each.value.azure_container_registry.key].login_server),
null
)

dynamic "set" {
for_each = try(each.value.sets, {})
Expand Down
4 changes: 4 additions & 0 deletions caf_solution/add-ons/aks_applications/app/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ variable "helm_charts" {
variable "kuztomization_settings" {
default = {}
}

variable "azure_container_registries" {
default = {}
}
7 changes: 4 additions & 3 deletions caf_solution/add-ons/aks_applications/applications.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "app" {
source = "./app"
namespaces = var.namespaces
helm_charts = var.helm_charts
source = "./app"
namespaces = var.namespaces
helm_charts = var.helm_charts
azure_container_registries = local.remote.azure_container_registries
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ locals {
vnets = {
for key, value in try(var.landingzone.tfstates, {}) : key => merge(try(data.terraform_remote_state.remote[key].outputs.objects[key].vnets, {}))
}
azure_container_registries = {
for key, value in try(var.landingzone.tfstates, {}) : key => merge(try(data.terraform_remote_state.remote[key].outputs.objects[key].azure_container_registries, {}))
}
}

}
}
4 changes: 2 additions & 2 deletions caf_solution/add-ons/aks_applications/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ terraform {
}
helm = {
source = "hashicorp/helm"
version = "~> 2.1.2"
version = "~> 2.5.0"
}
kustomization = {
source = "kbst/kustomization"
version = "~> 0.5.0"
}
}
required_version = ">= 0.13"
}
}