Skip to content

Commit 3a5063f

Browse files
authored
ci: test with both Terraform and OpenTofu (#24)
1 parent be77d09 commit 3a5063f

File tree

2 files changed

+40
-42
lines changed

2 files changed

+40
-42
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ jobs:
4040
with:
4141
version: latest
4242

43-
test-upcloud:
44-
name: Acceptance Tests (UpCloud)
43+
test:
44+
name: Acceptance Tests
45+
strategy:
46+
matrix:
47+
target:
48+
- UpCloud
49+
- Minio
50+
- moto
51+
cli:
52+
- terraform
53+
- tofu
4554
needs: build
4655
runs-on: ubuntu-latest
4756
timeout-minutes: 15
@@ -54,8 +63,18 @@ jobs:
5463
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
5564
with:
5665
terraform_wrapper: false
66+
if: matrix.cli == 'terraform'
67+
- uses: opentofu/setup-opentofu@592200bd4b9bbf4772ace78f887668b1aee8f716 # v1.0.5
68+
if: matrix.cli == 'tofu'
69+
- name: Set TF_ACC_* environment for OpenTofu
70+
run: |
71+
echo "TF_ACC_TERRAFORM_PATH=$(which tofu)" >> "$GITHUB_ENV"
72+
echo "TF_ACC_PROVIDER_NAMESPACE=hashicorp" >> "$GITHUB_ENV"
73+
echo "TF_ACC_PROVIDER_HOST=registry.opentofu.org" >> "$GITHUB_ENV"
74+
if: matrix.cli == 'tofu'
5775
- run: go mod download
58-
- env:
76+
- name: Test against UpCloud Managed Object Storage
77+
env:
5978
TF_ACC: "1"
6079
TEST_TARGET: UpCloud
6180
OBJSTO_ACCESS_KEY: ${{ secrets.UPCLOUD_ACCESS_KEY }}
@@ -64,23 +83,9 @@ jobs:
6483
OBJSTO_REGION: ${{ secrets.UPCLOUD_REGION }}
6584
run: go test -v -cover ./internal/provider/
6685
timeout-minutes: 10
67-
68-
test-minio:
69-
name: Acceptance Tests (Minio)
70-
needs: build
71-
runs-on: ubuntu-latest
72-
timeout-minutes: 15
73-
steps:
74-
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
75-
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
76-
with:
77-
go-version-file: 'go.mod'
78-
cache: true
79-
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
80-
with:
81-
terraform_wrapper: false
82-
- run: go mod download
83-
- env:
86+
if: matrix.target == 'UpCloud'
87+
- name: Test against Minio
88+
env:
8489
TF_ACC: "1"
8590
TEST_TARGET: Minio
8691
OBJSTO_ACCESS_KEY: access_key
@@ -92,23 +97,9 @@ jobs:
9297
9398
go test -v -cover ./internal/provider/
9499
timeout-minutes: 10
95-
96-
test-moto:
97-
name: Acceptance Tests (moto)
98-
needs: build
99-
runs-on: ubuntu-latest
100-
timeout-minutes: 15
101-
steps:
102-
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
103-
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
104-
with:
105-
go-version-file: 'go.mod'
106-
cache: true
107-
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
108-
with:
109-
terraform_wrapper: false
110-
- run: go mod download
111-
- env:
100+
if: matrix.target == 'Minio'
101+
- name: Test against moto
102+
env:
112103
TF_ACC: "1"
113104
TEST_TARGET: moto
114105
OBJSTO_ACCESS_KEY: access_key
@@ -120,3 +111,4 @@ jobs:
120111
121112
go test -v -cover ./internal/provider/
122113
timeout-minutes: 10
114+
if: matrix.target == 'moto'

internal/provider/bucket_resource_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"math/rand"
66
"os"
7+
"path/filepath"
78
"regexp"
89
"testing"
910

@@ -14,7 +15,7 @@ import (
1415
// From Kubernetes random suffixes.
1516
const letterBytes = "bcdfghjklmnpqrstvwxz2456789"
1617

17-
func RandomSuffix(n int) string {
18+
func randomSuffix(n int) string {
1819
b := make([]byte, n)
1920
for i := range b {
2021
b[i] = letterBytes[rand.Intn(len(letterBytes))]
@@ -23,20 +24,25 @@ func RandomSuffix(n int) string {
2324
}
2425

2526
func withSuffix(name string) string {
27+
nameAndCli := fmt.Sprintf("%s-terraform", name)
28+
if cliPath := os.Getenv("TF_ACC_TERRAFORM_PATH"); cliPath != "" {
29+
nameAndCli = fmt.Sprintf("%s-%s", name, filepath.Base(cliPath))
30+
}
31+
2632
job := os.Getenv("GITHUB_JOB")
2733
runNumber := os.Getenv("GITHUB_RUN_NUMBER")
2834
runAttempt := os.Getenv("GITHUB_RUN_ATTEMPT")
2935
if runNumber != "" && runAttempt != "" {
30-
return fmt.Sprintf("%s-github-%s-%s.%s", name, job, runNumber, runAttempt)
36+
return fmt.Sprintf("%s-github-%s-%s.%s", nameAndCli, job, runNumber, runAttempt)
3137
}
3238

33-
randStr := RandomSuffix(8)
39+
randStr := randomSuffix(8)
3440

3541
if os.Getenv("CI") != "" {
36-
return fmt.Sprintf("%s-ci-%s", name, randStr)
42+
return fmt.Sprintf("%s-ci-%s", nameAndCli, randStr)
3743
}
3844

39-
return fmt.Sprintf("%s-%s", name, randStr)
45+
return fmt.Sprintf("%s-%s", nameAndCli, randStr)
4046
}
4147

4248
func TestAccBucketResource_crud(t *testing.T) {

0 commit comments

Comments
 (0)