Skip to content

Commit 38d0f6f

Browse files
authored
perf(provisioner/terraform): upgrade hc-install (#7832)
By upgrading hc-install, we benefit from increased performance in checksum verification introduced here: - hashicorp/hc-install@858962c Also: - Made minor improvements to tests - Excluded TestInstall from the race detector
1 parent b62e227 commit 38d0f6f

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

go.mod

+6-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ require (
108108
github.com/hashicorp/go-reap v0.0.0-20170704170343-bf58d8a43e7b
109109
github.com/hashicorp/go-version v1.6.0
110110
github.com/hashicorp/golang-lru/v2 v2.0.1
111-
github.com/hashicorp/hc-install v0.5.1
111+
github.com/hashicorp/hc-install v0.5.2
112112
github.com/hashicorp/hcl/v2 v2.14.0
113113
github.com/hashicorp/terraform-config-inspect v0.0.0-20211115214459-90acf1ca460f
114114
github.com/hashicorp/terraform-json v0.16.0
@@ -354,4 +354,8 @@ require (
354354

355355
require github.com/gobwas/httphead v0.1.0
356356

357-
require github.com/gabriel-vasile/mimetype v1.4.2 // indirect
357+
require (
358+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
359+
github.com/cloudflare/circl v1.3.3 // indirect
360+
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
361+
)

go.sum

+9-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8
6868
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
6969
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
7070
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
71+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
72+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
7173
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
7274
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
7375
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
@@ -125,6 +127,7 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
125127
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
126128
github.com/bramvdbogaerde/go-scp v1.2.1-0.20221219230748-977ee74ac37b h1:UJeNthMS3NHVtMFKMhzZNxdaXpYqQlbLrDRtVXorT7w=
127129
github.com/bramvdbogaerde/go-scp v1.2.1-0.20221219230748-977ee74ac37b/go.mod h1:s4ZldBoRAOgUg8IrRP2Urmq5qqd2yPXQTPshACY8vQ0=
130+
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
128131
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 h1:3uZCA/BLTIu+DqCfguByNMJa2HVHpXvjfy0Dy7g6fuA=
129132
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
130133
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 h1:BjkPE3785EwPhhyuFkbINB+2a1xATwk8SNDWnJiD41g=
@@ -162,6 +165,9 @@ github.com/clbanning/mxj/v2 v2.5.7/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
162165
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
163166
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
164167
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
168+
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
169+
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
170+
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
165171
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
166172
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
167173
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
@@ -471,8 +477,8 @@ github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09
471477
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
472478
github.com/hashicorp/golang-lru/v2 v2.0.1 h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4=
473479
github.com/hashicorp/golang-lru/v2 v2.0.1/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
474-
github.com/hashicorp/hc-install v0.5.1 h1:eCqToNCob7m2R8kM8Gr7XcVmcRSz9ppCFSVZbMh0X+0=
475-
github.com/hashicorp/hc-install v0.5.1/go.mod h1:iDPCnzKo+SzToOh25R8OWpLdhhy7yBfJX3PmVWiYhrM=
480+
github.com/hashicorp/hc-install v0.5.2 h1:SfwMFnEXVVirpwkDuSF5kymUOhrUxrTq3udEseZdOD0=
481+
github.com/hashicorp/hc-install v0.5.2/go.mod h1:9QISwe6newMWIfEiXpzuu1k9HAGtQYgnSH8H9T8wmoI=
476482
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
477483
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
478484
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
@@ -1102,6 +1108,7 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc
11021108
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11031109
golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11041110
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1111+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11051112
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11061113
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11071114
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

provisioner/terraform/install_test.go

+35-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
//go:build !race
2+
3+
// This test is excluded from the race detector because the underlying
4+
// hc-install library makes massive allocations and can take 1-2 minutes
5+
// to complete.
16
package terraform_test
27

38
import (
49
"context"
510
"os"
611
"sync"
7-
"sync/atomic"
812
"testing"
913
"time"
1014

@@ -25,50 +29,62 @@ func TestInstall(t *testing.T) {
2529
dir := t.TempDir()
2630
log := slogtest.Make(t, nil)
2731

28-
// install spins off 8 installs with Version and waits for them all
29-
// to complete.
32+
// Install spins off 8 installs with Version and waits for them all
33+
// to complete. The locking mechanism within Install should
34+
// prevent multiple binaries from being installed, so the function
35+
// should perform like a single install.
3036
install := func(version *version.Version) string {
3137
var wg sync.WaitGroup
32-
var path atomic.Pointer[string]
38+
paths := make(chan string, 8)
3339
for i := 0; i < 8; i++ {
3440
wg.Add(1)
3541
go func() {
3642
defer wg.Done()
3743
p, err := terraform.Install(ctx, log, dir, version)
3844
assert.NoError(t, err)
39-
path.Store(&p)
45+
paths <- p
4046
}()
4147
}
42-
wg.Wait()
43-
if t.Failed() {
44-
t.FailNow()
48+
go func() {
49+
wg.Wait()
50+
close(paths)
51+
}()
52+
var firstPath string
53+
for p := range paths {
54+
if firstPath == "" {
55+
firstPath = p
56+
} else {
57+
require.Equal(t, firstPath, p, "installs returned different paths")
58+
}
4559
}
46-
return *path.Load()
60+
return firstPath
4761
}
4862

49-
binPath := install(terraform.TerraformVersion)
63+
version1 := terraform.TerraformVersion
64+
binPath := install(version1)
5065

51-
checkBin := func() time.Time {
66+
checkBinModTime := func() time.Time {
5267
binInfo, err := os.Stat(binPath)
5368
require.NoError(t, err)
5469
require.Greater(t, binInfo.Size(), int64(0))
5570
return binInfo.ModTime()
5671
}
5772

58-
firstMod := checkBin()
73+
modTime1 := checkBinModTime()
5974

6075
// Since we're using the same version the install should be idempotent.
6176
install(terraform.TerraformVersion)
62-
secondMod := checkBin()
63-
require.Equal(t, firstMod, secondMod)
77+
modTime2 := checkBinModTime()
78+
require.Equal(t, modTime1, modTime2)
6479

6580
// Ensure a new install happens when version changes
66-
differentVersion := version.Must(version.NewVersion("1.2.0"))
81+
version2 := version.Must(version.NewVersion("1.2.0"))
82+
6783
// Sanity-check
68-
require.NotEqual(t, differentVersion.String(), terraform.TerraformVersion.String())
84+
require.NotEqual(t, version2.String(), version1.String())
6985

70-
install(differentVersion)
86+
install(version2)
7187

72-
thirdMod := checkBin()
73-
require.Greater(t, thirdMod, secondMod)
88+
modTime3 := checkBinModTime()
89+
require.Greater(t, modTime3, modTime2)
7490
}

0 commit comments

Comments
 (0)