Skip to main content

Cloud

Create/Deploy Azure Kubernetes Service (AKS) Using Terraform Cloud Workspaces

Istock 1315109884

Objective

Automate the deployment of Azure Kubernetes Service (AKS) using Terraform Cloud Workspaces. This ensures Infrastructure as Code (IaC) is centrally managed, and all changes are traceable.


1. Set Up a Terraform Cloud Workspace Free Account

Step 1: Create a Terraform Cloud Account

  1. Navigate to https://developer.hashicorp.com/sign-up.
  2. Sign up or log in with a valid email ID.

Ss1

Step 2: Create an Organization

  1. After logging in, create an organization (if one doesn’t already exist):
    a. Go to Organizations > Create Organization.
    b. Provide a name for the organization.

              Ss2

Step 3: Create a Workspace

  1. Navigate to Workspaces:
    a. Go to your organization dashboard.
    b. Click on Workspaces > Create a New Workspace.

               Ss3

       2. Select a Workflow: Terraform Cloud offers three workflows:

            a. CLI-Driven Workflow: Ideal for local Terraform runs but stores state in Terraform Cloud.

2. Download and Install Azure CLI and Terraform

Step 1: Install Azure CLI

  1. Visit https://learn.microsoft.com/en-us/cli/azure/install-azure-cli.
  2. Download and install the CLI on your system.

Step 2: Install Terraform

  1. Go to https://releases.hashicorp.com/terraform/.
  2. Download the Terraform version that matches your system configuration.

3. Integration/Login from Local to Terraform Cloud

Step 1: Set Up Terraform Manifest Files

  1. Create a working directory.
  2. Within it, set up the root folder for the main module and child modules with provider configurations.

Step 2: Authenticate with Terraform Cloud

  1. Open the terminal in VS Code and run: “terraform login”
  2. Approve the request by entering yes.

          Ss4

       3. Generate and paste the API token:

            a. Navigate to Account Settings > Tokens > Create API Token.

            b. Copy the generated token (visible only once).

            c. Paste the token into the terminal.

                Ss5

Step 3: Initialize Terraform

  1. Run the terraform init command to download Azure provider plugins.
  2. While initializing, select the appropriate workspace name.
  3. Verify successful initialization with the message:
    “Terraform has been successfully initialized.”

4. Add Variables to Terraform Cloud Workspace

  1. Select your workspace and navigate to the Variables section.
  2. Add the required Azure variables:
    • Client ID
    • Client Secret
    • Subscription ID
    • Tenant ID

           Ss6

5. Develop Terraform Code

Step 1: Resource Group, VNet, and Subnet

Write Terraform scripts for creating:

  1. Resource Group (RG).
  2. Virtual Network (VNet).
  3. Subnet.

Step 2: Azure Kubernetes Service (AKS)

Write Terraform scripts for provisioning AKS.

Step 3: Test and Validate

Ensure the Terraform code is correct by running terraform plan.

6. Deploy Resources to Azure Cloud

Deployment Steps

  1. Run terraform init to initialize plugins and modules. and select the workspace name.

           Ss7

       2. Run terraform plan to preview the deployment.

          Ss8

        3.Run terraform apply to deploy the resources based on the plan output.

            Ss9

 

Post-Deployment

  1. Check the Run Logs in the Terraform Cloud Workspace for detailed insights.
  2. Verify the resources in the Azure Portal.

           Ss10

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sunil Talluri

Sunil is a Technical Consultant with expertise spanning DevOps and Cloud, specializing in Azure DevOps, Azure Cloud, and Terraform. Additionally, he knows AWS Cloud.

More from this Author

Categories
Follow Us