xbalajipge: Describe the design of the terraform code in tfe/modules/{projects,teams,workspaces} folder; give a high level over view as bullet points, suitable for presentationn
Workspace: Collecting workspace information# High-Level Design Overview: TFE Modules
Based on the Terraform code in tfe/modules/{projects,teams,workspaces}, here's a presentation-ready overview:
tfe/modules/projects- Project managementtfe/modules/teams- Team managementtfe/modules/workspaces- Workspace management
- Creates and manages Terraform Cloud (TFC) projects
- Organizes workspaces under logical project boundaries
- Simple project resource creation via
tfe_project - Sub-module:
project-accessfor managing team permissions - Supports read-only access for AD groups
- Returns project ID and metadata for downstream dependencies
tfe_project.this- Main project resourcetfe_team_project_access.read- Team access control
- Provisions TFC teams aligned with Active Directory groups
- Manages organization-level permissions
- Creates teams with
tfe_teamresource - Configurable permissions via
propertiesvariable:- Workspace management
- Policy management
- VCS settings
- Module/provider management
- Project access
- Sub-module:
team-accessfor workspace-level permissions
- Read-only: View workspaces and runs
- Apply: Execute runs, manage variables, write state
- Core module for creating and configuring TFC workspaces
- Manages workspace settings, variables, and integrations
- VCS integration (GitHub repo connection)
- Terraform version management
- Working directory specification
- Tag-based organization
- Terraform variables (
tfe_variable.tf_vars) - Environment variables (
tfe_variable.env_vars) - Auto-injection of workspace metadata (ID, name)
- Cloud provider-specific variables (AWS account, Azure subscription)
- Policy set attachments (
tfe_workspace_policy_set) - Run task integration (e.g., Prisma Cloud scanning)
- Drift detection support
- Auto-destroy scheduling
- Execution mode (remote/agent-based)
- Auto-apply configuration
- Queue behavior
- File trigger patterns
- AWS-specific variables (
account_num) - Azure-specific variables (
arm_subscription_id,arm_tenant_id) - Conditional logic based on
cspvariable
- Ignore changes on
queue_all_runsandtag_names(managed by OIDC lambda) - Preconditions for required cloud provider variables
- Lowercase enforcement for tags
- Environment-based tagging
- Application ID tracking
- Separate resource (
tfe_workspace_settings) for execution mode - Environment-specific run task enforcement (advisory for dev/test, mandatory for qa/prod)
- Terraform
>= 1.6.1 - TFE provider
>= 0.49.2
app.terraform.io/pgetech/utils/aws//modules/workspace-info- Workspace metadata- Active Directory groups for team membership
- VCS OAuth tokens for repository access
- Workspace ID, name, and full object
- Team IDs and metadata
- Project IDs and configurations
- Variable sets for downstream consumption
# Example from tfe/modules/tfc-workspace
module "workspaces" {
source = "./modules/workspaces"
name = "my-workspace"
organization = "pgetech"
vcs_repo = { identifier = "org/repo", branch = "main" }
tf_vars = { key = "value" }
project_name = "my-project"
}✅ Modular Design - Separation of concerns (projects, teams, workspaces)
✅ Enterprise-Ready - Multi-cloud, policy enforcement, drift detection
✅ Security-First - Team access controls, run task integration
✅ Automation-Friendly - Variable injection, OIDC integration, metadata tracking
✅ Scalable - Supports hundreds of workspaces via YAML-driven configuration
xbalajipge: Combine the above content for a unified design solution with
Terraform on Terraform: Automated TFC Management
Implemented approach uses Terraform to manage Terraform Cloud (TFC) resources programmatically.
Automates lifecycle of Projects, Teams, and Workspaces.
Two-Layer Architecture
Foundational Layer
Creates Projects for workspace grouping.
Creates Teams linked to AD groups for SSO.
Assigns teams to projects with high-level permissions.
Workspace Layer
Handles individual workspaces and their permissions.
Dynamic Workspace Provisioning
Workspace definitions sourced from external data files.
Loop-driven process creates hundreds of workspaces from a reusable template.
Module configures VCS repo, Terraform version, and auto-apply settings.
Granular Access Control
Dedicated module assigns AD groups to read-only and apply roles per workspace.
Workflow
Workspace requirements defined in a simple format.
Orchestration converts requirements into Terraform-ready data.
Foundational Layer ensures projects and teams exist.
Workspace Layer creates/updates workspaces and applies permissions.
- Self-Service Infrastructure: Uses Terraform to manage Terraform Cloud (TFC) resources programmatically
- Automation-First: Eliminates manual workspace creation and permission management
- Scalable Architecture: Supports hundreds of workspaces through declarative configuration
Projects → Teams → Project Access
-
projects
- Logical grouping containers for workspaces
- Namespace isolation for different applications/teams
- Foundation for permission inheritance
-
teams
- AD group integration via SSO
- Organization-level permissions (workspace admin, policy management)
- Reusable security principals across projects
-
Project-Level Access
- High-level team-to-project assignments
- Read-only access for AD groups (e.g., viewers, auditors)
- Establishes baseline permissions before workspace creation
Workspaces → Variables → Run Tasks → Team Access
-
workspaces
- Individual workspace provisioning
- VCS integration (GitHub repository connection)
- Terraform version pinning and working directory specification
-
Variable Management
- Terraform variables (application-specific)
- Environment variables (credentials, settings)
- Auto-injected metadata (workspace ID, cloud provider accounts)
-
Security & Compliance
- Policy set attachments (Sentinel policies)
- Run task integration (Prisma Cloud, cost estimation)
- Drift detection and auto-destroy scheduling
-
Workspace-Level Access
- Granular AD group permissions per workspace
- Read-Only: View runs and state
- Apply: Execute runs, manage variables, write state
YAML/JSON Definitions → Orchestration → Terraform Modules → TFC Resources
# workspace-definitions.yaml
workspaces:
- name: "app-prod-network"
project: "networking"
vcs_repo: "pgetech/terraform-network"
branch: "main"
read_teams: ["network-viewers"]
apply_teams: ["network-admins"]- External data processing (Lambda, GitHub Actions, etc.)
- Converts YAML/JSON into Terraform-compatible structures
- Enriches with environment-specific defaults
- Validates against organizational standards
# example workspace creation
module "workspaces" {
source = "./tfe/modules/workspaces"
for_each = local.workspace_definitions
name = each.value.name
project_name = each.value.project
vcs_repo = each.value.vcs_repo
# ...
}# example workspace access
module "workspace_access" {
source = "./tfe/modules/teams/modules/team-access"
for_each = local.workspace_permissions
workspace_id = module.workspaces[each.key].id
team_id = data.tfe_team.read_only[each.value.team].id
access = "read"
}Organization → Project → Workspace → Resource
| Team Type | Scope | Capabilities |
|---|---|---|
| Platform Teams | Organization | Manage all projects, teams, policies |
| Project Admins | Project | Create workspaces, assign teams |
| Workspace Admins | Workspace | Configure settings, manage runs, apply changes |
| Workspace Apply | Workspace | Execute runs, update variables |
| Workspace Read | Workspace | View runs, download state (read-only) |
# Example: Platform Infrastructure Team
module "platform_team" {
source = "./tfe/modules/teams"
name = "ad-platform-infrastructure"
properties = {
manage_workspaces = true
manage_policies = true
manage_vcs_settings = true
}
}
# Example: Application Team
module "app_team_read" {
source = "./tfe/modules/teams"
name = "ad-app-developers-read"
properties = {
manage_workspaces = false # Read-only access
}
}-
Project Creation
- Define logical boundaries (networking, data, applications)
- Execute projects
-
Team Provisioning
- Map AD groups to TFC teams
- Execute teams
- Assign organization-level permissions
-
Project Access
- Link teams to projects
- Establish baseline read permissions
-
Requirement Definition
# Simple format for developers workspace: name: my-app-prod cloud: aws repository: pgetech/my-app-infra
-
Orchestration Processing
- Validate against standards
- Enrich with defaults (Terraform version, policies)
- Generate Terraform variables
-
Workspace Creation
- Loop through definitions
- Execute workspaces
- Configure VCS, variables, run tasks
-
Permission Assignment
- Apply workspace-level team access
- Enforce least-privilege principle
-
Change Detection
- Monitor workspace definition files
- Trigger Terraform apply on updates
-
Drift Remediation
- Detect manual changes in TFC
- Re-apply Terraform to restore desired state
-
Lifecycle Automation
- Auto-destroy for ephemeral environments
- Tag management via OIDC Lambda integration
✅ Template-Based: One module supports hundreds of workspaces
✅ Loop-Driven: for_each eliminates repetitive code
✅ Data-Driven: Adding workspaces = updating data files
✅ AD Integration: SSO with existing identity provider
✅ Least Privilege: Granular permissions at workspace level
✅ Policy Enforcement: Sentinel policies attached automatically
✅ Audit Trail: All changes tracked in Terraform state
✅ Self-Service: Teams request workspaces via simple YAML
✅ Consistency: Standardized workspace configuration
✅ Fast Provisioning: Automated creation in minutes
✅ Infrastructure as Code: TFC infrastructure versioned in Git
✅ Idempotent: Safe to re-run without side effects
✅ Multi-Cloud: AWS/Azure support with conditional logic
✅ Compliance: Run tasks (Prisma Cloud) enforce security standards
tfe/
├── modules/
│ ├── projects/
│ │ ├── main.tf # Project resource
│ │ └── modules/
│ │ └── project-access/ # Team-to-project binding
│ ├── teams/
│ │ ├── main.tf # Team resource
│ │ └── modules/
│ │ └── team-access/ # Team-to-workspace binding
│ └── workspaces/
│ ├── main.tf # Workspace resource
│ ├── variables.tf # Multi-cloud variables
│ └── outputs.tf # Workspace metadata
External Data Source (YAML/JSON)
↓
Orchestration Layer (Lambda/Actions)
↓
Terraform Variables (tfvars)
↓
[Layer 1] Projects + Teams + Project Access
↓
[Layer 2] Workspaces + Variables + Team Access
↓
Terraform Cloud Infrastructure
# Conditional variable injection
locals {
aws_vars = var.csp == "aws" ? {
account_num = var.account_num
} : {}
azure_vars = var.csp == "azure" ? {
arm_subscription_id = var.arm_subscription_id
arm_tenant_id = var.arm_tenant_id
} : {}
}# 1. Create Project
module "data_platform" {
source = "./tfe/modules/projects"
name = "data-platform"
}
# 2. Create Teams
module "data_engineers" {
source = "./tfe/modules/teams"
name = "ad-data-engineers"
}
# 3. Assign Team to Project
module "project_access" {
source = "./tfe/modules/projects/modules/project-access"
project_id = module.data_platform.id
team_id = module.data_engineers.id
access = "read"
}
# 4. Create Workspace
module "glue_crawler" {
source = "./tfe/modules/workspaces"
name = "data-glue-crawler-prod"
project_name = "data-platform"
vcs_repo = {
identifier = "pgetech/terraform-glue"
branch = "main"
}
csp = "aws"
account_num = "123456789012"
}
# 5. Assign Workspace Permissions
module "workspace_access" {
source = "./tfe/modules/teams/modules/team-access"
workspace_id = module.glue_crawler.id
team_id = module.data_engineers.id
access = "apply"
}🎯 Declarative: Infrastructure defined as code
🎯 Modular: Reusable components with clear boundaries
🎯 Automated: Minimal manual intervention
🎯 Secure: AD-integrated, policy-enforced, least-privilege
🎯 Scalable: Supports enterprise-scale workspace management
🎯 Auditable: Complete change history in version control