katarinasvedman-ms / agent-test

Testing the AI dev team repo
0 stars 0 forks source link

Developer.Implement chain for #85 #89

Open agent-app-kapeltol[bot] opened 8 months ago

agent-app-kapeltol[bot] commented 8 months ago

// Output a command to add a new C# Web API project to the solution dotnet new webapi -n TodoListAPI dotnet sln add TodoListAPI

agent-app-kapeltol[bot] commented 8 months ago

Below is a bash script that accomplishes the creation of the files and directories necessary for the tasks assigned:

#!/bin/bash

# Create a directory for the project if it doesn't exist
mkdir -p TodoListAPI

# Navigate to the project directory
cd TodoListAPI

# Create the C# Web API project
dotnet new webapi -n TodoListAPI

# Navigate to the solution directory and add the new project to the solution
cd ..
dotnet sln add TodoListAPI/TodoListAPI.csproj

# Create a cloud-init file for VM creation with nginx
cat > cloud-init.txt <<EOF
#cloud-config
package_upgrade: true
packages:
- nginx
EOF

# Create a resource group
az group create --name myResourceGroupAutomate --location eastus

# Create the VM with the cloud-init configuration
az vm create \
  --resource-group myResourceGroupAutomate \
  --name myAutomatedVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --generate-ssh-keys \
  --custom-data cloud-init.txt

# Create a PowerShell script for runbook creation and role assignments
mkdir -p AutomationScripts
cd AutomationScripts

cat > create-runbook-and-assign-roles.ps1 <<'EOF'
# Sign in to Azure (this would be done in the portal, but including it for completeness)
$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal `
  -Tenant $connection.TenantID `
  -ApplicationId $connection.ApplicationID `
  -CertificateThumbprint $connection.CertificateThumbprint

Write-Output "Login successful.."

# Define the role assignments for the managed identities
$UAMI = "<User-Assigned Managed Identity Object ID>"
$SAMI = "<System-Assigned Managed Identity Object ID>"
$resourceGroup = "<Resource Group Name>"
$role1 = "<Role Name>"

# Assign role to User-Assigned Managed Identity
New-AzRoleAssignment `
  -ObjectId $UAMI `
  -ResourceGroupName $resourceGroup `
  -RoleDefinitionName $role1

# Assign 'Reader' role to System-Assigned Managed Identity
$role2 = "Reader"
New-AzRoleAssignment `
  -ObjectId $SAMI `
  -ResourceGroupName $resourceGroup `
  -RoleDefinitionName $role2

# Query data (example query provided in the task is incomplete, so using a placeholder)
$query = "<Your Kusto Query Here>"
EOF

cd ..

# Inform the user that the script has finished
echo "Setup complete!"

Remember to replace placeholders like <User-Assigned Managed Identity Object ID>, <System-Assigned Managed Identity Object ID>, <Resource Group Name>, and <Role Name> with actual values before running the PowerShell script. The comments in the code describe the intent of each section.