Skip to content

Commit 3364abe

Browse files
kylecarbscoadler
andauthored
chore: generate terraform testdata with matching terraform version (#13343)
Terraform changed the default output of the `terraform graph` command. You must put `-type=plan` to keep the prior behavior. Co-authored-by: Colin Adler <colin1adler@gmail.com>
1 parent ed6ee9a commit 3364abe

File tree

88 files changed

+878
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+878
-332
lines changed

.github/workflows/ci.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ jobs:
211211
- name: Setup sqlc
212212
uses: ./.github/actions/setup-sqlc
213213

214+
- name: Setup Terraform
215+
uses: ./.github/actions/setup-tf
216+
214217
- name: go install tools
215218
run: |
216219
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ gen: \
493493
coderd/apidoc/swagger.json \
494494
.prettierignore.include \
495495
.prettierignore \
496+
provisioner/terraform/testdata/version \
496497
site/.prettierrc.yaml \
497498
site/.prettierignore \
498499
site/.eslintignore \
@@ -684,6 +685,12 @@ provisioner/terraform/testdata/.gen-golden: $(wildcard provisioner/terraform/tes
684685
go test ./provisioner/terraform -run="Test.*Golden$$" -update
685686
touch "$@"
686687

688+
provisioner/terraform/testdata/version:
689+
if [[ "$(shell cat provisioner/terraform/testdata/version.txt)" != "$(shell terraform version -json | jq -r '.terraform_version')" ]]; then
690+
./provisioner/terraform/testdata/generate.sh
691+
fi
692+
.PHONY: provisioner/terraform/testdata/version
693+
687694
scripts/ci-report/testdata/.gen-golden: $(wildcard scripts/ci-report/testdata/*) $(wildcard scripts/ci-report/*.go)
688695
go test ./scripts/ci-report -run=TestOutputMatchesGoldenFile -update
689696
touch "$@"

provisioner/terraform/executor.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/coder/coder/v2/provisionersdk/proto"
2525
)
2626

27+
var version170 = version.Must(version.NewVersion("1.7.0"))
28+
2729
type executor struct {
2830
logger slog.Logger
2931
server *server
@@ -346,8 +348,16 @@ func (e *executor) graph(ctx, killCtx context.Context) (string, error) {
346348
return "", ctx.Err()
347349
}
348350

351+
ver, err := e.version(ctx)
352+
if err != nil {
353+
return "", err
354+
}
355+
args := []string{"graph"}
356+
if ver.GreaterThanOrEqual(version170) {
357+
args = append(args, "-type=plan")
358+
}
349359
var out strings.Builder
350-
cmd := exec.CommandContext(killCtx, e.binaryPath, "graph") // #nosec
360+
cmd := exec.CommandContext(killCtx, e.binaryPath, args...) // #nosec
351361
cmd.Stdout = &out
352362
cmd.Dir = e.workdir
353363
cmd.Env = e.basicEnv()
@@ -356,7 +366,7 @@ func (e *executor) graph(ctx, killCtx context.Context) (string, error) {
356366
slog.F("binary_path", e.binaryPath),
357367
slog.F("args", "graph"),
358368
)
359-
err := cmd.Start()
369+
err = cmd.Start()
360370
if err != nil {
361371
return "", err
362372
}

provisioner/terraform/testdata/calling-module/calling-module.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
coder = {
44
source = "coder/coder"
5-
version = "0.6.1"
5+
version = "0.22.0"
66
}
77
}
88
}

provisioner/terraform/testdata/calling-module/calling-module.tfplan.dot

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/calling-module/calling-module.tfplan.json

+28-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/calling-module/calling-module.tfstate.dot

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/calling-module/calling-module.tfstate.json

+26-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/chaining-resources/chaining-resources.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
coder = {
44
source = "coder/coder"
5-
version = "0.6.1"
5+
version = "0.22.0"
66
}
77
}
88
}

provisioner/terraform/testdata/chaining-resources/chaining-resources.tfplan.dot

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/chaining-resources/chaining-resources.tfplan.json

+28-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/chaining-resources/chaining-resources.tfstate.dot

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioner/terraform/testdata/chaining-resources/chaining-resources.tfstate.json

+26-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)