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

🤖 Update tests and related GH test workflows #223

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions .github/workflows/end-to-end-tfc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ name: E2E on Terraform Cloud

on:
schedule:
- cron: '30 5 * * *'
pull_request:
branches:
- main
- cron: '30 5 * * 0'
push:
branches:
- main
paths:
- 'controllers/**'
workflow_dispatch:

jobs:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/end-to-end-tfe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ name: E2E on Terraform Enterprise

on:
schedule:
- cron: '30 5 * * *'
pull_request:
branches:
- main
- cron: '30 5 * * 0'
push:
branches:
- main
paths:
- 'controllers/**'
workflow_dispatch:

jobs:
Expand All @@ -33,3 +32,4 @@ jobs:
TFC_TOKEN: ${{ secrets.TFE_TOKEN }}
TFC_VCS_REPO: ${{ secrets.TFE_VCS_REPO }}
TFE_ADDRESS: ${{ secrets.TFE_ADDRESS }}
TFC_TLS_SKIP_VERIFY: true
11 changes: 6 additions & 5 deletions .github/workflows/helm-end-to-end-tfc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ name: E2E on Terraform Cloud [Helm]

on:
schedule:
- cron: '30 6 * * *'
pull_request:
branches:
- main
- cron: '30 6 * * 0'
push:
branches:
- main
paths:
- 'controllers/**'
- 'charts/terraform-cloud-operator/**'
workflow_dispatch:

env:
USE_EXISTING_CLUSTER: true
CLUSTER_NAME: 'this'
DOCKER_IMAGE: 'this'
KIND_VERSION: ${{ vars.KIND_VERSION }}
KUBECONFIG: ${{ github.workspace }}/.kube/config

jobs:
Expand All @@ -36,7 +37,7 @@ jobs:
uses: helm/kind-action@fa81e57adff234b2908110485695db0f181f3c67 # v1.7.0
with:
wait: 2m
version: v0.18.0 # Installs Kubernetes v1.26.3
version: v${{ env.KIND_VERSION }}
cluster_name: ${{ env.CLUSTER_NAME }}

- name: Set up Helm
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/helm-end-to-end-tfe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ name: E2E on Terraform Enterprise [Helm]

on:
schedule:
- cron: '30 6 * * *'
pull_request:
branches:
- main
- cron: '30 6 * * 0'
push:
branches:
- main
paths:
- 'controllers/**'
- 'charts/terraform-cloud-operator/**'
workflow_dispatch:

env:
USE_EXISTING_CLUSTER: true
CLUSTER_NAME: 'this'
DOCKER_IMAGE: 'this'
KIND_VERSION: ${{ vars.KIND_VERSION }}
KUBECONFIG: ${{ github.workspace }}/.kube/config

jobs:
Expand All @@ -36,7 +37,7 @@ jobs:
uses: helm/kind-action@fa81e57adff234b2908110485695db0f181f3c67 # v1.7.0
with:
wait: 2m
version: v0.18.0 # Installs Kubernetes v1.26.3
KIND_VERSION: ${{ vars.KIND_VERSION }}
cluster_name: ${{ env.CLUSTER_NAME }}

