Skip to content

Commit 675a3ec

Browse files
authored
Update README.md
1 parent 43b2def commit 675a3ec

File tree

1 file changed

+147
-22
lines changed

1 file changed

+147
-22
lines changed

README.md

Lines changed: 147 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,154 @@
1-
# Azure Storage Account and Log Analytics Integration
1+
# Deploy Azure Resources
22

3-
This project demonstrates deploying an Azure Storage Account with IP restrictions and associating it with a Log Analytics workspace using GitHub Actions and Bicep templates.
3+
This repository demonstrates how to automate the deployment of Azure resources using GitHub Actions and Bicep templates. The workflow provisions a resource group, a storage account, and a blob container with restricted IP access, and associates a Log Analytics workspace for monitoring.
44

5-
---
5+
## Workflow Overview
6+
The GitHub Actions workflow is triggered on a `push` to the `main` branch and performs the following steps:
67

7-
## Project Overview
8+
1. Checks out the repository.
9+
2. Logs in to Azure using a service principal.
10+
3. Creates a resource group.
11+
4. Deploys a storage account and blob container.
12+
5. Configures diagnostic settings to send logs to a Log Analytics workspace.
813

9-
This repository contains resources for deploying:
10-
- A resource group.
11-
- A storage account.
12-
- A blob container with public access.
13-
- IP restrictions to secure access.
14-
- A Log Analytics workspace for monitoring.
15-
- Diagnostic settings to associate the storage account with the Log Analytics workspace.
14+
### GitHub Actions Workflow File
15+
```yaml
16+
name: Deploy Azure Resources
1617

17-
---
18+
on:
19+
push:
20+
branches:
21+
- main
1822

19-
## Folder Structure
23+
jobs:
24+
deploy:
25+
runs-on: ubuntu-latest
2026

21-
```plaintext
22-
.
23-
├── .github
24-
│ └── workflows
25-
│ └── deploy-storage-account.yml # GitHub Actions workflow file
26-
├── bicep
27-
│ ├── storage-account.bicep # Bicep template for storage account
28-
│ └── log-analytics.bicep # Bicep template for Log Analytics workspace
29-
├── README.md # Project documentation
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v3
30+
31+
- name: Login to Azure
32+
uses: azure/login@v1
33+
with:
34+
creds: ${{ secrets.AZURE_CREDENTIALS }}
35+
36+
- name: Create Resource Group
37+
run: |
38+
az group create --name rrblobtest --location "UK South"
39+
40+
- name: Deploy Storage Account
41+
run: |
42+
az deployment group create \
43+
--resource-group rrblobtest \
44+
--template-file bicep/storage-account.bicep \
45+
--parameters location="UK South" \
46+
storageAccountName="teststorage20241229" \
47+
containerName="images" \
48+
allowedIP="92.16.42.251"
49+
50+
- name: Associate Log Analytics Workspace
51+
run: |
52+
az monitor diagnostic-settings create \
53+
--name "storageAccountDiagnostics" \
54+
--resource /subscriptions/929d7635-207a-4b22-8d24-34e2ae29092b/resourceGroups/rrblobtest/providers/Microsoft.Storage/storageAccounts/teststorage20241229 \
55+
--metrics '[{"category": "Transaction", "enabled": true}, {"category": "Capacity", "enabled": true}]' \
56+
--workspace /subscriptions/929d7635-207a-4b22-8d24-34e2ae29092b/resourceGroups/rrblobtest/providers/Microsoft.OperationalInsights/workspaces/rrlogtest
57+
```
58+
59+
## Bicep Templates
60+
The following Bicep templates are used for deploying the Log Analytics workspace and the storage account with the blob container.
61+
62+
### Log Analytics Workspace
63+
```bicep
64+
@description('The location for the Log Analytics workspace.')
65+
param location string
66+
67+
@description('The name of the Log Analytics workspace.')
68+
param logAnalyticsWorkspaceName string
69+
70+
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
71+
name: logAnalyticsWorkspaceName
72+
location: location
73+
properties: {
74+
sku: {
75+
name: 'PerGB2018'
76+
}
77+
retentionInDays: 30
78+
}
79+
}
80+
81+
output logAnalyticsWorkspaceId string = logAnalyticsWorkspace.id
82+
```
83+
84+
### Storage Account and Blob Container
85+
```bicep
86+
@description('The location for all resources.')
87+
param location string
88+
89+
@description('The name of the storage account.')
90+
param storageAccountName string
91+
92+
@description('The name of the container to create.')
93+
param containerName string
94+
95+
@description('The IP address allowed to access the storage account.')
96+
param allowedIP string
97+
98+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
99+
name: storageAccountName
100+
location: location
101+
sku: {
102+
name: 'Standard_LRS'
103+
}
104+
kind: 'StorageV2'
105+
properties: {
106+
accessTier: 'Hot'
107+
allowBlobPublicAccess: true
108+
networkAcls: {
109+
bypass: 'AzureServices'
110+
defaultAction: 'Deny'
111+
ipRules: [
112+
{
113+
value: allowedIP
114+
action: 'Allow'
115+
}
116+
]
117+
}
118+
}
119+
}
120+
121+
resource blobService 'Microsoft.Storage/storageAccounts/blobServices@2022-09-01' = {
122+
parent: storageAccount
123+
name: 'default'
124+
}
125+
126+
resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2022-09-01' = {
127+
parent: blobService
128+
name: containerName
129+
properties: {
130+
publicAccess: 'Blob'
131+
}
132+
}
133+
```
134+
135+
## How to Use
136+
1. **Clone the Repository:**
137+
```bash
138+
git clone https://github.com/your-repo.git
139+
```
140+
2. **Set Up Azure Credentials:**
141+
Add the `AZURE_CREDENTIALS` secret to your GitHub repository. This should contain the JSON output from creating a service principal.
142+
143+
3. **Modify Parameters:**
144+
Update the Bicep template parameters as needed (e.g., `storageAccountName`, `allowedIP`).
145+
146+
4. **Push Changes:**
147+
Commit and push your changes to the `main` branch to trigger the workflow.
148+
149+
5. **Monitor Deployment:**
150+
Check the Actions tab in your GitHub repository for deployment logs.
151+
152+
## Resources
153+
- [GitHub Actions for Azure](https://learn.microsoft.com/en-us/azure/developer/github/)
154+
- [Bicep Documentation](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/)

0 commit comments

Comments
 (0)