Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(mc): initial multicloud IaC boilerplate GKE, AKS, Kind #1268

Merged
merged 22 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5f8f356
test(mc): initial multicloud IaC boilerplate GKE, AKS, Kind
SRodi Jan 24, 2025
944e23c
test(mc): fix md linting
SRodi Jan 24, 2025
a490362
test(mc): fix more md linting
SRodi Jan 24, 2025
171891d
test(mc): add OpenTofu installation link
SRodi Jan 24, 2025
09e7c08
test(mc): lock providers
SRodi Jan 24, 2025
52f0acd
test(mc): add terratest and GH workflow
SRodi Jan 24, 2025
ae2d0ac
test(mc): fix working dir for mc GH workflow
SRodi Jan 24, 2025
63c4bf0
test(mc): add setup-opentofu to GH workflow
SRodi Jan 24, 2025
fb12b95
Merge branch 'main' into test/mc
SRodi Jan 24, 2025
4233201
test(mc): add reference to terratest
SRodi Jan 24, 2025
f3e2e6f
test(mc): add architecture diagram
SRodi Jan 27, 2025
d5474fe
test(mc): update doc as per comments
SRodi Jan 27, 2025
ca1703c
test(mc): refactor vars to parameterize all inputs
SRodi Jan 27, 2025
316741e
test(mc): refactor retina vars and add retina-kind integration test
SRodi Jan 27, 2025
a0bc1de
Merge branch 'main' into test/mc
SRodi Jan 27, 2025
ae07020
test(mc): update integration test prefix (tests run in parallel)
SRodi Jan 27, 2025
5b54a47
test(mc): update integration test for retina-kind
SRodi Jan 27, 2025
021e250
test(mc): address comment on README.md
SRodi Jan 27, 2025
9bfc55b
test(mc): run tofu fmt and add sensitive to secret outputs
SRodi Jan 27, 2025
90f89cb
Merge branch 'main' into test/mc
SRodi Jan 27, 2025
a2b7094
test(mc): refactor output, utils and add GKE flow (commented)
SRodi Jan 28, 2025
76744bd
Merge branch 'main' into test/mc
SRodi Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test-multicloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test Multicloud

on:
pull_request:
paths:
- 'test/multicloud/**'

jobs:
multicloud-test:
runs-on: ubuntu-latest

steps:
- uses: opentofu/setup-opentofu@v1
with:
tofu_version: 1.8.3

- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.23'

- name: Install dependencies
run: go mod download
working-directory: test/multicloud/

- name: Run tests
run: make test
working-directory: test/multicloud/
6 changes: 6 additions & 0 deletions test/multicloud/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
terraform.tfvars
.terraform
terraform.tfstate
*terraform.tfstate.*
service-key.json
mc-kind-config
42 changes: 42 additions & 0 deletions test/multicloud/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
PREFIX ?= retina
STACK_NAME ?= $(PREFIX)-aks

.PHONY: init plan apply quick gke aks kind destroy clean kind-kubeconfig test

plan:
cd live/$(STACK_NAME) && \
tofu fmt && tofu init && tofu plan

apply:
cd live/$(STACK_NAME) && \
tofu apply --auto-approve

quick:
@make plan
@make apply

gke: export STACK_NAME=$(PREFIX)-gke
gke:
@make quick

aks: export STACK_NAME=$(PREFIX)-aks
aks:
@make quick

kind: export STACK_NAME=$(PREFIX)-kind
kind:
@make quick

destroy:
cd live/$(STACK_NAME) && \
tofu destroy --auto-approve

clean: destroy
@cd live/$(STACK_NAME) && \
rm -rf .terraform && rm terraform.tfstate && rm terraform.tfstate.backup

kind-kubeconfig:
@kubectl config set-context live/$(PREFIX)-kind/mc-kind-config

test:
@cd test && go test -v -count=1 -timeout 30m ./...
98 changes: 98 additions & 0 deletions test/multicloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Multi Cloud Retina

This project leverages [OpenTofu](https://opentofu.org/docs/intro/) Infrastructure as Code (IaC) to create Kubernetes infrastructure on multi-cloud and deploy [microsoft/retina](https://github.com/microsoft/retina) via Helm provider.

![Architecture Diagram](./diagrams/diagram.svg)

## Modules available

* [aks](./modules/aks/)
* [gke](./modules/gke/)
* [kind](./modules/kind/)
* [retina](./modules/retina/)

## Prerequisites

* [OpenTofu installation guide](https://opentofu.org/docs/intro/install/)

* AKS:

1. create an Azure account
2. [Install az](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli)

To deploy an AKS cluster and install retina, create file `live/retina-aks/terraform.tfvars` with the Azure TenantID and SubscriptionID

```sh
# example values
subscription_id = "d6050d84-e4dd-463d-afc7-a6ab3dc33ab7"
tenant_id = "ac8a4ccd-35f1-4f95-a688-f68e3d89adfc"
```

* GKE:

1. create a gcloud account, project and enable billing
2. create a service account and service account key
3. [Enable Kubernetes Engine API](https://console.developers.google.com/apis/api/container.googleapis.com/overview?project=mc-retina)
4. [Install gcloud](https://cloud.google.com/sdk/docs/install)

To deploy a GKE cluster export `GOOGLE_APPLICATION_CREDENTIALS` env variable to point to the path where your [service account key](https://cloud.google.com/iam/docs/keys-create-delete) is located.

```sh
# example
export GOOGLE_APPLICATION_CREDENTIALS=/Users/srodi/src/retina/test/multicloud/live/retina-gke/service-key.json
```

* Kind:

1. Docker installed on the host machine

## Quickstart
SRodi marked this conversation as resolved.
Show resolved Hide resolved

The following Make targets can be used to manage each stack lifecycle.

### Create

Format code, initialize OpenTofu, plan and apply the stack to create infra and deploy retina

* AKS:

```sh
make aks
```

* GKE:

```sh
make gke
```

* Kind:

```sh
make kind
```

### Clean up

To destroy the cluster specify the `STACK_NAME` and run `make clean`.

```sh
# destroy AKS and cleanup local state files
# set a different stack as needed (i.e. retina-gke, retina-kind)
export STACK_NAME=retina-aks
make clean
```

### Test

The test framework is levergaing Go and [Terratest](https://terratest.gruntwork.io/docs/). To run tests:

```sh
make test
```

## Providers references

* [GKE resource documentation](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster)
* [AKS resource documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster)
* [Kind resource documentation](https://registry.terraform.io/providers/tehcyx/kind/latest/docs/resources/cluster)
Loading
Loading