Skip to content

Commit 711212d

Browse files
committed
deploy infra + connections + prepare demo data
1 parent ceacdf8 commit 711212d

14 files changed

Lines changed: 1566 additions & 71 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Local .terraform directories
22
.terraform/
3+
*.terraform.lock.hcl
4+
.terraform.lock.hcl
5+
*src/.env
36

47
# .tfstate files
58
*.tfstate

TROUBLESHOOTING.md

Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
# Troubleshooting Guide - Overview
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[brown9804](https://github.com/brown9804)
7+
8+
Last updated: 2025-11-12
9+
10+
----------
11+
12+
> This guide covers common issues you may encounter when deploying and running this Azure AI Shopping demo application.
13+
14+
## Table of Contents
15+
- [Python Environment Issues](#python-environment-issues)
16+
- [Azure Authentication Issues](#azure-authentication-issues)
17+
- [Cosmos DB Issues](#cosmos-db-issues)
18+
- [Data Pipeline Issues](#data-pipeline-issues)
19+
- [Terraform Issues](#terraform-issues)
20+
21+
---
22+
23+
## Python Environment Issues
24+
25+
### Python Not Found
26+
```
27+
ERROR: Python is not installed or not in PATH
28+
```
29+
30+
**Solution**:
31+
- Install Python 3.8+ from https://www.python.org/downloads/
32+
- Ensure Python is added to your system PATH during installation
33+
- Verify installation: `python --version`
34+
35+
### Virtual Environment Creation Failed
36+
```
37+
ERROR: Failed to create virtual environment
38+
```
39+
40+
**Solution**:
41+
- Ensure you have write permissions to the `src` directory
42+
- Try deleting existing `venv` folder: `Remove-Item -Recurse -Force venv`
43+
- Check if `python -m venv` works manually: `python -m venv test_venv`
44+
- On Windows, ensure your execution policy allows script execution
45+
46+
### Package Installation Failed
47+
```
48+
ERROR: Could not install packages due to an OSError
49+
```
50+
51+
**Solution**:
52+
- Update pip: `python -m pip install --upgrade pip`
53+
- Clear pip cache: `pip cache purge`
54+
- Try installing with `--no-cache-dir`: `pip install --no-cache-dir -r requirements.txt`
55+
- For Windows + pandas issues, use pre-built wheels by ensuring `pandas>=2.2.2` in requirements.txt
56+
57+
---
58+
59+
## Azure Authentication Issues
60+
61+
### Not Logged into Azure CLI
62+
```
63+
ERROR: Please run 'az login' to setup account
64+
```
65+
66+
**Solution**:
67+
```powershell
68+
# Login to Azure CLI
69+
az login
70+
71+
# Verify you're logged in with the correct account
72+
az account show
73+
74+
# If needed, set the correct subscription
75+
az account set --subscription <subscription-id>
76+
```
77+
78+
### AAD Authentication Failed
79+
```
80+
DefaultAzureCredential failed to retrieve a token
81+
```
82+
83+
**Solution**:
84+
1. Ensure you're logged into Azure CLI: `az login`
85+
2. Check your account has proper permissions
86+
3. Verify the resource exists and you have access
87+
4. Try clearing Azure credentials cache: `az account clear` then `az login` again
88+
89+
---
90+
91+
## Cosmos DB Issues
92+
93+
### Local Authorization Disabled Error
94+
```
95+
ERROR: Local Authorization is disabled. Use an AAD token to authorize all requests.
96+
```
97+
98+
This error occurs when Cosmos DB requires Azure Active Directory (AAD) authentication instead of key-based authentication.
99+
100+
**Common Causes and Solutions**:
101+
102+
#### 1. Not logged into Azure CLI
103+
104+
```powershell
105+
# Login to Azure CLI
106+
az login
107+
108+
# Verify you're logged in with the correct account
109+
az account show
110+
111+
# If needed, set the correct subscription
112+
az account set --subscription <subscription-id>
113+
```
114+
115+
After logging in, try running the script again.
116+
117+
#### 2. Public Network Access Disabled
118+
119+
If your Cosmos DB has public network access disabled, your local machine or Codespace VM cannot connect.
120+
121+
**Solution via Azure Portal**:
122+
- Navigate to your Cosmos DB account in the Azure portal
123+
- Select **Networking** from the Settings menu
124+
- Ensure **Public network access** is set to **All networks**
125+
- Click **Save**
126+
- Wait a few minutes for the change to propagate
127+
- Try running the script again
128+
129+
**Solution via Azure CLI**:
130+
```powershell
131+
az cosmosdb update \
132+
--name <cosmos-account-name> \
133+
--resource-group <resource-group-name> \
134+
--enable-public-network true
135+
```
136+
137+
#### 3. Insufficient Permissions
138+
139+
Your Azure account needs appropriate role assignments on the Cosmos DB account.
140+
141+
**Required roles**:
142+
- `Cosmos DB Built-in Data Contributor` (for read/write access)
143+
- Or `Contributor` at the resource group level
144+
145+
**Solution via Azure CLI**:
146+
```powershell
147+
# Get your user object ID
148+
$userId = (az ad signed-in-user show --query id -o tsv)
149+
150+
# Assign Cosmos DB Data Contributor role
151+
az cosmosdb sql role assignment create \
152+
--account-name <cosmos-account-name> \
153+
--resource-group <resource-group-name> \
154+
--role-definition-id 00000000-0000-0000-0000-000000000002 \
155+
--principal-id $userId \
156+
--scope "/"
157+
```
158+
159+
### Connection Timeout
160+
```
161+
ERROR: Request timeout
162+
```
163+
164+
**Solution**:
165+
- Check your network connection
166+
- Verify Cosmos DB firewall settings allow your IP address
167+
- Ensure public network access is enabled (see above)
168+
- Check if Azure services are experiencing outages: https://status.azure.com/
169+
170+
---
171+
172+
## Data Pipeline Issues
173+
174+
### CSV File Not Found
175+
```
176+
WARNING: CSV data file not found at data/updated_product_catalog(in).csv
177+
```
178+
179+
**Solution**:
180+
Download or place the product catalog CSV file in the `src/data/` directory:
181+
182+
```bash
183+
curl -o src/data/updated_product_catalog(in).csv https://raw.githubusercontent.com/microsoft/TechWorkshop-L300-AI-Apps-and-agents/main/src/data/updated_product_catalog(in).csv
184+
```
185+
186+
### CSV Parsing Error
187+
```
188+
ERROR: Error tokenizing data. C error: Expected X fields, saw Y
189+
```
190+
191+
**Solution**:
192+
- Ensure CSV fields with commas are properly quoted
193+
- Check for special characters or encoding issues
194+
- Verify the CSV has the correct number of columns (6): ProductID, ProductName, ProductCategory, ProductDescription, Price, ImageUrl
195+
- Try opening the CSV in a text editor to check for formatting issues
196+
197+
### Environment File Missing
198+
```
199+
ERROR: .env file not found
200+
```
201+
202+
**Solution**:
203+
```bash
204+
# Run Terraform to generate the .env file
205+
cd terraform-infrastructure
206+
terraform apply -auto-approve
207+
```
208+
209+
### Failed to Authenticate to Cosmos DB
210+
```
211+
ERROR: Failed to authenticate to Cosmos DB using DefaultAzureCredential and no valid COSMOS_DB_KEY was provided
212+
```
213+
214+
**Solution**:
215+
- Ensure your `.env` file is properly generated with correct keys
216+
- Run `terraform apply` again if needed
217+
- Check that `COSMOS_DB_ENDPOINT` and `COSMOS_DB_KEY` are set correctly in `.env`
218+
- The script will automatically try AAD authentication first, then fall back to key-based auth
219+
220+
---
221+
222+
## Terraform Issues
223+
224+
### Resource Already Exists
225+
```
226+
ERROR: A resource with the ID already exists
227+
```
228+
229+
**Solution**:
230+
- Import the existing resource: `terraform import <resource_type>.<name> <azure_resource_id>`
231+
- Or destroy and recreate: `terraform destroy` then `terraform apply`
232+
- Check for resources in other resource groups with the same name
233+
234+
### Insufficient Permissions
235+
```
236+
ERROR: The client does not have authorization to perform action
237+
```
238+
239+
**Solution**:
240+
- Ensure your Azure account has `Contributor` or `Owner` role on the subscription or resource group
241+
- Check if specific Azure policies are blocking resource creation
242+
- Contact your Azure administrator to grant necessary permissions
243+
244+
### Provider Configuration Error
245+
```
246+
ERROR: Error configuring the backend "azurerm"
247+
```
248+
249+
**Solution**:
250+
- Verify your Azure credentials are configured: `az login`
251+
- Check that the specified subscription exists and you have access
252+
- Ensure the backend storage account and container exist (if using remote state)
253+
254+
### State Lock Error
255+
```
256+
ERROR: Error acquiring the state lock
257+
```
258+
259+
**Solution**:
260+
```bash
261+
# Force unlock (use with caution)
262+
terraform force-unlock <lock-id>
263+
```
264+
265+
Only force-unlock if you're certain no other Terraform process is running.
266+
267+
---
268+
269+
## General Tips
270+
271+
### Enable Verbose Logging
272+
273+
For more detailed error information:
274+
275+
**Azure CLI**:
276+
```powershell
277+
az <command> --debug
278+
```
279+
280+
**Python Scripts**:
281+
Set environment variable before running:
282+
```powershell
283+
$env:AZURE_LOG_LEVEL = "DEBUG"
284+
python pipelines/script.py
285+
```
286+
287+
**Terraform**:
288+
```bash
289+
export TF_LOG=DEBUG
290+
terraform apply
291+
```
292+
293+
### Check Azure Service Health
294+
295+
If experiencing unexpected issues, check Azure service status:
296+
- https://status.azure.com/
297+
298+
### Clean Up and Retry
299+
300+
> Sometimes a clean slate helps:
301+
302+
```bash
303+
# Clean Python environment
304+
Remove-Item -Recurse -Force venv
305+
python -m venv venv
306+
307+
# Clean Terraform state (use with caution)
308+
terraform destroy
309+
Remove-Item -Recurse -Force .terraform
310+
terraform init
311+
terraform apply
312+
```
313+
314+
---
315+
316+
## Still Having Issues?
317+
318+
> If you continue experiencing problems:
319+
320+
1. Check the [GitHub repository issues](https://github.com/MicrosoftCloudEssentials-LearningHub/Agentic-DevOps-AI-Shopping/issues)
321+
2. Review Azure documentation for specific services
322+
3. Enable detailed logging as described above
323+
4. Collect error messages, logs, and configuration details
324+
5. Create a new issue with detailed information about your problem
325+
326+
<!-- START BADGE -->
327+
<div align="center">
328+
<img src="https://img.shields.io/badge/Total%20views-1386-limegreen" alt="Total views">
329+
<p>Refresh Date: 2025-11-12</p>
330+
</div>
331+
<!-- END BADGE -->

0 commit comments

Comments
 (0)