Skip to content

Commit

Permalink
feat: add second example
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenmartius committed Nov 12, 2024
1 parent 0374785 commit d63d711
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 8 deletions.
1 change: 0 additions & 1 deletion 01_example_outputs/aks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ provider "azurerm" {
resource "azurerm_resource_group" "main" {
name = "${var.environment}-aks-env-out"
location = var.location

}

resource "random_id" "name" {
Expand Down
40 changes: 40 additions & 0 deletions 02_example_data_sources/network/aks/flux/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
provider "azurerm" {
features {}
}

data "terraform_remote_state" "cluster" {
backend = "local"

config = {
path = "../terraform.tfstate"
}

depends_on = [null_resource.deployment_trigger]
}

# data "azurerm_kubernetes_cluster" "cluster" {
# name = "dev2-aks-cluster-aks"
# resource_group_name = "${var.environment}-aks-env-out"

# depends_on = [null_resource.deployment_trigger]
# }

resource "null_resource" "deployment_trigger" {}

provider "helm" {
kubernetes {
host = "https://${data.terraform_remote_state.cluster.outputs.host}"
client_certificate = base64decode(data.terraform_remote_state.cluster.outputs.client_certificate)
client_key = base64decode(data.terraform_remote_state.cluster.outputs.client_key)
cluster_ca_certificate = base64decode(data.terraform_remote_state.cluster.outputs.cluster_ca_certificate)
}
}

resource "helm_release" "flux" {
repository = "https://fluxcd-community.github.io/helm-charts"
chart = "flux2"
name = "flux2"
namespace = "flux-system"
create_namespace = true

}
Empty file.
5 changes: 5 additions & 0 deletions 02_example_data_sources/network/aks/flux/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stack {
name = "02_flux"
description = "Flux Controller deployed via Helm in Kubernetes"
id = "2ac5c655-b876-44dd-8ab7-137d07e67097"
}
12 changes: 12 additions & 0 deletions 02_example_data_sources/network/aks/flux/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
helm = {
source = "hashicorp/helm"
version = "~>2.0"
}
}
}
5 changes: 5 additions & 0 deletions 02_example_data_sources/network/aks/flux/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "environment" {
type = string
description = "Environment to deploy (dev, test, prod)."
default = "dev2"
}
75 changes: 75 additions & 0 deletions 02_example_data_sources/network/aks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "main" {
name = "${var.environment}-aks-env-out"
location = var.location

}

resource "random_id" "name" {
byte_length = 8
}

# data "azurerm_virtual_network" "network" {
# name = "${var.environment}-env-out"
# resource_group_name = "${var.environment}-env-out"

# depends_on = [null_resource.deployment_trigger]
# }

data "terraform_remote_state" "vpc" {
backend = "local"

config = {
path = "../terraform.tfstate"
}

depends_on = [null_resource.deployment_trigger]
}

resource "null_resource" "deployment_trigger" {}

module "cluster" {
source = "Azure/aks/azurerm"
version = "8.0.0"

# Cluster base config
resource_group_name = azurerm_resource_group.main.name
prefix = "dev2-aks-cluster"
sku_tier = "Standard"
node_os_channel_upgrade = "NodeImage"

# Cluster system pool
agents_availability_zones = [1, 2, 3]
enable_auto_scaling = true
agents_max_count = 4
agents_min_count = 3

# Cluster networking
# vnet_subnet_id = var.vnet_subnet_id
vnet_subnet_id = data.terraform_remote_state.vpc.outputs.aks_subnet_id
network_plugin = "azure"

# Cluster node pools
node_pools = {
nodepool1 = {
name = "pool1"
vm_size = "Standard_DS3_v2"
enable_auto_scaling = true
max_count = 4
min_count = 1
# vnet_subnet_id = var.vnet_subnet_id
vnet_subnet_id = data.terraform_remote_state.vpc.outputs.aks_subnet_id
zones = [1, 2, 3]
}
}

# Cluster Authentication
role_based_access_control_enabled = true
rbac_aad = false

depends_on = [azurerm_resource_group.main]
}

19 changes: 19 additions & 0 deletions 02_example_data_sources/network/aks/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "host" {
value = module.cluster.cluster_fqdn
sensitive = false
}

output "client_certificate" {
value = module.cluster.client_certificate
sensitive = true
}

output "client_key" {
value = module.cluster.client_key
sensitive = true
}

output "cluster_ca_certificate" {
value = module.cluster.cluster_ca_certificate
sensitive = true
}
5 changes: 5 additions & 0 deletions 02_example_data_sources/network/aks/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stack {
name = "02_aks"
description = "Managed Kubernetes cluster on Azure"
id = "5d97b4f1-4e0a-4831-8ea8-ad2d1b90f7b5"
}
16 changes: 16 additions & 0 deletions 02_example_data_sources/network/aks/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "location" {
type = string
description = "Azure region to use."
default = "eastus"
}

variable "environment" {
type = string
description = "Environment to deploy (dev, test, prod)."
default = "dev2"
}

# variable "vnet_subnet_id" {
# type = string
# description = "ID of the subnet to deploy the AKS cluster into."
# }
23 changes: 23 additions & 0 deletions 02_example_data_sources/network/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
provider "azurerm" {
features {}

}

resource "azurerm_resource_group" "main" {
name = "${var.environment}-env-out"
location = var.location
}

module "network" {
source = "Azure/vnet/azurerm"
version = "4.1.0"

resource_group_name = azurerm_resource_group.main.name
vnet_location = azurerm_resource_group.main.location
vnet_name = azurerm_resource_group.main.name
use_for_each = true
address_space = [var.cidr]

subnet_names = keys(var.subnet_prefixes)
subnet_prefixes = values(var.subnet_prefixes)
}
19 changes: 19 additions & 0 deletions 02_example_data_sources/network/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "subnet_ids" {
description = "Map of subnet names to IDs."
value = module.network.vnet_subnets_name_id
}

output "aks_subnet_id" {
description = "ID of the subnet to deploy the AKS cluster into."
value = module.network.vnet_subnets_name_id["aks"]
}

output "vnet_id" {
description = "VNet ID."
value = module.network.vnet_id
}

output "environment" {
description = "Environment used for deployment"
value = var.environment
}
5 changes: 5 additions & 0 deletions 02_example_data_sources/network/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stack {
name = "02_network"
description = "Main VPC managed on Azure"
id = "5999e860-86d6-49b6-aa18-c91df7586483"
}
8 changes: 8 additions & 0 deletions 02_example_data_sources/network/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
}
26 changes: 26 additions & 0 deletions 02_example_data_sources/network/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
variable "location" {
type = string
description = "Azure region to use."
default = "eastus"
}

variable "environment" {
type = string
description = "Environment to deploy (dev, test, prod)."
default = "dev2"
}

variable "cidr" {
type = string
description = "CIDR block for the virtual network."
default = "10.10.0.0/16"
}

variable "subnet_prefixes" {
type = map(string)
description = "Map of CIDR blocks for the subnets."

default = {
aks = "10.10.0.0/24"
}
}
Loading

0 comments on commit d63d711

Please sign in to comment.