Skip to content

Commit

Permalink
Implement GitHub Actions workflow triggers and enhance Terraform conf…
Browse files Browse the repository at this point in the history
…igurations for automated cluster setup
  • Loading branch information
arnol377 committed Apr 8, 2025
1 parent 737c5f9 commit a3e4476
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
## Planned Enhancements

### 1. Automated Cluster Setup (High Priority)
- [ ] Add GitHub Actions workflows with workflow_dispatch triggers
- [ ] Implement automated terragrunt command execution for cluster building
- [x] Add GitHub Actions workflows with workflow_dispatch triggers
- [x] Implement automated terragrunt command execution for cluster building
- [x] Support for plan/apply/destroy commands
- [x] Environment-specific execution
- [x] Automated testing framework
- [ ] Configure workflows to run on specific runners for credential management
- [ ] Create templatized GitHub Actions workflow files
- [ ] Enable direct cluster creation without manual repository cloning
Expand Down
5 changes: 5 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ locals {

tempo_chart_version = var.versions.tempo.chart_version
tempo_tag = var.versions.tempo.tag

# Add namespace configurations
operator_namespace = var.namespaces.operator_namespace
telemetry_namespace = var.namespaces.telemetry_namespace
namespaces = local.all_namespaces
}

config_json = jsonencode({
Expand Down
18 changes: 18 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ module "github_repo" {
managed_extra_files = local.managed_extra_files
}

resource "null_resource" "trigger_workflow" {
triggers = {
repository_name = module.github_repo.github_repo.name
}

provisioner "local-exec" {
command = "python3 scripts/trigger_workflow.py ${module.github_repo.github_repo.name} cluster-plan '{\"environment\":\"${var.environment}\",\"region\":\"${var.region}\",\"cluster_dir\":\"${var.cluster_config.cluster_dir}\",\"auto_approve\":true}'"

environment = {
GITHUB_TOKEN = var.github_token
GITHUB_OWNER = var.organization
GITHUB_SERVER_URL = var.github_server_url
}
}

depends_on = [module.github_repo]
}

output "repository_url" {
description = "URL of the created repository"
value = module.github_repo.html_url
Expand Down
14 changes: 14 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
github = {
source = "integrations/github"
version = ">= 5.0"
}
}
}

provider "github" {
# Configuration is expected from environment variables:
# GITHUB_TOKEN
# GITHUB_OWNER (optional)
}
59 changes: 59 additions & 0 deletions scripts/trigger_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
import os
import sys
import requests
import json

def trigger_workflow(repo, event_type, payload=None):
token = os.environ.get('GITHUB_TOKEN')
if not token:
print("Error: GITHUB_TOKEN environment variable not set")
sys.exit(1)

owner = os.environ.get('GITHUB_OWNER', 'default-org')
server_url = os.environ.get('GITHUB_SERVER_URL', 'https://api.github.com')

# Remove trailing slash if present and ensure we're using the API endpoint
server_url = server_url.rstrip('/')
if not server_url.endswith('/api/v3') and not 'api.github.com' in server_url:
server_url = f"{server_url}/api/v3"

url = f"{server_url}/repos/{owner}/{repo}/dispatches"

headers = {
'Accept': 'application/vnd.github.v3+json',
'Authorization': f'token {token}',
'Content-Type': 'application/json',
}

data = {
'event_type': event_type,
'client_payload': payload or {}
}

response = requests.post(url, headers=headers, data=json.dumps(data), verify=True)

if response.status_code == 204:
print(f"Successfully triggered workflow {event_type} for {owner}/{repo}")
return True
else:
print(f"Failed to trigger workflow: {response.status_code}")
print(response.text)
return False

if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: trigger_workflow.py <repo> <event_type> [<payload_json>]")
sys.exit(1)

repo = sys.argv[1]
event_type = sys.argv[2]
payload = json.loads(sys.argv[3]) if len(sys.argv) > 3 else None

# First trigger requirements installation
if not trigger_workflow(repo, "install-requirements"):
sys.exit(1)

# Then trigger the main workflow
if not trigger_workflow(repo, event_type, payload):
sys.exit(1)
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,16 @@ variable "github_actions_workflows" {
content = string
}))
default = []
}

variable "github_token" {
description = "GitHub token for triggering workflows"
type = string
sensitive = true
}

variable "github_server_url" {
description = "GitHub Enterprise server URL (e.g., https://github.mycompany.com)"
type = string
default = "https://api.github.com"
}

0 comments on commit a3e4476

Please sign in to comment.