Skip to content

Commit 0eff4b5

Browse files
committed
pin terraform version constraint as terraform add is removed after v1.1.0-alpha20211020
1 parent 457ada8 commit 0eff4b5

File tree

3 files changed

+79
-23
lines changed

3 files changed

+79
-23
lines changed

go.mod

+71-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/charmbracelet/bubbletea v0.15.0
1010
github.com/charmbracelet/lipgloss v0.4.0
1111
github.com/hashicorp/go-azure-helpers v0.16.5
12-
github.com/hashicorp/go-multierror v1.1.1 // indirect
1312
github.com/hashicorp/go-version v1.3.0
1413
github.com/hashicorp/hcl/v2 v2.10.1
1514
github.com/hashicorp/terraform-exec v0.14.1-0.20210812105923-7fa6ba66697a
@@ -20,5 +19,76 @@ require (
2019
github.com/muesli/reflow v0.3.0
2120
github.com/stretchr/testify v1.7.0
2221
github.com/zclconf/go-cty v1.9.0
22+
)
23+
24+
require (
25+
cloud.google.com/go v0.61.0 // indirect
26+
cloud.google.com/go/storage v1.10.0 // indirect
27+
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
28+
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
29+
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
30+
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
31+
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
32+
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
33+
github.com/Azure/go-autorest/logger v0.2.1 // indirect
34+
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
35+
github.com/agext/levenshtein v1.2.2 // indirect
36+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
37+
github.com/atotto/clipboard v0.1.2 // indirect
38+
github.com/aws/aws-sdk-go v1.25.3 // indirect
39+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
40+
github.com/charmbracelet/harmonica v0.1.0 // indirect
41+
github.com/containerd/console v1.0.2 // indirect
42+
github.com/davecgh/go-spew v1.1.1 // indirect
43+
github.com/dimchansky/utfbom v1.1.1 // indirect
44+
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
45+
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
46+
github.com/golang/protobuf v1.4.2 // indirect
47+
github.com/google/go-cmp v0.5.6 // indirect
48+
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
49+
github.com/hashicorp/errwrap v1.0.0 // indirect
50+
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
51+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
52+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
53+
github.com/hashicorp/go-getter v1.5.3 // indirect
54+
github.com/hashicorp/go-multierror v1.1.1 // indirect
55+
github.com/hashicorp/go-safetemp v1.0.0 // indirect
56+
github.com/hashicorp/go-uuid v1.0.1 // indirect
57+
github.com/hashicorp/terraform-json v0.12.0 // indirect
58+
github.com/hashicorp/terraform-plugin-go v0.3.0 // indirect
59+
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
60+
github.com/jstemmer/go-junit-report v0.9.1 // indirect
61+
github.com/klauspost/compress v1.11.2 // indirect
62+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
63+
github.com/mattn/go-isatty v0.0.13 // indirect
64+
github.com/mattn/go-runewidth v0.0.13 // indirect
65+
github.com/mitchellh/copystructure v1.2.0 // indirect
66+
github.com/mitchellh/go-homedir v1.1.0 // indirect
67+
github.com/mitchellh/go-testing-interface v1.0.4 // indirect
68+
github.com/mitchellh/mapstructure v1.1.2 // indirect
69+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
70+
github.com/muesli/termenv v0.9.0 // indirect
71+
github.com/pkg/errors v0.9.1 // indirect
72+
github.com/pmezard/go-difflib v1.0.0 // indirect
73+
github.com/rivo/uniseg v0.2.0 // indirect
74+
github.com/sahilm/fuzzy v0.1.0 // indirect
75+
github.com/ulikunitz/xz v0.5.8 // indirect
76+
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
77+
go.opencensus.io v0.22.4 // indirect
78+
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
79+
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
80+
golang.org/x/mod v0.3.0 // indirect
81+
golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect
82+
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
83+
golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79 // indirect
84+
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // indirect
85+
golang.org/x/text v0.3.5 // indirect
2386
golang.org/x/tools v0.0.0-20201119191246-c0d5e8918928 // indirect
87+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
88+
google.golang.org/api v0.29.0 // indirect
89+
google.golang.org/appengine v1.6.6 // indirect
90+
google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect
91+
google.golang.org/grpc v1.32.0 // indirect
92+
google.golang.org/protobuf v1.25.0 // indirect
93+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
2494
)

