diff --git a/.github/workflows/Assignment1.yml b/.github/workflows/Assignment1.yml new file mode 100644 index 0000000..dee7451 --- /dev/null +++ b/.github/workflows/Assignment1.yml @@ -0,0 +1,33 @@ +name: Assignment1 + +on: + workflow_dispatch: + push: + branches: + - Assignment1 + +permissions: + id-token: write + contents: read + +jobs: + list-resources: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Azure login with OIDC + uses: azure/login@v3 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true + + - name: Run PowerShell script + uses: azure/powershell@v2 + with: + inlineScript: ./Assignment1/Assignment1.ps1 + azPSVersion: "latest" \ No newline at end of file diff --git a/Assignment1/Assignment1.ps1 b/Assignment1/Assignment1.ps1 new file mode 100644 index 0000000..68d4c36 --- /dev/null +++ b/Assignment1/Assignment1.ps1 @@ -0,0 +1,45 @@ +# Assignment 1: Create and Delete Azure Storage Account + +# Define variables +$subscription_id = "98ef8437-66f2-4a03-9d1a-cf7057d27d9c" +$resourceGroupName = "assignment1-rg" +$location = "westus2" +$tempStorageName = ("a1temp" + (Get-Random -Maximum 99999999)) + +# Connect to Azure account +Write-Host "Connecting to Azure account..." +Set-AzContext -SubscriptionId $subscription_id | Out-Null + +# List resources before creating storage account +Write-Host "Listing resources before create:" +Get-AzResource | +Select-Object Name, ResourceGroupName, ResourceType, Location | +Format-Table -AutoSize + +# Create a temporary storage account +Write-Host "Creating temp storage account: $tempStorageName" +New-AzStorageAccount ` + -ResourceGroupName $resourceGroupName ` + -Name $tempStorageName ` + -Location $location ` + -SkuName Standard_LRS ` + -Kind StorageV2 | Out-Null + +# List resources after creating storage account +Write-Host "Listing resources after create:" +Get-AzResource | +Select-Object Name, ResourceGroupName, ResourceType, Location | +Format-Table -AutoSize + +# Delete the temporary storage account +Write-Host "Deleting temp storage account: $tempStorageName" +Remove-AzStorageAccount ` + -ResourceGroupName $resourceGroupName ` + -Name $tempStorageName ` + -Force + +# List resources after deleting storage account +Write-Host "Listing resources after delete:" +Get-AzResource | +Select-Object Name, ResourceGroupName, ResourceType, Location | +Format-Table -AutoSize \ No newline at end of file