diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 52397a8cc..a1dca1499 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -42,9 +42,13 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: '1.22' + # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -58,7 +62,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 # ℹī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -71,6 +75,6 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 9989711e8..7d6b4bcdf 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.22' - uses: actions/checkout@v4 - name: Run static checks @@ -22,7 +22,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.22' - uses: actions/checkout@v4 - run: make build @@ -32,7 +32,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.22' - uses: actions/checkout@v4 - run: make fmtcheck @@ -48,7 +48,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.22' - uses: actions/checkout@v4 - name: Install Terraform @@ -64,7 +64,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.22' - uses: goreleaser/goreleaser-action@b508e2e3ef3b19d4e4146d4f8fb3ba9db644a757 with: @@ -80,7 +80,7 @@ jobs: fetch-depth: 0 # goreleaser needs the whole history to build the release notes - uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.22' - uses: goreleaser/goreleaser-action@b508e2e3ef3b19d4e4146d4f8fb3ba9db644a757 with: diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 25e0ab4d8..26d38126f 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.22' - name: Checkout uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 010eb0779..e1d860b54 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ full-test: go test -v ./... static: - go install honnef.co/go/tools/cmd/staticcheck@2022.1 + go install honnef.co/go/tools/cmd/staticcheck@2023.1.7 staticcheck --version staticcheck ./... diff --git a/awshelper/s3.go b/awshelper/s3.go index 5626d470c..4fbeda114 100644 --- a/awshelper/s3.go +++ b/awshelper/s3.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "os" "path/filepath" "reflect" "regexp" @@ -136,7 +136,7 @@ func SaveS3Status(bucketInfo *BucketInfo, folder string) (err error) { if err != nil { return } - err = ioutil.WriteFile(filepath.Join(folder, CacheFile), jsonString, 0644) + err = os.WriteFile(filepath.Join(folder, CacheFile), jsonString, 0644) return } @@ -153,7 +153,7 @@ func CheckS3Status(sourceBucketInfo *BucketInfo, folder string) error { return fmt.Errorf("error while reading %s: %w", *sourceBucketInfo, err) } - content, err := ioutil.ReadFile(filepath.Join(folder, CacheFile)) + content, err := os.ReadFile(filepath.Join(folder, CacheFile)) if err != nil { return err } diff --git a/cli/download_source.go b/cli/download_source.go index b4274bebb..9bb7533de 100644 --- a/cli/download_source.go +++ b/cli/download_source.go @@ -2,7 +2,6 @@ package cli import ( "fmt" - "io/ioutil" "net/url" "os" "regexp" @@ -130,7 +129,7 @@ func readVersionFile(terraformSource *TerraformSource) (string, error) { // calculated using the encodeSourceVersion method. func writeVersionFile(terraformSource *TerraformSource) error { version := encodeSourceVersion(terraformSource.CanonicalSourceURL) - return tgerrors.WithStackTrace(ioutil.WriteFile(terraformSource.VersionFile, []byte(version), 0640)) + return tgerrors.WithStackTrace(os.WriteFile(terraformSource.VersionFile, []byte(version), 0640)) } // Take the given source path and create a TerraformSource struct from it, including the folder where the source should @@ -141,25 +140,25 @@ func writeVersionFile(terraformSource *TerraformSource) error { // To maximize reuse, given a working directory w and a source URL s, we download code from S into the folder /T/W/H // where: // -// 1. S is the part of s before the double-slash (//). This typically represents the root of the repo (e.g. -// github.com/foo/infrastructure-modules). We download the entire repo so that relative paths to other files in that -// repo resolve correctly. If no double-slash is specified, all of s is used. -// 1. T is the OS temp dir (e.g. /tmp). -// 2. W is the base 64 encoded sha1 hash of w. This ensures that if you are running Terragrunt concurrently in -// multiple folders (e.g. during automated tests), then even if those folders are using the same source URL s, they -// do not overwrite each other. -// 3. H is the base 64 encoded sha1 of S without its query string. For remote source URLs (e.g. Git -// URLs), this is based on the assumption that the scheme/host/path of the URL (e.g. git::github.com/foo/bar) -// identifies the repo, and we always want to download the same repo into the same folder (see the encodeSourceName -// method). We also assume the version of the module is stored in the query string (e.g. ref=v0.0.3), so we store -// the base 64 encoded sha1 of the query string in a file called .terragrunt-source-version within /T/W/H. +// 1. S is the part of s before the double-slash (//). This typically represents the root of the repo (e.g. +// github.com/foo/infrastructure-modules). We download the entire repo so that relative paths to other files in that +// repo resolve correctly. If no double-slash is specified, all of s is used. +// 1. T is the OS temp dir (e.g. /tmp). +// 2. W is the base 64 encoded sha1 hash of w. This ensures that if you are running Terragrunt concurrently in +// multiple folders (e.g. during automated tests), then even if those folders are using the same source URL s, they +// do not overwrite each other. +// 3. H is the base 64 encoded sha1 of S without its query string. For remote source URLs (e.g. Git +// URLs), this is based on the assumption that the scheme/host/path of the URL (e.g. git::github.com/foo/bar) +// identifies the repo, and we always want to download the same repo into the same folder (see the encodeSourceName +// method). We also assume the version of the module is stored in the query string (e.g. ref=v0.0.3), so we store +// the base 64 encoded sha1 of the query string in a file called .terragrunt-source-version within /T/W/H. // // The downloadTerraformSourceIfNecessary decides when we should download the Terraform code and when not to. It uses // the following rules: // -// 1. Always download source URLs pointing to local file paths. -// 2. Only download source URLs pointing to remote paths if /T/W/H doesn't already exist or, if it does exist, if the -// version number in /T/W/H/.terragrunt-source-version doesn't match the current version. +// 1. Always download source URLs pointing to local file paths. +// 2. Only download source URLs pointing to remote paths if /T/W/H doesn't already exist or, if it does exist, if the +// version number in /T/W/H/.terragrunt-source-version doesn't match the current version. func processTerraformSource(source string, terragruntOptions *options.TerragruntOptions) (*TerraformSource, error) { canonicalWorkingDir, err := util.CanonicalPath(terragruntOptions.WorkingDir, "") if err != nil { diff --git a/cli/download_source_test.go b/cli/download_source_test.go index 1be694f5e..01d9853b9 100644 --- a/cli/download_source_test.go +++ b/cli/download_source_test.go @@ -2,7 +2,6 @@ package cli import ( "fmt" - "io/ioutil" "net/url" "os" "path/filepath" @@ -183,7 +182,7 @@ func testAlreadyHaveLatestCode(t *testing.T, canonicalURL string, downloadDir st } func tmpDir(t *testing.T) string { - dir, err := ioutil.TempDir("", "download-source-test") + dir, err := os.MkdirTemp("", "download-source-test") if err != nil { t.Fatal(err) } diff --git a/config/config_export_variables.go b/config/config_export_variables.go index b62b29df0..50f74789f 100644 --- a/config/config_export_variables.go +++ b/config/config_export_variables.go @@ -3,7 +3,7 @@ package config import ( "encoding/json" "fmt" - "io/ioutil" + "os" "path/filepath" "strings" @@ -85,7 +85,7 @@ func (conf *TerragruntConfig) ExportVariables(existingTerraformVariables map[str if len(content) > 0 && content[len(content)-1] != '\n' { content = append(content, '\n') } - if err = ioutil.WriteFile(writePath, content, 0644); handleError(err) != nil { + if err = os.WriteFile(writePath, content, 0644); handleError(err) != nil { return fmt.Errorf("file write error: %v", err) } } diff --git a/config/config_helpers.go b/config/config_helpers.go index 4cf667fd8..f19b78167 100644 --- a/config/config_helpers.go +++ b/config/config_helpers.go @@ -217,7 +217,8 @@ func (ctx *resolveContext) getParentDir() (string, error) { } // Returns the named environment variable or default value if it does not exist -// get_env(variable_name, default_value) +// +// get_env(variable_name, default_value) func (ctx *resolveContext) getEnvironmentVariable(env, defValue string) string { if value, exists := ctx.options.Env[env]; exists { return value diff --git a/config/config_test.go b/config/config_test.go index a35613bdb..c610dc77a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2,7 +2,7 @@ package config import ( "fmt" - "io/ioutil" + "os" "path" "path/filepath" "testing" @@ -464,7 +464,7 @@ func TestReadTerragruntConfigHooksAreInitalized(t *testing.T) { fixturesDir := "../test/fixture-hooks" - files, err := ioutil.ReadDir(fixturesDir) + files, err := os.ReadDir(fixturesDir) if err != nil { t.Fatal(err) } diff --git a/configstack/running_module.go b/configstack/running_module.go index 04b32aab8..da62d229f 100644 --- a/configstack/running_module.go +++ b/configstack/running_module.go @@ -161,9 +161,9 @@ func toRunningModules(modules []*TerraformModule, dependencyOrder dependencyOrde // Loop through the map of runningModules and for each module M: // -// * If dependencyOrder is NormalOrder, plug in all the modules M depends on into the Dependencies field and all the -// modules that depend on M into the NotifyWhenDone field. -// * If dependencyOrder is ReverseOrder, do the reverse. +// - If dependencyOrder is NormalOrder, plug in all the modules M depends on into the Dependencies field and all the +// modules that depend on M into the NotifyWhenDone field. +// - If dependencyOrder is ReverseOrder, do the reverse. func crossLinkDependencies(modules map[string]*runningModule, dependencyOrder dependencyOrder) (map[string]*runningModule, error) { for _, module := range modules { for _, dependency := range module.Module.Dependencies { diff --git a/configstack/stack_test.go b/configstack/stack_test.go index 9aeea3fcb..90eeb83e0 100644 --- a/configstack/stack_test.go +++ b/configstack/stack_test.go @@ -1,7 +1,6 @@ package configstack import ( - "io/ioutil" "os" "path/filepath" "strings" @@ -52,7 +51,7 @@ func TestFindStackInSubfolders(t *testing.T) { } func createTempFolder(t *testing.T) string { - tmpFolder, err := ioutil.TempDir("", "") + tmpFolder, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("Failed to create temp directory: %s\n", err.Error()) } @@ -69,7 +68,7 @@ func writeDummyTerragruntConfigs(t *testing.T, tmpFolder string, paths []string) containingDir := filepath.Dir(absPath) createDirIfNotExist(t, containingDir) - err := ioutil.WriteFile(absPath, contents, os.ModePerm) + err := os.WriteFile(absPath, contents, os.ModePerm) if err != nil { t.Fatalf("Failed to write file at path %s: %s\n", path, err.Error()) } diff --git a/dynamodb/dynamo_lock_test_utils.go b/dynamodb/dynamo_lock_test_utils.go index b288d3a6f..cee81720f 100644 --- a/dynamodb/dynamo_lock_test_utils.go +++ b/dynamodb/dynamo_lock_test_utils.go @@ -6,7 +6,6 @@ import ( "fmt" "math/rand" "testing" - "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/dynamodb" @@ -15,10 +14,6 @@ import ( "github.com/stretchr/testify/assert" ) -func init() { - rand.Seed(time.Now().UnixNano()) -} - var mockOptions = options.NewTerragruntOptionsForTest("dynamo_lock_test_utils") // Returns a unique (ish) id we can use to name resources so they don't conflict with each other. Uses base 62 to diff --git a/go.mod b/go.mod index 6cc91ed18..c74e5d27b 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ module github.com/coveooss/terragrunt/v2 -go 1.18 +go 1.22 require ( github.com/alecthomas/kingpin/v2 v2.4.0 - github.com/aws/aws-sdk-go-v2 v1.25.2 - github.com/aws/aws-sdk-go-v2/config v1.27.4 - github.com/aws/aws-sdk-go-v2/credentials v1.17.4 - github.com/aws/aws-sdk-go-v2/service/dynamodb v1.30.1 - github.com/aws/aws-sdk-go-v2/service/s3 v1.51.1 - github.com/aws/aws-sdk-go-v2/service/ssm v1.49.1 - github.com/aws/aws-sdk-go-v2/service/sts v1.28.1 + github.com/aws/aws-sdk-go-v2 v1.26.1 + github.com/aws/aws-sdk-go-v2/config v1.27.11 + github.com/aws/aws-sdk-go-v2/credentials v1.17.11 + github.com/aws/aws-sdk-go-v2/service/dynamodb v1.31.1 + github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 + github.com/aws/aws-sdk-go-v2/service/ssm v1.49.5 + github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 github.com/cheekybits/genny v1.0.0 github.com/coveooss/gotemplate/v3 v3.7.5 github.com/coveooss/multilogger v0.5.2 @@ -23,9 +23,9 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/rs/xid v1.5.0 github.com/sirupsen/logrus v1.9.3 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/urfave/cli v1.22.14 - github.com/zclconf/go-cty v1.14.2 + github.com/zclconf/go-cty v1.14.4 gopkg.in/matryer/try.v1 v1.0.0-20150601225556-312d2599e12e gopkg.in/yaml.v2 v2.4.0 ) @@ -46,20 +46,20 @@ require ( github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/apparentlymart/go-versions v1.0.1 // indirect github.com/aws/aws-sdk-go v1.37.0 // indirect - github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect - github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.2 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.2 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.2 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.2 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 // indirect - github.com/aws/smithy-go v1.20.1 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.6 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect + github.com/aws/smithy-go v1.20.2 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bmatcuk/doublestar v1.3.4 // indirect github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect diff --git a/go.sum b/go.sum index b7df08910..6c2d662e7 100644 --- a/go.sum +++ b/go.sum @@ -125,48 +125,48 @@ github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3A github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.37.0 h1:GzFnhOIsrGyQ69s7VgqtrG2BG8v7X7vwB3Xpbd/DBBk= github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= -github.com/aws/aws-sdk-go-v2 v1.25.2 h1:/uiG1avJRgLGiQM9X3qJM8+Qa6KRGK5rRPuXE0HUM+w= -github.com/aws/aws-sdk-go-v2 v1.25.2/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 h1:gTK2uhtAPtFcdRRJilZPx8uJLL2J85xK11nKtWL0wfU= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1/go.mod h1:sxpLb+nZk7tIfCWChfd+h4QwHNUR57d8hA1cleTkjJo= -github.com/aws/aws-sdk-go-v2/config v1.27.4 h1:AhfWb5ZwimdsYTgP7Od8E9L1u4sKmDW2ZVeLcf2O42M= -github.com/aws/aws-sdk-go-v2/config v1.27.4/go.mod h1:zq2FFXK3A416kiukwpsd+rD4ny6JC7QSkp4QdN1Mp2g= -github.com/aws/aws-sdk-go-v2/credentials v1.17.4 h1:h5Vztbd8qLppiPwX+y0Q6WiwMZgpd9keKe2EAENgAuI= -github.com/aws/aws-sdk-go-v2/credentials v1.17.4/go.mod h1:+30tpwrkOgvkJL1rUZuRLoxcJwtI/OkeBLYnHxJtVe0= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 h1:AK0J8iYBFeUk2Ax7O8YpLtFsfhdOByh2QIkHmigpRYk= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2/go.mod h1:iRlGzMix0SExQEviAyptRWRGdYNo3+ufW/lCzvKVTUc= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 h1:bNo4LagzUKbjdxE0tIcR9pMzLR2U/Tgie1Hq1HQ3iH8= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2/go.mod h1:wRQv0nN6v9wDXuWThpovGQjqF1HFdcgWjporw14lS8k= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 h1:EtOU5jsPdIQNP+6Q2C5e3d65NKT1PeCiQk+9OdzO12Q= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2/go.mod h1:tyF5sKccmDz0Bv4NrstEr+/9YkSPJHrcO7UsUKf7pWM= +github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA= +github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg= +github.com/aws/aws-sdk-go-v2/config v1.27.11 h1:f47rANd2LQEYHda2ddSCKYId18/8BhSRM4BULGmfgNA= +github.com/aws/aws-sdk-go-v2/config v1.27.11/go.mod h1:SMsV78RIOYdve1vf36z8LmnszlRWkwMQtomCAI0/mIE= +github.com/aws/aws-sdk-go-v2/credentials v1.17.11 h1:YuIB1dJNf1Re822rriUOTxopaHHvIq0l/pX3fwO+Tzs= +github.com/aws/aws-sdk-go-v2/credentials v1.17.11/go.mod h1:AQtFPsDH9bI2O+71anW6EKL+NcD7LG3dpKGMV4SShgo= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 h1:FVJ0r5XTHSmIHJV6KuDmdYhEpvlHpiSd38RQWhut5J4= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1/go.mod h1:zusuAeqezXzAB24LGuzuekqMAEgWkVYukBec3kr3jUg= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 h1:aw39xVGeRWlWx9EzGVnhOR4yOjQDHPQ6o6NmBlscyQg= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5/go.mod h1:FSaRudD0dXiMPK2UjknVwwTYyZMRsHv3TtkabsZih5I= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 h1:PG1F3OD1szkuQPzDw3CIQsRIrtTlUC3lP84taWzHlq0= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5/go.mod h1:jU1li6RFryMz+so64PpKtudI+QzbKoIEivqdf6LNpOc= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.2 h1:en92G0Z7xlksoOylkUhuBSfJgijC7rHVLRdnIlHEs0E= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.2/go.mod h1:HgtQ/wN5G+8QSlK62lbOtNwQ3wTSByJ4wH2rCkPt+AE= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.30.1 h1:haLXE5R07oaq/UnvSyE43V4jp9gA2XRMYcxkFYHEpdU= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.30.1/go.mod h1:mM51J0CILKQjqIawPDM4g6E1nyxdlvk/qaCDyJkx0II= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibRTVAs6ECHZOw5/wlylS9OcTzwyjeQMudmREjE= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1/go.mod h1:JKpmtYhhPs7D97NL/ltqz7yCkERFW5dOlHyVl66ZYF8= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.2 h1:zSdTXYLwuXDNPUS+V41i1SFDXG7V0ITp0D9UT9Cvl18= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.2/go.mod h1:v8m8k+qVy95nYi7d56uP1QImleIIY25BPiNJYzPBdFE= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.2 h1:3tS2g6P3N+Wz64e9aNx7X4BCWN/gT9MUvIuv5l2eoho= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.2/go.mod h1:1Pf5vPqk8t9pdYB3dmUMRE/0m8u0IHHg8ESSiutJd0I= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2 h1:5ffmXjPtwRExp1zc7gENLgCPyHFbhEPwVTkTiH9niSk= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2/go.mod h1:Ru7vg1iQ7cR4i7SZ/JTLYN9kaXtbL69UdgG0OQWQxW0= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.2 h1:1oY1AVEisRI4HNuFoLdRUB0hC63ylDAN6Me3MrfclEg= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.2/go.mod h1:KZ03VgvZwSjkT7fOetQ/wF3MZUvYFirlI1H5NklUNsY= -github.com/aws/aws-sdk-go-v2/service/s3 v1.51.1 h1:juZ+uGargZOrQGNxkVHr9HHR/0N+Yu8uekQnV7EAVRs= -github.com/aws/aws-sdk-go-v2/service/s3 v1.51.1/go.mod h1:SoR0c7Jnq8Tpmt0KSLXIavhjmaagRqQpe9r70W3POJg= -github.com/aws/aws-sdk-go-v2/service/ssm v1.49.1 h1:MeYuN4Ld4FWVJb9ZiOJkon7/foj0Zm2GTDorSaInHj4= -github.com/aws/aws-sdk-go-v2/service/ssm v1.49.1/go.mod h1:TM0pqkfTRMVtsMlPnOivUmrZSIANsLbq9FTm4oJPcPQ= -github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 h1:utEGkfdQ4L6YW/ietH7111ZYglLJvS+sLriHJ1NBJEQ= -github.com/aws/aws-sdk-go-v2/service/sso v1.20.1/go.mod h1:RsYqzYr2F2oPDdpy+PdhephuZxTfjHQe7SOBcZGoAU8= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 h1:9/GylMS45hGGFCcMrUZDVayQE1jYSIN6da9jo7RAYIw= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1/go.mod h1:YjAPFn4kGFqKC54VsHs5fn5B6d+PCY2tziEa3U/GB5Y= -github.com/aws/aws-sdk-go-v2/service/sts v1.28.1 h1:3I2cBEYgKhrWlwyZgfpSO2BpaMY1LHPqXYk/QGlu2ew= -github.com/aws/aws-sdk-go-v2/service/sts v1.28.1/go.mod h1:uQ7YYKZt3adCRrdCBREm1CD3efFLOUNH77MrUCvx5oA= -github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw= -github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 h1:81KE7vaZzrl7yHBYHVEzYB8sypz11NMOZ40YlWvPxsU= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5/go.mod h1:LIt2rg7Mcgn09Ygbdh/RdIm0rQ+3BNkbP1gyVMFtRK0= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.31.1 h1:dZXY07Dm59TxAjJcUfNMJHLDI/gLMxTRZefn2jFAVsw= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.31.1/go.mod h1:lVLqEtX+ezgtfalyJs7Peb0uv9dEpAQP5yuq2O26R44= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 h1:ZMeFZ5yk+Ek+jNr1+uwCd2tG89t6oTS5yVWpa6yy2es= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7/go.mod h1:mxV05U+4JiHqIpGqqYXOHLPKUC6bDXC44bsUhNjOEwY= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.6 h1:6tayEze2Y+hiL3kdnEUxSPsP+pJsUfwLSFspFl1ru9Q= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.6/go.mod h1:qVNb/9IOVsLCZh0x2lnagrBwQ9fxajUpXS7OZfIsKn0= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 h1:ogRAwT1/gxJBcSWDMZlgyFUM962F51A5CRhDLbxLdmo= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7/go.mod h1:YCsIZhXfRPLFFCl5xxY+1T9RKzOKjCut+28JSX2DnAk= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 h1:f9RyWNtS8oH7cZlbn+/JNPpjUk5+5fLd5lM9M0i49Ys= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5/go.mod h1:h5CoMZV2VF297/VLhRhO1WF+XYWOzXo+4HsObA4HjBQ= +github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7jz8TsskTTccbgc= +github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o= +github.com/aws/aws-sdk-go-v2/service/ssm v1.49.5 h1:KBwyHzP2QG8J//hoGuPyHWZ5tgL1BzaoMURUkecpI4g= +github.com/aws/aws-sdk-go-v2/service/ssm v1.49.5/go.mod h1:Ebk/HZmGhxWKDVxM4+pwbxGjm3RQOQLMjAEosI3ss9Q= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 h1:vN8hEbpRnL7+Hopy9dzmRle1xmDc7o8tmY0klsr175w= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.5/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 h1:Jux+gDDyi1Lruk+KHF91tK2KCuY61kzoCpvtvJJBtOE= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4/go.mod h1:mUYPBhaF2lGiukDEjJX2BLRRKTmoUSitGDUgM4tRxak= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 h1:cwIxeBttqPN3qkaAjcEcsh8NYr8n2HZPkcKgPAi1phU= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.6/go.mod h1:FZf1/nKNEkHdGGJP/cI2MoIMquumuRK6ol3QQJNDxmw= +github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= +github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= @@ -572,8 +572,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tencentcloud/tencentcloud-sdk-go v3.0.82+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= github.com/tencentyun/cos-go-sdk-v5 v0.0.0-20190808065407-f07404cefc8c/go.mod h1:wk2XFUg6egk4tSDNZtXeKfe2G6690UVyt163PuUxBZk= github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -601,8 +602,8 @@ github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.8.3/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.14.2 h1:kTG7lqmBou0Zkx35r6HJHUQTvaRPr5bIAf3AoHS0izI= -github.com/zclconf/go-cty v1.14.2/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= +github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= github.com/zclconf/go-cty-yaml v1.0.2 h1:dNyg4QLTrv2IfJpm7Wtxi55ed5gLGOlPrZ6kMd51hY0= github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= @@ -731,6 +732,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/remote/terraform_state_file.go b/remote/terraform_state_file.go index 187a54bc4..f6b0639e3 100644 --- a/remote/terraform_state_file.go +++ b/remote/terraform_state_file.go @@ -3,10 +3,9 @@ package remote import ( "encoding/json" "fmt" - "io/ioutil" - "github.com/coveooss/terragrunt/v2/tgerrors" "github.com/coveooss/terragrunt/v2/util" + "os" ) // TODO: this file could be changed to use the Terraform Go code to read state files, but that code is relatively @@ -59,7 +58,7 @@ func parseTerraformStateFileFromLocation(workingDir string) (*TerraformState, er // Parse the Terraform .tfstate file at the given path func parseTerraformStateFile(path string) (*TerraformState, error) { - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { return nil, tgerrors.WithStackTrace(errCantParseTerraformStateFile{Path: path, UnderlyingErr: err}) } diff --git a/shell/run_shell_cmd.go b/shell/run_shell_cmd.go index 7f0475d32..b1415cd81 100644 --- a/shell/run_shell_cmd.go +++ b/shell/run_shell_cmd.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "os/exec" "os/signal" @@ -178,7 +177,7 @@ func (c CommandContext) Run() error { c.log.Log(c.LogLevel, verb, "command: ", c.DisplayCommand, " ", strings.Join(cmd.Args[1:], " ")) if tempFile != "" { - content, _ := ioutil.ReadFile(tempFile) + content, _ := os.ReadFile(tempFile) if c.DisplayCommand == "" { c.options.Logger.Debugf("\n%s", string(content)) } diff --git a/test/integration_hooks_test.go b/test/integration_hooks_test.go index 5ec32df30..2fed1b810 100644 --- a/test/integration_hooks_test.go +++ b/test/integration_hooks_test.go @@ -3,7 +3,6 @@ package test import ( "bytes" "fmt" - "io/ioutil" "os" "strings" "testing" @@ -23,7 +22,7 @@ func TestTerragruntBeforeHook(t *testing.T) { runTerragrunt(t, fmt.Sprintf("terragrunt apply --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath)) - _, exception := ioutil.ReadFile(rootPath + "/file.out") + _, exception := os.ReadFile(rootPath + "/file.out") assert.NoError(t, exception) } @@ -38,7 +37,7 @@ func TestTerragruntAfterHook(t *testing.T) { runTerragrunt(t, fmt.Sprintf("terragrunt apply --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath)) - _, exception := ioutil.ReadFile(rootPath + "/file.out") + _, exception := os.ReadFile(rootPath + "/file.out") assert.NoError(t, exception) } @@ -53,8 +52,8 @@ func TestTerragruntBeforeAndAfterHook(t *testing.T) { runTerragrunt(t, fmt.Sprintf("terragrunt apply --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath)) - _, beforeException := ioutil.ReadFile(rootPath + "/before.out") - _, afterException := ioutil.ReadFile(rootPath + "/after.out") + _, beforeException := os.ReadFile(rootPath + "/before.out") + _, afterException := os.ReadFile(rootPath + "/after.out") assert.NoError(t, beforeException) assert.NoError(t, afterException) @@ -83,11 +82,11 @@ func TestTerragruntBeforeAndAfterMergeHook(t *testing.T) { runTerragrunt(t, fmt.Sprintf("terragrunt apply --terragrunt-non-interactive --terragrunt-config %s --terragrunt-working-dir %s", tmpTerragruntConfigPath, childPath)) - _, beforeException := ioutil.ReadFile(childPath + "/before.out") - _, beforeChildException := ioutil.ReadFile(childPath + "/before-child.out") - _, beforeOverriddenParentException := ioutil.ReadFile(childPath + "/before-parent.out") - _, afterException := ioutil.ReadFile(childPath + "/after.out") - _, afterParentException := ioutil.ReadFile(childPath + "/after-parent.out") + _, beforeException := os.ReadFile(childPath + "/before.out") + _, beforeChildException := os.ReadFile(childPath + "/before-child.out") + _, beforeOverriddenParentException := os.ReadFile(childPath + "/before-parent.out") + _, afterException := os.ReadFile(childPath + "/after.out") + _, afterParentException := os.ReadFile(childPath + "/after-parent.out") assert.NoError(t, beforeException) assert.NoError(t, beforeChildException) @@ -137,7 +136,7 @@ func TestTerragruntHookExitCode1(t *testing.T) { err := runTerragruntCommand(t, fmt.Sprintf("terragrunt plan -detailed-exitcode --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath), os.Stdout, os.Stderr) - _, exception := ioutil.ReadFile(rootPath + "/test.out") + _, exception := os.ReadFile(rootPath + "/test.out") assert.Error(t, exception) assert.Contains(t, err.Error(), "Error while executing hooks(post_hook_1): exit status 1") } @@ -152,7 +151,7 @@ func TestTerragruntHookExitCode1RunOnErrors(t *testing.T) { err := runTerragruntCommand(t, fmt.Sprintf("terragrunt plan -detailed-exitcode --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath), os.Stdout, os.Stderr) - _, exception := ioutil.ReadFile(rootPath + "/test.out") + _, exception := os.ReadFile(rootPath + "/test.out") assert.NoError(t, exception) assert.Contains(t, err.Error(), "Error while executing hooks(post_hook_1): exit status 1") } @@ -167,7 +166,7 @@ func TestTerragruntHookExitCode2(t *testing.T) { err := runTerragruntCommand(t, fmt.Sprintf("terragrunt plan -detailed-exitcode --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath), os.Stdout, os.Stderr) - _, exception := ioutil.ReadFile(rootPath + "/test.out") + _, exception := os.ReadFile(rootPath + "/test.out") assert.NoError(t, exception) assert.Contains(t, err.Error(), "There are changes in the plan") } @@ -182,7 +181,7 @@ func TestTerragruntHookExitCode2InPreHook(t *testing.T) { err := runTerragruntCommand(t, fmt.Sprintf("terragrunt plan -detailed-exitcode --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath), os.Stdout, os.Stderr) - _, exception := ioutil.ReadFile(rootPath + "/test2.out") + _, exception := os.ReadFile(rootPath + "/test2.out") assert.NoError(t, exception) assert.Contains(t, err.Error(), "There are changes in the plan") } @@ -197,7 +196,7 @@ func TestTerragruntHookExitCode2PlanAll(t *testing.T) { err := runTerragruntCommand(t, fmt.Sprintf("terragrunt plan-all -detailed-exitcode --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath), os.Stdout, os.Stderr) - _, exception := ioutil.ReadFile(rootPath + "/test.out") + _, exception := os.ReadFile(rootPath + "/test.out") assert.NoError(t, exception) assert.Contains(t, err.Error(), "There are changes in the plan") } @@ -212,7 +211,7 @@ func TestTerragruntHookWithEnvVars(t *testing.T) { var stdout, stderr bytes.Buffer runTerragruntRedirectOutput(t, fmt.Sprintf("terragrunt cmd%d --terragrunt-non-interactive --terragrunt-working-dir %s", i, rootPath), &stdout, &stderr) - content, err := ioutil.ReadFile(util.JoinPath(rootPath, fmt.Sprintf("result%d", i))) + content, err := os.ReadFile(util.JoinPath(rootPath, fmt.Sprintf("result%d", i))) assert.NoError(t, err, "Reading result%d", i) assert.Equal(t, string(content), stdout.String(), "Comparing result %d", i) }) @@ -227,7 +226,7 @@ func TestTerragruntHookOverwrite(t *testing.T) { var stdout bytes.Buffer runTerragruntRedirectOutput(t, fmt.Sprintf("terragrunt cmd --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath), &stdout, os.Stderr) - content, err := ioutil.ReadFile(util.JoinPath(rootPath, "result")) + content, err := os.ReadFile(util.JoinPath(rootPath, "result")) assert.NoError(t, err, "Reading result") assert.Equal(t, string(content), stdout.String(), "Comparing result") } diff --git a/test/integration_test.go b/test/integration_test.go index c2079bb83..60500ea43 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -4,15 +4,6 @@ import ( "bytes" "context" "fmt" - "io" - "io/ioutil" - "math/rand" - "os" - "path/filepath" - "strings" - "testing" - "time" - "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/dynamodb" "github.com/aws/aws-sdk-go-v2/service/s3" @@ -25,14 +16,16 @@ import ( "github.com/coveooss/terragrunt/v2/remote" "github.com/coveooss/terragrunt/v2/util" "github.com/stretchr/testify/assert" + "io" + "math/rand" + "os" + "path/filepath" + "strings" + "testing" ) const terraformRemoteStateS3Region = "us-west-2" -func init() { - rand.Seed(time.Now().UnixNano()) -} - func trim(s string) string { return fmt.Sprintln(strings.TrimSpace(collections.UnIndent(s))) } func TestTerragruntWorksWithLocalTerraformVersion(t *testing.T) { @@ -492,7 +485,7 @@ func withEnv(variables string, testFunction func()) { } func copyEnvironment(t *testing.T, environmentPath string) string { - tmpDir, err := ioutil.TempDir("", "terragrunt-stack-test") + tmpDir, err := os.MkdirTemp("", "terragrunt-stack-test") if err != nil { t.Fatalf("Failed to create temp dir due to error: %v", err) } @@ -526,15 +519,15 @@ func copyEnvironment(t *testing.T, environmentPath string) string { } func copyFile(srcPath string, destPath string) error { - contents, err := ioutil.ReadFile(srcPath) + contents, err := os.ReadFile(srcPath) if err != nil { return err } - return ioutil.WriteFile(destPath, contents, 0644) + return os.WriteFile(destPath, contents, 0644) } func createTmpTerragruntConfigWithParentAndChild(t *testing.T, parentPath string, childRelPath string, s3BucketName string, parentConfigFileName string, childConfigFileName string) string { - tmpDir, err := ioutil.TempDir("", "terragrunt-parent-child-test") + tmpDir, err := os.MkdirTemp("", "terragrunt-parent-child-test") if err != nil { t.Fatalf("Failed to create temp dir due to error: %v", err) } @@ -557,7 +550,7 @@ func createTmpTerragruntConfigWithParentAndChild(t *testing.T, parentPath string } func createTmpTerragruntConfig(t *testing.T, templatesPath string, s3BucketName string, lockTableName string, configFileName string) string { - tmpFolder, err := ioutil.TempDir("", "terragrunt-test") + tmpFolder, err := os.MkdirTemp("", "terragrunt-test") if err != nil { t.Fatalf("Failed to create temp folder due to error: %v", err) } @@ -578,7 +571,7 @@ func copyTerragruntConfigAndFillPlaceholders(t *testing.T, configSrcPath string, contents = strings.Replace(contents, "__FILL_IN_BUCKET_NAME__", s3BucketName, -1) contents = strings.Replace(contents, "__FILL_IN_LOCK_TABLE_NAME__", lockTableName, -1) - if err := ioutil.WriteFile(configDestPath, []byte(contents), 0444); err != nil { + if err := os.WriteFile(configDestPath, []byte(contents), 0444); err != nil { t.Fatalf("Error writing temp Terragrunt config to %s: %v", configDestPath, err) } } diff --git a/util/collections.go b/util/collections.go index fda1c9aa3..30243ed82 100644 --- a/util/collections.go +++ b/util/collections.go @@ -44,9 +44,10 @@ func RemoveDuplicatesFromListKeepLast(list []string) []string { // RemoveDuplicatesFromList returns a copy of the given list with all duplicates removed (keeping the last encountereds) // Params: -// list: The list to filter -// keepLast: Indicates whether the last or first encountered duplicate element should be kept -// getKey: Function used to extract the actual key from the string +// +// list: The list to filter +// keepLast: Indicates whether the last or first encountered duplicate element should be kept +// getKey: Function used to extract the actual key from the string func RemoveDuplicatesFromList(list []string, keepLast bool, getKey func(key string) string) []string { out := make([]string, 0, len(list)) present := make(map[string]bool) diff --git a/util/file.go b/util/file.go index 089a4dda1..19bdf44b6 100644 --- a/util/file.go +++ b/util/file.go @@ -3,7 +3,6 @@ package util import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -93,7 +92,7 @@ func Grep(regex *regexp.Regexp, folder string, patterns ...string) (bool, error) } for _, match := range matches { - bytes, err := ioutil.ReadFile(match) + bytes, err := os.ReadFile(match) if err != nil { return false, tgerrors.WithStackTrace(err) } @@ -174,7 +173,7 @@ func GetPathRelativeToMax(path, basePath string, maxLevel uint) (result string) // ReadFileAsString returns the contents of the file at the given path as a string func ReadFileAsString(path string) (string, error) { - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { return "", tgerrors.WithStackTraceAndPrefix(err, "Error reading file at path %s", path) } @@ -326,7 +325,7 @@ var sharedContent = map[string]bool{} // CopyFolderContents copies the files and folders within the source folder into the destination folder. Note that hidden files and folders // (those starting with a dot) will be skipped. func CopyFolderContents(source, destination string, excluded ...string) error { - files, err := ioutil.ReadDir(source) + files, err := os.ReadDir(source) if err != nil { return tgerrors.WithStackTrace(err) } @@ -340,7 +339,7 @@ func CopyFolderContents(source, destination string, excluded ...string) error { if PathContainsHiddenFileOrFolder(src) { continue } else if file.IsDir() { - if err := os.MkdirAll(dest, file.Mode()); err != nil { + if err := os.MkdirAll(dest, file.Type()); err != nil { return tgerrors.WithStackTrace(err) } @@ -370,7 +369,7 @@ func PathContainsHiddenFileOrFolder(path string) bool { // CopyFile copies a file from source to destination func CopyFile(source string, destination string) error { - contents, err := ioutil.ReadFile(source) + contents, err := os.ReadFile(source) if err != nil { return tgerrors.WithStackTrace(err) } @@ -386,7 +385,7 @@ func WriteFileWithSamePermissions(source string, destination string, contents [] return tgerrors.WithStackTrace(err) } - return ioutil.WriteFile(destination, contents, fileInfo.Mode()) + return os.WriteFile(destination, contents, fileInfo.Mode()) } // JoinPath always use / as the separator. diff --git a/util/get.go b/util/get.go index bc0b428cf..1d5381e0f 100644 --- a/util/get.go +++ b/util/get.go @@ -2,7 +2,6 @@ package util import ( "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -37,7 +36,7 @@ const ( // can't be updated on its own. func GetCopy(dst, src, fileRegex string) error { // Create the temporary directory to do the real Get to - tmpDir, err := ioutil.TempDir("", "tf") + tmpDir, err := os.MkdirTemp("", "tf") if err != nil { return err } diff --git a/util/random.go b/util/random.go index ea92172d8..dc5a14cf3 100644 --- a/util/random.go +++ b/util/random.go @@ -6,7 +6,9 @@ import ( ) // GetRandomTime returns random time duration between the lower bound and upper bound. This is useful because some of our -// automated tests wound up flooding the AWS API all at once, leading to a "Subscriber limit exceeded" error. +// +// automated tests wound up flooding the AWS API all at once, leading to a "Subscriber limit exceeded" error. +// // TODO: Some of the more exotic test cases fail, but it's not worth catching them given the intended use of this function. func GetRandomTime(lowerBound, upperBound time.Duration) time.Duration { if lowerBound < 0 { @@ -37,6 +39,5 @@ func GetRandomTime(lowerBound, upperBound time.Duration) time.Duration { // Generate a random int between min and max, inclusive func random(min int, max int) int { - rand.Seed(time.Now().UnixNano()) return rand.Intn(max-min) + min } diff --git a/util/terraform.go b/util/terraform.go index 65c7d7046..93b79834c 100644 --- a/util/terraform.go +++ b/util/terraform.go @@ -2,7 +2,6 @@ package util import ( "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -102,7 +101,7 @@ func LoadVariablesFromFile(path, cwd string, applyTemplate bool, context ...inte } } - bytes, err := ioutil.ReadFile(path) + bytes, err := os.ReadFile(path) if err != nil { return nil, err } @@ -264,7 +263,7 @@ func createTerraformVariablesTemporaryFolder(folder string) (tmpDir string, err } var content []byte - if content, err = ioutil.ReadFile(filename); err != nil { + if content, err = os.ReadFile(filename); err != nil { return } @@ -288,7 +287,7 @@ func createTerraformVariablesTemporaryFolder(folder string) (tmpDir string, err if len(generated) > 0 { // We write the resulting files - if tmpDir, err = ioutil.TempDir("", "load_defaults"); err != nil { + if tmpDir, err = os.MkdirTemp("", "load_defaults"); err != nil { return } for filename, value := range generated { @@ -299,7 +298,7 @@ func createTerraformVariablesTemporaryFolder(folder string) (tmpDir string, err case json.Dictionary: content = []byte(value.PrettyPrint()) } - if err = ioutil.WriteFile(path.Join(tmpDir, filename), content, 0644); err != nil { + if err = os.WriteFile(path.Join(tmpDir, filename), content, 0644); err != nil { return } }