diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..6db2030 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,63 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.3" + hashes = [ + "h1:+AnORRgFbRO6qqcfaQyeX80W0eX3VmjadjnUFUJTiXo=", + "zh:22d062e5278d872fe7aed834f5577ba0a5afe34a3bdac2b81f828d8d3e6706d2", + "zh:23dead00493ad863729495dc212fd6c29b8293e707b055ce5ba21ee453ce552d", + "zh:28299accf21763ca1ca144d8f660688d7c2ad0b105b7202554ca60b02a3856d3", + "zh:55c9e8a9ac25a7652df8c51a8a9a422bd67d784061b1de2dc9fe6c3cb4e77f2f", + "zh:756586535d11698a216291c06b9ed8a5cc6a4ec43eee1ee09ecd5c6a9e297ac1", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:9d5eea62fdb587eeb96a8c4d782459f4e6b73baeece4d04b4a40e44faaee9301", + "zh:a6355f596a3fb8fc85c2fb054ab14e722991533f87f928e7169a486462c74670", + "zh:b5a65a789cff4ada58a5baffc76cb9767dc26ec6b45c00d2ec8b1b027f6db4ed", + "zh:db5ab669cf11d0e9f81dc380a6fdfcac437aea3d69109c7aef1a5426639d2d65", + "zh:de655d251c470197bcbb5ac45d289595295acb8f829f6c781d4a75c8c8b7c7dd", + "zh:f5c68199f2e6076bce92a12230434782bf768103a427e9bb9abee99b116af7b5", + ] +} + +provider "registry.terraform.io/hashicorp/tls" { + version = "4.0.6" + hashes = [ + "h1:dYSb3V94K5dDMtrBRLPzBpkMTPn+3cXZ/kIJdtFL+2M=", + "zh:10de0d8af02f2e578101688fd334da3849f56ea91b0d9bd5b1f7a243417fdda8", + "zh:37fc01f8b2bc9d5b055dc3e78bfd1beb7c42cfb776a4c81106e19c8911366297", + "zh:4578ca03d1dd0b7f572d96bd03f744be24c726bfd282173d54b100fd221608bb", + "zh:6c475491d1250050765a91a493ef330adc24689e8837a0f07da5a0e1269e11c1", + "zh:81bde94d53cdababa5b376bbc6947668be4c45ab655de7aa2e8e4736dfd52509", + "zh:abdce260840b7b050c4e401d4f75c7a199fafe58a8b213947a258f75ac18b3e8", + "zh:b754cebfc5184873840f16a642a7c9ef78c34dc246a8ae29e056c79939963c7a", + "zh:c928b66086078f9917aef0eec15982f2e337914c5c4dbc31dd4741403db7eb18", + "zh:cded27bee5f24de6f2ee0cfd1df46a7f88e84aaffc2ecbf3ff7094160f193d50", + "zh:d65eb3867e8f69aaf1b8bb53bd637c99c6b649ba3db16ded50fa9a01076d1a27", + "zh:ecb0c8b528c7a619fa71852bb3fb5c151d47576c5aab2bf3af4db52588722eeb", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/integrations/github" { + version = "6.6.0" + constraints = ">= 5.0.0" + hashes = [ + "h1:Fp0RrNe+w167AQkVUWC1WRAsyjhhHN7aHWUky7VkKW8=", + "zh:0b1b5342db6a17de7c71386704e101be7d6761569e03fb3ff1f3d4c02c32d998", + "zh:2fb663467fff76852126b58315d9a1a457e3b04bec51f04bf1c0ddc9dfbb3517", + "zh:4183e557a1dfd413dae90ca4bac37dbbe499eae5e923567371f768053f977800", + "zh:48b2979f88fb55cdb14b7e4c37c44e0dfbc21b7a19686ce75e339efda773c5c2", + "zh:5d803fb06625e0bcf83abb590d4235c117fa7f4aa2168fa3d5f686c41bc529ec", + "zh:6f1dd094cbab36363583cda837d7ca470bef5f8abf9b19f23e9cd8b927153498", + "zh:772edb5890d72b32868f9fdc0a9a1d4f4701d8e7f8acb37a7ac530d053c776e3", + "zh:798f443dbba6610431dcef832047f6917fb5a4e184a3a776c44e6213fb429cc6", + "zh:cc08dfcc387e2603f6dbaff8c236c1254185450d6cadd6bad92879fe7e7dbce9", + "zh:d5e2c8d7f50f91d6847ddce27b10b721bdfce99c1bbab42a68fa271337d73d63", + "zh:e69a0045440c706f50f84a84ff8b1df520ec9bf757de4b8f9959f2ed20c3f440", + "zh:efc5358573a6403cbea3a08a2fcd2407258ac083d9134c641bdcb578966d8bdf", + "zh:f627a255e5809ec2375f79949c79417847fa56b9e9222ea7c45a463eb663f137", + "zh:f7c02f762e4cf1de7f58bde520798491ccdd54a5bd52278d579c146d1d07d4f0", + "zh:fbd1fee2c9df3aa19cf8851ce134dea6e45ea01cb85695c1726670c285797e25", + ] +} diff --git a/.terraform/modules/github_repo b/.terraform/modules/github_repo new file mode 160000 index 0000000..b6b6cba --- /dev/null +++ b/.terraform/modules/github_repo @@ -0,0 +1 @@ +Subproject commit b6b6cba8c08f2997b7a4058c421d41744ef7793d diff --git a/.terraform/modules/modules.json b/.terraform/modules/modules.json new file mode 100644 index 0000000..3ca46f1 --- /dev/null +++ b/.terraform/modules/modules.json @@ -0,0 +1 @@ +{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"github_repo","Source":"registry.terraform.io/HappyPathway/repo/github","Version":"1.0.83","Dir":".terraform/modules/github_repo"}]} \ No newline at end of file diff --git a/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 b/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 new file mode 120000 index 0000000..fe28aef --- /dev/null +++ b/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 @@ -0,0 +1 @@ +/data/terraform/workspaces/arnol377/terraform-plugin-cache/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 \ No newline at end of file diff --git a/.terraform/providers/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 b/.terraform/providers/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 new file mode 120000 index 0000000..08157aa --- /dev/null +++ b/.terraform/providers/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 @@ -0,0 +1 @@ +/data/terraform/workspaces/arnol377/terraform-plugin-cache/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 \ No newline at end of file diff --git a/.terraform/providers/registry.terraform.io/integrations/github/6.6.0/linux_amd64 b/.terraform/providers/registry.terraform.io/integrations/github/6.6.0/linux_amd64 new file mode 120000 index 0000000..26dfde5 --- /dev/null +++ b/.terraform/providers/registry.terraform.io/integrations/github/6.6.0/linux_amd64 @@ -0,0 +1 @@ +/data/terraform/workspaces/arnol377/terraform-plugin-cache/registry.terraform.io/integrations/github/6.6.0/linux_amd64 \ No newline at end of file diff --git a/examples/basic/basic.tftest.hcl b/basic.tftest.hcl similarity index 69% rename from examples/basic/basic.tftest.hcl rename to basic.tftest.hcl index 48bd466..6bdd237 100644 --- a/examples/basic/basic.tftest.hcl +++ b/basic.tftest.hcl @@ -1,10 +1,23 @@ variables { github_token = "mock-token" + name = "test-eks-cluster" + organization = "test-org" + template_repo_org = "test-org" + environment = "dev" + region = "us-east-1" + 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" + } } provider "github" { - owner = "my-org" - token = "mock-token" + token = var.github_token base_url = "https://github.mycompany.com/api/v3" } @@ -12,7 +25,7 @@ run "verify_repository_config" { command = plan assert { - condition = module.eks_deployment.github_repo.name == "eks-test-cluster" + condition = module.eks_deployment.github_repo.name == "test-eks-cluster" error_message = "Repository name does not match expected value" } diff --git a/examples/basic/.terraform/modules/eks_deployment.github_repo b/examples/basic/.terraform/modules/eks_deployment.github_repo new file mode 160000 index 0000000..b6b6cba --- /dev/null +++ b/examples/basic/.terraform/modules/eks_deployment.github_repo @@ -0,0 +1 @@ +Subproject commit b6b6cba8c08f2997b7a4058c421d41744ef7793d diff --git a/examples/basic/.terraform/modules/modules.json b/examples/basic/.terraform/modules/modules.json new file mode 100644 index 0000000..2ad9006 --- /dev/null +++ b/examples/basic/.terraform/modules/modules.json @@ -0,0 +1 @@ +{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"eks_deployment","Source":"../..","Dir":"../.."},{"Key":"eks_deployment.github_repo","Source":"registry.terraform.io/HappyPathway/repo/github","Version":"1.0.83","Dir":".terraform/modules/eks_deployment.github_repo"}]} \ No newline at end of file diff --git a/examples/basic/workflow_trigger.tftest.hcl b/examples/basic/workflow_trigger.tftest.hcl deleted file mode 100644 index 501393d..0000000 --- a/examples/basic/workflow_trigger.tftest.hcl +++ /dev/null @@ -1,32 +0,0 @@ -variables { - github_token = "mock-token" -} - -mock_provider "github" { - mock_resource "github_repository_dispatch" { - defaults = { - result = { - status_code = 204 - } - } - - assert "verify_workflow_payload" { - condition = self.input.event_type == "cluster-plan" && - self.input.client_payload.environment == "dev" && - self.input.client_payload.region == "us-east-1" && - self.input.client_payload.cluster_dir == "dev-eks-01" - error_message = "Invalid workflow dispatch payload" - } - } -} - -run "verify_workflow_trigger" { - command = plan - - # This test verifies that the workflow trigger mechanism works - # without actually making API calls - assert { - condition = true - error_message = "Workflow trigger test failed" - } -} \ No newline at end of file diff --git a/main.tf b/main.tf index d168751..35861cc 100644 --- a/main.tf +++ b/main.tf @@ -19,11 +19,11 @@ module "github_repo" { resource "null_resource" "trigger_workflow" { triggers = { - repository_name = module.github_repo.github_repo.name + github_repo_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}'" + 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}'" environment = { GITHUB_TOKEN = var.github_token diff --git a/terraform_data_dirs/default/modules/github_repo b/terraform_data_dirs/default/modules/github_repo new file mode 160000 index 0000000..b6b6cba --- /dev/null +++ b/terraform_data_dirs/default/modules/github_repo @@ -0,0 +1 @@ +Subproject commit b6b6cba8c08f2997b7a4058c421d41744ef7793d diff --git a/terraform_data_dirs/default/modules/modules.json b/terraform_data_dirs/default/modules/modules.json new file mode 100644 index 0000000..a03d773 --- /dev/null +++ b/terraform_data_dirs/default/modules/modules.json @@ -0,0 +1 @@ +{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"github_repo","Source":"registry.terraform.io/HappyPathway/repo/github","Version":"1.0.83","Dir":"/data/terraform/workspaces/arnol377/git/terraform-eks-deployment/terraform_data_dirs/default/modules/github_repo"}]} \ No newline at end of file diff --git a/terraform_data_dirs/default/providers/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 b/terraform_data_dirs/default/providers/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 new file mode 120000 index 0000000..fe28aef --- /dev/null +++ b/terraform_data_dirs/default/providers/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 @@ -0,0 +1 @@ +/data/terraform/workspaces/arnol377/terraform-plugin-cache/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64 \ No newline at end of file diff --git a/terraform_data_dirs/default/providers/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 b/terraform_data_dirs/default/providers/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 new file mode 120000 index 0000000..08157aa --- /dev/null +++ b/terraform_data_dirs/default/providers/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 @@ -0,0 +1 @@ +/data/terraform/workspaces/arnol377/terraform-plugin-cache/registry.terraform.io/hashicorp/tls/4.0.6/linux_amd64 \ No newline at end of file diff --git a/terraform_data_dirs/default/providers/registry.terraform.io/integrations/github/6.6.0/linux_amd64 b/terraform_data_dirs/default/providers/registry.terraform.io/integrations/github/6.6.0/linux_amd64 new file mode 120000 index 0000000..26dfde5 --- /dev/null +++ b/terraform_data_dirs/default/providers/registry.terraform.io/integrations/github/6.6.0/linux_amd64 @@ -0,0 +1 @@ +/data/terraform/workspaces/arnol377/terraform-plugin-cache/registry.terraform.io/integrations/github/6.6.0/linux_amd64 \ No newline at end of file diff --git a/examples/basic/validation.tftest.hcl b/validation.tftest.hcl similarity index 63% rename from examples/basic/validation.tftest.hcl rename to validation.tftest.hcl index 3339064..666f4fa 100644 --- a/examples/basic/validation.tftest.hcl +++ b/validation.tftest.hcl @@ -1,10 +1,23 @@ variables { github_token = "mock-token" + name = "test-eks-cluster" + organization = "test-org" + template_repo_org = "test-org" + environment = "dev" + region = "us-east-1" + 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" + } } provider "github" { - owner = "my-org" - token = "mock-token" + token = var.github_token base_url = "https://github.mycompany.com/api/v3" } diff --git a/varfiles/default.json b/varfiles/default.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/varfiles/default.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/varfiles/default.tfvars b/varfiles/default.tfvars new file mode 100644 index 0000000..e69de29 diff --git a/workflow_trigger.tftest.hcl b/workflow_trigger.tftest.hcl new file mode 100644 index 0000000..84b50e5 --- /dev/null +++ b/workflow_trigger.tftest.hcl @@ -0,0 +1,31 @@ +variables { + github_token = "mock-token" + name = "test-eks-cluster" + organization = "test-org" + template_repo_org = "test-org" + environment = "dev" + region = "us-east-1" + 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" + } +} + +provider "github" { + token = var.github_token + base_url = "https://github.mycompany.com/api/v3" +} + +run "verify_workflow_trigger" { + command = plan + + assert { + condition = can([github_repository_dispatch.dispatch]) + error_message = "Workflow trigger failed to dispatch" + } +} \ No newline at end of file