Skip to content

Commit 51838e8

Browse files
author
Scribd Bot
committed
feat: Bump scribd/terraform-service-foundations changes to v1.5.0
1 parent 2a80cfd commit 51838e8

7 files changed

+745
-0
lines changed

.cursor/rules/git-commits.mdc

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
---
2+
description: Git commit guidelines to ensure consistent and error-free commits
3+
globs:
4+
---
5+
6+
# Git Commit Guidelines
7+
8+
## Commit Message Format
9+
10+
### Structure
11+
12+
The commit message should be structured as follows:
13+
```
14+
<type>[optional scope]: <description>
15+
16+
[optional body]
17+
18+
[optional footer(s)]
19+
```
20+
21+
### Types
22+
23+
- `feat`: New feature
24+
- `fix`: Bug fix
25+
- `docs`: Documentation
26+
- `style`: Formatting
27+
- `refactor`: Code restructuring
28+
- `test`: Test changes
29+
- `chore`: Maintenance
30+
31+
## Specification
32+
33+
- Commits MUST be prefixed with a type, which consists of a noun, feat, fix, etc., followed by the OPTIONAL scope, OPTIONAL !, and REQUIRED terminal colon and space.
34+
- The type feat MUST be used when a commit adds a new feature to your application or library.
35+
- The type fix MUST be used when a commit represents a bug fix for your application.
36+
- A scope MAY be provided after a type. A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., fix(parser):
37+
- A description MUST immediately follow the colon and space after the type/scope prefix. The description is a short summary of the code changes, e.g., fix: array parsing issue when multiple spaces were contained in string.
38+
- A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
39+
- A commit body is free-form and MAY consist of any number of newline separated paragraphs.
40+
- One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a :<space> or <space># separator, followed by a string value (this is inspired by the git trailer convention).
41+
- A footer’s token MUST use - in place of whitespace characters, e.g., Acked-by (this helps differentiate the footer section from a multi-paragraph body). An exception is made for BREAKING CHANGE, which MAY also be used as a token.
42+
- A footer’s value MAY contain spaces and newlines, and parsing MUST terminate when the next valid footer token/separator pair is observed.
43+
- Breaking changes MUST be indicated in the type/scope prefix of a commit, or as an entry in the footer.
44+
- If included as a footer, a breaking change MUST consist of the uppercase text BREAKING CHANGE, followed by a colon, space, and description, e.g., BREAKING CHANGE: environment variables now take precedence over config files.
45+
- If included in the type/scope prefix, breaking changes MUST be indicated by a ! immediately before the :. If ! is used, BREAKING CHANGE: MAY be omitted from the footer section, and the commit description SHALL be used to describe the breaking change.
46+
- Types other than feat and fix MAY be used in your commit messages, e.g., docs: update ref docs.
47+
- The units of information that make up Conventional Commits MUST NOT be treated as case sensitive by implementors, with the exception of BREAKING CHANGE which MUST be uppercase.
48+
BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE, when used as a token in a footer.
49+
50+
## Error Prevention
51+
52+
### ✅ CORRECT Patterns
53+
54+
- Commit message with description and breaking change footer:
55+
```bash
56+
git commit -m 'feat: allow provided config object to extend other configs' -m 'BREAKING CHANGE: `extends` key in config file is now used for extending other config files'
57+
```
58+
59+
- Commit message with ! to draw attention to breaking change:
60+
```bash
61+
git commit -m "feat!: send an email to the customer when a product is shipped"
62+
```
63+
64+
- Commit message with scope and ! to draw attention to breaking change
65+
```bash
66+
git commit -m "feat(api)!: send an email to the customer when a product is shipped"
67+
```
68+
69+
- Commit message with both ! and BREAKING CHANGE footer:
70+
```bash
71+
git commit -m "chore!: drop support for Node 6" -m "BREAKING CHANGE: use JavaScript features not available in Node 6."
72+
```
73+
74+
- Commit message with no body:
75+
```bash
76+
git commit -m "docs: correct spelling of CHANGELOG"
77+
```
78+
79+
- Commit message with scope:
80+
```bash
81+
git commit -m "feat(lang): add Polish language"
82+
```
83+
84+
- Commit message with multi-paragraph body and multiple footers:
85+
```bash
86+
git commit -m "fix: prevent racing of requests
87+
88+
Introduce a request id and a reference to latest request. Dismiss
89+
incoming responses other than from latest request.
90+
91+
Remove timeouts which were used to mitigate the racing issue but are
92+
obsolete now.
93+
94+
Reviewed-by: Z
95+
Refs: #123"
96+
```
97+
98+
### ❌ INCORRECT Patterns
99+
100+
```bash
101+
# No prefix used
102+
git commit -m "Add code"
103+
```
104+
105+
## Best Practices
106+
107+
### Message Guidelines
108+
109+
1. Use one of the message types from the list of the provided above types
110+
2. Use imperative mood ("add" not "adds")
111+
3. Keep first line under 50 characters
112+
4. No period at end of subject line
113+
5. Be specific and clear
114+
6. Reference issue numbers when relevant
115+
116+
### Commit Organization
117+
118+
1. Make atomic commits (one logical change)
119+
2. Verify changes before committing
120+
3. Run tests before pushing
121+
4. Review the diff before committing
122+
5. Keep commits focused and small
123+
124+
## Common Patterns
125+
126+
### Feature Work
127+
128+
```bash
129+
git commit -m "feat(user): add email verification"
130+
git commit -m "feat(auth): implement 2FA support"
131+
```
132+
133+
### Bug Fixes
134+
135+
```bash
136+
git commit -m "fix(api): resolve rate limiting issue"
137+
git commit -m "fix(ui): correct button alignment"
138+
```
139+
140+
### Documentation
141+
142+
```bash
143+
git commit -m "docs(api): update endpoint documentation"
144+
git commit -m "docs(setup): add deployment guide"
145+
```
146+
147+
### Refactoring
148+
149+
```bash
150+
git commit -m "refactor(core): optimize data processing"
151+
git commit -m "refactor(auth): simplify login flow"
152+
```
153+
154+
## Recovery Procedures
155+
156+
### Fix Last Commit
157+
158+
```bash
159+
# Amend commit message
160+
git commit --amend -m "type(scope): corrected message"
161+
162+
# Amend commit content
163+
git add forgotten-file
164+
git commit --amend --no-edit
165+
```
166+
167+
### Split Failed Commit
168+
169+
```bash
170+
# Reset last commit
171+
git reset HEAD~1
172+
173+
# Commit changes separately
174+
git add feature-files
175+
git commit -m "feat(scope): first part"
176+
git add test-files
177+
git commit -m "test(scope): add tests"
178+
```
179+
180+
## Pre-commit Checklist
181+
182+
### Code Quality
183+
184+
- Run linters
185+
- Check formatting
186+
- Remove debug code
187+
- Run tests
188+
189+
### Security
190+
191+
- No sensitive data
192+
- No API keys
193+
- No credentials
194+
- Check file permissions
195+
196+
### Commit Message
197+
198+
- Correct type and scope
199+
- Clear description
200+
- Reference issues if applicable
201+
202+
### Changes
203+
204+
- Review diff
205+
- Verify file inclusions
206+
- Check for unintended changes
207+
- Confirm test coverage
208+
209+
### Mandatory Diff Review
210+
211+
#### Pre-Commit Diff Check
212+
213+
Before any commit, ALWAYS run:
214+
215+
```bash
216+
# Check status first
217+
git status | cat
218+
219+
# Then review changes in detail
220+
git diff | cat
221+
222+
# For staged changes
223+
git diff --staged | cat
224+
```
225+
226+
#### Diff Review Checklist
227+
228+
1. File Changes
229+
- Confirm all intended files are modified
230+
- No unintended file deletions
231+
- No sensitive files exposed
232+
233+
2. Code Changes
234+
- Review each chunk of changes
235+
- Verify line deletions are intentional
236+
- Check for debugging code
237+
- Confirm formatting changes
238+
239+
3. Large Changes Warning
240+
- If more than 500 lines changed, break into smaller commits
241+
- For large deletions, double-check necessity
242+
- Request confirmation for significant file removals
243+
244+
4. Post-Review Actions
245+
- Address any unintended changes
246+
- Remove debug statements
247+
- Fix formatting issues
248+
- Split into multiple commits if needed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
description: Additional Terraform guidelines for best practices, security, and maintainability.
3+
globs: *.tf
4+
alwaysApply: false
5+
---
6+
7+
# Terraform common guidelines
8+
9+
- **Use Remote State**: Store Terraform state files remotely to enable collaboration and prevent conflicts. Use AWS S3 with DynamoDB locking.
10+
- Properly configure access controls for your remote state backend to prevent unauthorized access.
11+
- Implement versioning for state files to track changes and facilitate rollbacks.
12+
- **Validation and Formatting**: Always validate and format Terraform code using `terraform fmt` and `terraform validate` to ensure quality and consistency.
13+
- Integrate `terraform fmt` and `terraform validate` into your CI/CD pipeline.
14+
- Use a linter such as TFLint to enforce organization-specific coding best practices.
15+
- **Use Existing Shared and Community Modules**: Leverage pre-built modules from the Terraform Registry or other trusted sources to avoid reinventing the wheel.
16+
- Thoroughly review modules before use to understand their functionality and security implications.
17+
- Pin module versions to prevent unexpected changes.
18+
- **Import Existing Infrastructure**: Use the `terraform import` command to bring existing infrastructure under Terraform management.
19+
- Understand the limitations of `terraform import` and manually verify the imported configuration.
20+
- **Tag Resources**: Tag all Terraform resources with relevant metadata (`department`, `env`, `repo`, `terraform`).
21+
- Use consistent tagging conventions across your infrastructure.
22+
- Leverage tags for cost allocation and resource management.
23+
- **Common Patterns and Anti-patterns:**
24+
- **Design Patterns:**
25+
- **Singleton Pattern:** Ensure only one instance of a critical resource exists (e.g., a VPC). Use `count = var.create_vpc ? 1 : 0` to conditionally create a single VPC.
26+
- **Factory Pattern:** Use modules to create multiple instances of a resource with different configurations (e.g., multiple EC2 instances with different sizes and roles).
27+
- **Facade Pattern:** Create a module that simplifies the creation of complex infrastructure by abstracting away the underlying details.
28+
- **Recommended Approaches:**
29+
- Use data sources to retrieve information about existing resources instead of hardcoding their IDs or names.
30+
- Use dynamic blocks to create multiple resources or configure resource properties based on variable values.
31+
- Use lifecycle rules to manage resource creation, modification, and deletion.
32+
- **Anti-patterns:**
33+
- **Hardcoding values:** Avoid hardcoding values in your Terraform configurations. Use variables instead.
34+
- **Creating monolithic configurations:** Break down large configurations into smaller, more manageable modules.
35+
- **Ignoring errors:** Always handle errors and provide meaningful error messages.
36+
- **State Management Best Practices:**
37+
- **Remote State:** Always use remote state to store Terraform state files.
38+
- **State Locking:** Enable state locking to prevent concurrent modifications.
39+
- **State Encryption:** Encrypt state files to protect sensitive data.
40+
- **State Versioning:** Implement versioning for state files.
41+
- **Error Handling Patterns:**
42+
- Use the `try` and `can` functions to handle errors when retrieving data or evaluating expressions.
43+
- Use `validation` blocks to validate variable values and prevent invalid configurations.
44+
- Provide meaningful error messages to help users diagnose and fix issues.
45+
- **Performance Considerations:**
46+
- **Optimization Techniques:**
47+
- Use the `count` and `for_each` meta-arguments to create multiple resources efficiently.
48+
- Use data sources to retrieve information about existing resources instead of creating new ones.
49+
- Use the `depends_on` meta-argument sparingly to avoid unnecessary dependencies.
50+
- **Memory Management:**
51+
- Be mindful of the memory usage of your Terraform configurations, especially when working with large datasets.
52+
- Avoid creating large variables or outputs that can consume excessive memory.
53+
- **Rendering Optimization:**
54+
- Use efficient string interpolation techniques to avoid unnecessary string concatenation.
55+
- Use the `templatefile` function to render complex templates efficiently.
56+
- **Security Best Practices:**
57+
- **Common Vulnerabilities:**
58+
- **Hardcoded secrets:** Avoid hardcoding secrets in your Terraform configurations.
59+
- **Publicly accessible resources:** Ensure that resources are not publicly accessible unless explicitly required.
60+
- **Insufficient access controls:** Implement strict access controls to prevent unauthorized access to resources.
61+
- **Input Validation:**
62+
- Validate variable values to prevent invalid or malicious input.
63+
- Use regular expressions to enforce specific input formats.
64+
- **Authentication and Authorization Patterns:**
65+
- Use IAM roles and policies to grant resources the necessary permissions.
66+
- Use Terraform Cloud or other secrets management tools to manage sensitive credentials.
67+
- **Data Protection Strategies:**
68+
- Encrypt sensitive data at rest and in transit.
69+
- Use encryption keys managed by a key management service (KMS).
70+
- **Secure API Communication:**
71+
- Use HTTPS for all API communication.
72+
- Validate API responses to prevent data injection attacks.
73+
- **Testing Approaches:**
74+
- **Unit Testing Strategies:**
75+
- Use `terraform show` and `terraform plan` to verify that your Terraform configurations create the expected resources.
76+
- Use `terratest` or other testing frameworks to write automated unit tests.
77+
- **Common Pitfalls and Gotchas:**
78+
- **Frequent Mistakes:**
79+
- **Incorrect resource dependencies:** Ensure that resource dependencies are correctly defined.
80+
- **Ignoring resource lifecycle:** Understand the lifecycle of Terraform resources and how they are created, modified, and deleted.
81+
- **Using outdated Terraform versions:** Keep your Terraform version up to date to take advantage of new features and bug fixes.
82+
- **Edge Cases:**
83+
- **Handling resource conflicts:** Be prepared to handle resource conflicts that can occur when multiple Terraform configurations are applied simultaneously.
84+
- **Managing resources with external dependencies:** Be aware of resources that have external dependencies (e.g., DNS records) and handle them appropriately.
85+
- **Version-specific Issues:**
86+
- Be aware of version-specific issues and compatibility concerns when upgrading Terraform or provider versions.
87+
- Consult the Terraform and provider documentation for any breaking changes or migration guides.
88+
- **Compatibility Concerns:**
89+
- Ensure that your Terraform configurations are compatible with the target infrastructure environment.
90+
- Use provider versions that are compatible with the Terraform version.
91+
- **Tooling and Environment:**
92+
- **Recommended Development Tools:**
93+
- **Terraform CLI:** The official Terraform command-line interface.
94+
- **IDE/Text Editor:** Cursor editor (recommended) for seamless integration with project guidelines.
95+
- **TFLint:** A linter for Terraform code.
96+
- **Terratest:** A testing framework for Terraform code.
97+
- **Build Configuration:**
98+
- Use a consistent build configuration across all environments.
99+
- Use environment variables to configure the build environment.
100+
- **Linting and Formatting:**
101+
- Integrate linting and formatting into your CI/CD pipeline.
102+
- Use `terraform fmt` and TFLint to ensure code quality and consistency.

0 commit comments

Comments
 (0)