Skip to content

Commit

Permalink
Terraform: AKS cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
blastomussa committed Sep 10, 2022
1 parent 447614b commit fbc5487
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ tests/*
/test.py

# terraform
terraform/variables.tf
*/.terraform*
*/terraform.*
terraform.tfvars
terraform.*
*.terraform.*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
Empty file removed kubernetes.tf
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ terraform {
}
}

resource "random_pet" "prefix" {}

# Azure Resource Manager provider
provider "azurerm" {
features {}
Expand Down Expand Up @@ -39,8 +41,4 @@ resource "azurerm_kubernetes_cluster" "k8s" {
}

role_based_access_control_enabled = true

tags = {
environment = "Demo"
}
}
37 changes: 37 additions & 0 deletions terraform/kubernetes/cluster/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "kubernetes_cluster_name" {
value = azurerm_kubernetes_cluster.k8s.name
}

output "host" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.host
sensitive = true
}

output "client_key" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key
sensitive = true
}

output "client_certificate" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate
sensitive = true
}

output "kube_config" {
value = azurerm_kubernetes_cluster.k8s.kube_config_raw
sensitive = true
}

output "cluster_username" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.username
sensitive = true
}

output "cluster_password" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.password
sensitive = true
}
19 changes: 19 additions & 0 deletions terraform/kubernetes/cluster/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "appId" {
description = "Azure Kubernetes Service Cluster service principal"
}

variable "password" {
description = "Azure Kubernetes Service Cluster password"
}

variable "subscription_id" {
default = "397b1839-a1f6-41ec-8b40-b97cf5258c0f"
}

variable "resource_group_name" {
default = "k8s-RG"
}

variable "resource_group_location" {
default = "eastus"
}
29 changes: 29 additions & 0 deletions terraform/kubernetes/resources/kubernetes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider?in=terraform/kubernetes
# https://github.com/hashicorp/learn-terraform-deploy-nginx-kubernetes-provider/blob/aks/kubernetes.tf
# how do I deploy custom docker image via Azure Container Registry; service principal?

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.0.2"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.1"
}
}
}

data "terraform_remote_state" "aks" {
backend = "local"

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

# Retrieve AKS cluster information
provider "azurerm" {
features {}
}
7 changes: 3 additions & 4 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ resource "azurerm_subnet" "frontend" {
delegation {
name = "delegation"

service_delegation { //Container Instance REQUIRES delegation
service_delegation { //Container Instance REQUIRES delegation
name = "Microsoft.ContainerInstance/containerGroups"
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
}
Expand Down Expand Up @@ -292,7 +292,6 @@ resource "azurerm_cosmosdb_mongo_collection" "coll" {
account_name = azurerm_cosmosdb_account.acc.name
database_name = azurerm_cosmosdb_mongo_database.mongodb.name
default_ttl_seconds = "777"
shard_key = "uniqueKey"
throughput = 400
index {
keys = ["_id"]
Expand All @@ -301,7 +300,7 @@ resource "azurerm_cosmosdb_mongo_collection" "coll" {
depends_on = [azurerm_cosmosdb_mongo_database.mongodb]
}


# Image name needs to be dynamic
# Azure Container Instance
resource "azurerm_container_group" "frontend" {
name = var.aci_name
Expand All @@ -320,7 +319,7 @@ resource "azurerm_container_group" "frontend" {

container {
name = "frontend-app"
image = "testcontainer12359.azurecr.io/frontend:ca1" # THIS NEEDS TO BE DYNAMIC!!!!!!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
image = "testcontainer12359.azurecr.io/frontend:ca2" # THIS NEEDS TO BE DYNAMIC!!!!!!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FIX THIS
cpu = "0.5"
memory = "1.5"

Expand Down
14 changes: 7 additions & 7 deletions terraform/variables.tf.example → terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
variable "subscription_id" {
default = "****************************"
description = "Subscription ID of Azure Tenant"
}

variable "github_pat" {
description = "Github PAT scoped for access to public repos and repo status"
}

variable "resource_group_name" {
Expand All @@ -19,21 +23,17 @@ variable "cosmos_db_database_name" {
}

variable "cosmos_db_collection_name" {
default = "test-collection"
default = "test_collection"
}

variable "container_registry_name" {
default = "testcontainer12359"
}

variable "github_pat" {
default = "***************************"
}

variable "vnet_name" {
default = "test-vnet"
}

variable "aci_name" {
default = "frontend_test"
default = "frontend-app"
}
7 changes: 0 additions & 7 deletions variables.tf

This file was deleted.

0 comments on commit fbc5487

Please sign in to comment.