Skip to content

Commit 7d50880

Browse files
committed
docs: update README, GAP_ANALYSIS, add CHANGELOG
- README: added Remote State Setup and Module Structure sections - GAP_ANALYSIS: updated to reflect completed modules and backend - CHANGELOG: added to document all refactoring changes
1 parent 3a62150 commit 7d50880

3 files changed

Lines changed: 172 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6+
7+
## [Unreleased]
8+
9+
### Added
10+
- **Terraform Modules**: Refactored infrastructure into reusable modules
11+
- `modules/s3/` - S3 bucket with versioning and lifecycle rules
12+
- `modules/dynamodb/` - DynamoDB table with GSI and TTL support
13+
- `modules/lambda/` - Lambda function with CloudWatch log group
14+
- `modules/api_gateway/` - API Gateway REST API with Lambda integration
15+
- **Remote State Backend**: Added S3 + DynamoDB backend configuration
16+
- `backend-setup/` directory with Terraform to create state infrastructure
17+
- Commented backend block in `provider.tf` ready for activation
18+
- State locking via DynamoDB for team collaboration
19+
- **Documentation**: Added remote state setup instructions to README
20+
21+
### Changed
22+
- **main.tf**: Migrated from inline resources to module calls
23+
- **outputs.tf**: Updated outputs to reference module outputs
24+
- **provider.tf**: Added remote state backend configuration (commented)
25+
26+
### Security
27+
- **IAM**: Documented least-privilege policy in `docs/GAP_ANALYSIS.md`
28+
- Note: AWS Academy LabRole used due to environment constraints
29+
- Production policy template provided for non-Academy deployments
30+
31+
### Infrastructure
32+
- All resources maintain consistent tagging (Project, Environment, ManagedBy, Repository)
33+
- Module-based structure enables reuse across environments
34+
- Variables and locals used for all configurable values
35+
36+
## [1.0.0] - 2025-01-19
37+
38+
### Added
39+
- Initial Telegram chatbot infrastructure
40+
- Lambda function for message handling
41+
- API Gateway webhook endpoint
42+
- DynamoDB for session storage with GSIs
43+
- S3 for conversation archival with lifecycle policies
44+
- CloudWatch logging
45+
- CI/CD with GitHub Actions
46+
- Comprehensive documentation (README, CONTRIBUTING, GAP_ANALYSIS)

