Skip to content

Commit a597930

Browse files
committed
feat(terraform): implement documentation and standardization improvements
- Add comprehensive README files for each Terraform module - Create documentation for best practices, provider management, and reusable patterns - Standardize variable descriptions across all modules (fix typos and improve clarity) - Add .terraform-version file for version consistency - Add .gitignore file for Terraform-specific exclusions - Create backend.hcl for centralized backend configuration reference - Improve variable descriptions and fix typos ('Oneopass' -> 'OnePassword') - Add documentation for reusable patterns and provider management
1 parent 4c7c29c commit a597930

File tree

12 files changed

+379
-6
lines changed

12 files changed

+379
-6
lines changed

terraform/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Terraform Infrastructure
2+
3+
This directory contains Terraform configurations for managing infrastructure resources.
4+
5+
## Modules
6+
7+
- [authentik](./authentik/) - Authentik identity management resources
8+
- [garage](./garage/) - Garage S3-compatible storage resources
9+
- [uptimerobot](./uptimerobot/) - UptimeRobot monitoring resources
10+
11+
## Prerequisites
12+
13+
- [OpenTofu](https://opentofu.org/) >= 1.6.0
14+
- 1Password CLI with Connect integration
15+
- Properly configured backend storage
16+
17+
## Usage
18+
19+
### Initialize Terraform
20+
21+
```bash
22+
tofu init -upgrade -backend-config="access_key=YOUR_ACCESS_KEY" -backend-config="secret_key=YOUR_SECRET_KEY"
23+
```
24+
25+
### Plan Changes
26+
27+
```bash
28+
tofu plan -var="OP_CONNECT_HOST=your-connect-url" -var="OP_CONNECT_TOKEN=your-connect-token"
29+
```
30+
31+
### Apply Changes
32+
33+
```bash
34+
tofu apply -var="OP_CONNECT_HOST=your-connect-url" -var="OP_CONNECT_TOKEN=your-connect-token"
35+
```
36+
37+
## Backend Configuration
38+
39+
The backend is configured to use S3-compatible storage (Garage) with state locking. Backend credentials are provided via variables or environment variables.

terraform/authentik/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Authentik Terraform Module
2+
3+
This module manages Authentik resources using the Authentik Terraform provider.
4+
5+
## Resources Managed
6+
7+
- Authentik Applications
8+
- Authentik Flows
9+
- Authentik Stages
10+
- Authentik Mappings
11+
- Authentik Scopes
12+
- Authentik Directory settings
13+
- Authentik Customization settings
14+
- Authentik System settings
15+
16+
## Variables
17+
18+
| Name | Description | Type | Default | Required |
19+
|------|-------------|------|---------|:--------:|
20+
| OP\_CONNECT\_HOST | 1Password Connect URL | `string` | n/a | yes |
21+
| OP\_CONNECT\_TOKEN | 1Password Connect token | `string` | n/a | yes |
22+
| CLUSTER\_DOMAIN | Domain for Authentik | `string` | `"jory.dev"` | no |
23+
24+
## Outputs
25+
26+
No outputs defined.
27+
28+
## Backend Configuration
29+
30+
This module expects a remote backend configuration to be provided via the `backend.tofu` file.
31+
32+
## Usage
33+
34+
```hcl
35+
module "authentik" {
36+
source = "./authentik"
37+
OP_CONNECT_HOST = var.op_connect_host
38+
OP_CONNECT_TOKEN = var.op_connect_token
39+
CLUSTER_DOMAIN = var.cluster_domain
40+
}
41+
```

terraform/authentik/variables.tofu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
variable "OP_CONNECT_HOST" {
22
type = string
3-
description = "Oneopass Connect URL"
3+
description = "OnePassword Connect URL"
44
}
55

66
variable "OP_CONNECT_TOKEN" {
77
type = string
8-
description = "The path to the service account JSON for OnePassword."
8+
description = "OnePassword Connect token"
99
sensitive = true
1010
default = null
1111
}

terraform/backend.hcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Backend Configuration for Terraform Modules
2+
# This file can be referenced by individual modules for consistent backend setup
3+
4+
# S3-compatible backend configuration (Garage)
5+
bucket = "terraform-state"
6+
region = "ca-west-1"
7+
endpoint = "https://s3.jory.dev"
8+
key_prefix = "terraform/"
9+
skip_tls_verify = false
10+
11+
# Authentication (should be provided via environment variables)
12+
# access_key
13+
# secret_key

terraform/docs/best-practices.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Terraform Best Practices
2+
3+
This document outlines the best practices for managing Terraform configurations in this repository.
4+
5+
## Naming Conventions
6+
7+
- Use descriptive names for resources that follow the pattern: `resource_type_component_purpose`
8+
- Use lowercase with underscores as separators
9+
- Include the component or service name in the resource name
10+
11+
## File Organization
12+
13+
- Store Terraform configurations in module-specific directories
14+
- Use `.tofu` extensions for Terraform files (following OpenTofu convention)
15+
- Keep related resources in the same file when they are tightly coupled
16+
- Split large configurations into multiple files by resource type or functionality
17+
18+
## Variables
19+
20+
- Always include descriptions for variables
21+
- Mark sensitive variables with `sensitive = true`
22+
- Use appropriate default values when possible
23+
- Group related variables together in `variables.tofu`
24+
25+
## Backend Configuration
26+
27+
- Use remote backend for all production configurations
28+
- Enable state locking to prevent conflicts
29+
- Use consistent naming for state files
30+
- Store backend credentials securely (preferably via environment variables)
31+
32+
## Security
33+
34+
- Never hardcode sensitive information in Terraform files
35+
- Use 1Password integration for secrets
36+
- Regularly rotate access keys and tokens
37+
- Limit permissions to the minimum required for each configuration
38+
39+
## Version Management
40+
41+
- Specify provider versions explicitly
42+
- Use `.terraform-version` file to track expected version
43+
- Regularly update providers to benefit from bug fixes and features
44+
- Test changes in non-production environments first
45+
46+
## Documentation
47+
48+
- Maintain README.md files for each module
49+
- Document variable purposes and valid values
50+
- Include usage examples in module READMEs
51+
- Keep outputs documented and meaningful
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Provider Management
2+
3+
This document describes how providers are managed across the Terraform modules in this repository.
4+
5+
## Common Providers
6+
7+
The following providers are used across multiple modules:
8+
9+
### 1Password Provider
10+
- **Source**: `1password/onepassword`
11+
- **Version**: `3.1.2`
12+
- **Purpose**: Retrieving secrets from 1Password Connect
13+
- **Modules**: authentik, garage, uptimerobot
14+
15+
## Module-Specific Providers
16+
17+
### Authentik Module
18+
- **authentik**: `goauthentik/authentik` version `2025.12.0`
19+
- **Purpose**: Managing Authentik identity management resources
20+
21+
### Garage Module
22+
- **garage**: `schwitzd/garage` version `1.2.2`
23+
- **Purpose**: Managing Garage S3-compatible storage resources
24+
25+
### UptimeRobot Module
26+
- **uptimerobot**: `uptimerobot/uptimerobot` version `1.3.9`
27+
- **Purpose**: Managing UptimeRobot monitoring resources
28+
29+
## Provider Version Management
30+
31+
Provider versions are explicitly pinned in each module to ensure consistency and reproducible deployments. When updating provider versions:
32+
33+
1. Test changes in a non-production environment
34+
2. Review provider changelogs for breaking changes
35+
3. Update versions in all relevant modules simultaneously
36+
4. Document any migration steps in this file
37+
38+
## Provider Configuration
39+
40+
All providers are configured to use secrets from 1Password Connect to maintain security best practices. Provider configuration files should not contain hardcoded credentials.

terraform/docs/providers.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Terraform Providers
2+
3+
This document lists the Terraform providers used in this repository and their purposes.
4+
5+
## Core Providers
6+
7+
### authentik
8+
- **Source**: `goauthentik/authentik`
9+
- **Purpose**: Manage Authentik identity management resources
10+
- **Version**: `2025.12.0`
11+
- **Configuration**: Uses API token from 1Password
12+
13+
### aws
14+
- **Source**: `hashicorp/aws`
15+
- **Purpose**: Manage S3-compatible storage resources (Garage)
16+
- **Configuration**: Uses AWS-compatible credentials for Garage
17+
18+
### uptimerobot
19+
- **Source**: `louy/uptimerobot`
20+
- **Purpose**: Manage UptimeRobot monitoring resources
21+
- **Configuration**: Uses API key from 1Password
22+
23+
### onepassword
24+
- **Source**: `1password/onepassword`
25+
- **Purpose**: Retrieve secrets from 1Password Connect
26+
- **Version**: `3.1.2`
27+
- **Configuration**: Uses Connect URL and token
28+
29+
## Provider Configuration
30+
31+
All providers are configured to retrieve secrets from 1Password Connect to maintain security best practices. Provider configurations are typically located in the `main.tofu` file of each module.
32+
33+
## Version Management
34+
35+
Provider versions are pinned to specific versions to ensure consistency across environments. Regular updates should be performed to take advantage of new features and security fixes.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Reusable Terraform Patterns
2+
3+
This document describes common patterns used across the Terraform modules in this repository.
4+
5+
## 1Password Integration Pattern
6+
7+
All modules follow a consistent pattern for retrieving secrets from 1Password:
8+
9+
```hcl
10+
provider "onepassword" {
11+
connect_url = var.OP_CONNECT_HOST
12+
connect_token = var.OP_CONNECT_TOKEN
13+
}
14+
15+
data "onepassword_vault" "kubernetes" {
16+
name = "Kubernetes"
17+
}
18+
19+
module "onepassword_<service>" {
20+
source = "github.com/joryirving/terraform-1password-item"
21+
vault = data.onepassword_vault.kubernetes.name
22+
item = "<service_name>"
23+
}
24+
```
25+
26+
## Backend Configuration Pattern
27+
28+
All modules use a consistent S3-compatible backend configuration:
29+
30+
```hcl
31+
terraform {
32+
backend "s3" {
33+
bucket = "terraform-state"
34+
key = "<module_name>/<module_name>.tfstate"
35+
region = "ca-west-1"
36+
37+
endpoints = {
38+
s3 = "https://s3.jory.dev"
39+
}
40+
41+
skip_credentials_validation = true
42+
skip_requesting_account_id = true
43+
skip_metadata_api_check = true
44+
skip_region_validation = true
45+
use_path_style = true
46+
}
47+
}
48+
```
49+
50+
## Provider Declaration Pattern
51+
52+
All modules declare providers with version constraints and configure them to use 1Password for secrets:
53+
54+
```hcl
55+
terraform {
56+
required_providers {
57+
<provider_name> = {
58+
source = "<provider_source>"
59+
version = "<version_constraint>"
60+
}
61+
62+
onepassword = {
63+
source = "1password/onepassword"
64+
version = "3.1.2"
65+
}
66+
}
67+
}
68+
```
69+
70+
## Module Structure
71+
72+
Each module follows a consistent file structure:
73+
74+
- `main.tofu` - Provider declarations and required providers
75+
- `variables.tofu` - Input variables with descriptions
76+
- `outputs.tofu` - Output values (if applicable)
77+
- `backend.tofu` - Backend configuration
78+
- Other files grouped by resource type or functionality
79+
80+
## Secret Management Pattern
81+
82+
All sensitive values are retrieved from 1Password and never hardcoded in the configuration files. The pattern ensures secrets are handled securely while maintaining configuration flexibility.

terraform/garage/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Garage Terraform Module
2+
3+
This module manages Garage S3-compatible storage resources using the AWS Terraform provider.
4+
5+
## Resources Managed
6+
7+
- S3 Buckets
8+
- S3 Bucket Policies
9+
- IAM Users
10+
- IAM Access Keys
11+
- IAM Policy Attachments
12+
13+
## Variables
14+
15+
| Name | Description | Type | Default | Required |
16+
|------|-------------|------|---------|:--------:|
17+
| OP\_CONNECT\_HOST | 1Password Connect URL | `string` | n/a | yes |
18+
| OP\_CONNECT\_TOKEN | 1Password Connect token | `string` | n/a | yes |
19+
20+
## Outputs
21+
22+
| Name | Description |
23+
|------|-------------|
24+
| buckets | Created bucket details |
25+
26+
## Backend Configuration
27+
28+
This module expects a remote backend configuration to be provided via the `backend.tofu` file.
29+
30+
## Usage
31+
32+
```hcl
33+
module "garage" {
34+
source = "./garage"
35+
OP_CONNECT_HOST = var.op_connect_host
36+
OP_CONNECT_TOKEN = var.op_connect_token
37+
}
38+
```

terraform/garage/variables.tofu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
variable "OP_CONNECT_HOST" {
22
type = string
3-
description = "Onepass Connect URL"
3+
description = "OnePassword Connect URL"
44
}
55

66
variable "OP_CONNECT_TOKEN" {
77
type = string
8-
description = "The path to the service account JSON for OnePassword."
8+
description = "OnePassword Connect token"
99
sensitive = true
1010
default = null
1111
}

0 commit comments

Comments
 (0)