Skip to content

Commit

Permalink
Added az login
Browse files Browse the repository at this point in the history
  • Loading branch information
Abby Artagame committed Nov 18, 2024
1 parent eeac8bf commit f642a6c
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,10 @@ resource "null_resource" "build_image_template" {
}
provisioner "local-exec" {
command = <<EOT
# Variables for Service Principal authentication
CLIENT_ID="${var.clientId}"
TENANT_ID="${var.tenantId}"
CLIENT_SECRET="${var.clientSecret}"
# Variables for Image Builder
IMAGE_TEMPLATE_NAME="${var.imageTemplateName}"
RESOURCE_GROUP_NAME="${data.azurerm_resource_group.rg.name}"
CLIENT_ID=${var.clientId}
TENANT_ID=${var.tenantId}
CLIENT_SECRET=${var.clientSecret}
# Function for Azure login
perform_login() {
Expand All @@ -202,28 +198,18 @@ resource "null_resource" "build_image_template" {
fi
}
# Loop to keep logging in every 30 minutes
keep_logging_in() {
while true; do
perform_login
echo "Waiting for 30 minutes before the next login..."
sleep 1800 # 1800 seconds = 30 minutes
done
}
# Run the login process in the background
keep_logging_in &
# Capture the background process ID to ensure cleanup later
LOGIN_PROCESS_PID=$!
# Start a background process to refresh the token
(while true; do
perform_login
sleep 1800 # Refresh every 30 minutes
done) &
# Run the Azure Image Builder command
echo "Starting Azure Image Builder process..."
az image builder run -n "$IMAGE_TEMPLATE_NAME" -g "$RESOURCE_GROUP_NAME" --debug
# Run the main image builder command
az image builder run -n ${var.imageTemplateName} -g ${data.azurerm_resource_group.rg.name} --debug
# Clean up the background login process after Image Builder completes
echo "Image Builder process completed. Cleaning up background login process."
kill $LOGIN_PROCESS_PID
# Kill the background refresh process after completion
kill $!
sleep 300
EOT
}

Expand Down

0 comments on commit f642a6c

Please sign in to comment.