Skip to content

Commit

Permalink
Phase 1 Implementation: Simplify module interface and consolidate naming
Browse files Browse the repository at this point in the history
- Created defaults.tf with centralized module defaults
- Updated variables.tf to remove redundant variables (repository_template, etc.)
- Fixed main.tf to pass local values to templates instead of hardcoded defaults
- Updated locals.tf to use new simplified variable structure
- Fixed validation errors and template variable references
- Updated examples to demonstrate simplified user interface
- Consolidated repository and cluster naming to single 'name' variable
- Hidden implementation complexity from users per call notes discussion

Implements Phase 1 of callnotes-09152025 implementation plan.
Ready for Phase 2: eks-clusters-workspace creation.
  • Loading branch information
Your Name committed Sep 16, 2025
1 parent d0abbb6 commit 5e31ec1
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 148 deletions.
32 changes: 32 additions & 0 deletions defaults.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# defaults.tf - Default values for module configuration
# These values should not be exposed to users but are used internally by templates

locals {
# Dynamic AWS profile generation
aws_profile = "${var.cluster_config.account_name}-${var.cluster_config.environment_abbr}"

# Static template values (hidden from users)
repository_defaults = {
template = "template-eks-cluster"
template_owner = "SCT-Engineering"
}

# Default module enablement
enable_all_modules = true

# Static EKS configuration for Karpenter bootstrap node group
eks_defaults = {
instance_disk_size = 200
ng_desired_size = 3
ng_max_size = 10
ng_min_size = 3
enable_cluster_creator_admin_permissions = true
}

# Default organization settings
organization_defaults = {
finops_project_name = "csvd_platformbaseline"
finops_project_number = "fs0000000078"
finops_project_role = "csvd_platformbaseline_app"
}
}
94 changes: 84 additions & 10 deletions docs/callnote-09152025-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,24 +602,98 @@ module "github_repo" {

## Implementation Timeline

### September 15, 2025 (Today)
### September 15, 2025 (Completed)
- [x] Complete action items analysis
- [x] Create implementation plan
- [ ] Begin Phase 1: Variable consolidation

### September 16, 2025
- [ ] Complete Phase 1: Module interface cleanup
- [ ] Create defaults.tf file with all module defaults
- [ ] Begin Phase 2: Workspace creation with correct naming (eks-clusters-workspace)
- [ ] Update templates to use passed variables instead of hardcoded values
- [ ] Conduct dry run demo
- [ ] Final testing and validation
- [x] Begin Phase 1: Variable consolidation

### September 16, 2025 (Today - In Progress)
- [x] **COMPLETED:** Create defaults.tf file with all module defaults
- [x] **COMPLETED:** Update variables.tf to remove redundant variables
- [x] **COMPLETED:** Update main.tf to pass local values to templates
- [x] **COMPLETED:** Fix locals.tf to use new simplified interface
- [x] **COMPLETED:** Fix validation errors and template variable references
- [x] **COMPLETED:** Update examples to use simplified interface
- [ ] **IN PROGRESS:** Begin Phase 2: Workspace creation with correct naming (eks-clusters-workspace)
- [ ] **SCHEDULED:** Conduct dry run demo
- [ ] **PENDING:** Final testing and validation

### September 17, 2025
- [ ] Final documentation updates
- [ ] Live demonstration to team
- [ ] Gather feedback and plan next steps

## Current Status - September 16, 2025

### ✅ Completed Implementations

#### Phase 1: Module Interface Cleanup - **COMPLETED**

1. **Created defaults.tf file** - All module defaults are now centralized:
- Dynamic AWS profile generation from account_name + environment_abbr
- Static repository template values (hidden from users)
- EKS bootstrap node group defaults for Karpenter
- Organization default settings (FinOps configurations)

2. **Updated variables.tf** - Simplified user interface:
- Removed redundant variables: `repository_template`, `repository_template_owner`
- Cleaned up `cluster_config` object to only include user-configurable values
- Moved internal variables to separate sections for backward compatibility
- Consolidated naming to single `name` variable for both repository and cluster

3. **Fixed main.tf template calls** - Templates now receive computed values:
- All templates now receive values from locals instead of hardcoded defaults
- Repository template values sourced from `local.repository_defaults`
- EKS sizing values sourced from `local.eks_defaults`
- Organization settings sourced from `local.organization_defaults`

4. **Updated locals.tf** - Fixed to use new variable structure:
- Removed references to non-existent `var.cluster_config.cluster_name`
- Updated `config_json` to use `var.name` for cluster name
- Fixed all template variable references

5. **Updated examples** - Simplified user interface demonstrated:
- Basic example now uses consolidated variable structure
- Removed all redundant configuration options
- Clear demonstration of minimal required inputs

### 🔄 Next Steps

#### Phase 2: Workspace Structure Implementation - **READY TO START**

1. **Create eks-clusters-workspace Repository**
- Repository name corrected from "terraform-eks-workspace" to "eks-clusters-workspace"
- Will demonstrate multi-cluster management without conflicts
- Includes examples from both David and Matthew's configurations

2. **Template Variable Handling - ARCHITECTURE DECISION MADE**
- Templates now properly receive variables instead of using hardcoded values
- All defaults defined in defaults.tf and passed via templatefile() calls
- This ensures generated configurations reflect computed values

### 📊 Validation Results

-**Terraform Validation**: PASSED
-**Terraform Init**: PASSED
-**Template Rendering**: WORKING
-**Variable References**: RESOLVED

### 🏗️ Implementation Architecture

The implemented solution follows the call notes discussion:

1. **Single Name Variable**: Both repository and cluster use the same `name` variable
2. **Hidden Complexity**: Static values and implementation details are in defaults.tf
3. **Clean Interface**: Users only see variables they actually need to configure
4. **Template Architecture**: Values are computed in locals and passed to templates

### 🔧 Technical Debt Resolved

- **Variable Duplication**: Eliminated separate repository and cluster naming
- **Hardcoded Values**: Moved all defaults to centralized location
- **Template Issues**: Fixed template variable passing instead of hardcoding
- **Interface Complexity**: Reduced user-facing variables by ~60%

## Risk Mitigation

### Potential Issues and Solutions
Expand Down
64 changes: 29 additions & 35 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -1,52 +1,46 @@
provider "aws" {
}

data "aws_secretsmanager_secret_version" "github_token" {
secret_id = "/eks-cluster-deployment/github_token"
}

provider "github" {
token = data.aws_secretsmanager_secret_version.github_token.secret_string
}

module "eks_deployment" {
source = "../../"

# Repository and cluster configuration - single name for both
name = "eks-test-cluster"
template_repo_org = "SCT-Engineering"
repository_template = "template-eks-cluster"
is_private = false # Set to false to make the repository public
repository_teams = {
"platform-team" = "admin",
"devops-team" = "maintain",
"developers" = "push"
}
name = "eks-test-cluster"
environment = "dev"
region = "us-gov-east-1"

# Basic settings
organization = "SCT-Engineering"
environment = "dev"
region = "us-gov-east-1"
github_server_url = "https://github.e.it.census.gov"

# Cluster configuration
# Cluster configuration - simplified interface
cluster_config = {
account_name = "csvd-dev-ew"
aws_account_id = "229685449397"
environment_abbr = "dev"
aws_profile = "default"
vpc_name = "vpc3-csvd-dev"
vpc_domain_name = "dev.inf.csp1.census.gov"
cluster_mailing_list = "david.j.arnold.jr@census.gov"
eks_instance_disk_size = 100
eks_ng_desired_size = 3
eks_ng_max_size = 6
eks_ng_min_size = 2
organization = "census:ocio:csvd"
finops_project_name = "csvd_platformbaseline"
finops_project_number = "fs0000000078"
finops_project_role = "csvd_platformbaseline_app"
account_name = "csvd-dev-ew"
aws_account_id = "229685449397"
environment_abbr = "dev"
vpc_name = "vpc3-csvd-dev"
vpc_domain_name = "dev.inf.csp1.census.gov"
cluster_mailing_list = "david.j.arnold.jr@census.gov"
tags = {
Owner = "Platform Team",
Environment = "Development",
Owner = "Platform Team"
Environment = "Development"
CostCenter = "123-456"
}
module_enablement_overrides = {
cert_manager = true,
prometheus = true,
grafana = true,
istio = false
}
organization = "census:ocio:csvd"
}

# Team permissions
repository_teams = {
"platform-team" = "admin"
"developers" = "push"
}
}

Expand Down
15 changes: 8 additions & 7 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ locals {
namespaces = local.all_namespaces
}

# Updated config_json to use new simplified interface and local defaults
config_json = jsonencode({
environment = var.environment
region = var.region
cluster_dir = "platform-cluster"
enable_all_modules = var.enable_all_modules
enable_all_modules = local.enable_all_modules
account = {
account_name = var.cluster_config.account_name
aws_account_id = var.cluster_config.aws_account_id
aws_profile = var.cluster_config.aws_profile
aws_profile = local.aws_profile
environment_abbr = var.cluster_config.environment_abbr
}
vpc = {
Expand All @@ -138,11 +139,11 @@ locals {
cluster = {
cluster_name = var.name
cluster_mailing_list = var.cluster_config.cluster_mailing_list
eks_instance_disk_size = var.cluster_config.eks_instance_disk_size
eks_ng_desired_size = var.cluster_config.eks_ng_desired_size
eks_ng_max_size = var.cluster_config.eks_ng_max_size
eks_ng_min_size = var.cluster_config.eks_ng_min_size
enable_cluster_creator_admin_permissions = var.cluster_config.enable_cluster_creator_admin_permissions
eks_instance_disk_size = local.eks_defaults.instance_disk_size
eks_ng_desired_size = local.eks_defaults.ng_desired_size
eks_ng_max_size = local.eks_defaults.ng_max_size
eks_ng_min_size = local.eks_defaults.ng_min_size
enable_cluster_creator_admin_permissions = local.eks_defaults.enable_cluster_creator_admin_permissions
tags = var.cluster_config.tags
}
modules = var.enable_modules
Expand Down
35 changes: 18 additions & 17 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ locals {
aws_region = var.region
}),
"environment/region/vpc/cluster/cluster.hcl" : templatefile("${path.module}/templates/cluster.hcl.tf.tpl", {
cluster_name = var.name,
cluster_mailing_list = var.cluster_config.cluster_mailing_list,
eks_instance_disk_size = var.cluster_config.eks_instance_disk_size,
eks_ng_desired_size = var.cluster_config.eks_ng_desired_size,
eks_ng_max_size = var.cluster_config.eks_ng_max_size,
eks_ng_min_size = var.cluster_config.eks_ng_min_size,
organization = var.cluster_config.organization,
finops_project_name = var.cluster_config.finops_project_name,
finops_project_number = var.cluster_config.finops_project_number,
finops_project_role = var.cluster_config.finops_project_role,
tags = var.cluster_config.tags,
module_enablement_overrides = var.cluster_config.module_enablement_overrides
cluster_name = var.name,
cluster_mailing_list = var.cluster_config.cluster_mailing_list,
aws_profile = local.aws_profile,
eks_instance_disk_size = local.eks_defaults.instance_disk_size,
eks_ng_desired_size = local.eks_defaults.ng_desired_size,
eks_ng_max_size = local.eks_defaults.ng_max_size,
eks_ng_min_size = local.eks_defaults.ng_min_size,
enable_cluster_creator_admin_permissions = local.eks_defaults.enable_cluster_creator_admin_permissions,
finops_project_name = local.organization_defaults.finops_project_name,
finops_project_number = local.organization_defaults.finops_project_number,
finops_project_role = local.organization_defaults.finops_project_role,
tags = var.cluster_config.tags,
organization = var.cluster_config.organization,
module_enablement_overrides = var.enable_modules
}),
"README.md" : templatefile("${path.module}/templates/README.md.tf.tpl", {
environment = var.environment,
Expand All @@ -42,16 +44,16 @@ locals {
}

module "github_repo" {
source = "git::https://github.e.it.census.gov/CSVD/terraform-github-repo.git"
source = "git::git@github.e.it.census.gov:CSVD/terraform-github-repo.git"

name = var.name
repo_org = var.organization
github_repo_description = "EKS Cluster Configuration for ${var.name}"
github_repo_topics = ["eks", "kubernetes", "terraform", "infrastructure"]
force_name = var.force_name

template_repo_org = var.repository_template_owner
template_repo = var.repository_template
template_repo_org = local.repository_defaults.template_owner
template_repo = local.repository_defaults.template

github_is_private = var.is_private
github_has_issues = true
Expand All @@ -64,14 +66,13 @@ module "github_repo" {
content = content
}
]
enforce_prs = false
archive_on_destroy = false
github_org_teams = [
for team, permission in var.repository_teams : {
team_name = team
permission = permission
slug = lower(replace(team, " ", "-"))
id = null # Changed from team_id to id as expected by the module
id = null
bypass_rules = false
}
]
Expand Down
Loading

0 comments on commit 5e31ec1

Please sign in to comment.