Skip to content

Commit 780fa64

Browse files
committed
added command to check managed identity of akscluster
1 parent 080fd27 commit 780fa64

File tree

6 files changed

+90
-23
lines changed

6 files changed

+90
-23
lines changed

.github/workflows/deploy.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,27 @@ jobs:
3333
echo "AKS_VERSION=1.32.0" >> $GITHUB_ENV
3434
echo "Variables set successfully."
3535
36+
# - name: Set up Azure CLI with owner subscription
37+
# uses: azure/login@v1
38+
# with:
39+
# creds: |
40+
# {
41+
# "clientId": "${{ secrets.AZURE_CLIENT_ID }}",
42+
# "clientSecret": "${{ secrets.AZURE_CLIENT_SECRET }}",
43+
# "subscriptionId": "${{ secrets.AZURE_SUBSCRIPTION_ID }}",
44+
# "tenantId": "${{ secrets.AZURE_TENANT_ID }}"
45+
# }
46+
3647
# Checkout the code
3748
- name: Checkout code
3849
uses: actions/checkout@v3
3950

51+
# Install Terraform
52+
- name: Install Terraform
53+
uses: hashicorp/setup-terraform@v2
54+
with:
55+
terraform_version: 1.5.7
56+
4057
# Set up Azure CLI
4158
- name: Set up Azure CLI
4259
uses: azure/login@v1
@@ -136,11 +153,18 @@ jobs:
136153
docker build -t $ACR_NAME.azurecr.io/transaction-processor:latest ./app
137154
docker push $ACR_NAME.azurecr.io/transaction-processor:latest
138155
139-
# Deploy Service Bus Resources
140-
- name: Run Terraform
141-
working-directory: ./terraform
156+
- name: Terraform Init
142157
run: |
143158
terraform init
159+
160+
# Terraform Plan
161+
- name: Terraform Plan
162+
run: |
163+
terraform plan
164+
165+
# Terraform Apply
166+
- name: Terraform Apply
167+
run: |
144168
terraform apply -auto-approve
145169
146170
# Run Azure CLI scripts for Service Bus setup

scripts/aks-deploy.sh

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
#!/bin/bash
2-
AKS_CLUSTER="MyAKSCluster"
3-
RESOURCE_GROUP="MyResourceGroup"
4-
ACR_NAME="myregistry"
5-
NAMESPACE="transaction-namespace"
62

7-
az aks create --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER --node-count 3 --enable-addons monitoring --generate-ssh-keys
3+
# Use environment variables set in the GitHub workflow
4+
AKS_CLUSTER="${AKS_CLUSTER_NAME:-AKSSivaCluster}"
5+
RESOURCE_GROUP="${RESOURCE_GROUP:-MyResourceGroup}"
6+
ACR_NAME="${ACR_NAME:-akssivarg01}"
7+
NAMESPACE="${NAMESPACE:-transaction-namespace}"
8+
9+
# Get AKS credentials to manage the cluster
10+
echo "Retrieving AKS credentials..."
811
az aks get-credentials --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER
9-
kubectl create namespace $NAMESPACE
10-
kubectl create secret generic servicebus-secrets --from-literal=primary-connection="<primary_connection_string>" --from-literal=secondary-connection="<secondary_connection_string>" -n $NAMESPACE
12+
13+
# Create the namespace if it does not exist
14+
if ! kubectl get namespace $NAMESPACE &> /dev/null; then
15+
echo "Creating namespace: $NAMESPACE"
16+
kubectl create namespace $NAMESPACE
17+
else
18+
echo "Namespace $NAMESPACE already exists."
19+
fi
20+
21+
# Create or update the Kubernetes secret for Service Bus connection strings
22+
echo "Creating or updating secrets in namespace: $NAMESPACE"
23+
kubectl create secret generic servicebus-secrets \
24+
--from-literal=primary-connection="<primary_connection_string>" \
25+
--from-literal=secondary-connection="<secondary_connection_string>" \
26+
-n $NAMESPACE --dry-run=client -o yaml | kubectl apply -f -
27+
28+
# Apply the Kubernetes deployment and service configurations
29+
echo "Deploying application to AKS..."
1130
kubectl apply -f k8s/deployment.yaml -n $NAMESPACE
1231
echo "Application deployed successfully to AKS."

