Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/backend/local/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -207,7 +206,7 @@ func (b *Local) Workspaces() ([]string, tfdiags.Diagnostics) {
// the listing always start with "default"
envs := []string{backend.DefaultStateName}

entries, err := ioutil.ReadDir(b.stateWorkspaceDir())
entries, err := os.ReadDir(b.stateWorkspaceDir())
// no error if there's no envs configured
if os.IsNotExist(err) {
return envs, nil
Expand Down
6 changes: 3 additions & 3 deletions internal/backend/remote-state/consul/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package consul
import (
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"testing"
"time"
Expand All @@ -32,8 +32,8 @@ func newConsulTestServer(t *testing.T) *testutil.TestServer {
}

if !testing.Verbose() {
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard
}
})

Expand Down
5 changes: 2 additions & 3 deletions internal/backend/remote-state/cos/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -601,7 +600,7 @@ func getConfigFromProfile(d *schema.ResourceData, ProfileKey string) (interface{
providerConfig = make(map[string]interface{})
_, err = os.Stat(credentialPath)
if !os.IsNotExist(err) {
data, err := ioutil.ReadFile(credentialPath)
data, err := os.ReadFile(credentialPath)
if err != nil {
return nil, err
}
Expand All @@ -621,7 +620,7 @@ func getConfigFromProfile(d *schema.ResourceData, ProfileKey string) (interface{

_, err = os.Stat(configurePath)
if !os.IsNotExist(err) {
data, err := ioutil.ReadFile(configurePath)
data, err := os.ReadFile(configurePath)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/backend/remote-state/cos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"strings"
Expand Down Expand Up @@ -206,7 +206,7 @@ func (c *remoteClient) getObject(cosFile string) (exists bool, data []byte, chec
}

exists = true
data, err = ioutil.ReadAll(rsp.Body)
data, err = io.ReadAll(rsp.Body)
log.Printf("[DEBUG] getObject %s: data length: %d", cosFile, len(data))
if err != nil {
err = fmt.Errorf("failed to open file at %v: %v", cosFile, err)
Expand Down
8 changes: 4 additions & 4 deletions internal/backend/remote-state/cos/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp

request.Header.Set("X-TC-RequestClient", ReqClient)
inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName]))
requestBody, errRet := ioutil.ReadAll(bodyReader)
requestBody, errRet := io.ReadAll(bodyReader)
if errRet != nil {
return
}
Expand All @@ -67,11 +67,11 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp
if errRet != nil {
return
}
outBytes, errRet = ioutil.ReadAll(response.Body)
outBytes, errRet = io.ReadAll(response.Body)
if errRet != nil {
return
}
response.Body = ioutil.NopCloser(bytes.NewBuffer(outBytes))
response.Body = io.NopCloser(bytes.NewBuffer(outBytes))
return
}

Expand Down
6 changes: 3 additions & 3 deletions internal/backend/remote-state/gcs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"strconv"

"cloud.google.com/go/storage"
Expand Down Expand Up @@ -42,7 +42,7 @@ func (c *remoteClient) Get() (payload *remote.Payload, diags tfdiags.Diagnostics
}
defer stateFileReader.Close()

stateFileContents, err := ioutil.ReadAll(stateFileReader)
stateFileContents, err := io.ReadAll(stateFileReader)
if err != nil {
return nil, diags.Append(fmt.Errorf("Failed to read state file from %v: %v", c.stateFileURL(), err))
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (c *remoteClient) lockInfo() (*statemgr.LockInfo, error) {
}
defer r.Close()

rawData, err := ioutil.ReadAll(r)
rawData, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/backend/remote-state/gcs/path_or_contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package gcs

import (
"io/ioutil"
"os"

"github.com/mitchellh/go-homedir"
Expand All @@ -28,7 +27,7 @@ func readPathOrContents(poc string) (string, error) {
}

if _, err := os.Stat(path); err == nil {
contents, err := ioutil.ReadFile(path)
contents, err := os.ReadFile(path)
if err != nil {
return string(contents), err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package gcs

import (
"io"
"io/ioutil"
"os"
"os/user"
"strings"
Expand Down Expand Up @@ -121,7 +120,7 @@ func testTempFile(t *testing.T, baseDir ...string) (*os.File, func()) {
if len(baseDir) == 1 {
base = baseDir[0]
}
f, err := ioutil.TempFile(base, "tf")
f, err := os.CreateTemp(base, "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/backend/remote-state/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -102,7 +101,7 @@ func (c *httpClient) Lock(info *statemgr.LockInfo) (string, error) {
return "", fmt.Errorf("HTTP remote state endpoint invalid auth")
case http.StatusConflict, http.StatusLocked:
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", &statemgr.LockError{
Info: info,
Expand Down
3 changes: 1 addition & 2 deletions internal/backend/remote-state/oss/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -585,7 +584,7 @@ func getConfigFromProfile(d *schema.ResourceData, ProfileKey string) (interface{
providerConfig = make(map[string]interface{})
_, err := os.Stat(profilePath)
if !os.IsNotExist(err) {
data, err := ioutil.ReadFile(profilePath)
data, err := os.ReadFile(profilePath)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/backend/remote/backend_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -244,7 +243,7 @@ in order to capture the filesystem context the remote workspace expects:
// We did a check earlier to make sure we either have a config dir,
// or the plan is run with -destroy. So this else clause will only
// be executed when we are destroying and doesn't need the config.
configDir, err = ioutil.TempDir("", "tf")
configDir, err = os.MkdirTemp("", "tf")
if err != nil {
return nil, generalError("Failed to create temporary directory", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/hashicorp/terraform/internal/communicator"
Expand Down Expand Up @@ -132,7 +131,7 @@ func getSrc(v cty.Value) (string, bool, error) {

switch {
case !content.IsNull():
file, err := ioutil.TempFile("", "tf-file-content")
file, err := os.CreateTemp("", "tf-file-content")
if err != nil {
return "", true, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package localexec

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -38,7 +37,7 @@ func TestResourceProvider_Apply(t *testing.T) {
}

// Check the file
raw, err := ioutil.ReadFile("test_out")
raw, err := os.ReadFile("test_out")
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -182,7 +181,7 @@ func collectScripts(v cty.Value) ([]io.ReadCloser, error) {

var r []io.ReadCloser
for _, script := range scripts {
r = append(r, ioutil.NopCloser(bytes.NewReader([]byte(script))))
r = append(r, io.NopCloser(bytes.NewReader([]byte(script))))
}

return r, nil
Expand Down
5 changes: 2 additions & 3 deletions internal/cloud/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -132,7 +131,7 @@ func testRunner(t *testing.T, cases testCases, orgCount int, tfEnvFlags ...strin
lenInput := len(tfCmd.userInput)
lenInputOutput := len(tfCmd.postInputOutput)
if lenInput > 0 {
for i := 0; i < lenInput; i++ {
for i := range lenInput {
input := tfCmd.userInput[i]
exp.SendLine(input)
// use the index to find the corresponding
Expand Down Expand Up @@ -183,7 +182,7 @@ func setTfeClient() {

func setupBinary() func() {
log.Println("Setting up terraform binary")
tmpTerraformBinaryDir, err := ioutil.TempDir("", "terraform-test")
tmpTerraformBinaryDir, err := os.MkdirTemp("", "terraform-test")
if err != nil {
fmt.Printf("Could not create temp directory: %v\n", err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions internal/cloud/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cloud
import (
"bytes"
"context"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -99,7 +99,7 @@ func TestState(t *testing.T) {

state := testCloudState(t)

jsonState, err := ioutil.ReadFile("../command/testdata/show-json-state/sensitive-variables/output.json")
jsonState, err := os.ReadFile("../command/testdata/show-json-state/sensitive-variables/output.json")
if err != nil {
t.Fatal(err)
}
Expand Down
13 changes: 6 additions & 7 deletions internal/cloud/tfe_client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -151,7 +150,7 @@ func (m *MockApplies) Logs(ctx context.Context, applyID string) (io.Reader, erro
return bytes.NewBufferString("logfile does not exist"), nil
}

logs, err := ioutil.ReadFile(logfile)
logs, err := os.ReadFile(logfile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -371,7 +370,7 @@ func (m *MockCostEstimates) Logs(ctx context.Context, costEstimateID string) (io
return bytes.NewBufferString("logfile does not exist"), nil
}

logs, err := ioutil.ReadFile(logfile)
logs, err := os.ReadFile(logfile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -663,7 +662,7 @@ func (m *MockPlans) Logs(ctx context.Context, planID string) (io.Reader, error)
return bytes.NewBufferString("logfile does not exist"), nil
}

logs, err := ioutil.ReadFile(logfile)
logs, err := os.ReadFile(logfile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -937,7 +936,7 @@ func (m *MockPolicyChecks) Read(ctx context.Context, policyCheckID string) (*tfe
return nil, fmt.Errorf("logfile does not exist")
}

logs, err := ioutil.ReadFile(logfile)
logs, err := os.ReadFile(logfile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -986,7 +985,7 @@ func (m *MockPolicyChecks) Logs(ctx context.Context, policyCheckID string) (io.R
return bytes.NewBufferString("logfile does not exist"), nil
}

logs, err := ioutil.ReadFile(logfile)
logs, err := os.ReadFile(logfile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1394,7 +1393,7 @@ func (m *MockRuns) ReadWithOptions(ctx context.Context, runID string, options *t
r.Plan.Status = tfe.PlanRunning
}

logs, _ := ioutil.ReadFile(m.client.Plans.logs[r.Plan.LogReadURL])
logs, _ := os.ReadFile(m.client.Plans.logs[r.Plan.LogReadURL])
if (r.Status == tfe.RunPlanning || r.Status == tfe.RunPlannedAndSaved) && r.Plan.Status == tfe.PlanFinished {
hasChanges := r.IsDestroy ||
bytes.Contains(logs, []byte("1 to add")) ||
Expand Down
Loading
Loading