Skip to content

Commit 25e5f26

Browse files
committed
add claude action
1 parent 8a16b6b commit 25e5f26

File tree

2 files changed

+357
-0
lines changed

2 files changed

+357
-0
lines changed

.github/workflows/claude.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Claude PR Assistant
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
jobs:
14+
claude-code-action:
15+
if: |
16+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19+
(github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
pull-requests: read
24+
issues: read
25+
id-token: write
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 1
31+
32+
- name: Run Claude PR Action
33+
uses: anthropics/claude-code-action@beta
34+
with:
35+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
36+
timeout_minutes: "60"

CLAUDE.md

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
# Infrastructure Standards Enforcement Guide
2+
3+
This document consolidates AWS Tagging Standards and Infrastructure as Code (IaC) Standards for automated enforcement by AI agents and CI/CD systems.
4+
5+
## AWS Tagging Standards Enforcement
6+
7+
### Required Tags (ENFORCE - BLOCK ON FAILURE)
8+
9+
These tags are mandatory for all resources and must be validated:
10+
11+
| Tag | Validation Pattern | Error Message | Applies To |
12+
|-----|-------------------|---------------|------------|
13+
| `env` | `^[A-Za-z0-9\-_]+$` | "env tag is required. Valid formats: dev, prod, staging, ops" | ALL resources |
14+
| `service` | `^[A-Za-z0-9\-_]+$` | "service tag is required. Format: alphanumeric with hyphens/underscores only" | ALL resources |
15+
16+
### Required When Code Managed (ENFORCE - CONDITIONAL)
17+
18+
These tags are required when resources are managed by IaC:
19+
20+
| Tag | Validation Pattern | Error Message | Condition |
21+
|-----|-------------------|---------------|-----------|
22+
| `code_managed_by` | `^(terraform\|cloudformation\|serverless\|ansible\|cdk)$` | "code_managed_by must be one of: terraform, cloudformation, serverless, ansible, cdk" | When resource is IaC managed |
23+
| `code_managed_at` | `^[a-zA-Z0-9\-_/]+$` | "code_managed_at must specify repository location (e.g., org/aws-infra)" | When resource is IaC managed |
24+
25+
### Required for Ansible-Managed EC2 (ENFORCE - CONDITIONAL)
26+
27+
| Tag | Validation Pattern | Error Message | Condition |
28+
|-----|-------------------|---------------|-----------|
29+
| `profile` | `^[A-Za-z0-9\-_]+$` | "profile tag is required for Ansible-managed EC2 instances" | EC2 instances with Ansible management |
30+
31+
### Recommended Tags (WARN - DO NOT BLOCK)
32+
33+
These tags should be present but won't block deployment:
34+
35+
| Tag | Validation Pattern | Warning Message |
36+
|-----|-------------------|-----------------|
37+
| `version` | `^v[0-9.]+(\-rc[0-9]+)?$` | "version tag recommended. Format: v1.2.3 or v1.2.3-rc1" |
38+
| `datadog_managed` | `^(true\|false\|critical)$` | "datadog_managed tag recommended for monitoring setup" |
39+
| `rhythmic_managed` | `^(true\|false)$` | "rhythmic_managed tag recommended for service coverage tracking" |
40+
41+
### Optional Tags (INFO - NO VALIDATION)
42+
43+
These tags are optional and provide additional metadata:
44+
45+
- `component` - Component identifier (alphanumeric with hyphens/underscores)
46+
- `app` - Application identifier for grouping services
47+
- `cost_center` - Accounting cost center (must align to customer requirements)
48+
- `schedule` - External scheduling tag (must align to scheduler values)
49+
- `backup_policy` - Backup policy identifier
50+
- `dlm_policy` - Data Lifecycle Management policy identifier
51+
52+
### Bill Tags Identification
53+
54+
Tags marked as "Bill Tags" for cost allocation:
55+
56+
- `env` (Y)
57+
- `service` (Y)
58+
- `cost_center` (Y)
59+
60+
## Infrastructure as Code Standards Enforcement
61+
62+
### Tooling Requirements (ENFORCE)
63+
64+
#### Primary Tool Standards
65+
66+
```yaml
67+
terraform_requirements:
68+
version_pinning: REQUIRED
69+
validation_pattern: "^[0-9]+\.[0-9]+(\.[0-9]+)?$"
70+
error_message: "Terraform version must be pinned in .terraform-version or terraform block"
71+
72+
provider_versions:
73+
aws_provider: REQUIRED
74+
validation_pattern: "^~> [0-9]+\.[0-9]+$"
75+
error_message: "AWS provider version must be pinned to at least minor version"
76+
```
77+
78+
#### Repository Structure Validation
79+
80+
```yaml
81+
repository_naming:
82+
pattern: "^aws-[a-zA-Z0-9\-]+-[a-zA-Z0-9\-]+$"
83+
error_message: "Repository must follow pattern: aws-[client]-[purpose]"
84+
85+
required_files:
86+
- ".terraform-version"
87+
- "README.md"
88+
- ".gitignore"
89+
- "main.tf"
90+
- "variables.tf"
91+
- "outputs.tf"
92+
```
93+
94+
### Code Quality Standards (ENFORCE)
95+
96+
#### Terraform Formatting
97+
98+
```yaml
99+
terraform_fmt:
100+
enforce: true
101+
command: "terraform fmt -check -recursive"
102+
error_message: "Code must be formatted with 'terraform fmt'"
103+
104+
terraform_validate:
105+
enforce: true
106+
command: "terraform validate"
107+
error_message: "Terraform configuration must pass validation"
108+
```
109+
110+
#### Security Scanning
111+
112+
```yaml
113+
security_tools:
114+
checkov:
115+
enforce: true
116+
severity_threshold: "HIGH"
117+
error_message: "High severity security issues must be resolved"
118+
119+
tflint:
120+
enforce: true
121+
config_required: true
122+
error_message: "TFLint issues must be resolved"
123+
124+
trivy:
125+
enforce: true
126+
severity_threshold: "HIGH"
127+
error_message: "High severity vulnerabilities must be resolved"
128+
```
129+
130+
### State Management Standards (ENFORCE)
131+
132+
#### Backend Configuration
133+
134+
```yaml
135+
terraform_backend:
136+
type: "s3"
137+
required_settings:
138+
bucket: REQUIRED
139+
key: REQUIRED
140+
region: REQUIRED
141+
encrypt: true
142+
dynamodb_table: REQUIRED
143+
144+
validation:
145+
bucket_versioning: REQUIRED
146+
bucket_encryption: REQUIRED
147+
error_message: "S3 backend must have versioning and encryption enabled"
148+
```
149+
150+
#### State Organization
151+
152+
```yaml
153+
state_file_rules:
154+
max_resources_per_state: 50
155+
warning_threshold: 30
156+
separate_states_required:
157+
- "Critical infrastructure (networking, security)"
158+
- "Different environments (prod/staging/dev)"
159+
- "Independent workloads"
160+
```
161+
162+
### GitOps Workflow Standards (ENFORCE)
163+
164+
#### Branch Protection
165+
166+
```yaml
167+
branch_protection:
168+
master_branch:
169+
required_reviews: 1
170+
dismiss_stale_reviews: true
171+
require_code_owner_reviews: false
172+
required_status_checks:
173+
- "terraform-plan"
174+
- "terraform-validate"
175+
- "security-scan"
176+
restrict_pushes: true
177+
```
178+
179+
#### Pull Request Requirements
180+
181+
```yaml
182+
pr_requirements:
183+
terraform_plan: REQUIRED
184+
plan_in_description: REQUIRED
185+
validation_passed: REQUIRED
186+
security_scan_passed: REQUIRED
187+
188+
template_sections:
189+
- "## Changes"
190+
- "## Business Justification"
191+
- "## Terraform Plan Output"
192+
- "## Testing Performed"
193+
```
194+
195+
### Documentation Standards (WARN)
196+
197+
#### README Requirements
198+
199+
```yaml
200+
readme_sections:
201+
required:
202+
- "Purpose and scope"
203+
- "Prerequisites"
204+
- "Usage instructions"
205+
- "Variable documentation"
206+
207+
validation:
208+
min_length: 500
209+
terraform_docs: REQUIRED
210+
warning_message: "README should include all required sections"
211+
```
212+
213+
#### Module Documentation
214+
215+
```yaml
216+
module_documentation:
217+
terraform_docs: REQUIRED
218+
variable_descriptions: REQUIRED
219+
output_descriptions: REQUIRED
220+
example_usage: REQUIRED
221+
```
222+
223+
### Resource Naming Standards (ENFORCE)
224+
225+
#### Naming Convention
226+
227+
```yaml
228+
resource_naming:
229+
pattern: "^[client]-[env]-[service]-[resource]-[instance]$"
230+
validation_pattern: "^[a-zA-Z0-9\-]+-[a-zA-Z0-9\-]+-[a-zA-Z0-9\-]+-[a-zA-Z0-9\-]+-[a-zA-Z0-9\-]+$"
231+
error_message: "Resources must follow naming pattern: [client]-[env]-[service]-[resource]-[instance]"
232+
233+
naming_exceptions:
234+
- "IAM roles and policies (AWS character restrictions)"
235+
- "S3 buckets (global uniqueness requirements)"
236+
- "Lambda functions (length restrictions)"
237+
```
238+
239+
## AI Agent Implementation Rules
240+
241+
### Blocking vs Non-Blocking Validations
242+
243+
#### BLOCK DEPLOYMENT (Return Error Code)
244+
- Missing required tags (`env`, `service`)
245+
- Missing conditional required tags when applicable
246+
- Terraform validation failures
247+
- High severity security issues
248+
- Unpinned Terraform versions
249+
- Missing state backend configuration
250+
- Branch protection violations
251+
- Failed security scans
252+
253+
#### WARN ONLY (Log Warning, Continue)
254+
- Missing recommended tags
255+
- README documentation issues
256+
- Missing optional documentation
257+
- Style guide violations
258+
- Medium/Low severity security findings
259+
260+
#### INFO ONLY (Log Information)
261+
- Missing optional tags
262+
- Code optimization suggestions
263+
- Best practice recommendations
264+
265+
### Validation Order
266+
267+
1. **Repository Structure** - Validate naming and required files
268+
2. **Terraform Syntax** - Run terraform validate, fmt check
269+
3. **Security Scanning** - Run checkov, tflint, trivy
270+
4. **Tag Validation** - Check required and recommended tags
271+
5. **State Management** - Validate backend configuration
272+
6. **Documentation** - Check README and module docs
273+
7. **Naming Conventions** - Validate resource naming patterns
274+
275+
### Error Reporting Format
276+
277+
```json
278+
{
279+
"validation_result": "FAILED|PASSED|WARNING",
280+
"blocking_errors": [
281+
{
282+
"category": "TAGGING|SECURITY|SYNTAX|NAMING",
283+
"severity": "HIGH|MEDIUM|LOW",
284+
"message": "Detailed error message",
285+
"resource": "resource_name",
286+
"fix_suggestion": "How to resolve this issue"
287+
}
288+
],
289+
"warnings": [],
290+
"info": []
291+
}
292+
```
293+
294+
### Exception Handling
295+
296+
#### Tag Requirement Exceptions
297+
- Legacy resources (created before standards adoption)
298+
- Third-party managed resources
299+
- AWS managed resources
300+
301+
#### Process for Exceptions
302+
1. Document exception in pull request
303+
2. Add waiver comment in code
304+
3. Track exceptions for future remediation
305+
306+
### Continuous Monitoring
307+
308+
#### Drift Detection
309+
- Monitor for manual changes outside IaC
310+
- Alert on untagged resources
311+
- Track compliance metrics
312+
- Generate compliance reports
313+
314+
#### Metrics to Track
315+
- Tag compliance percentage
316+
- Security scan failure rate
317+
- Documentation coverage
318+
- Standard adoption rate
319+
- Exception requests and resolution
320+
321+
This enforcement guide ensures consistent application of infrastructure standards while providing clear guidance for automated validation and manual review processes.

0 commit comments

Comments
 (0)