Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .claude/plans/compliance-logging-rollout.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@

### Phase 2: Terraformer
#### 2.1 Development Environment
- [ ] Create `terraformer/auditd.pp`
- [ ] Create `terraformer.rules.erb`
- [ ] Testing and validation
- [ ] **Release**: `puppet-terraformer-auditd-dev-v1.0.0`
- [x] Create `terraformer/auditd.pp`
- [x] Create `terraformer.rules.erb`
- [x] Testing and validation
- [x] **Release**: `puppet-terraformer-auditd-dev-v1.0.0`

#### 2.2 Sandbox Environment
- [ ] Deploy to sandbox
- [ ] Infrastructure change simulations
- [ ] **Release**: `puppet-terraformer-auditd-sandbox-v1.0.0`
- [x] Deploy to sandbox
- [x] Infrastructure change simulations
- [x] **Release**: `puppet-terraformer-auditd-sandbox-v1.0.0`

#### 2.3 Global Modules (Production)
- [ ] Deploy to production
- [ ] **Release**: `puppet-terraformer-auditd-prod-v1.0.0`
- [x] Deploy to production
- [x] **Release**: `puppet-terraformer-auditd-prod-v1.0.0`

### Phase 3: Elasticsearch
#### 3.1 Development Environment
Expand Down
171 changes: 32 additions & 139 deletions .claude/plans/terraformer-cloudwatch-integration.md
Original file line number Diff line number Diff line change
@@ -1,157 +1,50 @@
# Terraformer CloudWatch Agent Integration Plan

## Overview
## Status: ✅ COMPLETED (2026-01-16)

This plan adds CloudWatch agent integration to the Terraformer role, enabling centralized logging
and metrics collection. The Terraform module (`terraform-aws-terraformer`) now passes
CloudWatch configuration via Puppet facts.
Implementation merged in commit `ec77460`.

## Background
## Summary

The `terraform-aws-terraformer` module has been updated to:
- Create a CloudWatch log group (`/aws/ec2/terraformer`)
- Pass facts to Puppet:
- `$facts['terraformer']['cloudwatch_log_group']` - Log group name
- `$facts['terraformer']['cloudwatch_namespace']` - Metrics namespace (default: `Terraformer/System`)

## Scope

**Environment:** `development` only (initial rollout)

**Files to create:**
- `environments/development/modules/profile/manifests/terraformer/cloudwatch_agent.pp`

**Files to modify:**
- `environments/development/modules/profile/manifests/terraformer.pp`

## Implementation Plan

### Step 1: Create CloudWatch Agent Subclass
Added CloudWatch agent integration to the Terraformer role (development environment), enabling centralized logging and metrics collection. Also added terraform command auditing via auditd.

Create `environments/development/modules/profile/manifests/terraformer/cloudwatch_agent.pp`:
## What Was Implemented

```puppet
# CloudWatch agent configuration for Terraformer
#
# This class configures the CloudWatch agent for Terraformer by including
# the shared base class with Terraformer-specific log collection.
#
# Terraformer-specific logs:
# - /var/log/terraform/*.log - Terraform operation logs (if present)
#
class profile::terraformer::cloudwatch_agent {
### CloudWatch Agent (`profile::terraformer::cloudwatch_agent`)
- File: `environments/development/modules/profile/manifests/terraformer/cloudwatch_agent.pp`
- Configures CloudWatch agent using facts from Terraform module
- Uses shared `profile::cloudwatch_agent` base class

# Only configure if CloudWatch log group is provided via Terraform facts
if $facts['terraformer'] and $facts['terraformer']['cloudwatch_log_group'] {
### Auditd Integration (`profile::terraformer::auditd`)
- File: `environments/development/modules/profile/manifests/terraformer/auditd.pp`
- Tracks all terraform command execution for compliance/audit trail
- Deploys terraformer-specific audit rules

# Include shared CloudWatch agent base class with Terraformer-specific extras
class { 'profile::cloudwatch_agent':
cloudwatch_log_group => $facts['terraformer']['cloudwatch_log_group'],
cloudwatch_namespace => pick($facts['terraformer']['cloudwatch_namespace'], 'Terraformer/System'),
extra_logs => [
# Terraform logs directory (optional - may not exist on all instances)
# { 'path' => '/var/log/terraform/*.log', 'stream' => 'terraform/operations' },
],
extra_procstat => [],
}
### Updated Terraformer Profile
- File: `environments/development/modules/profile/manifests/terraformer.pp`
- Now includes both `cloudwatch_agent` and `auditd` subclasses

}
}
```

### Step 2: Create Directory Structure
## Verification (Sandbox - 2026-01-16)

Facts confirmed working:
```bash
mkdir -p environments/development/modules/profile/manifests/terraformer
```

### Step 3: Update Terraformer Profile

Modify `environments/development/modules/profile/manifests/terraformer.pp` to include CloudWatch agent:

