Skip to content

Commit

Permalink
test(mc): add terratest and GH workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SRodi committed Jan 24, 2025
1 parent 09e7c08 commit 52f0acd
Show file tree
Hide file tree
Showing 21 changed files with 406 additions and 12 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test-multicloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test Multicloud

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

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

steps:
- 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

- name: Run tests
run: make test
8 changes: 5 additions & 3 deletions test/multicloud/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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
Expand Down Expand Up @@ -32,9 +34,9 @@ destroy:
clean: destroy
@cd live/$(STACK_NAME) && \
rm -rf .terraform && rm terraform.tfstate && rm terraform.tfstate.backup
@if [ $(STACK_NAME) == $(PREFIX)-kind ]; then \
rm -rf live/$(STACK_NAME)/mc-kind-config; \
fi

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

test:
@cd test && go test -v -count=1 -timeout 30m ./...
20 changes: 20 additions & 0 deletions test/multicloud/examples/aks/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/multicloud/examples/aks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "aks" {
source = "../../modules/aks"
location = var.location
resource_group_name = var.resource_group_name
prefix = var.prefix
labels = var.labels
}
20 changes: 20 additions & 0 deletions test/multicloud/examples/aks/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
terraform {
required_version = "1.8.3"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "4.15.0"
}
}
}

# Initialize the Azure provider
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
subscription_id = var.subscription_id
tenant_id = var.tenant_id
}
29 changes: 29 additions & 0 deletions test/multicloud/examples/aks/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "subscription_id" {
description = "The subscription ID for the Azure account."
type = string
}

variable "tenant_id" {
description = "The tenant ID for the Azure account."
type = string
}

variable "location" {
description = "The Azure Cloud location where AKS will be deployed to."
type = string
}

variable "resource_group_name" {
description = "The name of the resource group."
type = string
}

variable "prefix" {
description = "A prefix to add to all resources."
type = string
}

variable "labels" {
description = "A map of labels to add to all resources."
type = map(string)
}
20 changes: 20 additions & 0 deletions test/multicloud/examples/gke/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/multicloud/examples/gke/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "gke" {
source = "../../modules/gke"
location = var.location
prefix = var.prefix
project = var.project
machine_type = var.machine_type
}
15 changes: 15 additions & 0 deletions test/multicloud/examples/gke/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
required_version = "1.8.3"
required_providers {
google = {
source = "hashicorp/google"
version = "6.17.0"
}
}
}

# Initialize the Google provider
provider "google" {
project = var.project
region = var.location
}
19 changes: 19 additions & 0 deletions test/multicloud/examples/gke/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "project" {
description = "The Google Cloud project where resources will be deployed."
type = string
}

variable "location" {
description = "The Google Cloud location where GKE will be deployed to."
type = string
}

variable "prefix" {
description = "A prefix to add to all resources."
type = string
}

variable "machine_type" {
description = "The machine type to use for the GKE nodes."
type = string
}
16 changes: 16 additions & 0 deletions test/multicloud/examples/kind/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/multicloud/examples/kind/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "kind" {
source = "../../modules/kind"
prefix = var.prefix
}
12 changes: 12 additions & 0 deletions test/multicloud/examples/kind/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_version = "1.8.3"
required_providers {
kind = {
source = "tehcyx/kind"
version = "0.7.0"
}
}
}

# Initialize the kind provider
provider "kind" {}
3 changes: 3 additions & 0 deletions test/multicloud/examples/kind/test-kind-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v1
kind: Config
preferences: {}
4 changes: 4 additions & 0 deletions test/multicloud/examples/kind/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "prefix" {
description = "A prefix to add to all resources."
type = string
}
9 changes: 0 additions & 9 deletions test/multicloud/live/retina-kind/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,3 @@ module "retina" {
depends_on = [module.kind]
source = "../../modules/retina"
}

# output "kubeconfig" {
# value = module.kind.kubeconfig
# }

# resource "local_file" "kubeconfig" {
# content = module.kind.kubeconfig
# filename = "${path.module}/kubeconfig.yaml"
# }
38 changes: 38 additions & 0 deletions test/multicloud/test/example_aks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
)

func TestAKSExample(t *testing.T) {
t.Parallel()

opts := &terraform.Options{
TerraformDir: "../examples/aks",

Vars: map[string]interface{}{
"prefix": "test",
"location": "uksouth",
"subscription_id": "d6050d84-e4dd-463d-afc7-a6ab3dc33ab7", // TODO: replace with actual project once we get azure "public" access
"tenant_id": "ac8a4ccd-35f1-4f95-a688-f68e3d89adfc",
"resource_group_name": "test",
"labels": map[string]string{
"environment": "test",
"owner": "test",
"project": "test",
},
},
}

// clean up at the end of the test
defer terraform.Destroy(t, opts)

terraform.Init(t, opts)

// TODO: uncomment once we get creds for azure "public"
// terraform.Apply(t, opts)

// TODO: add actual tests here
}
32 changes: 32 additions & 0 deletions test/multicloud/test/example_gke_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
)

func TestGKEExample(t *testing.T) {
t.Parallel()

opts := &terraform.Options{
TerraformDir: "../examples/gke",

Vars: map[string]interface{}{
"prefix": "test",
"location": "eu-central1",
"project": "mc-retina", // TODO: replace with actual project once we get gcloud access
"machine_type": "e2-standard-4",
},
}

// clean up at the end of the test
defer terraform.Destroy(t, opts)

terraform.Init(t, opts)

// TODO: uncomment once we get creds for gcloud
// terraform.Apply(t, opts)

// TODO: add actual tests here
}
27 changes: 27 additions & 0 deletions test/multicloud/test/example_kind_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
)

func TestKindExample(t *testing.T) {
t.Parallel()

opts := &terraform.Options{
TerraformDir: "../examples/kind",

Vars: map[string]interface{}{
"prefix": "test",
},
}

// clean up at the end of the test
defer terraform.Destroy(t, opts)

terraform.Init(t, opts)
terraform.Apply(t, opts)

// TODO: add actual tests here
}
38 changes: 38 additions & 0 deletions test/multicloud/test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module github.com/microsoft/retina/test/multicloud/test

go 1.23.4

require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gruntwork-io/terratest v0.48.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter/v2 v2.2.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
github.com/hashicorp/terraform-json v0.23.0 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tmccombs/hcl2json v0.6.4 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 52f0acd

Please sign in to comment.