diff --git a/ROADMAP.md b/ROADMAP.md index f7160db..12f698f 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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 diff --git a/locals.tf b/locals.tf index 333ceb6..30494ed 100644 --- a/locals.tf +++ b/locals.tf @@ -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({ diff --git a/main.tf b/main.tf index 380a7c6..d168751 100644 --- a/main.tf +++ b/main.tf @@ -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 diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..e01c942 --- /dev/null +++ b/providers.tf @@ -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) +} \ No newline at end of file diff --git a/scripts/trigger_workflow.py b/scripts/trigger_workflow.py new file mode 100755 index 0000000..f5b1fb2 --- /dev/null +++ b/scripts/trigger_workflow.py @@ -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 []") + 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) \ No newline at end of file diff --git a/variables.tf b/variables.tf index 6924186..2a6534f 100644 --- a/variables.tf +++ b/variables.tf @@ -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" } \ No newline at end of file