README.md

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ This project deploys a **Telegram chatbot** on AWS using Infrastructure as Code
1313
* [Features](#features)
1414
* [Prerequisites](#prerequisites)
1515
* [AWS Academy Setup](#aws-academy-setup)
16+
* [Remote State Setup](#remote-state-setup)
1617
* [Deployment](#deployment)
1718
* [Telegram Webhook Setup](#telegram-webhook-setup)
1819
* [Bot Commands](#bot-commands)
1920
* [Project Structure](#project-structure)
21+
* [Module Structure](#module-structure)
2022
* [Data Storage](#data-storage)
2123
* [Verification](#verification)
2224
* [Troubleshooting](#troubleshooting)
@@ -141,6 +143,63 @@ Output: `arn:aws:iam::ACCOUNT_ID:role/LabRole`
141143

142144
---
143145

146+
## Remote State Setup
147+
148+
Remote state stores your Terraform state in S3 with DynamoDB locking, enabling team collaboration and state protection.
149+
150+
### Prerequisites
151+
152+
Before enabling remote state, you need to create the backend infrastructure:
153+
154+
1. **Create Backend Resources**
155+
156+
```bash
157+
cd backend-setup
158+
terraform init
159+
terraform apply -auto-approve
160+
```
161+
162+
This creates:
163+
- S3 bucket: `terraform-state-{ACCOUNT_ID}` (versioned, encrypted)
164+
- DynamoDB table: `terraform-locks` (for state locking)
165+
166+
2. **Note the Output**
167+
168+
After applying, note the `backend_config` output which shows the exact configuration to use.
169+
170+
3. **Enable Remote State**
171+
172+
Edit `provider.tf` and uncomment the backend block:
173+
174+
```hcl
175+
terraform {
176+
# ... required_providers ...
177+
178+
backend "s3" {
179+
bucket = "terraform-state-<ACCOUNT_ID>"
180+
key = "ai-chatbot/terraform.tfstate"
181+
region = "us-east-1"
182+
encrypt = true
183+
dynamodb_table = "terraform-locks"
184+
}
185+
}
186+
```
187+
188+
4. **Migrate State**
189+
190+
```bash
191+
cd .. # Return to project root
192+
terraform init -migrate-state
193+
```
194+
195+
Terraform will ask to copy your existing local state to the new S3 backend.
196+
197+
### AWS Academy Note
198+
199+
In AWS Academy environments, the backend S3 bucket and DynamoDB table may need to be recreated each session since resources are deleted when labs end. For persistent setups, consider using a personal AWS account.
200+
201+
---
202+
144203
## Deployment
145204

146205
### 1. Clone and Configure
@@ -268,11 +327,18 @@ If the bot stops responding after redeployment:
268327

269328
```
270329
.
271-
├── provider.tf # AWS provider configuration
330+
├── provider.tf # AWS provider + backend configuration
272331
├── variables.tf # Variable definitions with validation
273332
├── locals.tf # Local values for naming/tags
274-
├── main.tf # Infrastructure resources
275-
├── outputs.tf # Terraform outputs
333+
├── main.tf # Module calls and data sources
334+
├── outputs.tf # Terraform outputs (from modules)
335+
├── modules/ # Reusable Terraform modules
336+
│ ├── s3/ # S3 bucket module
337+
│ ├── dynamodb/ # DynamoDB table module
338+
│ ├── lambda/ # Lambda function module
339+
│ └── api_gateway/ # API Gateway module
340+
├── backend-setup/ # Remote state infrastructure
341+
│ └── main.tf # S3 bucket + DynamoDB for state
276342
├── terraform.tfvars.example # Example configuration
277343
├── terraform.tfvars # Your configuration (gitignored)
278344
├── requirements.txt # Python dependencies
@@ -289,13 +355,67 @@ If the bot stops responding after redeployment:
289355
│ ├── pr-check.yml # CI: PR validation
290356
│ └── deploy.yml # CD: AWS deployment
291357
├── CONTRIBUTING.md # Branch strategy & guidelines
358+
├── CHANGELOG.md # Project changelog
292359
├── .gitignore # Git ignore rules
293360
├── LICENSE # GPL v3 License
294361
└── README.md # This documentation
295362
```
296363

297364
---
298365

366+
## Module Structure
367+
368+
The infrastructure is organized into reusable modules:
369+
370+
### S3 Module (`modules/s3/`)
371+
372+
Creates an S3 bucket with versioning and lifecycle rules.
373+
374+
| Variable | Description | Default |
375+
|----------|-------------|---------|
376+
| `bucket_name` | Name of the bucket | Required |
377+
| `versioning_enabled` | Enable versioning | `true` |
378+
| `enable_lifecycle_rules` | Enable archival rules | `true` |
379+
| `transition_to_ia_days` | Days before IA transition | `90` |
380+
| `transition_to_glacier_days` | Days before Glacier | `180` |
381+
382+
### DynamoDB Module (`modules/dynamodb/`)
383+
384+
Creates a DynamoDB table with GSIs and TTL support.
385+
386+
| Variable | Description | Default |
387+
|----------|-------------|---------|
388+
| `table_name` | Name of the table | Required |
389+
| `billing_mode` | PAY_PER_REQUEST or PROVISIONED | `PAY_PER_REQUEST` |
390+
| `hash_key` | Partition key name | Required |
391+
| `global_secondary_indexes` | List of GSI configurations | `[]` |
392+
| `ttl_enabled` | Enable TTL | `false` |
393+
394+
### Lambda Module (`modules/lambda/`)
395+
396+
Creates a Lambda function with CloudWatch log group.
397+
398+
| Variable | Description | Default |
399+
|----------|-------------|---------|
400+
| `function_name` | Name of the function | Required |
401+
| `filename` | Path to deployment package | Required |
402+
| `handler` | Function handler | `handler.lambda_handler` |
403+
| `runtime` | Lambda runtime | `python3.9` |
404+
| `role_arn` | IAM role ARN | Required |
405+
406+
### API Gateway Module (`modules/api_gateway/`)
407+
408+
Creates a REST API with Lambda integration.
409+
410+
| Variable | Description | Default |
411+
|----------|-------------|---------|
412+
| `api_name` | Name of the API | Required |
413+
| `resource_path` | API path (e.g., webhook) | `webhook` |
414+
| `lambda_invoke_arn` | Lambda invoke ARN | Required |
415+
| `stage_name` | Deployment stage | `dev` |
416+
417+
---
418+
299419
## Data Storage
300420

301421
### DynamoDB (Active Sessions)

docs/GAP_ANALYSIS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
| Separate files | ✅ Implemented | `provider.tf`, `variables.tf`, `locals.tf`, `main.tf`, `outputs.tf` |
4242
| Variables file | ✅ Implemented | Dedicated `variables.tf` with validation |
4343
| Locals block | ✅ Implemented | `locals.tf` for common tags and naming |
44-
| Backend config | ⚠️ Partial | Local state (remote state optional for AWS Academy) |
45-
| Modules | ⚠️ Future | Single-project, modules planned for scaling |
44+
| Backend config | ✅ Implemented | S3 + DynamoDB backend in `backend-setup/`, config in `provider.tf` |
45+
| Modules | ✅ Implemented | `modules/s3`, `modules/dynamodb`, `modules/lambda`, `modules/api_gateway` |
4646

4747
**Current File Structure:**
4848
```
@@ -127,6 +127,7 @@ AWS Academy restricts IAM role creation. We use the pre-existing `LabRole`.
127127
```hcl
128128
common_tags = {
129129
Project = "AI-Chatbot"
130+
Team = "CloudDev"
130131
Environment = var.environment # dev, staging, prod
131132
ManagedBy = "Terraform"
132133
Repository = "github.com/Man2Dev/cloud-Ai"

0 commit comments

Comments
 (0)