internal/meta/meta_impl.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
"github.com/hashicorp/terraform-exec/tfexec"
2222
)
2323

24-
// The minimun required terraform version that has the `terraform add` command.
25-
var minRequiredTFVersion = version.Must(version.NewSemver("1.1.0-alpha20210811"))
24+
// The required terraform version that has the `terraform add` command.
25+
var minRequiredTFVersion = version.Must(version.NewSemver("v1.1.0-alpha20210630"))
26+
var maxRequiredTFVersion = version.Must(version.NewSemver("v1.1.0-alpha20211006"))
2627

2728
type MetaImpl struct {
2829
subscriptionId string
@@ -92,7 +93,7 @@ func newMetaImpl(rg string, outputDir string) (Meta, error) {
9293
}
9394

9495
// Initialize the Terraform
95-
execPath, err := FindTerraform(ctx, tfDir, minRequiredTFVersion)
96+
execPath, err := FindTerraform(ctx, tfDir, minRequiredTFVersion, maxRequiredTFVersion)
9697
if err != nil {
9798
return nil, fmt.Errorf("error finding a terraform exectuable: %w", err)
9899
}

internal/meta/tfinstall_find.go

+4-19
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8-
"strconv"
9-
"strings"
108

119
"github.com/hashicorp/go-version"
1210
"github.com/hashicorp/terraform-exec/tfexec"
1311
"github.com/hashicorp/terraform-exec/tfinstall"
1412
)
1513

16-
// FindTerraform finds the path to the terraform executable whose version meets the min version constraint.
14+
// FindTerraform finds the path to the terraform executable whose version meets the min/max version constraint.
1715
// It first tries to find from the local OS PATH. If there is no match, it will then download the release of the minVersion from hashicorp to the tfDir.
18-
func FindTerraform(ctx context.Context, tfDir string, minVersion *version.Version) (string, error) {
16+
func FindTerraform(ctx context.Context, tfDir string, minVersion, maxVersion *version.Version) (string, error) {
1917
var terraformPath string
2018
opts := []tfinstall.ExecPathFinder{
2119
tfinstall.LookPath(),
2220
tfinstall.ExactPath(filepath.Join(tfDir, terraformBinary)),
23-
tfinstall.ExactVersion(minVersion.String(), tfDir),
21+
tfinstall.ExactVersion(maxVersion.String(), tfDir),
2422
}
2523

2624
// go through the options in order
@@ -41,7 +39,7 @@ func FindTerraform(ctx context.Context, tfDir string, minVersion *version.Versio
4139
return "", fmt.Errorf("error getting terraform version for executable found at path %s: %w", p, err)
4240
}
4341

44-
if stripPrereleaseAndMeta(v).LessThan(stripPrereleaseAndMeta(minVersion)) {
42+
if v.LessThan(minVersion) || v.GreaterThan(maxVersion) {
4543
continue
4644
}
4745

@@ -67,16 +65,3 @@ func getTerraformVersion(ctx context.Context, execPath string) (*version.Version
6765
}
6866
return ver, nil
6967
}
70-
71-
func stripPrereleaseAndMeta(v *version.Version) *version.Version {
72-
if v == nil {
73-
return nil
74-
}
75-
segs := []string{}
76-
for _, s := range v.Segments() {
77-
segs = append(segs, strconv.Itoa(s))
78-
}
79-
vs := strings.Join(segs, ".")
80-
clean, _ := version.NewVersion(vs)
81-
return clean
82-
}

0 commit comments

Comments
 (0)