From 57c952387d6eee0392b013ed3e769f5a489c5558 Mon Sep 17 00:00:00 2001 From: Masayuki Morita Date: Thu, 19 Oct 2023 10:34:25 +0900 Subject: [PATCH] Add OpenTofu to test matrix --- .github/workflows/test.yaml | 22 +++++++++++++++++++++- Dockerfile | 4 ++++ command/test_helper.go | 14 ++++++++++++-- docker-compose.yml | 2 ++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b802d28..493e9cf 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,7 +26,7 @@ jobs: go-version-file: '.go-version' - name: test run: make test - testacc: + testacc_terraform: runs-on: ubuntu-latest timeout-minutes: 10 strategy: @@ -39,6 +39,7 @@ jobs: - 0.12.31 env: TERRAFORM_VERSION: ${{ matrix.terraform }} + TFSCHEMA_TF_MODE: terraform steps: - uses: actions/checkout@v3 - name: docker build @@ -47,3 +48,22 @@ jobs: run: docker-compose run --rm tfschema terraform --version - name: testacc run: docker-compose run --rm tfschema make testacc + testacc_opentofu: + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + matrix: + opentofu: + - 1.6.0-alpha3 + env: + OPENTOFU_VERSION: ${{ matrix.opentofu }} + TFSCHEMA_TF_MODE: opentofu + steps: + - uses: actions/checkout@v3 + - name: docker build + run: docker-compose build + - name: opentofu --version + run: | + docker-compose run --rm tfschema tofu --version + - name: testacc + run: docker-compose run --rm tfschema make testacc diff --git a/Dockerfile b/Dockerfile index 8129e17..561126a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ ARG TERRAFORM_VERSION=latest +ARG OPENTOFU_VERSION=latest + FROM hashicorp/terraform:$TERRAFORM_VERSION AS terraform +FROM ghcr.io/opentofu/opentofu:$OPENTOFU_VERSION AS opentofu FROM golang:1.21-alpine3.18 RUN apk --no-cache add make git bash @@ -12,6 +15,7 @@ RUN apk --no-cache add make git bash RUN git config --global --add safe.directory /work COPY --from=terraform /bin/terraform /usr/local/bin/ +COPY --from=opentofu /usr/local/bin/tofu /usr/local/bin/ WORKDIR /work COPY go.mod go.sum ./ diff --git a/command/test_helper.go b/command/test_helper.go index d3a48b2..5b5b255 100644 --- a/command/test_helper.go +++ b/command/test_helper.go @@ -58,10 +58,20 @@ func setupTestAcc(t *testing.T, providerName string, providerVersion string) { }) // terraform init - cmd := exec.Command("terraform", "init") + terraformExecPath := "" + tfMode := os.Getenv("TFSCHEMA_TF_MODE") + switch tfMode { + case "terraform": + terraformExecPath = "terraform" + case "opentofu": + terraformExecPath = "tofu" + default: + t.Fatalf("unknown TFSCHEMA_TF_MODE: %s", tfMode) + } + cmd := exec.Command(terraformExecPath, "init") cmd.Dir = workDir if out, err := cmd.CombinedOutput(); err != nil { - t.Fatalf("failed to run terraform init: %s, out: %s", err, out) + t.Fatalf("failed to run %s init: %s, out: %s", terraformExecPath, err, out) } // check if the workDir was initizalied. diff --git a/docker-compose.yml b/docker-compose.yml index 7d8cc4a..c229bbe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,11 @@ services: context: . args: TERRAFORM_VERSION: ${TERRAFORM_VERSION:-latest} + OPENTOFU_VERSION: ${OPENTOFU_VERSION:-latest} volumes: - ".:/work" environment: + TFSCHEMA_TF_MODE: ${TFSCHEMA_TF_MODE:-terraform} CGO_ENABLED: 0 # disable cgo for go test # Use the same filesystem to avoid a checksum mismatch error # or a file busy error caused by asynchronous IO.