Skip to content

Commit ec789e8

Browse files
nithyatsuCopilot
andauthored
pin tf version to avoid surprise breaking changes (#11779)
# Description Pinning tf vesion in code. ## Type of change - This pull request is a minor refactor, code cleanup, test improvement, or other maintenance task and doesn't change the functionality of Radius (issue link optional). ## Contributor checklist Please verify that the PR meets the following requirements, where applicable: <!-- This checklist uses "TaskRadio" comments to make certain options mutually exclusive. See: https://github.com/mheap/require-checklist-action?tab=readme-ov-file#radio-groups For details on how this works and why it's required. --> - An overview of proposed schema changes is included in a linked GitHub issue. - [ ] Yes <!-- TaskRadio schema --> - [x] Not applicable <!-- TaskRadio schema --> - A design document PR is created in the [design-notes repository](https://github.com/radius-project/design-notes/), if new APIs are being introduced. - [ ] Yes <!-- TaskRadio design-pr --> - [x] Not applicable <!-- TaskRadio design-pr --> - The design document has been reviewed and approved by Radius maintainers/approvers. - [ ] Yes <!-- TaskRadio design-review --> - [x] Not applicable <!-- TaskRadio design-review --> - A PR for the [samples repository](https://github.com/radius-project/samples) is created, if existing samples are affected by the changes in this PR. - [ ] Yes <!-- TaskRadio samples-pr --> - [x] Not applicable <!-- TaskRadio samples-pr --> - A PR for the [documentation repository](https://github.com/radius-project/docs) is created, if the changes in this PR affect the documentation or any user facing updates are made. - [ ] Yes <!-- TaskRadio docs-pr --> - [x] Not applicable <!-- TaskRadio docs-pr --> - A PR for the [recipes repository](https://github.com/radius-project/recipes) is created, if existing recipes are affected by the changes in this PR. - [ ] Yes <!-- TaskRadio recipes-pr --> - [x] Not applicable <!-- TaskRadio recipes-pr --> --------- Co-authored-by: Copilot <copilot@github.com>
1 parent 210a9ec commit ec789e8

5 files changed

Lines changed: 95 additions & 5 deletions

File tree

‎.terraform-version‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.14.9

‎build/build.mk‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ else
5353
endif
5454

5555
# Linker flags: https://cmake.org/cmake/help/latest/envvar/LDFLAGS.html.
56-
LDFLAGS := "-s -w -X $(BASE_PACKAGE_NAME)/pkg/version.channel=$(REL_CHANNEL) -X $(BASE_PACKAGE_NAME)/pkg/version.release=$(REL_VERSION) -X $(BASE_PACKAGE_NAME)/pkg/version.commit=$(GIT_COMMIT) -X $(BASE_PACKAGE_NAME)/pkg/version.version=$(GIT_VERSION) -X $(BASE_PACKAGE_NAME)/pkg/version.chartVersion=$(CHART_VERSION)"
56+
TERRAFORM_VERSION := $(shell cat .terraform-version)
57+
LDFLAGS := "-s -w -X $(BASE_PACKAGE_NAME)/pkg/version.channel=$(REL_CHANNEL) -X $(BASE_PACKAGE_NAME)/pkg/version.release=$(REL_VERSION) -X $(BASE_PACKAGE_NAME)/pkg/version.commit=$(GIT_COMMIT) -X $(BASE_PACKAGE_NAME)/pkg/version.version=$(GIT_VERSION) -X $(BASE_PACKAGE_NAME)/pkg/version.chartVersion=$(CHART_VERSION) -X $(BASE_PACKAGE_NAME)/pkg/recipes/terraform.terraformVersion=$(TERRAFORM_VERSION)"
5758

5859
# Combination of flags into GOARGS.
5960
GOARGS := -v -gcflags $(GCFLAGS) -ldflags $(LDFLAGS)

‎pkg/recipes/terraform/install.go‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/go-logr/logr"
27+
"github.com/hashicorp/go-version"
2728
install "github.com/hashicorp/hc-install"
2829
"github.com/hashicorp/hc-install/product"
2930
"github.com/hashicorp/hc-install/releases"
@@ -174,10 +175,7 @@ func downloadAndInstallTerraform(ctx context.Context, installer *install.Install
174175

175176
installStartTime := time.Now()
176177
execPath, err := installer.Ensure(ctx, []src.Source{
177-
&releases.LatestVersion{
178-
Product: product.Terraform,
179-
InstallDir: globalDir,
180-
},
178+
&releases.ExactVersion{Product: product.Terraform, Version: version.Must(version.NewVersion(terraformVersion))},
181179
})
182180
if err != nil {
183181
metrics.DefaultRecipeEngineMetrics.RecordTerraformInstallationDuration(ctx, installStartTime,

‎pkg/recipes/terraform/version.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2026 The Radius Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package terraform
18+
19+
// terraformVersion is the version of Terraform that Radius downloads and
20+
// uses to execute Terraform recipes.
21+
//
22+
// The canonical source of truth is the .terraform-version file at the
23+
// repository root (matching the .node-version / .python-version
24+
// convention used by tfenv, tfswitch, asdf, and mise). The Makefile reads
25+
// that file and overrides this value at build time via the
26+
// -X linker flag. The hard-coded default below is used by `go test`,
27+
// `go run`, and other invocations that do not go through the Makefile;
28+
// the TestTerraformVersionMatchesFile test guarantees it stays in sync
29+
// with the file.
30+
var terraformVersion = "1.14.9"
31+
32+
// TerraformVersion returns the Terraform version Radius will install.
33+
func TerraformVersion() string {
34+
return terraformVersion
35+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2026 The Radius Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package terraform
18+
19+
import (
20+
"os"
21+
"path/filepath"
22+
"runtime"
23+
"strings"
24+
"testing"
25+
26+
"github.com/stretchr/testify/require"
27+
)
28+
29+
// TestTerraformVersionMatchesFile guarantees that the hard-coded
30+
// terraformVersion default in version.go stays in sync with the
31+
// .terraform-version file at the repository root.
32+
func TestTerraformVersionMatchesFile(t *testing.T) {
33+
_, thisFile, _, ok := runtime.Caller(0)
34+
require.True(t, ok, "unable to determine test file location")
35+
36+
// Walk up from this file to the repo root (which contains go.mod).
37+
dir := filepath.Dir(thisFile)
38+
for {
39+
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
40+
break
41+
}
42+
parent := filepath.Dir(dir)
43+
require.NotEqual(t, parent, dir, "could not locate repository root (go.mod)")
44+
dir = parent
45+
}
46+
47+
contents, err := os.ReadFile(filepath.Join(dir, ".terraform-version"))
48+
require.NoError(t, err, "failed to read .terraform-version at repo root")
49+
50+
require.Equal(t,
51+
strings.TrimSpace(string(contents)),
52+
terraformVersion,
53+
"terraformVersion default in version.go must match .terraform-version at repo root",
54+
)
55+
}

0 commit comments

Comments
 (0)