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
2 changes: 1 addition & 1 deletion .github/actions/lint-go-tfe/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/0b5709648c8ba9780e821faf16c5c2bb3262ce3e/install.sh | sh -s -- -b $(go env GOPATH)/bin $GOLANGCILINT_VERSION
shell: bash
env:
GOLANGCILINT_VERSION: v1.52.2
GOLANGCILINT_VERSION: v1.64.8

- run: make lint
shell: bash
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ linters:
# - noctx #https://github.com/sonatard/noctx
- nilerr #https://github.com/gostaticanalysis/nilerr
- nestif #https://github.com/nakabonne/nestif
- exportloopref #https://github.com/kyoh86/exportloopref
- copyloopvar #https://github.com/karamaru-alpha/copyloopvar
- bodyclose #https://github.com/timakin/bodyclose
- goconst #https://github.com/jgautheron/goconst
- gofmt
Expand Down Expand Up @@ -55,7 +55,6 @@ linters-settings:
- hugeParam
- singleCaseSwitch
- ifElseChain
- sloppyTestFuncName
revive:
# see https://github.com/mgechev/revive#available-rules for details.
ignore-generated-header: false #recommended in their configuration
Expand Down
5 changes: 4 additions & 1 deletion configuration_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ func TestConfigurationVersionsReadWithOptions(t *testing.T) {

require.NoError(t, err)

cv := w.(*Workspace).CurrentRun.ConfigurationVersion
ws, ok := w.(*Workspace)
require.True(t, ok, "Expected Workspace, got %T", w)

cv := ws.CurrentRun.ConfigurationVersion

t.Run("when the configuration version exists", func(t *testing.T) {
options := &ConfigurationVersionReadOptions{
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
module github.com/hashicorp/go-tfe

go 1.19
go 1.24

require (
github.com/google/go-querystring v1.1.0
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hashicorp/go-slug v0.16.4
github.com/hashicorp/go-retryablehttp v0.7.8
github.com/hashicorp/go-slug v0.16.7
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/jsonapi v1.4.3-0.20250220162346-81a76b606f3e
github.com/stretchr/testify v1.10.0
go.uber.org/mock v0.4.0
golang.org/x/sync v0.10.0
golang.org/x/time v0.10.0
go.uber.org/mock v0.6.0
golang.org/x/sync v0.16.0
golang.org/x/time v0.12.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/sys v0.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 17 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-slug v0.16.4 h1:kI0mOUVjbBsyocwO29pZIQzzkBnfQNdU4eqlUpNdNVA=
github.com/hashicorp/go-slug v0.16.4/go.mod h1:THWVTAXwJEinbsp4/bBRcmbaO5EYNLTqxbG4tZ3gCYQ=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
github.com/hashicorp/go-slug v0.16.7 h1:sBW8y1sX+JKOZKu9a+DQZuWDVaX+U9KFnk6+VDQvKcw=
github.com/hashicorp/go-slug v0.16.7/go.mod h1:X5fm++dL59cDOX8j48CqHr4KARTQau7isGh0ZVxJB5I=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/jsonapi v1.4.3-0.20250220162346-81a76b606f3e h1:xwy/1T0cxHWaLx2MM0g4BlaQc1BXn/9835mPrBqwSPU=
github.com/hashicorp/jsonapi v1.4.3-0.20250220162346-81a76b606f3e/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/time v0.10.0 h1:3usCWA8tQn0L8+hFJQNgzpWbd89begxN66o1Ojdn5L4=
golang.org/x/time v0.10.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 2 additions & 2 deletions helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,9 +1281,9 @@ func applyableStatuses(r *Run) []RunStatus {
}
} else if r.CostEstimate != nil {
return []RunStatus{RunCostEstimated}
} else {
return []RunStatus{RunPlanned}
}

return []RunStatus{RunPlanned}
}

// pollRunStatus will poll the given run until its status matches one of the given run statuses or the given context
Expand Down
11 changes: 6 additions & 5 deletions internal_run_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ func (irt internalRunTask) ToRunTask() *RunTask {
}
obj.WorkspaceRunTasks = workspaceTasks

var boolVal bool
// Check if the global configuration exists
if val, ok := irt.RawGlobal["enabled"]; !ok {
// The enabled property is required so we can assume now that the
// global configuration was not supplied
return &obj
} else if boolVal, ok := val.(bool); !ok {
} else if boolVal, ok = val.(bool); !ok {
// The enabled property exists but it is invalid (Couldn't cast to boolean)
// so assume the global configuration was not supplied
return &obj
} else {
obj.Global = &GlobalRunTask{
Enabled: boolVal,
}
}

obj.Global = &GlobalRunTask{
Enabled: boolVal,
}

// Global Enforcement Level
Expand Down
1 change: 0 additions & 1 deletion notification_configuration_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func TestNotificationConfigurationsCreate_byType(t *testing.T) {
}

for _, trigger := range testCases {
trigger := trigger
message := fmt.Sprintf("with trigger %s and all required values", trigger)

t.Run(message, func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions organization_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *organizationTags) AddWorkspaces(ctx context.Context, tag string, option
}

func (opts *OrganizationTagsDeleteOptions) valid() error {
if opts.IDs == nil || len(opts.IDs) == 0 {
if len(opts.IDs) == 0 {
return ErrRequiredTagID
}

Expand All @@ -166,7 +166,7 @@ func (opts *OrganizationTagsDeleteOptions) valid() error {
}

func (w *AddWorkspacesToTagOptions) valid() error {
if w.WorkspaceIDs == nil || len(w.WorkspaceIDs) == 0 {
if len(w.WorkspaceIDs) == 0 {
return ErrRequiredTagWorkspaceID
}

Expand Down
10 changes: 8 additions & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func (r ClientRequest) Do(ctx context.Context, model interface{}) error {

// If the caller provided a response header hook then we'll call it
// once we have a response.
respHeaderHook := contextResponseHeaderHook(ctx)
respHeaderHook, err := contextResponseHeaderHook(ctx)
if err != nil {
return err
}

// Add the context to the request.
reqWithCxt := r.retryableRequest.WithContext(ctx)
Expand Down Expand Up @@ -94,7 +97,10 @@ func (r *ClientRequest) DoJSON(ctx context.Context, model any) error {

// If the caller provided a response header hook then we'll call it
// once we have a response.
respHeaderHook := contextResponseHeaderHook(ctx)
respHeaderHook, err := contextResponseHeaderHook(ctx)
if err != nil {
return err
}

// Execute the request and check the response.
resp, err := r.http.Do(contextReq)
Expand Down
12 changes: 9 additions & 3 deletions request_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ func ContextWithResponseHeaderHook(parentCtx context.Context, cb func(status int
return context.WithValue(parentCtx, contextResponseHeaderHookKey, finalCb)
}

func contextResponseHeaderHook(ctx context.Context) func(int, http.Header) {
func contextResponseHeaderHook(ctx context.Context) (func(int, http.Header), error) {
cbI := ctx.Value(contextResponseHeaderHookKey)
if cbI == nil {
// Stub callback that does absolutely nothing, then.
return func(int, http.Header) {}
return func(int, http.Header) {}, nil
}
return cbI.(func(int, http.Header))

cb, ok := cbI.(func(int, http.Header))
if !ok {
return nil, fmt.Errorf("context has response header hook of invalid type %T", cbI)
}

return cb, nil
}

// contextResponseHeaderHookKey is the type of the internal key used to store
Expand Down
5 changes: 4 additions & 1 deletion run_tasks_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ func TestTaskResultsCallbackRequestOptions_Marshal(t *testing.T) {
require.NoError(t, err)
expectedBody := `{"data":{"type":"task-results","attributes":{"message":"4 passed, 0 skipped, 0 failed","status":"passed","url":"https://external.service.dev/terraform-plan-checker/run-i3Df5to9ELvibKpQ"},"relationships":{"outcomes":{"data":[{"type":"task-result-outcomes","attributes":{"body":"# Resolution for issue ST-2942\n\n## Impact\n\nFollow instructions in the [AWS S3 docs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/MultiFactorAuthenticationDelete.html) to manually configure the MFA setting.\n—-- Payload truncated —--","description":"ST-2942:S3 Bucket will not enforce MFA login on delete requests","outcome-id":"PRTNR-CC-TF-127","tags":{"Cost Centre":[{"label":"IT-OPS"}],"Severity":[{"label":"High","level":"error"},{"label":"Recoverable","level":"info"}],"Status":[{"label":"Denied","level":"error"}]},"url":"https://external.service.dev/result/PRTNR-CC-TF-127"}}]}}}}
`
assert.Equal(t, reqBody.(*bytes.Buffer).String(), expectedBody)
buf, ok := reqBody.(*bytes.Buffer)
require.True(t, ok, "expected request body to be a bytes.Buffer")

assert.Equal(t, buf.String(), expectedBody)
}

func TestRunTasksIntegration_ValidateCallback(t *testing.T) {
Expand Down
35 changes: 28 additions & 7 deletions state_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,15 +606,36 @@ func TestStateVersionOutputs(t *testing.T) {
values[op.Name] = op.Value
}

testOutputString, ok := values["test_output_string"].(string)
require.True(t, ok)

testOutputNumber, ok := values["test_output_number"].(float64)
require.True(t, ok)

testOutputBool, ok := values["test_output_bool"].(bool)
require.True(t, ok)

testOutputListString, ok := values["test_output_list_string"].([]interface{})
require.True(t, ok)

testOutputTupleNumber, ok := values["test_output_tuple_number"].([]interface{})
require.True(t, ok)

testOutputTupleString, ok := values["test_output_tuple_string"].([]interface{})
require.True(t, ok)

testOutputObject, ok := values["test_output_object"].(map[string]interface{})
require.True(t, ok)

// These asserts are based off of the values in
// test-fixtures/state-version/terraform.tfstate
assert.Equal(t, "9023256633839603543", values["test_output_string"].(string))
assert.Equal(t, float64(5), values["test_output_number"].(float64))
assert.Equal(t, true, values["test_output_bool"].(bool))
assert.Equal(t, []interface{}{"us-west-1a"}, values["test_output_list_string"].([]interface{}))
assert.Equal(t, []interface{}{float64(1), float64(2)}, values["test_output_tuple_number"].([]interface{}))
assert.Equal(t, []interface{}{"one", "two"}, values["test_output_tuple_string"].([]interface{}))
assert.Equal(t, map[string]interface{}{"foo": "bar"}, values["test_output_object"].(map[string]interface{}))
assert.Equal(t, "9023256633839603543", testOutputString)
assert.Equal(t, float64(5), testOutputNumber)
assert.Equal(t, true, testOutputBool)
assert.Equal(t, []interface{}{"us-west-1a"}, testOutputListString)
assert.Equal(t, []interface{}{float64(1), float64(2)}, testOutputTupleNumber)
assert.Equal(t, []interface{}{"one", "two"}, testOutputTupleString)
assert.Equal(t, map[string]interface{}{"foo": "bar"}, testOutputObject)
})

t.Run("with list options", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions team_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *teamMembers) Remove(ctx context.Context, teamID string, options TeamMem
// kind returns "users" or "organization-memberships"
// depending on which is defined
func (o *TeamMemberAddOptions) kind() string {
if o.Usernames != nil && len(o.Usernames) != 0 {
if len(o.Usernames) != 0 {
return "users"
}
return "organization-memberships"
Expand All @@ -212,7 +212,7 @@ func (o *TeamMemberAddOptions) kind() string {
// kind returns "users" or "organization-memberships"
// depending on which is defined
func (o *TeamMemberRemoveOptions) kind() string {
if o.Usernames != nil && len(o.Usernames) != 0 {
if len(o.Usernames) != 0 {
return "users"
}
return "organization-memberships"
Expand Down
Loading