diff --git a/.gitignore b/.gitignore index 4d2aca6..ff7ecfd 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ terraform.rc # Codefresh Config -.cfconfig \ No newline at end of file +.cfconfig +.Codefresh \ No newline at end of file diff --git a/README.md b/README.md index c4a6601..bf7f47d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,42 @@ # This repository is experimental. Please be careful using this repository at this time. +Currently working to support Amazon cloud and GitHub. + +You'll need the following today to spin up a demo environment. + +1. [Codefresh Account](https://g.codefresh.io/signup) +1. [Amazon Account](https://aws.amazon.com/) +1. [GitHub Account](https://github.com/signup) + ## This project is meant to... -1. Create the necessary infrastructure in Amazon for Codefresh. -1. Install Codefresh Runtime -1. Install GitOps Runtime -1. Install a Demo GitOps Application \ No newline at end of file +1. Create the necessary Cloud infrastructure for Codefresh. +1. Install [Codefresh Runtime](https://artifacthub.io/packages/helm/codefresh-runner/cf-runtime) +1. Install [GitOps Runtime](https://artifacthub.io/packages/helm/codefresh-gitops-runtime/gitops-runtime) +1. Install a [Demo GitOps Application](https://github.com/codefresh-contrib/example-voting-app) + +### Required Variables + +| Arguments | DEFAULT | TYPE | DESCRIPTION | +|------------------|-------------------------|--------|---------------------------------------------------------------------------------------------------------------------------------| +| eks_cluster_name | Amazon EKS Cluster Name | string | Used throughout Terraform as unique name for many Amazon/Codefresh Resources | +| cf_account_id | Codefresh Account ID | string | https://g.codefresh.io/2.0/account-settings/account-information | +| cf_api_token | Codefresh API Key | string | [Generate API Key](https://g.codefresh.io/user/settings) All Scopes | +| github_api_token | GitHub API Token | string | [Generate Classic Token](https://github.com/settings/tokens), Scopes - *.repo, admin:repo_hook.*, | +| github_owner | GitHub Organization | string | Organization or Personal Account | +| jira_api_token | Jira API Token | string | [Generate API Token](https://id.atlassian.com/manage-profile/security/api-tokens) | + +Example Variable Files + +``` terraform.tfvars.json +{ + "eks_cluster_name": "", + "cf_account_id": "", + "cf_api_token": "", + "github_api_token": "", + "github_owner": "", + "jira_api_token": "" +} +``` + +If you need to customize either runtime installation you'll find Helm values files in this repository which will be applied to the installs. \ No newline at end of file diff --git a/terraform/amazon/github/.terraform.lock.hcl b/terraform/amazon/github/.terraform.lock.hcl index b4f4883..7a60863 100644 --- a/terraform/amazon/github/.terraform.lock.hcl +++ b/terraform/amazon/github/.terraform.lock.hcl @@ -102,6 +102,44 @@ provider "registry.terraform.io/hashicorp/kubernetes" { ] } +provider "registry.terraform.io/hashicorp/local" { + version = "2.4.0" + hashes = [ + "h1:ZUEYUmm2t4vxwzxy1BvN1wL6SDWrDxfH7pxtzX8c6d0=", + "zh:53604cd29cb92538668fe09565c739358dc53ca56f9f11312b9d7de81e48fab9", + "zh:66a46e9c508716a1c98efbf793092f03d50049fa4a83cd6b2251e9a06aca2acf", + "zh:70a6f6a852dd83768d0778ce9817d81d4b3f073fab8fa570bff92dcb0824f732", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:82a803f2f484c8b766e2e9c32343e9c89b91997b9f8d2697f9f3837f62926b35", + "zh:9708a4e40d6cc4b8afd1352e5186e6e1502f6ae599867c120967aebe9d90ed04", + "zh:973f65ce0d67c585f4ec250c1e634c9b22d9c4288b484ee2a871d7fa1e317406", + "zh:c8fa0f98f9316e4cfef082aa9b785ba16e36ff754d6aba8b456dab9500e671c6", + "zh:cfa5342a5f5188b20db246c73ac823918c189468e1382cb3c48a9c0c08fc5bf7", + "zh:e0e2b477c7e899c63b06b38cd8684a893d834d6d0b5e9b033cedc06dd7ffe9e2", + "zh:f62d7d05ea1ee566f732505200ab38d94315a4add27947a60afa29860822d3fc", + "zh:fa7ce69dde358e172bd719014ad637634bbdabc49363104f4fca759b4b73f2ce", + ] +} + +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.1" + hashes = [ + "h1:ydA0/SNRVB1o95btfshvYsmxA+jZFRZcvKzZSB+4S1M=", + "zh:58ed64389620cc7b82f01332e27723856422820cfd302e304b5f6c3436fb9840", + "zh:62a5cc82c3b2ddef7ef3a6f2fedb7b9b3deff4ab7b414938b08e51d6e8be87cb", + "zh:63cff4de03af983175a7e37e52d4bd89d990be256b16b5c7f919aff5ad485aa5", + "zh:74cb22c6700e48486b7cabefa10b33b801dfcab56f1a6ac9b6624531f3d36ea3", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:79e553aff77f1cfa9012a2218b8238dd672ea5e1b2924775ac9ac24d2a75c238", + "zh:a1e06ddda0b5ac48f7e7c7d59e1ab5a4073bbcf876c73c0299e4610ed53859dc", + "zh:c37a97090f1a82222925d45d84483b2aa702ef7ab66532af6cbcfb567818b970", + "zh:e4453fbebf90c53ca3323a92e7ca0f9961427d2f0ce0d2b65523cc04d5d999c2", + "zh:e80a746921946d8b6761e77305b752ad188da60688cfd2059322875d363be5f5", + "zh:fbdb892d9822ed0e4cb60f2fedbdbb556e4da0d88d3b942ae963ed6ff091e48f", + "zh:fca01a623d90d0cad0843102f9b8b9fe0d3ff8244593bd817f126582b52dd694", + ] +} + provider "registry.terraform.io/hashicorp/time" { version = "0.9.1" constraints = ">= 0.9.0" @@ -143,24 +181,24 @@ provider "registry.terraform.io/hashicorp/tls" { } provider "registry.terraform.io/integrations/github" { - version = "5.35.0" + version = "5.37.0" constraints = "~> 5.0" hashes = [ - "h1:cb6h49eXpQYHiYVd86sst51qbW3D82dTLpR+OMcdjSE=", - "zh:03ff6c16a542481abb9a25cbcbdffde18e6718df642af72f20471dca6f897146", - "zh:10b4bb35e3ebf1f7107f33b6ba00e09834bb83a28608fc5fd52e13be4be0afc9", - "zh:13dc63090f2c082a3e48b5e54fe59de0a903c5f92e9a7aaa288aba457877b981", - "zh:17d4ca56bdf2adc97188a2ad01fbd58f5896f39909e47c578b532f3cf15ed873", - "zh:1a020df3dde41f1abeb8a98dc46dec2233f1ec2cbd613ecc52f895a390f1fa72", - "zh:4060287ece2ddd455a3257db126f292e027503c9ee5a77962a7a2c68db630b91", - "zh:442c9bd6cbacbe280b26774fff84a07c6071ce65e9b1d7fca54e3a61fab59a47", - "zh:5fafd1438da70811380e75a1369b3a21c23eedc515560296d9a3f2deba41f2a2", - "zh:6db476eeaad71fbb5f0f39e60571b38a23b35f76e6a255ba34df80c3b2e1b19a", - "zh:a289d31d53f92a26578997d67f1ea1ef916507404d51d1d11451aa7157c71f5d", - "zh:b6ae8cabb4abd95f2bac9f3d90edbabfc322fec0fc744c806538154b306369cb", - "zh:d18b3e1e0b9e8cf874f54ef3103d6f751ef94c16028181f7ff7b8ca11cf05a3c", - "zh:db48193a6b6b21c9f33e1d4f91b8448d57f587612d16f58361827fb701ca8b6a", - "zh:e127b0776a874a9ad8da9010749b38b8cf8b1df0398f0c334661a9ef4c800a27", + "h1:uPmf3/0IVrCHUx55PltKKFDa2RnZtIfOaHid7LMXACU=", + "zh:0dfc44b954d02165330080836ae73dd47490ac5c4c1655bf59ab7dea3142617a", + "zh:164dde511b92d7568df38302d5300d127fd63646983f161fdf614c3e7b7bfff4", + "zh:394234dce2ffd3b7c4dd1a2bc74f4c67c0d972502c962c5320ab19860f99b3d7", + "zh:3a828099a1b9910555d1977290ca72fbc9bd217d1ba8956fe1889c712d2b63ad", + "zh:3f00d738069da7c85305eba4ab1633bdc3a3b3453d16cdccfa759c6ec2595a99", + "zh:548b7dadc86ba6b7eae6fe5b8498995fa9f2e7b647ca02edcae55d158abae049", + "zh:598424868f0d26974dcaf1c37abbaab9ad42c3517f3c2c072f14ebb92ae35aea", + "zh:9747adf559fe826ae94d205a64670f2fe243342e3d30354f739dfc7f29cad170", + "zh:9ebfb1cd63571a9ac8c9bc61eae43fa79ca2fbdc9c87f8374e86be412af7218a", + "zh:9ec05a279bb2b71859e67476eca83c24e7840ee52d8e585935b97d5b9588ea22", + "zh:c05b9e5c0581ef837f56761e96295e2b9baeb6749e47feccd85d55afcaac7cb9", + "zh:c094294a907558e03811ef8ff2711845a6aea6d740df3c1dc4b4cb5bf414dd62", + "zh:f1370689625826553ba5dfc2733c4809f90a6a89158218b5a345210a920a62f1", + "zh:fdfd5bdcfb028df3985978a7fda6541945e89285a02ef39288a2506fbb01edc2", ] } diff --git a/terraform/amazon/github/bootstrap.tf b/terraform/amazon/github/bootstrap.tf index da32636..cf985fd 100644 --- a/terraform/amazon/github/bootstrap.tf +++ b/terraform/amazon/github/bootstrap.tf @@ -64,8 +64,51 @@ module "eks" { tags = var.eks_mng_tags } +# Create KubeConfig + +data "aws_eks_cluster_auth" current { + name = module.eks.cluster_name +} + +locals { + kubeconfig = <<-EOT + apiVersion: v1 + clusters: + - cluster: + server: ${module.eks.cluster_endpoint} + certificate-authority-data: ${module.eks.cluster_certificate_authority_data} + name: ${module.eks.cluster_name} + contexts: + - context: + cluster: ${module.eks.cluster_name} + user: ${module.eks.cluster_name} + name: ${module.eks.cluster_name} + current-context: ${module.eks.cluster_name} + kind: Config + preferences: {} + users: + - name: ${module.eks.cluster_name} + user: + token: ${nonsensitive(data.aws_eks_cluster_auth.current.token)} + EOT +} + +resource "local_file" "temp_config" { + filename = "${module.eks.cluster_name}-kube-config.yaml" + content = local.kubeconfig +} + # Setup EBS Access data "aws_iam_policy_document" "cf_runtime_assume_role_policy" { + statement { + actions = ["sts:AssumeRole"] + effect = "Allow" + + principals { + identifiers = [module.eks.eks_managed_node_groups.node_group.iam_role_arn] + type = "AWS" + } + } statement { actions = ["sts:AssumeRoleWithWebIdentity"] effect = "Allow" @@ -131,7 +174,7 @@ data "aws_iam_policy_document" "cf_runtime_ebs_csi" { } resource "aws_iam_policy" "cf_runtime_ebs_csi" { - name = "cf_runtime_ebs_csi" + name = "${var.eks_cluster_name}_ebs_csi" description = "Custom EBS Policy for Codefresh" policy = data.aws_iam_policy_document.cf_runtime_ebs_csi.json } @@ -143,8 +186,8 @@ resource "aws_iam_role_policy_attachment" "ebs_csi" { # Setup S3 (Storage Integration) -resource "aws_s3_bucket" "codefresh-demo" { - bucket = "codefresh-demo" +resource "aws_s3_bucket" "codefresh-demo-s3-bucket" { + bucket = var.eks_cluster_name tags = { Name = "Codefresh Demo" @@ -158,59 +201,119 @@ resource "aws_iam_role_policy_attachment" "s3_poweruser" { } # Setup EC2 Container Registry +# BUG: Destroy is unable to delete repositories containing images +# https://github.com/hashicorp/terraform-provider-aws/issues/33523 +# TODO: Write script to clean out images before deletion by destroy + +# Workaround for 33523 +resource "null_resource" "delete_result_images" { + triggers = { + aws_region = var.aws_region + repository_name = var.eks_cluster_name + } + provisioner "local-exec" { + when = destroy + command = <