Skip to content

Commit

Permalink
Merge pull request #202 from Azure/mtms
Browse files Browse the repository at this point in the history
Mtms
  • Loading branch information
arnaudlh committed Jun 23, 2021
2 parents b7f063a + 052cee1 commit 7ffdab4
Show file tree
Hide file tree
Showing 97 changed files with 2,961 additions and 215 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
**/*.log
**/backend.azurerm.tf
public
aztfmod
aztfmod
*output.json
26 changes: 17 additions & 9 deletions caf_launchpad/landingzone.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
module "launchpad" {
source = "aztfmod/caf/azurerm"
version = "~>5.3.2"
# source = "aztfmod/caf/azurerm"
# version = "~>5.3.2"

# source = "git::https://github.com/aztfmod/terraform-azurerm-caf.git?ref=master"
source = "git::https://github.com/aztfmod/terraform-azurerm-caf.git?ref=mtms"
# source = "../../aztfmod"

# azuread = var.azuread
azuread_api_permissions = var.azuread_api_permissions
azuread_apps = var.azuread_apps
azuread_groups = var.azuread_groups
azuread_roles = var.azuread_roles
azuread_users = var.azuread_users
current_landingzone_key = var.landingzone.key
custom_role_definitions = var.custom_role_definitions
enable = var.enable
Expand All @@ -22,6 +17,7 @@ module "launchpad" {
logged_aad_app_objectId = var.logged_aad_app_objectId
logged_user_objectId = var.logged_user_objectId
managed_identities = var.managed_identities
remote_objects = local.remote
resource_groups = var.resource_groups
role_mapping = var.role_mapping
storage_accounts = var.storage_accounts
Expand All @@ -30,6 +26,18 @@ module "launchpad" {
tenant_id = var.tenant_id
user_type = var.user_type

azuread = {
azuread_api_permissions = var.azuread_api_permissions
azuread_applications = var.azuread_applications
azuread_apps = var.azuread_apps
azuread_credential_policies = var.azuread_credential_policies
azuread_groups = var.azuread_groups
azuread_roles = var.azuread_roles
azuread_service_principal_passwords = var.azuread_service_principal_passwords
azuread_service_principals = var.azuread_service_principals
azuread_users = var.azuread_users
}

diagnostics = {
diagnostics_definition = try(var.diagnostics.diagnostics_definition, var.diagnostics_definition)
diagnostics_destinations = try(var.diagnostics.diagnostics_destinations, var.diagnostics_destinations)
Expand Down
7 changes: 7 additions & 0 deletions caf_launchpad/local.remote.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
locals {
remote = {
azuread_service_principals = {
for key, value in try(var.landingzone.tfstates, {}) : key => merge(try(data.terraform_remote_state.remote[key].outputs.objects[key].azuread_service_principals, {}))
}
}
}
36 changes: 36 additions & 0 deletions caf_launchpad/locals.remote_tfstates.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
locals {
landingzone = {
current = {
storage_account_name = var.tfstate_storage_account_name
container_name = var.tfstate_container_name
resource_group_name = var.tfstate_resource_group_name
}
}
}

data "terraform_remote_state" "remote" {
for_each = try(var.landingzone.tfstates, {})

backend = var.landingzone.backend_type
config = local.remote_state[try(each.value.backend_type, var.landingzone.backend_type, "azurerm")][each.key]
}

locals {

remote_state = {

azurerm = {
for key, value in try(var.landingzone.tfstates, {}) : key => {
container_name = value.workspace
key = value.tfstate
resource_group_name = value.resource_group_name
storage_account_name = value.storage_account_name
subscription_id = value.subscription_id
tenant_id = value.tenant_id
sas_token = try(value.sas_token, null) != null ? var.sas_token : null
}
}

}

}
17 changes: 17 additions & 0 deletions caf_launchpad/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ variable "tenant_id" {}
variable "landingzone" {
description = "The landing zone name is used to reference the tfstate in configuration files. Therefore while set it is recommended not to change"
}
variable "sas_token" {
description = "SAS Token to access the remote state in another Azure AD tenant."
default = null
}

variable "passthrough" {
default = false
Expand Down Expand Up @@ -100,6 +104,15 @@ variable "azuread_users" {
variable "azuread_roles" {
default = {}
}
variable "azuread_credential_policies" {
default = {}
}
variable "azuread_service_principals" {
default = {}
}
variable "azuread_service_principal_passwords" {
default = {}
}
variable "managed_identities" {
default = {}
}
Expand Down Expand Up @@ -152,6 +165,10 @@ variable "azuread_api_permissions" {
default = {}
}

variable "azuread_applications" {
default = {}
}

variable "environment" {
type = string
description = "This variable is set by the rover during the deployment based on the -env or -environment flags. Default to sandpit"
Expand Down
5 changes: 4 additions & 1 deletion caf_solution/add-ons/aad-pod-identity/aad-msi-binding.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# https://github.com/Azure/aad-pod-identity/blob/b3ee1d07209f26c47a96abf3ba20749932763de6/website/content/en/docs/Concepts/azureidentity.md

apiVersion: aadpodidentity.k8s.io/v1
kind: AzureIdentity
metadata:
Expand All @@ -13,4 +15,5 @@ metadata:
name: podmi-gitlab-runner-binding
spec:
azureIdentity: podmi-caf-rover-platform-level0
selector: podmi-caf-rover-platform-level0
selector: podmi-caf-rover-platform-level0

2 changes: 2 additions & 0 deletions caf_solution/add-ons/aad-pod-identity/aad_pod_identity.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# https://github.com/Azure/aad-pod-identity/blob/b3ee1d07209f26c47a96abf3ba20749932763de6/website/content/en/docs/Concepts/azureidentity.md

resource "kubernetes_namespace" "ns" {
metadata {
name = var.aad_pod_identity.namespace
Expand Down
2 changes: 1 addition & 1 deletion caf_solution/add-ons/aad-pod-identity/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ variable "lower_container_name" {}
variable "lower_resource_group_name" {}

variable "tfstate_subscription_id" {
description = "This value is propulated by the rover. subscription id hosting the remote tfstates"
description = "This value is populated by the rover. subscription id hosting the remote tfstates"
}
variable "tfstate_storage_account_name" {}
variable "tfstate_container_name" {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ locals {
) : format("%s-%s", msi.key, msi.msi_key) => msi
}
}

resource "azurerm_key_vault_access_policy" "keyvault_policy" {
# provider = azurerm.launchpad
for_each = var.keyvaults

key_vault_id = local.remote.keyvaults[each.value.lz_key][each.value.key].id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = local.remote.aks_clusters[var.aks_clusters[var.aks_cluster_key].lz_key][var.aks_clusters[var.aks_cluster_key].key].kubelet_identity[0].object_id
secret_permissions = each.value.secret_permissions
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ locals {
aks_clusters = {
for key, value in try(var.landingzone.tfstates, {}) : key => merge(try(data.terraform_remote_state.remote[key].outputs.objects[key].aks_clusters, {}))
}
keyvaults = {
for key, value in try(var.landingzone.tfstates, {}) : key => merge(try(data.terraform_remote_state.remote[key].outputs.objects[key].keyvaults, {}))
}
managed_identities = {
for key, value in try(var.landingzone.tfstates, {}) : key => merge(try(data.terraform_remote_state.remote[key].outputs.objects[key].managed_identities, {}))
}
Expand Down
9 changes: 9 additions & 0 deletions caf_solution/add-ons/aks-secure-baseline/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ provider "azurerm" {
}
}

provider "azurerm" {
alias = "launchpad"
subscription_id = var.tfstate_subscription_id
features {
}
}

provider "kubernetes" {
host = local.k8sconfigs[var.aks_cluster_key].host
username = local.k8sconfigs[var.aks_cluster_key].username
Expand Down Expand Up @@ -31,6 +38,8 @@ locals {
}
}

data "azurerm_client_config" "current" {}

# Get kubeconfig from AKS clusters
data "azurerm_kubernetes_cluster" "kubeconfig" {
for_each = var.aks_clusters
Expand Down
5 changes: 4 additions & 1 deletion caf_solution/add-ons/aks-secure-baseline/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ variable "managed_identities" {
description = "Map of the user managed identities."
}

variable "aad_pod_identity" {}
variable "aad_pod_identity" {}
variable "keyvaults" {
default = {}
}
20 changes: 13 additions & 7 deletions caf_solution/add-ons/aks_applications/app/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
provider "kubernetes" {
alias = "k8s"
}

provider "helm" {
alias = "helm"
}
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
}
helm = {
source = "hashicorp/helm"
}
kustomization = {
source = "kbst/kustomization"
}
}
}
5 changes: 2 additions & 3 deletions caf_solution/add-ons/aks_applications/app/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ resource "kubernetes_namespace" "namespaces" {
name = each.value.name
}

provider = kubernetes.k8s
}

# https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release
Expand All @@ -22,6 +21,7 @@ resource "helm_release" "charts" {
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)

dynamic "set" {
for_each = try(each.value.sets, {})
Expand All @@ -39,9 +39,8 @@ resource "helm_release" "charts" {
}
}

provider = helm.helm

depends_on = [kubernetes_namespace.namespaces]
# depends_on = [kubernetes_namespace.namespaces]
# values = [
# "${file("values.yaml")}"
# ]
Expand Down
12 changes: 9 additions & 3 deletions caf_solution/add-ons/aks_applications/app/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
variable "cluster" {}
variable "namespaces" {
default = {}
}

variable "namespaces" {}
variable "helm_charts" {
default = {}
}

variable "helm_charts" {}
variable "kuztomization_settings" {
default = {}
}
24 changes: 1 addition & 23 deletions caf_solution/add-ons/aks_applications/applications.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
module "app1" {
module "app" {
source = "./app"
for_each = try(local.clusters[var.cluster_re1_key], null) != null ? { (var.cluster_re1_key) = local.clusters[var.cluster_re1_key] } : {}

cluster = each.value
namespaces = var.namespaces
helm_charts = var.helm_charts

providers = {
kubernetes.k8s = kubernetes.k8s1
helm.helm = helm.helm1
}
}

module "app2" {
source = "./app"
for_each = try(local.clusters[var.cluster_re2_key], null) != null ? { (var.cluster_re2_key) = local.clusters[var.cluster_re2_key] } : {}

cluster = each.value
namespaces = var.namespaces
helm_charts = var.helm_charts

providers = {
kubernetes.k8s = kubernetes.k8s2
helm.helm = helm.helm2
}
}
31 changes: 31 additions & 0 deletions caf_solution/add-ons/aks_applications/kustomization.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module "kustomization" {
source = "./kustomize"
for_each = try(data.kustomization_overlay.manifest, {})

settings = each.value

}

data "kustomization_overlay" "manifest" {
for_each = var.kustomization_overlays

resources = each.value.resources

namespace = each.value.namespace

dynamic "patches"{
for_each = try(each.value.patches, {})
content {
patch = patches.value.patch
target = patches.value.target
}
}
kustomize_options = {
load_restrictor = "none"
}
}

output "manifests" {
value = data.kustomization_overlay.manifest
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "kustomization_resource" "p0" {
for_each = var.settings.ids_prio[0]
manifest = var.settings.manifests[each.value]
}

resource "kustomization_resource" "p1" {
depends_on = [kustomization_resource.p0]
for_each = var.settings.ids_prio[1]
manifest = var.settings.manifests[each.value]
}

resource "kustomization_resource" "p2" {
depends_on = [kustomization_resource.p1]
for_each = var.settings.ids_prio[2]
manifest = var.settings.manifests[each.value]
}
7 changes: 7 additions & 0 deletions caf_solution/add-ons/aks_applications/kustomize/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
kustomization = {
source = "kbst/kustomization"
}
}
}
2 changes: 2 additions & 0 deletions caf_solution/add-ons/aks_applications/kustomize/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
variable "settings" {
}
Loading

0 comments on commit 7ffdab4

Please sign in to comment.