terraform/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Use a lightweight base image with Terraform
22
FROM hashicorp/terraform:1.5.7
33

4-
# Install Azure CLI
4+
# Install Azure CLI and other necessary tools
55
RUN apk update && \
66
apk add --no-cache curl bash jq && \
77
curl -sL https://aka.ms/InstallAzureCLIDeb | bash

terraform/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
terraform:
3+
image: hashicorp/terraform:1.6.2
4+
volumes:
5+
- ./setup:/tf/setup
6+
- ./deploy:/tf/deploy
7+
working_dir: /tf
8+
environment:
9+
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
10+
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
11+
- AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}
12+
- AWS_DEFAULT_REGION=us-east-1
13+
- TF_WORKSPACE=${TF_WORKSPACE}
14+
- TF_VAR_db_password=${TF_VAR_db_password}
15+
- TF_VAR_django_secret_key=${TF_VAR_django_secret_key}
16+
- TF_VAR_ecr_proxy_image=${TF_VAR_ecr_proxy_image}
17+
- TF_VAR_ecr_app_image=${TF_VAR_ecr_app_image}

terraform/main.tf

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,59 @@
1+
# Unified main.tf
2+
13
terraform {
4+
backend "azurerm" {
5+
resource_group_name = "MyResourceGroup"
6+
storage_account_name = "akssiva"
7+
container_name = "tfstate"
8+
key = "terraform.tfstate"
9+
}
210
required_providers {
311
azurerm = {
412
source = "hashicorp/azurerm"
513
version = "3.74.0"
614
}
715
}
8-
required_version = ">= 1.0"
916
}
1017

1118
provider "azurerm" {
1219
features {}
1320
subscription_id = var.subscription_id
1421
}
1522

16-
# Create Resource Group
23+
# Resource Group (already exists, so use import if not in state)
1724
resource "azurerm_resource_group" "example" {
1825
name = var.resource_group_name
1926
location = var.primary_location
2027
tags = var.tags
2128
}
2229

23-
# Create Primary Service Bus Namespace
30+
# Primary Service Bus Namespace
2431
resource "azurerm_servicebus_namespace" "primary" {
2532
name = var.primary_namespace
2633
location = var.primary_location
2734
resource_group_name = azurerm_resource_group.example.name
2835
sku = "Standard"
2936
}
3037

31-
# Create Secondary Service Bus Namespace
38+
# Secondary Service Bus Namespace
3239
resource "azurerm_servicebus_namespace" "secondary" {
3340
name = var.secondary_namespace
3441
location = var.secondary_location
3542
resource_group_name = azurerm_resource_group.example.name
3643
sku = "Standard"
3744
}
3845

39-
# Create Service Bus Queue in Primary Namespace
46+
# Service Bus Queue
4047
resource "azurerm_servicebus_queue" "transaction" {
41-
name = var.queue_name
42-
namespace_id = azurerm_servicebus_namespace.primary.id
48+
name = var.queue_name
49+
namespace_id = azurerm_servicebus_namespace.primary.id
4350
}
4451

45-
# Geo Disaster Recovery Alias
52+
# Geo-Disaster Recovery Alias
4653
resource "azurerm_servicebus_georecovery_alias" "geo_dr" {
47-
name = "TransactionAlias"
48-
resource_group_name = azurerm_resource_group.example.name
49-
namespace_name = azurerm_servicebus_namespace.primary.name
50-
partner_namespace_id = azurerm_servicebus_namespace.secondary.id
54+
name = "TransactionAlias"
55+
resource_group_name = azurerm_resource_group.example.name
56+
namespace_name = azurerm_servicebus_namespace.primary.name
57+
partner_namespace_id = azurerm_servicebus_namespace.secondary.id
5158
requires_manual_failover = true
5259
}
File renamed without changes.

0 commit comments

Comments
 (0)