diff --git a/README.md b/README.md index 0bac3a8..282aa3a 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ module "eks_deployment" { } github_token = "your-github-token" - github_server_url = "https://github.mycompany.com" # Optional, for GitHub Enterprise + github_server_url = "https://github.e.it.census.gov" # Optional, for GitHub Enterprise } ``` diff --git a/basic.tftest.hcl b/basic.tftest.hcl index 6bdd237..1036299 100644 --- a/basic.tftest.hcl +++ b/basic.tftest.hcl @@ -1,10 +1,10 @@ variables { - github_token = "mock-token" name = "test-eks-cluster" - organization = "test-org" - template_repo_org = "test-org" + organization = "SCT-Engineering" + template_repo_org = "SCT-Engineering" environment = "dev" - region = "us-east-1" + region = "us-gov-east-1" + github_server_url = "https://github.e.it.census.gov" cluster_config = { cluster_name = "dev-eks-01" account_name = "dev-account" @@ -14,47 +14,32 @@ variables { vpc_name = "dev-vpc" vpc_domain_name = "dev.example.com" } + enable_modules = { + cert_manager = true + prometheus = true + grafana = true + } } provider "github" { - token = var.github_token - base_url = "https://github.mycompany.com/api/v3" + base_url = var.github_server_url } run "verify_repository_config" { - command = plan + command = apply assert { - condition = module.eks_deployment.github_repo.name == "test-eks-cluster" + condition = module.github_repo.github_repo.name == var.name error_message = "Repository name does not match expected value" } assert { - condition = module.eks_deployment.github_repo.description == "EKS Cluster Configuration for dev-eks-01" - error_message = "Repository description does not match expected value" + condition = contains(module.github_repo.github_repo.topics, "eks") + error_message = "Repository topics should include 'eks'" } assert { - condition = module.eks_deployment.github_repo.visibility == "private" + condition = module.github_repo.github_repo.visibility == "private" error_message = "Repository visibility should be private" } -} - -run "verify_module_defaults" { - command = plan - - assert { - condition = length(module.eks_deployment.enable_modules.*.cert_manager) > 0 - error_message = "cert-manager module should be enabled" - } - - assert { - condition = length(module.eks_deployment.enable_modules.*.prometheus) > 0 - error_message = "prometheus module should be enabled" - } - - assert { - condition = length(module.eks_deployment.enable_modules.*.grafana) > 0 - error_message = "grafana module should be enabled" - } } \ No newline at end of file diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 44645ff..437b6ac 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -14,7 +14,7 @@ module "eks_deployment" { template_repo_org = "my-org" github_token = var.github_token - github_server_url = "https://github.mycompany.com" + github_server_url = "https://github.e.it.census.gov" cluster_config = { cluster_name = "dev-eks-01" diff --git a/main.tf b/main.tf index 35861cc..1027f77 100644 --- a/main.tf +++ b/main.tf @@ -19,15 +19,15 @@ module "github_repo" { resource "null_resource" "trigger_workflow" { triggers = { - github_repo_name = module.github_repo.github_repo.name + github_repo_name = module.github_repo.full_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_name}\",\"auto_approve\":true}'" + command = "python3 scripts/trigger_workflow.py ${module.github_repo.full_name} cluster-plan '{\"environment\":\"${var.environment}\",\"region\":\"${var.region}\",\"cluster_dir\":\"${var.cluster_config.cluster_name}\",\"auto_approve\":true}'" environment = { GITHUB_TOKEN = var.github_token - GITHUB_OWNER = var.organization + GITHUB_OWNER = var.organization GITHUB_SERVER_URL = var.github_server_url } } diff --git a/scripts/test_trigger_workflow.py b/scripts/test_trigger_workflow.py index ae786fd..47ba51e 100644 --- a/scripts/test_trigger_workflow.py +++ b/scripts/test_trigger_workflow.py @@ -10,7 +10,7 @@ def test_trigger_workflow_success(): mock_post.return_value = mock_response os.environ['GITHUB_TOKEN'] = 'test-token' - os.environ['GITHUB_OWNER'] = 'test-org' + os.environ['GITHUB_OWNER'] = 'SCT-Engineering' os.environ['GITHUB_SERVER_URL'] = 'https://github.example.com' result = trigger_workflow('test-repo', 'cluster-plan', { @@ -31,7 +31,7 @@ def test_trigger_workflow_failure(): mock_post.return_value = mock_response os.environ['GITHUB_TOKEN'] = 'invalid-token' - os.environ['GITHUB_OWNER'] = 'test-org' + os.environ['GITHUB_OWNER'] = 'SCT-Engineering' result = trigger_workflow('test-repo', 'cluster-plan', {}) diff --git a/validation.tftest.hcl b/validation.tftest.hcl.tmp similarity index 90% rename from validation.tftest.hcl rename to validation.tftest.hcl.tmp index 666f4fa..e609b16 100644 --- a/validation.tftest.hcl +++ b/validation.tftest.hcl.tmp @@ -1,10 +1,10 @@ variables { - github_token = "mock-token" name = "test-eks-cluster" organization = "test-org" template_repo_org = "test-org" environment = "dev" region = "us-east-1" + github_server_url = "https://github.e.it.census.gov" cluster_config = { cluster_name = "dev-eks-01" account_name = "dev-account" @@ -17,8 +17,7 @@ variables { } provider "github" { - token = var.github_token - base_url = "https://github.mycompany.com/api/v3" + base_url = var.github_server_url } # Test invalid cluster version diff --git a/variables.tf b/variables.tf index 4afa3c5..cab10ae 100644 --- a/variables.tf +++ b/variables.tf @@ -209,7 +209,7 @@ variable "github_token" { } variable "github_server_url" { - description = "GitHub Enterprise server URL (e.g., https://github.mycompany.com)" + description = "GitHub Enterprise server URL (e.g., https://github.e.it.census.gov)" type = string default = "https://api.github.com" } \ No newline at end of file diff --git a/workflow_trigger.tftest.hcl b/workflow_trigger.tftest.hcl index 84b50e5..11ffc81 100644 --- a/workflow_trigger.tftest.hcl +++ b/workflow_trigger.tftest.hcl @@ -5,6 +5,7 @@ variables { template_repo_org = "test-org" environment = "dev" region = "us-east-1" + github_server_url = "https://github.e.it.census.gov" cluster_config = { cluster_name = "dev-eks-01" account_name = "dev-account" @@ -14,18 +15,28 @@ variables { vpc_name = "dev-vpc" vpc_domain_name = "dev.example.com" } + enable_modules = { + cert_manager = true + prometheus = true + grafana = true + } } provider "github" { token = var.github_token - base_url = "https://github.mycompany.com/api/v3" + base_url = var.github_server_url } run "verify_workflow_trigger" { - command = plan + command = apply + + assert { + condition = can(null_resource.trigger_workflow) + error_message = "Workflow trigger resource should exist" + } assert { - condition = can([github_repository_dispatch.dispatch]) - error_message = "Workflow trigger failed to dispatch" + condition = null_resource.trigger_workflow.triggers.github_repo_name == module.github_repo.full_name + error_message = "Workflow trigger should use correct repository name" } } \ No newline at end of file diff --git a/workflow_trigger.tftest.hcl.tmp b/workflow_trigger.tftest.hcl.tmp new file mode 100644 index 0000000..1812c1f --- /dev/null +++ b/workflow_trigger.tftest.hcl.tmp @@ -0,0 +1,40 @@ +variables { + name = "test-eks-cluster" + organization = "test-org" + template_repo_org = "test-org" + environment = "dev" + region = "us-east-1" + github_server_url = "https://github.e.it.census.gov" + cluster_config = { + cluster_name = "dev-eks-01" + account_name = "dev-account" + aws_account_id = "123456789012" + aws_profile = "dev-profile" + environment_abbr = "dev" + vpc_name = "dev-vpc" + vpc_domain_name = "dev.example.com" + } + enable_modules = { + cert_manager = true + prometheus = true + grafana = true + } +} + +provider "github" { + base_url = var.github_server_url +} + +run "verify_workflow_trigger" { + command = apply + + assert { + condition = can(null_resource.trigger_workflow) + error_message = "Workflow trigger resource should exist" + } + + assert { + condition = null_resource.trigger_workflow.triggers.github_repo_name == module.github_repo.full_name + error_message = "Workflow trigger should use correct repository name" + } +} \ No newline at end of file