Skip to content

Commit

Permalink
Update GitHub server URL and refactor related configurations for EKS …
Browse files Browse the repository at this point in the history
…deployment
  • Loading branch information
arnol377 committed Apr 14, 2025
1 parent fbf89c9 commit 7e9ae4e
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down
45 changes: 15 additions & 30 deletions basic.tftest.hcl
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/test_trigger_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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', {})

Expand Down
5 changes: 2 additions & 3 deletions validation.tftest.hcl → validation.tftest.hcl.tmp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
19 changes: 15 additions & 4 deletions workflow_trigger.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
}
40 changes: 40 additions & 0 deletions workflow_trigger.tftest.hcl.tmp
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 7e9ae4e

Please sign in to comment.