```puppet
# @summary: Terraformer profile.
class profile::terraformer (
$terraform_version = lookup(
'profile::terraformer::terraform_version', undef, undef, 'latest'
)
) {
package { 'terraform':
ensure => $terraform_version
}

# CloudWatch agent for logging and metrics
include profile::terraformer::cloudwatch_agent
root@ip-10-1-1-156:~# facter -p terraformer
{
cloudwatch_log_group => "/aws/ec2/terraformer/sandbox/terraformer",
cloudwatch_namespace => "Terraformer/System"
}
```

## Testing Plan

1. **Deploy Puppet changes** to development environment
2. **Test with existing Terraformer instance** (if any):
```bash
# On the terraformer instance
sudo facter -p terraformer
sudo puppet agent -t --environment development
```
3. **Verify CloudWatch agent**:
```bash
sudo systemctl status amazon-cloudwatch-agent
sudo /usr/local/bin/check-cloudwatch-agent
```
4. **Check CloudWatch Logs** in AWS Console for log streams
## Next Steps (Optional)

## Rollout Sequence
1. **Promote to production** - Copy changes to production environment when ready
2. **Add terraform operation logs** - Uncomment extra_logs in cloudwatch_agent.pp if `/var/log/terraform/` is used
3. **Verify CloudWatch console** - Confirm log streams appearing in AWS CloudWatch Logs

1. Merge this Puppet change to development environment
2. Deploy to development (ih-puppet apply or agent run)
3. Test Terraform module with `make test` (uses development environment)
4. If successful, promote Puppet changes to production
5. Release new Terraform module version
## Original Background

## Dependencies

- `profile::cloudwatch_agent` base class (already exists in development)
- CloudWatch agent package available in APT repository
- Terraform module passing correct facts

## Risks and Mitigations

| Risk | Mitigation |
|------|------------|
| Facts not available on existing instances | Conditional check: `if $facts['terraformer']` |
| CloudWatch agent fails to start | Service has explicit dependencies on config |
| Log group doesn't exist | Terraform creates it before instance boots |

## Verification Commands

After deployment, run these on the Terraformer instance:

```bash
# Check facts are present
sudo facter -p terraformer

# Expected output:
# {
# cloudwatch_log_group => "/aws/ec2/terraformer",
# cloudwatch_namespace => "Terraformer/System"
# }

# Check CloudWatch agent status
sudo systemctl status amazon-cloudwatch-agent

# Check agent config
sudo cat /etc/aws/amazon-cloudwatch-agent.json | jq .

# Check logs are being collected
aws logs describe-log-streams \
--log-group-name "/aws/ec2/terraformer" \
--order-by LastEventTime \
--descending
```

## Estimated Effort

- Implementation: 15 minutes
- Testing: 30 minutes
- Total: ~45 minutes
The `terraform-aws-terraformer` module was updated to:
- Create a CloudWatch log group (`/aws/ec2/terraformer`)
- Pass facts to Puppet:
- `$facts['terraformer']['cloudwatch_log_group']` - Log group name
- `$facts['terraformer']['cloudwatch_namespace']` - Metrics namespace
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
puppet-code (0.1.0-1build275) noble; urgency=medium

* commit event. see changes history in git log

-- root <packager@infrahouse.com> Fri, 16 Jan 2026 21:00:02 +0000

puppet-code (0.1.0-1build274) noble; urgency=medium

* commit event. see changes history in git log
Expand Down
6 changes: 6 additions & 0 deletions environments/sandbox/modules/profile/manifests/terraformer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
package { 'terraform':
ensure => $terraform_version
}

# Audit logging for terraform command tracking
include profile::terraformer::auditd

# CloudWatch agent for logging and metrics
include profile::terraformer::cloudwatch_agent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Terraformer-specific auditd configuration
# Tracks all Terraform command execution for compliance and audit trail
class profile::terraformer::auditd {

# Include the base auditd profile
include profile::auditd

# Deploy terraformer-specific audit rules
file { '/etc/audit/rules.d/50-terraformer.rules':
ensure => file,
owner => 'root',
group => 'root',
mode => '0640',
content => template('profile/terraformer/terraformer.rules.erb'),
notify => Exec['augenrules'],
require => Package['auditd'],
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# CloudWatch agent configuration for Terraformer
#
# This class configures the CloudWatch agent for Terraformer by including
# the shared base class with Terraformer-specific log collection.
#
# Terraformer-specific logs:
# - /var/log/terraform/*.log - Terraform operation logs (if present)
#
class profile::terraformer::cloudwatch_agent {

# Only configure if CloudWatch log group is provided via Terraform facts
if $facts['terraformer'] and $facts['terraformer']['cloudwatch_log_group'] {

# Include shared CloudWatch agent base class with Terraformer-specific extras
class { 'profile::cloudwatch_agent':
cloudwatch_log_group => $facts['terraformer']['cloudwatch_log_group'],
cloudwatch_namespace => pick($facts['terraformer']['cloudwatch_namespace'], 'Terraformer/System'),
extra_logs => [
# Terraform logs directory (optional - may not exist on all instances)
# { 'path' => '/var/log/terraform/*.log', 'stream' => 'terraform/operations' },
],
extra_procstat => [],
}

}
}
Loading