{"id":22260953,"url":"https://github.com/piyushsachdeva/terraform_aks","last_synced_at":"2025-04-11T17:32:29.557Z","repository":{"id":164693885,"uuid":"564609619","full_name":"piyushsachdeva/Terraform_AKS","owner":"piyushsachdeva","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-22T09:19:51.000Z","size":18,"stargazers_count":38,"open_issues_count":0,"forks_count":118,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T13:47:18.671Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piyushsachdeva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-11T04:33:17.000Z","updated_at":"2025-02-18T09:42:33.000Z","dependencies_parsed_at":"2023-06-03T12:30:11.146Z","dependency_job_id":null,"html_url":"https://github.com/piyushsachdeva/Terraform_AKS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyushsachdeva%2FTerraform_AKS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyushsachdeva%2FTerraform_AKS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyushsachdeva%2FTerraform_AKS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyushsachdeva%2FTerraform_AKS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piyushsachdeva","download_url":"https://codeload.github.com/piyushsachdeva/Terraform_AKS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449936,"owners_count":21105587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T09:10:56.359Z","updated_at":"2025-04-11T17:32:29.538Z","avatar_url":"https://github.com/piyushsachdeva.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Provision AKS cluster using Terraform via Service Principal\n\nIn this project, we will be creating AKS cluster the right way by using service principle.kubeconfig and service principle will be generated after the terraform plan and secret will be upload to keyvault to be used further.\n\n## Below resources will be created using this terraform configuration:-\n- Resource Group\n- Service Principle\n- AKS cluster using the SPN\n- Azure key vault to store the client secret\n- Secret uploaded to key vault\n- kubeconfig for AKS\n\n\n## Pre-requisites\n\n- kubectl cli installed\n- Azure CLI installed and logged in\n- Storage Account and blob container created to store the tfstate file as backend, you can use below shell script as well\n\n``` shell\n#!/bin/bash\n\nRESOURCE_GROUP_NAME=backend-rg\nSTORAGE_ACCOUNT_NAME=backendsa101\nCONTAINER_NAME=tfstate\n\n# Create resource group\naz group create --name $RESOURCE_GROUP_NAME --location canadacentral\n\n# Create storage account\naz storage account create --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME --sku Standard_LRS --encryption-services blob\n\n# Create blob container\naz storage container create --name $CONTAINER_NAME --account-name $STORAGE_ACCOUNT_NAME\n```\n\n\n## Usage/Examples\n\n### 1) login to the CLI\n```shell\naz login --use-device-code\n```\n### 2) set alias\n```shell\nalias tf=terraform\n```\n### 3) initialize the providers\n```shell\ntf init\n```\n### 4) Run the plan\n```shell\ntf plan\n```\n### 5) Apply the changes\n```shell\ntf apply --auto-approve\n```\n\n\n\n\n## Some common Errors\n\n#### Error1:-\n``` shell\nError: creating Cluster: (Managed Cluster Name \n\"clusternew-aks-cluster\" / Resource Group \"rgname\"): \ncontainerservice.ManagedClustersClient#CreateOrUpdate: \nFailure sending request: StatusCode=404 -- Original Error: \nCode=\"ServicePrincipalNotFound\" Message=\"Service principal \nclientID: xxxx-xxxxx-xxxx-xxxxx not found in Active Directory\n tenant xxxx-xxxxx-xxxx-xxxxx, Please see https://aka.ms/\n aks-sp-help for more details.\"\n```\n#### Resolution:-\nRerun the tf apply command, this could be a bug in the \nparticular provider version. Running the command again \nresolves the issue.\n\n\n#### Error2:-\n``` shell\nError: checking for presence of existing Secret \n\"xxxx-xxxxx-xxxx-xxxxx\" (Key Vault \"https://keyvaultname.\nvault.azure.net/\"): keyvault.BaseClient#GetSecret: Failure \nresponding to request: StatusCode=403 -- Original Error: \nautorest/azure: Service returned an error. Status=403 \nCode=\"Forbidden\" Message=\"Caller is not authorized to perform\n action on resource.\\r\\nIf role assignments, deny assignments\n  or role definitions were changed recently, InnerError=\n  {\"code\":\"ForbiddenByRbac\"}\n  \n  on main.tf line 46, in resource \"azurerm_key_vault_secret\"\n   \"example\":      \n  46: resource \"azurerm_key_vault_secret\" \"example\" {\n```\n\n#### Resolution:-\nUser should have keyvault admin role even if the user has owner role.\n\n## Video reference\n\nCheckout the below video for complete hands-on demo of this project\n\n[![AKS Cluster using Terraform](https://i9.ytimg.com/vi_webp/I-MbnfNcikk/mqdefault.webp?v=63443239\u0026sqp=CLjds6MG\u0026rs=AOn4CLAhbOYDv2--Gi37A6TWX3ZjFof4kQ)](https://youtu.be/I-MbnfNcikk)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyushsachdeva%2Fterraform_aks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiyushsachdeva%2Fterraform_aks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyushsachdeva%2Fterraform_aks/lists"}