From f767ed672b0f9d782e6b400522f7ba0bd651e33f Mon Sep 17 00:00:00 2001 From: Philipp Strube Date: Fri, 28 May 2021 15:29:40 +0200 Subject: [PATCH] Update starters to new directory layout and modules --- .github/workflows/main.yml | 18 +- quickstart/build_artifacts/dist.py | 9 +- .../src/configurations/_shared/README.md | 177 +++++++++--------- .../src/configurations/_shared/tpl_gitignore | 3 - ...config.auto.tfvars => aks_zero_cluster.tf} | 6 +- .../configurations/aks/aks_zero_ingress.tf | 27 +++ .../configurations/aks/aks_zero_providers.tf | 4 + quickstart/src/configurations/aks/clusters.tf | 5 - .../src/configurations/aks/variables.tf | 4 - quickstart/src/configurations/aks/versions.tf | 8 +- quickstart/src/configurations/eks/clusters.tf | 9 - ...config.auto.tfvars => eks_zero_cluster.tf} | 10 +- .../configurations/eks/eks_zero_ingress.tf | 31 +++ .../configurations/eks/eks_zero_providers.tf | 30 +++ .../src/configurations/eks/providers.tf | 8 - .../src/configurations/eks/variables.tf | 4 - quickstart/src/configurations/eks/versions.tf | 12 +- quickstart/src/configurations/gke/clusters.tf | 5 - ...config.auto.tfvars => gke_zero_cluster.tf} | 6 +- .../configurations/gke/gke_zero_ingress.tf | 27 +++ .../configurations/gke/gke_zero_providers.tf | 4 + .../src/configurations/gke/variables.tf | 4 - quickstart/src/configurations/gke/versions.tf | 8 +- .../src/configurations/kind/clusters.tf | 5 - ...onfig.auto.tfvars => kind_zero_cluster.tf} | 6 +- .../kind/kind_zero_providers.tf | 4 + .../src/configurations/kind/variables.tf | 4 - .../src/configurations/kind/versions.tf | 9 +- .../multi-cloud/aks_zero_cluster.tf | 28 +++ .../multi-cloud/aks_zero_ingress.tf | 27 +++ .../multi-cloud/aks_zero_providers.tf | 4 + .../configurations/multi-cloud/clusters.tf | 21 --- .../multi-cloud/config.auto.tfvars | 112 ----------- .../multi-cloud/eks_zero_cluster.tf | 47 +++++ .../multi-cloud/eks_zero_ingress.tf | 31 +++ .../multi-cloud/eks_zero_providers.tf | 31 +++ .../multi-cloud/gke_zero_cluster.tf | 49 +++++ .../multi-cloud/gke_zero_ingress.tf | 27 +++ .../multi-cloud/gke_zero_providers.tf | 4 + .../configurations/multi-cloud/providers.tf | 8 - .../configurations/multi-cloud/variables.tf | 4 - .../configurations/multi-cloud/versions.tf | 12 +- 42 files changed, 540 insertions(+), 312 deletions(-) rename quickstart/src/configurations/aks/{config.auto.tfvars => aks_zero_cluster.tf} (91%) create mode 100644 quickstart/src/configurations/aks/aks_zero_ingress.tf create mode 100644 quickstart/src/configurations/aks/aks_zero_providers.tf delete mode 100644 quickstart/src/configurations/aks/clusters.tf delete mode 100644 quickstart/src/configurations/aks/variables.tf delete mode 100644 quickstart/src/configurations/eks/clusters.tf rename quickstart/src/configurations/eks/{config.auto.tfvars => eks_zero_cluster.tf} (88%) create mode 100644 quickstart/src/configurations/eks/eks_zero_ingress.tf create mode 100644 quickstart/src/configurations/eks/eks_zero_providers.tf delete mode 100644 quickstart/src/configurations/eks/providers.tf delete mode 100644 quickstart/src/configurations/eks/variables.tf delete mode 100644 quickstart/src/configurations/gke/clusters.tf rename quickstart/src/configurations/gke/{config.auto.tfvars => gke_zero_cluster.tf} (91%) create mode 100644 quickstart/src/configurations/gke/gke_zero_ingress.tf create mode 100644 quickstart/src/configurations/gke/gke_zero_providers.tf delete mode 100644 quickstart/src/configurations/gke/variables.tf delete mode 100644 quickstart/src/configurations/kind/clusters.tf rename quickstart/src/configurations/kind/{config.auto.tfvars => kind_zero_cluster.tf} (80%) create mode 100644 quickstart/src/configurations/kind/kind_zero_providers.tf delete mode 100644 quickstart/src/configurations/kind/variables.tf create mode 100644 quickstart/src/configurations/multi-cloud/aks_zero_cluster.tf create mode 100644 quickstart/src/configurations/multi-cloud/aks_zero_ingress.tf create mode 100644 quickstart/src/configurations/multi-cloud/aks_zero_providers.tf delete mode 100644 quickstart/src/configurations/multi-cloud/clusters.tf delete mode 100644 quickstart/src/configurations/multi-cloud/config.auto.tfvars create mode 100644 quickstart/src/configurations/multi-cloud/eks_zero_cluster.tf create mode 100644 quickstart/src/configurations/multi-cloud/eks_zero_ingress.tf create mode 100644 quickstart/src/configurations/multi-cloud/eks_zero_providers.tf create mode 100644 quickstart/src/configurations/multi-cloud/gke_zero_cluster.tf create mode 100644 quickstart/src/configurations/multi-cloud/gke_zero_ingress.tf create mode 100644 quickstart/src/configurations/multi-cloud/gke_zero_providers.tf delete mode 100644 quickstart/src/configurations/multi-cloud/providers.tf delete mode 100644 quickstart/src/configurations/multi-cloud/variables.tf diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d665b95..27b978ca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -116,28 +116,28 @@ jobs: working-directory: ./kubestack-starter-${{ matrix.starter }} run: | # ALL: set name_prefix - sed -i 's/name_prefix = ""/name_prefix = "test"/g' config.auto.tfvars + sed -i 's/name_prefix = ""/name_prefix = "test"/g' *_cluster.tf # ALL: set base_domain - sed -i 's/base_domain = ""/base_domain = "infra.serverwolken.de"/g' config.auto.tfvars + sed -i 's/base_domain = ""/base_domain = "infra.serverwolken.de"/g' *_cluster.tf # AKS: set resource_group - sed -i 's/resource_group = ""/resource_group = "terraform-kubestack-testing"/g' config.auto.tfvars + sed -i 's/resource_group = ""/resource_group = "terraform-kubestack-testing"/g' aks_zero_cluster.tf || true # EKS: set region - sed -i 's/region = ""/region = "eu-west-1"/g' providers.tf || true + sed -i 's/region = ""/region = "eu-west-1"/g' eks_zero_providers.tf || true # EKS: set cluster_availability_zones - sed -i 's/cluster_availability_zones = ""/cluster_availability_zones = "eu-west-1a,eu-west-1b"/g' config.auto.tfvars + sed -i 's/cluster_availability_zones = ""/cluster_availability_zones = "eu-west-1a,eu-west-1b"/g' eks_zero_cluster.tf || true # GKE: set project_id - sed -i 's/project_id = ""/project_id = "terraform-kubestack-testing"/g' config.auto.tfvars + sed -i 's/project_id = ""/project_id = "terraform-kubestack-testing"/g' gke_zero_cluster.tf || true # GKE: set region - sed -i 's/region = ""/region = "europe-west1"/g' config.auto.tfvars + sed -i 's/region = ""/region = "europe-west1"/g' gke_zero_cluster.tf || true # GKE: set cluster_node_locations - sed -i 's/cluster_node_locations = ""/cluster_node_locations = "europe-west1-b,europe-west1-c,europe-west1-d"/g' config.auto.tfvars + sed -i 's/cluster_node_locations = ""/cluster_node_locations = "europe-west1-b,europe-west1-c,europe-west1-d"/g' gke_zero_cluster.tf || true - name: 'Terraform init' working-directory: ./kubestack-starter-${{ matrix.starter }} @@ -177,7 +177,7 @@ jobs: -v `pwd`:/infra \ -v /var/run/docker.sock:/var/run/docker.sock \ test-image:${{ github.sha }} \ - terraform plan + terraform plan --target module.aks_zero --target module.eks_zero --target module.gke_zero publish-image: runs-on: ubuntu-latest diff --git a/quickstart/build_artifacts/dist.py b/quickstart/build_artifacts/dist.py index 97e1d154..b2167557 100755 --- a/quickstart/build_artifacts/dist.py +++ b/quickstart/build_artifacts/dist.py @@ -13,7 +13,6 @@ def replace_template(dist_path, file_name, context): - # Replace templated variable with version in clusters.tf jinja = Environment(loader=FileSystemLoader(dist_path)) template = jinja.get_template(file_name) data = template.render(context) @@ -38,9 +37,11 @@ def dist(version, image_name, configuration): copytree(configuration_src, configuration_dist) copytree(manifests_src, manifests_dist) - # Replace templated version variable in clusters.tf - replace_template(configuration_dist, 'clusters.tf', - {'version': version}) + # Replace templated version variables in *.tf files + for tf_file in [n for n in listdir(configuration_dist) + if n.endswith('.tf')]: + replace_template(configuration_dist, tf_file, + {'version': version}) # Replace templated variables in Dockerfiles dockerfiles = ['Dockerfile', 'Dockerfile.loc'] diff --git a/quickstart/src/configurations/_shared/README.md b/quickstart/src/configurations/_shared/README.md index 6640c0fe..9909400e 100644 --- a/quickstart/src/configurations/_shared/README.md +++ b/quickstart/src/configurations/_shared/README.md @@ -2,141 +2,140 @@ This repository uses [Kubestack][1]. Kubestack is the open source GitOps framework for teams that want to automate infrastructure, not reinvent automation. - * Infrastructure is defined using Terraform configuration - * Cluster manifests are defined using Kustomize bases and overlays - * Bases and overlays can be bespoke, or consumed from the [catalog][2]. - * Both infrastructure and manifests follow the Kubestack [inheritance model][3] to prevent configuration drift between the *ops* and *apps* environments - * All changes follow the same four step process. +- Cluster infrastructure and cluster services are defined using Terraform modules. +- Popular cluster services are available from the Terraform module [catalog][2]. +- Both cluster and cluster service modules follow the Kubestack [inheritance model][3] to prevent configuration drift between environments. +- All changes follow the same four-step process. Full [framework documentation][4] is available online. ## Making changes -All changes to the Kubernetes cluster, supporting infrastructure and the services defined as part of the manifests in this repository follow the Kubestack [GitOps process][5]. The GitOps process ensures that changes are safely applied by first reviewing the proposed changes, then validating the changes against the *ops* environment and only then promoting the changes to be applied against the *apps* environment by setting a tag. +To make changes to the Kubernetes cluster(s), supporting infrastructure or the Kubernetes services defined in this repository follow the Kubestack [GitOps process][5]. The GitOps process ensures that changes are safely applied by first reviewing the proposed changes, then validating the changes against the _ops_ environment and finally promoting the changes to be applied against the _apps_ environment by setting a tag. -To accelerate the developer workflow, a [development environment][6], can be run on localhost. +To accelerate the developer workflow an auto-updating [development environment][6] can be run on localhost using the `kbst local apply` command. - 1. Change +1. Change - Make changes to the configuration in a new branch. Commit the changed configuration. Validate your changes by pushing the new branch. The pipeline runs `terraform plan` against the *ops* workspace. + Make changes to the configuration in a new branch. Commit the changed configuration and push your branch. The pipeline runs `terraform plan` against the _ops_ workspace. - ```shell - # checkout a new branch from master - git checkout -b examplechange master + ```shell + # checkout a new branch from main + git checkout -b examplechange main - # make your changes + # make your changes - # commit your changes - git commit # write a meaningful commit message + # commit your changes + git commit # write a meaningful commit message - # push your changes - git push origin examplechange - ``` + # push your changes + git push origin examplechange + ``` - 1. Review +1. Review - Request a peer review of your changes. Team members review the changes and the Terraform plan. If reviewers require changes, make additional commits in the branch. + Request a peer review of your changes. Team members review the changes and the Terraform plan. If reviewers require changes, make additional commits in the branch. - ```shell - # make sure you're in the correct branch - git checkout examplechange + ```shell + # make sure you're in the correct branch + git checkout examplechange - # make changes required by the review + # make changes required by the review - # commit and push the required changes - git commit # write a meaningful commit message - git push origin examplechange - ``` + # commit and push the required changes + git commit # write a meaningful commit message + git push origin examplechange + ``` - 1. Merge +1. Merge - If approved, merge your changes to master, to apply them against the *ops* environment. After applying to *ops* was successful, the pipeline runs Terraform plan against the *apps* environment. + If approved, merge your changes to main, to apply them against the _ops_ environment. After applying to _ops_ was successful, the pipeline runs Terraform plan against the _apps_ environment. - ```shell - # you can merge on the commandline - # or by merging a pull request - git checkout master - git merge examplechange - git push origin master - ``` + ```shell + # you can merge on the commandline + # or by merging a pull request + git checkout main + git merge examplechange + git push origin main + ``` - 1. Promote +1. Promote - Review the previous *apps* environment plan and tag the merge commit to promote the same changes to the *apps* environment. + Review the previous _apps_ environment plan and tag the merge commit to promote the same changes to the _apps_ environment. - ```shell - # make sure you're on the correct commit - git checkout master - git pull - git log -1 + ```shell + # make sure you're on the correct commit + git checkout main + git pull + git log -1 - # if correct, tag the current commit - # any tag prefixed with `apps-deploy-` - # will trigger the pipeline - git tag apps-deploy-$(date -I)-0 + # if correct, tag the current commit + # any tag prefixed with `apps-deploy-` + # will trigger the pipeline + git tag apps-deploy-$(date -I)-0 - # in case of multiple deploys on the same day, - # increase the counter - # e.g. git tag apps-deploy-2020-05-14-1 - ``` + # in case of multiple deploys on the same day, + # increase the counter + # e.g. git tag apps-deploy-2020-05-14-1 + ``` ## Manual operations In case of the automation being unavailable, upgrades requiring manual steps or in disaster recovery scenarios run Terraform and the cloud CLI locally. Kubestack provides container images bundling all dependencies to use for both automated and manual operations. - 1. Exec into container +1. Exec into container - ```shell - # Build the bootstrap container - docker build -t kubestack . + ```shell + # Build the container image + docker build -t kubestack . - # Exec into the bootstrap container - # add docker socket mount for local dev - # -v /var/run/docker.sock:/var/run/docker.sock - docker run --rm -ti \ - -v `pwd`:/infra \ - kubestack - ``` + # Exec into the container image + # add docker socket mount for local dev + # -v /var/run/docker.sock:/var/run/docker.sock + docker run --rm -ti \ + -v `pwd`:/infra \ + kubestack + ``` - 1. Authenticate providers +1. Authenticate providers - Credentials are cached inside the `.user` directory. The directory is excluded from Git by the default `.gitignore`. + Credentials are cached inside the `.user` directory. The directory is excluded from Git by the default `.gitignore`. - ```shell - # for AWS - aws configure + ```shell + # for AWS + aws configure - # for Azure - az login + # for Azure + az login - # for GCP - gcloud init - gcloud auth application-default login - ``` + # for GCP + gcloud init + gcloud auth application-default login + ``` - 1. Select desired environment +1. Select desired environment - ```shell - # for ops - terraform workspace select ops + ```shell + # for ops + terraform workspace select ops - # or for apps - terraform workspace select apps - ``` + # or for apps + terraform workspace select apps + ``` - 1. Run Terraform commands +1. Run Terraform commands - ```shell - # run terraform init - terraform init + ```shell + # run terraform init + terraform init - # run, e.g. terraform plan - terraform plan - ``` + # run, e.g. terraform plan + terraform plan + ``` [1]: https://www.kubestack.com [2]: https://www.kubestack.com/catalog [3]: https://www.kubestack.com/framework/documentation/inheritance-model [4]: https://www.kubestack.com/framework/documentation [5]: https://www.kubestack.com/framework/documentation/gitops-process -[6]: https://www.kubestack.com/framework/documentation/tutorial-build-local-lab +[6]: https://www.kubestack.com/framework/documentation/tutorial-develop-locally#provision-local-clusters diff --git a/quickstart/src/configurations/_shared/tpl_gitignore b/quickstart/src/configurations/_shared/tpl_gitignore index 5ecc0882..6b5248d2 100644 --- a/quickstart/src/configurations/_shared/tpl_gitignore +++ b/quickstart/src/configurations/_shared/tpl_gitignore @@ -7,6 +7,3 @@ # .user home directory .user/ - -# terraform generated clusters directory -clusters/ diff --git a/quickstart/src/configurations/aks/config.auto.tfvars b/quickstart/src/configurations/aks/aks_zero_cluster.tf similarity index 91% rename from quickstart/src/configurations/aks/config.auto.tfvars rename to quickstart/src/configurations/aks/aks_zero_cluster.tf index 556e2e45..04cff955 100644 --- a/quickstart/src/configurations/aks/config.auto.tfvars +++ b/quickstart/src/configurations/aks/aks_zero_cluster.tf @@ -1,5 +1,7 @@ -clusters = { - aks_zero = { +module "aks_zero" { + source = "github.com/kbst/terraform-kubestack//azurerm/cluster?ref={{version}}" + + configuration = { # apps envrionment configuration apps = { # Set name_prefix used to generate the cluster_name diff --git a/quickstart/src/configurations/aks/aks_zero_ingress.tf b/quickstart/src/configurations/aks/aks_zero_ingress.tf new file mode 100644 index 00000000..ccacd0cf --- /dev/null +++ b/quickstart/src/configurations/aks/aks_zero_ingress.tf @@ -0,0 +1,27 @@ +module "aks_zero_nginx" { + providers = { + kustomization = kustomization.aks_zero + } + source = "kbst.xyz/catalog/nginx/kustomization" + version = "0.46.0-kbst.1" + + configuration = { + apps = { + patches = [{ + patch = <<-EOF + apiVersion: v1 + kind: Service + metadata: + name: ingress-nginx-controller + namespace: ingress-nginx + spec: + loadBalancerIP: ${module.aks_zero.default_ingress_ip} + EOF + }] + } + + ops = {} + + loc = {} + } +} diff --git a/quickstart/src/configurations/aks/aks_zero_providers.tf b/quickstart/src/configurations/aks/aks_zero_providers.tf new file mode 100644 index 00000000..68b8e25d --- /dev/null +++ b/quickstart/src/configurations/aks/aks_zero_providers.tf @@ -0,0 +1,4 @@ +provider "kustomization" { + alias = "aks_zero" + kubeconfig_raw = module.aks_zero.kubeconfig +} diff --git a/quickstart/src/configurations/aks/clusters.tf b/quickstart/src/configurations/aks/clusters.tf deleted file mode 100644 index 19bb48e8..00000000 --- a/quickstart/src/configurations/aks/clusters.tf +++ /dev/null @@ -1,5 +0,0 @@ -module "aks_zero" { - source = "github.com/kbst/terraform-kubestack//azurerm/cluster?ref={{version}}" - - configuration = var.clusters["aks_zero"] -} diff --git a/quickstart/src/configurations/aks/variables.tf b/quickstart/src/configurations/aks/variables.tf deleted file mode 100644 index 2222aa47..00000000 --- a/quickstart/src/configurations/aks/variables.tf +++ /dev/null @@ -1,4 +0,0 @@ -variable "clusters" { - description = "Map, holding configuration of all clusters." - type = map(map(map(string))) -} diff --git a/quickstart/src/configurations/aks/versions.tf b/quickstart/src/configurations/aks/versions.tf index 6b6318de..04edc12f 100644 --- a/quickstart/src/configurations/aks/versions.tf +++ b/quickstart/src/configurations/aks/versions.tf @@ -1,3 +1,9 @@ terraform { - required_version = ">= 0.13" + required_providers { + kustomization = { + source = "kbst/kustomization" + } + } + + required_version = ">= 0.15" } diff --git a/quickstart/src/configurations/eks/clusters.tf b/quickstart/src/configurations/eks/clusters.tf deleted file mode 100644 index 3eb5d455..00000000 --- a/quickstart/src/configurations/eks/clusters.tf +++ /dev/null @@ -1,9 +0,0 @@ -module "eks_zero" { - providers = { - aws = aws.eks_zero - } - - source = "github.com/kbst/terraform-kubestack//aws/cluster?ref={{version}}" - - configuration = var.clusters["eks_zero"] -} diff --git a/quickstart/src/configurations/eks/config.auto.tfvars b/quickstart/src/configurations/eks/eks_zero_cluster.tf similarity index 88% rename from quickstart/src/configurations/eks/config.auto.tfvars rename to quickstart/src/configurations/eks/eks_zero_cluster.tf index 732845b6..b01f9afb 100644 --- a/quickstart/src/configurations/eks/config.auto.tfvars +++ b/quickstart/src/configurations/eks/eks_zero_cluster.tf @@ -1,5 +1,11 @@ -clusters = { - eks_zero = { +module "eks_zero" { + providers = { + aws = aws.eks_zero + } + + source = "github.com/kbst/terraform-kubestack//aws/cluster?ref={{version}}" + + configuration = { # apps environment apps = { # Set name_prefix used to generate the cluster_name diff --git a/quickstart/src/configurations/eks/eks_zero_ingress.tf b/quickstart/src/configurations/eks/eks_zero_ingress.tf new file mode 100644 index 00000000..4f9d5692 --- /dev/null +++ b/quickstart/src/configurations/eks/eks_zero_ingress.tf @@ -0,0 +1,31 @@ +module "eks_zero_nginx" { + providers = { + kustomization = kustomization.eks_zero + } + source = "kbst.xyz/catalog/nginx/kustomization" + version = "0.46.0-kbst.1" + + configuration = { + apps = {} + + ops = {} + + loc = {} + } +} + +module "eks_zero_dns_zone" { + providers = { + aws = aws.eks_zero + kubernetes = kubernetes.eks_zero + } + + source = "github.com/kbst/terraform-kubestack//aws/cluster/elb-dns?ref={{version}}" + + ingress_service_name = "ingress-nginx-controller" + ingress_service_namespace = "ingress-nginx" + + metadata_fqdn = module.eks_zero.current_metadata["fqdn"] + + depends_on = [module.eks_zero, module.eks_zero_nginx] +} diff --git a/quickstart/src/configurations/eks/eks_zero_providers.tf b/quickstart/src/configurations/eks/eks_zero_providers.tf new file mode 100644 index 00000000..c06b00cb --- /dev/null +++ b/quickstart/src/configurations/eks/eks_zero_providers.tf @@ -0,0 +1,30 @@ +provider "aws" { + alias = "eks_zero" + + # The AWS provider requires a region. Specify your region here, + # the alias above is used to inject the correct provider into + # the respective cluster module in clusters.tf + region = "" +} + +provider "kustomization" { + alias = "eks_zero" + kubeconfig_raw = module.eks_zero.kubeconfig +} + +locals { + eks_zero_kubeconfig = yamldecode(module.eks_zero.kubeconfig) +} + +provider "kubernetes" { + alias = "eks_zero" + + host = local.eks_zero_kubeconfig["clusters"][0]["cluster"]["server"] + cluster_ca_certificate = base64decode(local.eks_zero_kubeconfig["clusters"][0]["cluster"]["certificate-authority-data"]) + + exec { + api_version = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["apiVersion"] + args = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["args"] + command = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["command"] + } +} diff --git a/quickstart/src/configurations/eks/providers.tf b/quickstart/src/configurations/eks/providers.tf deleted file mode 100644 index abb79904..00000000 --- a/quickstart/src/configurations/eks/providers.tf +++ /dev/null @@ -1,8 +0,0 @@ -provider "aws" { - alias = "eks_zero" - - # The AWS provider requires a region. Specify your region here, - # the alias above is used to inject the correct provider into - # the respective cluster module in clusters.tf - region = "" -} diff --git a/quickstart/src/configurations/eks/variables.tf b/quickstart/src/configurations/eks/variables.tf deleted file mode 100644 index 2222aa47..00000000 --- a/quickstart/src/configurations/eks/variables.tf +++ /dev/null @@ -1,4 +0,0 @@ -variable "clusters" { - description = "Map, holding configuration of all clusters." - type = map(map(map(string))) -} diff --git a/quickstart/src/configurations/eks/versions.tf b/quickstart/src/configurations/eks/versions.tf index 6b6318de..2c8242de 100644 --- a/quickstart/src/configurations/eks/versions.tf +++ b/quickstart/src/configurations/eks/versions.tf @@ -1,3 +1,13 @@ terraform { - required_version = ">= 0.13" + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + } + + kustomization = { + source = "kbst/kustomization" + } + } + + required_version = ">= 0.15" } diff --git a/quickstart/src/configurations/gke/clusters.tf b/quickstart/src/configurations/gke/clusters.tf deleted file mode 100644 index 40eea518..00000000 --- a/quickstart/src/configurations/gke/clusters.tf +++ /dev/null @@ -1,5 +0,0 @@ -module "gke_zero" { - source = "github.com/kbst/terraform-kubestack//google/cluster?ref={{version}}" - - configuration = var.clusters["gke_zero"] -} diff --git a/quickstart/src/configurations/gke/config.auto.tfvars b/quickstart/src/configurations/gke/gke_zero_cluster.tf similarity index 91% rename from quickstart/src/configurations/gke/config.auto.tfvars rename to quickstart/src/configurations/gke/gke_zero_cluster.tf index 86b1ca58..c4989503 100644 --- a/quickstart/src/configurations/gke/config.auto.tfvars +++ b/quickstart/src/configurations/gke/gke_zero_cluster.tf @@ -1,5 +1,7 @@ -clusters = { - gke_zero = { +module "gke_zero" { + source = "github.com/kbst/terraform-kubestack//google/cluster?ref={{version}}" + + configuration = { # apps environment apps = { # The Google cloud project ID to use diff --git a/quickstart/src/configurations/gke/gke_zero_ingress.tf b/quickstart/src/configurations/gke/gke_zero_ingress.tf new file mode 100644 index 00000000..80e5bbfb --- /dev/null +++ b/quickstart/src/configurations/gke/gke_zero_ingress.tf @@ -0,0 +1,27 @@ +module "gke_zero_nginx" { + providers = { + kustomization = kustomization.gke_zero + } + source = "kbst.xyz/catalog/nginx/kustomization" + version = "0.46.0-kbst.1" + + configuration = { + apps = { + patches = [{ + patch = <<-EOF + apiVersion: v1 + kind: Service + metadata: + name: ingress-nginx-controller + namespace: ingress-nginx + spec: + loadBalancerIP: ${module.gke_zero.default_ingress_ip} + EOF + }] + } + + ops = {} + + loc = {} + } +} diff --git a/quickstart/src/configurations/gke/gke_zero_providers.tf b/quickstart/src/configurations/gke/gke_zero_providers.tf new file mode 100644 index 00000000..ac9142ac --- /dev/null +++ b/quickstart/src/configurations/gke/gke_zero_providers.tf @@ -0,0 +1,4 @@ +provider "kustomization" { + alias = "gke_zero" + kubeconfig_raw = module.gke_zero.kubeconfig +} diff --git a/quickstart/src/configurations/gke/variables.tf b/quickstart/src/configurations/gke/variables.tf deleted file mode 100644 index 2222aa47..00000000 --- a/quickstart/src/configurations/gke/variables.tf +++ /dev/null @@ -1,4 +0,0 @@ -variable "clusters" { - description = "Map, holding configuration of all clusters." - type = map(map(map(string))) -} diff --git a/quickstart/src/configurations/gke/versions.tf b/quickstart/src/configurations/gke/versions.tf index 6b6318de..04edc12f 100644 --- a/quickstart/src/configurations/gke/versions.tf +++ b/quickstart/src/configurations/gke/versions.tf @@ -1,3 +1,9 @@ terraform { - required_version = ">= 0.13" + required_providers { + kustomization = { + source = "kbst/kustomization" + } + } + + required_version = ">= 0.15" } diff --git a/quickstart/src/configurations/kind/clusters.tf b/quickstart/src/configurations/kind/clusters.tf deleted file mode 100644 index 39aa0ba3..00000000 --- a/quickstart/src/configurations/kind/clusters.tf +++ /dev/null @@ -1,5 +0,0 @@ -module "kind_zero" { - source = "github.com/kbst/terraform-kubestack//kind/cluster?ref={{version}}" - - configuration = var.clusters["kind_zero"] -} diff --git a/quickstart/src/configurations/kind/config.auto.tfvars b/quickstart/src/configurations/kind/kind_zero_cluster.tf similarity index 80% rename from quickstart/src/configurations/kind/config.auto.tfvars rename to quickstart/src/configurations/kind/kind_zero_cluster.tf index f85719e2..cf5fc5bf 100644 --- a/quickstart/src/configurations/kind/config.auto.tfvars +++ b/quickstart/src/configurations/kind/kind_zero_cluster.tf @@ -1,5 +1,7 @@ -clusters = { - kind_zero = { +module "kind_zero" { + source = "github.com/kbst/terraform-kubestack//kind/cluster?ref={{version}}" + + configuration = { # Settings for Apps-cluster apps = { name_prefix = "kind" diff --git a/quickstart/src/configurations/kind/kind_zero_providers.tf b/quickstart/src/configurations/kind/kind_zero_providers.tf new file mode 100644 index 00000000..aef316c3 --- /dev/null +++ b/quickstart/src/configurations/kind/kind_zero_providers.tf @@ -0,0 +1,4 @@ +provider "kustomization" { + alias = "kind_zero" + kubeconfig_raw = module.kind_zero.kubeconfig +} diff --git a/quickstart/src/configurations/kind/variables.tf b/quickstart/src/configurations/kind/variables.tf deleted file mode 100644 index 2222aa47..00000000 --- a/quickstart/src/configurations/kind/variables.tf +++ /dev/null @@ -1,4 +0,0 @@ -variable "clusters" { - description = "Map, holding configuration of all clusters." - type = map(map(map(string))) -} diff --git a/quickstart/src/configurations/kind/versions.tf b/quickstart/src/configurations/kind/versions.tf index 2606a5ac..04edc12f 100644 --- a/quickstart/src/configurations/kind/versions.tf +++ b/quickstart/src/configurations/kind/versions.tf @@ -1,4 +1,9 @@ - terraform { - required_version = ">= 0.13" + required_providers { + kustomization = { + source = "kbst/kustomization" + } + } + + required_version = ">= 0.15" } diff --git a/quickstart/src/configurations/multi-cloud/aks_zero_cluster.tf b/quickstart/src/configurations/multi-cloud/aks_zero_cluster.tf new file mode 100644 index 00000000..f131e1dc --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/aks_zero_cluster.tf @@ -0,0 +1,28 @@ +module "aks_zero" { + source = "github.com/kbst/terraform-kubestack//azurerm/cluster?ref={{version}}" + + configuration = { + # Settings for Apps-cluster + apps = { + # Set name_prefix used to generate the cluster_name + # [name_prefix]-[workspace]-[region] + # e.g. name_prefix = kbst becomes: `kbst-apps-eu-west-1` + # for small orgs the name works well + # for bigger orgs consider department or team names + name_prefix = "" + + # Set the base_domain used to generate the FQDN of the cluster + # [cluster_name].[provider_name].[base_domain] + # e.g. kbst-apps-eu-west-1.aws.infra.example.com + base_domain = "" + + # The Azure resource group to use + resource_group = "" + } + + # Settings for Ops-cluster + ops = {} + + loc = {} + } +} diff --git a/quickstart/src/configurations/multi-cloud/aks_zero_ingress.tf b/quickstart/src/configurations/multi-cloud/aks_zero_ingress.tf new file mode 100644 index 00000000..ccacd0cf --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/aks_zero_ingress.tf @@ -0,0 +1,27 @@ +module "aks_zero_nginx" { + providers = { + kustomization = kustomization.aks_zero + } + source = "kbst.xyz/catalog/nginx/kustomization" + version = "0.46.0-kbst.1" + + configuration = { + apps = { + patches = [{ + patch = <<-EOF + apiVersion: v1 + kind: Service + metadata: + name: ingress-nginx-controller + namespace: ingress-nginx + spec: + loadBalancerIP: ${module.aks_zero.default_ingress_ip} + EOF + }] + } + + ops = {} + + loc = {} + } +} diff --git a/quickstart/src/configurations/multi-cloud/aks_zero_providers.tf b/quickstart/src/configurations/multi-cloud/aks_zero_providers.tf new file mode 100644 index 00000000..68b8e25d --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/aks_zero_providers.tf @@ -0,0 +1,4 @@ +provider "kustomization" { + alias = "aks_zero" + kubeconfig_raw = module.aks_zero.kubeconfig +} diff --git a/quickstart/src/configurations/multi-cloud/clusters.tf b/quickstart/src/configurations/multi-cloud/clusters.tf deleted file mode 100644 index 1a456de8..00000000 --- a/quickstart/src/configurations/multi-cloud/clusters.tf +++ /dev/null @@ -1,21 +0,0 @@ -module "aks_zero" { - source = "github.com/kbst/terraform-kubestack//azurerm/cluster?ref={{version}}" - - configuration = var.clusters["aks_zero"] -} - -module "eks_zero" { - providers = { - aws = aws.eks_zero - } - - source = "github.com/kbst/terraform-kubestack//aws/cluster?ref={{version}}" - - configuration = var.clusters["eks_zero"] -} - -module "gke_zero" { - source = "github.com/kbst/terraform-kubestack//google/cluster?ref={{version}}" - - configuration = var.clusters["gke_zero"] -} diff --git a/quickstart/src/configurations/multi-cloud/config.auto.tfvars b/quickstart/src/configurations/multi-cloud/config.auto.tfvars deleted file mode 100644 index 137c3e9c..00000000 --- a/quickstart/src/configurations/multi-cloud/config.auto.tfvars +++ /dev/null @@ -1,112 +0,0 @@ -clusters = { - aks_zero = { - # Settings for Apps-cluster - apps = { - # Set name_prefix used to generate the cluster_name - # [name_prefix]-[workspace]-[region] - # e.g. name_prefix = kbst becomes: `kbst-apps-eu-west-1` - # for small orgs the name works well - # for bigger orgs consider department or team names - name_prefix = "" - - # Set the base_domain used to generate the FQDN of the cluster - # [cluster_name].[provider_name].[base_domain] - # e.g. kbst-apps-eu-west-1.aws.infra.example.com - base_domain = "" - - # The Azure resource group to use - resource_group = "" - } - - # Settings for Ops-cluster - ops = {} - - loc = {} - } - - eks_zero = { - # Settings for Apps-cluster - apps = { - # Set name_prefix used to generate the cluster_name - # [name_prefix]-[workspace]-[region] - # e.g. name_prefix = kbst becomes: `kbst-apps-eu-west-1` - # for small orgs the name works well - # for bigger orgs consider department or team names - name_prefix = "" - - # Set the base_domain used to generate the FQDN of the cluster - # [cluster_name].[provider_name].[base_domain] - # e.g. kbst-apps-eu-west-1.aws.infra.example.com - base_domain = "" - - cluster_instance_type = "t3.small" - cluster_desired_capacity = "1" - cluster_min_size = "1" - cluster_max_size = "3" - - # Comma-separated list of zone names to deploy worker nodes in - # EKS requires a min. of 2 zones - # Must match region set in provider - # e.g. cluster_availability_zones = "eu-west-1a,eu-west-1b,eu-west-1c" - # FIXME: Use actual list when TF 0.12 finally supports heterogeneous maps - cluster_availability_zones = "" - } - - # Settings for Ops-cluster - ops = { - # Overwrite apps["cluster_availability_zones"] to have a smaller - # ops cluster - # EKS requires a min. of 2 zones - # e.g. cluster_availability_zones = "eu-west-1a,eu-west-1b" - cluster_availability_zones = "" - } - - loc = {} - } - - gke_zero = { - # Settings for Apps-cluster - apps = { - # The Google cloud project ID to use - project_id = "" - - # Set name_prefix used to generate the cluster_name - # [name_prefix]-[workspace]-[region] - # e.g. name_prefix = kbst becomes: `kbst-apps-europe-west3` - # for small orgs the name works well, - # for bigger orgs consider department or team names - name_prefix = "" - - # Set the base_domain used to generate the FQDN of the cluster - # [cluster_name].[provider_name].[base_domain] - # e.g. kbst-apps-europe-west3.gcp.infra.example.com - base_domain = "" - - # Initial desired K8s version, will be upgraded automatically - cluster_min_master_version = "1.15" - - # Initial number of desired nodes per zone - cluster_initial_node_count = 1 - - # The Google cloud region to deploy the clusters in - region = "" - - # Comma-separated list of zone names to deploy worker nodes in. - # Must match region above. - # e.g. cluster_node_locations = "europe-west3-a,europe-west3-b,europe-west3-c" - # FIXME: Use actual list when TF 0.12 finally supports heterogeneous maps - cluster_node_locations = "" - } - - # Settings for Ops-cluster - # configuration here overwrites the values from apps - ops = { - # Overwrite apps["cluster_node_locations"] to have a smaller - # ops cluster - # e.g. cluster_node_locations = "europe-west3-a" - cluster_node_locations = "" - } - - loc = {} - } -} diff --git a/quickstart/src/configurations/multi-cloud/eks_zero_cluster.tf b/quickstart/src/configurations/multi-cloud/eks_zero_cluster.tf new file mode 100644 index 00000000..84de7a48 --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/eks_zero_cluster.tf @@ -0,0 +1,47 @@ +module "eks_zero" { + providers = { + aws = aws.eks_zero + } + + source = "github.com/kbst/terraform-kubestack//aws/cluster?ref={{version}}" + + configuration = { + # Settings for Apps-cluster + apps = { + # Set name_prefix used to generate the cluster_name + # [name_prefix]-[workspace]-[region] + # e.g. name_prefix = kbst becomes: `kbst-apps-eu-west-1` + # for small orgs the name works well + # for bigger orgs consider department or team names + name_prefix = "" + + # Set the base_domain used to generate the FQDN of the cluster + # [cluster_name].[provider_name].[base_domain] + # e.g. kbst-apps-eu-west-1.aws.infra.example.com + base_domain = "" + + cluster_instance_type = "t3.small" + cluster_desired_capacity = "1" + cluster_min_size = "1" + cluster_max_size = "3" + + # Comma-separated list of zone names to deploy worker nodes in + # EKS requires a min. of 2 zones + # Must match region set in provider + # e.g. cluster_availability_zones = "eu-west-1a,eu-west-1b,eu-west-1c" + # FIXME: Use actual list when TF 0.12 finally supports heterogeneous maps + cluster_availability_zones = "" + } + + # Settings for Ops-cluster + ops = { + # Overwrite apps["cluster_availability_zones"] to have a smaller + # ops cluster + # EKS requires a min. of 2 zones + # e.g. cluster_availability_zones = "eu-west-1a,eu-west-1b" + cluster_availability_zones = "" + } + + loc = {} + } +} diff --git a/quickstart/src/configurations/multi-cloud/eks_zero_ingress.tf b/quickstart/src/configurations/multi-cloud/eks_zero_ingress.tf new file mode 100644 index 00000000..4f9d5692 --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/eks_zero_ingress.tf @@ -0,0 +1,31 @@ +module "eks_zero_nginx" { + providers = { + kustomization = kustomization.eks_zero + } + source = "kbst.xyz/catalog/nginx/kustomization" + version = "0.46.0-kbst.1" + + configuration = { + apps = {} + + ops = {} + + loc = {} + } +} + +module "eks_zero_dns_zone" { + providers = { + aws = aws.eks_zero + kubernetes = kubernetes.eks_zero + } + + source = "github.com/kbst/terraform-kubestack//aws/cluster/elb-dns?ref={{version}}" + + ingress_service_name = "ingress-nginx-controller" + ingress_service_namespace = "ingress-nginx" + + metadata_fqdn = module.eks_zero.current_metadata["fqdn"] + + depends_on = [module.eks_zero, module.eks_zero_nginx] +} diff --git a/quickstart/src/configurations/multi-cloud/eks_zero_providers.tf b/quickstart/src/configurations/multi-cloud/eks_zero_providers.tf new file mode 100644 index 00000000..c89a6d77 --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/eks_zero_providers.tf @@ -0,0 +1,31 @@ +provider "aws" { + alias = "eks_zero" + + # The AWS provider requires a region. Specify your region here, + # the alias above is used to inject the correct provider into + # the respective cluster module in clusters.tf + region = "" +} + + +provider "kustomization" { + alias = "eks_zero" + kubeconfig_raw = module.eks_zero.kubeconfig +} + +locals { + eks_zero_kubeconfig = yamldecode(module.eks_zero.kubeconfig) +} + +provider "kubernetes" { + alias = "eks_zero" + + host = local.eks_zero_kubeconfig["clusters"][0]["cluster"]["server"] + cluster_ca_certificate = base64decode(local.eks_zero_kubeconfig["clusters"][0]["cluster"]["certificate-authority-data"]) + + exec { + api_version = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["apiVersion"] + args = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["args"] + command = local.eks_zero_kubeconfig["users"][0]["user"]["exec"]["command"] + } +} diff --git a/quickstart/src/configurations/multi-cloud/gke_zero_cluster.tf b/quickstart/src/configurations/multi-cloud/gke_zero_cluster.tf new file mode 100644 index 00000000..398dea13 --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/gke_zero_cluster.tf @@ -0,0 +1,49 @@ +module "gke_zero" { + source = "github.com/kbst/terraform-kubestack//google/cluster?ref={{version}}" + + configuration = { + # Settings for Apps-cluster + apps = { + # The Google cloud project ID to use + project_id = "" + + # Set name_prefix used to generate the cluster_name + # [name_prefix]-[workspace]-[region] + # e.g. name_prefix = kbst becomes: `kbst-apps-europe-west3` + # for small orgs the name works well, + # for bigger orgs consider department or team names + name_prefix = "" + + # Set the base_domain used to generate the FQDN of the cluster + # [cluster_name].[provider_name].[base_domain] + # e.g. kbst-apps-europe-west3.gcp.infra.example.com + base_domain = "" + + # Initial desired K8s version, will be upgraded automatically + cluster_min_master_version = "1.15" + + # Initial number of desired nodes per zone + cluster_initial_node_count = 1 + + # The Google cloud region to deploy the clusters in + region = "" + + # Comma-separated list of zone names to deploy worker nodes in. + # Must match region above. + # e.g. cluster_node_locations = "europe-west3-a,europe-west3-b,europe-west3-c" + # FIXME: Use actual list when TF 0.12 finally supports heterogeneous maps + cluster_node_locations = "" + } + + # Settings for Ops-cluster + # configuration here overwrites the values from apps + ops = { + # Overwrite apps["cluster_node_locations"] to have a smaller + # ops cluster + # e.g. cluster_node_locations = "europe-west3-a" + cluster_node_locations = "" + } + + loc = {} + } +} diff --git a/quickstart/src/configurations/multi-cloud/gke_zero_ingress.tf b/quickstart/src/configurations/multi-cloud/gke_zero_ingress.tf new file mode 100644 index 00000000..80e5bbfb --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/gke_zero_ingress.tf @@ -0,0 +1,27 @@ +module "gke_zero_nginx" { + providers = { + kustomization = kustomization.gke_zero + } + source = "kbst.xyz/catalog/nginx/kustomization" + version = "0.46.0-kbst.1" + + configuration = { + apps = { + patches = [{ + patch = <<-EOF + apiVersion: v1 + kind: Service + metadata: + name: ingress-nginx-controller + namespace: ingress-nginx + spec: + loadBalancerIP: ${module.gke_zero.default_ingress_ip} + EOF + }] + } + + ops = {} + + loc = {} + } +} diff --git a/quickstart/src/configurations/multi-cloud/gke_zero_providers.tf b/quickstart/src/configurations/multi-cloud/gke_zero_providers.tf new file mode 100644 index 00000000..ac9142ac --- /dev/null +++ b/quickstart/src/configurations/multi-cloud/gke_zero_providers.tf @@ -0,0 +1,4 @@ +provider "kustomization" { + alias = "gke_zero" + kubeconfig_raw = module.gke_zero.kubeconfig +} diff --git a/quickstart/src/configurations/multi-cloud/providers.tf b/quickstart/src/configurations/multi-cloud/providers.tf deleted file mode 100644 index abb79904..00000000 --- a/quickstart/src/configurations/multi-cloud/providers.tf +++ /dev/null @@ -1,8 +0,0 @@ -provider "aws" { - alias = "eks_zero" - - # The AWS provider requires a region. Specify your region here, - # the alias above is used to inject the correct provider into - # the respective cluster module in clusters.tf - region = "" -} diff --git a/quickstart/src/configurations/multi-cloud/variables.tf b/quickstart/src/configurations/multi-cloud/variables.tf deleted file mode 100644 index 2222aa47..00000000 --- a/quickstart/src/configurations/multi-cloud/variables.tf +++ /dev/null @@ -1,4 +0,0 @@ -variable "clusters" { - description = "Map, holding configuration of all clusters." - type = map(map(map(string))) -} diff --git a/quickstart/src/configurations/multi-cloud/versions.tf b/quickstart/src/configurations/multi-cloud/versions.tf index d9b6f790..2c8242de 100644 --- a/quickstart/src/configurations/multi-cloud/versions.tf +++ b/quickstart/src/configurations/multi-cloud/versions.tf @@ -1,3 +1,13 @@ terraform { - required_version = ">= 0.12" + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + } + + kustomization = { + source = "kbst/kustomization" + } + } + + required_version = ">= 0.15" }