- name: Set up Helm
Expand Down Expand Up @@ -91,3 +92,4 @@ jobs:
TFC_TOKEN: ${{ secrets.TFC_TOKEN }}
TFC_VCS_REPO: ${{ secrets.TFC_VCS_REPO }}
TFE_ADDRESS: ${{ secrets.TFE_ADDRESS }}
TFC_TLS_SKIP_VERIFY: true
5 changes: 4 additions & 1 deletion controllers/module_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ var _ = Describe("Module controller", Ordered, func() {
)

BeforeAll(func() {
if cloudEndpoint != tfcDefaultAddress {
Skip("Does not run against TFC, skip this test")
}
// Set default Eventually timers
SetDefaultEventuallyTimeout(syncPeriod * 4)
SetDefaultEventuallyPollingInterval(2 * time.Second)
Expand Down Expand Up @@ -54,7 +57,7 @@ var _ = Describe("Module controller", Ordered, func() {
},
},
Module: &appv1alpha2.ModuleSource{
Source: fmt.Sprintf("%s/%v/module-random/provider", cloudEndpoint, organization),
Source: "github.com/arybolovlev/terraform-provider-module-random",
Version: "0.0.4",
},
DestroyOnDeletion: true,
Expand Down
22 changes: 21 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ package controllers

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -43,7 +47,8 @@ var tfClient *tfc.Client

var organization = os.Getenv("TFC_ORG")
var terraformToken = os.Getenv("TFC_TOKEN")
var cloudEndpoint = "app.terraform.io"
var tfcDefaultAddress = "app.terraform.io"
var cloudEndpoint = tfcDefaultAddress

var syncPeriod = 30 * time.Second

Expand Down Expand Up @@ -104,6 +109,21 @@ var _ = BeforeSuite(func() {
}
// Terraform Cloud Client
tfClient, err = tfc.NewClient(&tfc.Config{Token: os.Getenv("TFC_TOKEN")})
httpClient := tfc.DefaultConfig().HTTPClient
insecure := false
if v, ok := os.LookupEnv("TFC_TLS_SKIP_VERIFY"); ok {
insecure, err = strconv.ParseBool(v)
if err != nil {
Fail(fmt.Sprintf("Cannot convert value of TFC_TLS_SKIP_VERIFY into a bool: %v", err))
}
}
fmt.Fprintf(GinkgoWriter, "TFC_TLS_SKIP_VERIFY: %v", insecure)
httpClient.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: insecure}
tfcConfig := &tfc.Config{
Token: os.Getenv("TFC_TOKEN"),
HTTPClient: httpClient,
}
tfClient, err = tfc.NewClient(tfcConfig)
Expect(err).Should(Succeed())
Expect(tfClient).ToNot(BeNil())

Expand Down
17 changes: 14 additions & 3 deletions controllers/workspace_controller_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package controllers

import (
"fmt"
"os"
"time"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -92,6 +91,9 @@ var _ = Describe("Workspace controller", Label("Notifications"), Ordered, func()
})

It("can create multiple notifications", func() {
if cloudEndpoint != tfcDefaultAddress {
Skip("Does not run against TFC, skip this test")
}
instance.Spec.Notifications = append(instance.Spec.Notifications, appv1alpha2.Notification{
Name: "slack",
Type: tfc.NotificationDestinationTypeSlack,
Expand All @@ -109,6 +111,9 @@ var _ = Describe("Workspace controller", Label("Notifications"), Ordered, func()
})

It("can re-create notifications", func() {
if cloudEndpoint != tfcDefaultAddress {
Skip("Does not run against TFC, skip this test")
}
instance.Spec.Notifications = append(instance.Spec.Notifications, appv1alpha2.Notification{
Name: "slack",
Type: tfc.NotificationDestinationTypeSlack,
Expand All @@ -132,6 +137,9 @@ var _ = Describe("Workspace controller", Label("Notifications"), Ordered, func()
})

It("can update notifications", func() {
if cloudEndpoint != tfcDefaultAddress {
Skip("Does not run against TFC, skip this test")
}
instance.Spec.Notifications = append(instance.Spec.Notifications, appv1alpha2.Notification{
Name: "email",
Type: tfc.NotificationDestinationTypeEmail,
Expand All @@ -150,6 +158,9 @@ var _ = Describe("Workspace controller", Label("Notifications"), Ordered, func()
})

It("can delete notifications", func() {
if cloudEndpoint != tfcDefaultAddress {
Skip("Does not run against TFC, skip this test")
}
instance.Spec.Notifications = append(instance.Spec.Notifications, appv1alpha2.Notification{
Name: "email",
Type: tfc.NotificationDestinationTypeEmail,
Expand All @@ -168,8 +179,8 @@ var _ = Describe("Workspace controller", Label("Notifications"), Ordered, func()
})

It("can create Terraform Enterprise email address notifications", func() {
if _, ok := os.LookupEnv("TFE_ADDRESS"); !ok {
Skip("Environment variable TFE_ADDRESS is either not set or empty")
if cloudEndpoint == tfcDefaultAddress {
Skip("Does not run against TFC, skip this test")
}
instance.Spec.Notifications = append(instance.Spec.Notifications, appv1alpha2.Notification{
Name: "email",
Expand Down
3 changes: 3 additions & 0 deletions controllers/workspace_controller_outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var _ = Describe("Workspace controller", Ordered, func() {
})

BeforeEach(func() {
if cloudEndpoint != tfcDefaultAddress {
Skip("Does not run against TFC, skip this test")
}
// Create a new workspace object for each test
instance = &appv1alpha2.Workspace{
TypeMeta: metav1.TypeMeta{
Expand Down
4 changes: 2 additions & 2 deletions controllers/workspace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var _ = Describe("Workspace controller", Ordered, func() {
instance.Spec.AllowDestroyPlan = false
instance.Spec.Description = fmt.Sprintf("%v-new", instance.Spec.Description)
instance.Spec.ExecutionMode = "local"
instance.Spec.TerraformVersion = "1.5.2"
instance.Spec.TerraformVersion = "1.4.4"
instance.Spec.WorkingDirectory = fmt.Sprintf("%v/new", instance.Spec.WorkingDirectory)
Expect(k8sClient.Update(ctx, instance)).Should(Succeed())

Expand All @@ -148,7 +148,7 @@ var _ = Describe("Workspace controller", Ordered, func() {
})

It("can keep Terraform version", func() {
instance.Spec.TerraformVersion = "1.5.1"
instance.Spec.TerraformVersion = "1.4.1"
// Create a new Kubernetes workspace object and wait until the controller finishes the reconciliation
createWorkspace(instance, namespacedName)

Expand Down