Skip to content

Commit 49bb10d

Browse files
Preparatory cleanup work ahead of the v2 provider (#652)
* Cleanup dead code * Remove code duplication for HandleResourceNotFound * Upgrade terraform-plugin-framework * Remove claude worktree * Add claude to gitignore
1 parent afcc0b2 commit 49bb10d

56 files changed

Lines changed: 124 additions & 463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Behind the scenes
2+
body: Cleanup dead code
3+
time: 2026-04-01T09:28:50.753001+03:00

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ TODO.md
88
NOTES.md
99
.DS_Store
1010
.env
11-
/terraform-config-files
11+
/terraform-config-files
12+
.claude

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ go 1.24.8
55
require (
66
github.com/go-playground/validator/v10 v10.28.0
77
github.com/hashicorp/terraform-plugin-docs v0.19.2
8-
github.com/hashicorp/terraform-plugin-framework v1.8.0
8+
github.com/hashicorp/terraform-plugin-framework v1.13.0
99
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
10-
github.com/hashicorp/terraform-plugin-go v0.23.0
10+
github.com/hashicorp/terraform-plugin-go v0.25.0
1111
github.com/hashicorp/terraform-plugin-log v0.9.0
12-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
1312
github.com/hashicorp/terraform-plugin-testing v1.10.0
1413
github.com/oapi-codegen/nullable v1.1.0
1514
github.com/samber/lo v1.39.0
@@ -45,7 +44,7 @@ require (
4544
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
4645
github.com/hashicorp/go-hclog v1.6.3 // indirect
4746
github.com/hashicorp/go-multierror v1.1.1 // indirect
48-
github.com/hashicorp/go-plugin v1.6.0 // indirect
47+
github.com/hashicorp/go-plugin v1.6.2 // indirect
4948
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
5049
github.com/hashicorp/go-uuid v1.0.3 // indirect
5150
github.com/hashicorp/go-version v1.7.0 // indirect
@@ -54,6 +53,7 @@ require (
5453
github.com/hashicorp/logutils v1.0.0 // indirect
5554
github.com/hashicorp/terraform-exec v0.21.0 // indirect
5655
github.com/hashicorp/terraform-json v0.22.1 // indirect
56+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
5757
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
5858
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
5959
github.com/hashicorp/yamux v0.1.1 // indirect
@@ -89,9 +89,9 @@ require (
8989
golang.org/x/text v0.31.0 // indirect
9090
golang.org/x/tools v0.38.0 // indirect
9191
google.golang.org/appengine v1.6.8 // indirect
92-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
93-
google.golang.org/grpc v1.63.2 // indirect
94-
google.golang.org/protobuf v1.34.0 // indirect
92+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
93+
google.golang.org/grpc v1.67.1 // indirect
94+
google.golang.org/protobuf v1.35.1 // indirect
9595
gopkg.in/yaml.v2 v2.3.0 // indirect
9696
gopkg.in/yaml.v3 v3.0.1 // indirect
9797
)

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH
9090
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
9191
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
9292
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
93-
github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A=
94-
github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI=
93+
github.com/hashicorp/go-plugin v1.6.2 h1:zdGAEd0V1lCaU0u+MxWQhtSDQmahpkwOun8U8EiRVog=
94+
github.com/hashicorp/go-plugin v1.6.2/go.mod h1:CkgLQ5CZqNmdL9U9JzM532t8ZiYQ35+pj3b1FD37R0Q=
9595
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
9696
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
9797
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
@@ -111,12 +111,12 @@ github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7
111111
github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A=
112112
github.com/hashicorp/terraform-plugin-docs v0.19.2 h1:YjdKa1vuqt9EnPYkkrv9HnGZz175HhSJ7Vsn8yZeWus=
113113
github.com/hashicorp/terraform-plugin-docs v0.19.2/go.mod h1:gad2aP6uObFKhgNE8DR9nsEuEQnibp7il0jZYYOunWY=
114-
github.com/hashicorp/terraform-plugin-framework v1.8.0 h1:P07qy8RKLcoBkCrY2RHJer5AEvJnDuXomBgou6fD8kI=
115-
github.com/hashicorp/terraform-plugin-framework v1.8.0/go.mod h1:/CpTukO88PcL/62noU7cuyaSJ4Rsim+A/pa+3rUVufY=
114+
github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw=
115+
github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU=
116116
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
117117
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
118-
github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co=
119-
github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ=
118+
github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks=
119+
github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw=
120120
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
121121
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
122122
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE=
@@ -287,14 +287,14 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
287287
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
288288
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
289289
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
290-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
291-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
292-
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
293-
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
290+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
291+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
292+
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
293+
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
294294
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
295295
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
296-
google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4=
297-
google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
296+
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
297+
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
298298
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
299299
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
300300
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

pkg/dbt_cloud/adapter.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package dbt_cloud
22

3-
import (
4-
"encoding/json"
5-
"fmt"
6-
"net/http"
7-
"strconv"
8-
"strings"
9-
)
10-
113
type Adapter struct {
124
ID *int `json:"id,omitempty"`
135
AccountID int64 `json:"account_id"`
@@ -61,59 +53,3 @@ type AdapterCredentialFieldMetadataOptions struct {
6153
Label string `json:"label"`
6254
Value string `json:"value"`
6355
}
64-
65-
func createGenericAdapter(c *Client, newAdapter Adapter, projectID int) (*int, error) {
66-
currentUser, err := c.GetConnectedUser()
67-
if err != nil {
68-
69-
// if GetConnectedUser is the following specific error, it means that the user is using a service token
70-
// as there is no way to get the current token ID, we always use 1
71-
if strings.Contains(err.Error(), "This endpoint cannot be accessed with a service token") {
72-
73-
// we just get the first service token ID from the list
74-
allServiceTokens, err := c.GetAllServiceTokens()
75-
if err != nil {
76-
return nil, err
77-
}
78-
newAdapter.CreatedByServiceTokenID = allServiceTokens[0].ID
79-
} else {
80-
// if the error is different, return it
81-
return nil, err
82-
}
83-
} else {
84-
// if there is no error, the user is using a user token
85-
newAdapter.CreatedByID = &currentUser.ID
86-
}
87-
88-
newAdapterData, err := json.Marshal(newAdapter)
89-
if err != nil {
90-
return nil, err
91-
}
92-
93-
req, err := http.NewRequest(
94-
"POST",
95-
fmt.Sprintf(
96-
"%s/v3/accounts/%s/projects/%s/adapters/",
97-
c.HostURL,
98-
strconv.FormatInt(c.AccountID, 10),
99-
strconv.Itoa(projectID),
100-
),
101-
strings.NewReader(string(newAdapterData)),
102-
)
103-
if err != nil {
104-
return nil, err
105-
}
106-
107-
body, err := c.doRequestWithRetry(req)
108-
if err != nil {
109-
return nil, err
110-
}
111-
112-
adapterResponse := AdapterResponse{}
113-
err = json.Unmarshal(body, &adapterResponse)
114-
if err != nil {
115-
return nil, err
116-
}
117-
118-
return adapterResponse.Data.ID, nil
119-
}

pkg/framework/objects/athena_credential/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
10+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
1011
"github.com/hashicorp/terraform-plugin-framework/path"
1112
"github.com/hashicorp/terraform-plugin-framework/resource"
1213
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -138,8 +139,7 @@ func (r *athenaCredentialResource) Read(
138139

139140
credential, err := r.client.GetAthenaCredential(projectID, credentialID)
140141
if err != nil {
141-
if strings.Contains(err.Error(), "resource-not-found") {
142-
resp.State.RemoveResource(ctx)
142+
if helper.HandleResourceNotFound(ctx, err, &resp.Diagnostics, &resp.State, "athena credential") {
143143
return
144144
}
145145

pkg/framework/objects/bigquery_credential/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
10+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
1011
"github.com/hashicorp/terraform-plugin-framework/path"
1112
"github.com/hashicorp/terraform-plugin-framework/resource"
1213
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -155,8 +156,7 @@ func (r *bigqueryCredentialResource) Read(
155156

156157
credential, err := r.client.GetBigQueryCredential(projectID, credentialID)
157158
if err != nil {
158-
if strings.Contains(err.Error(), "resource-not-found") {
159-
resp.State.RemoveResource(ctx)
159+
if helper.HandleResourceNotFound(ctx, err, &resp.Diagnostics, &resp.State, "bigquery credential") {
160160
return
161161
}
162162

pkg/framework/objects/connection_catalog_config/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
10+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
1011
"github.com/hashicorp/terraform-plugin-framework/path"
1112
"github.com/hashicorp/terraform-plugin-framework/resource"
1213
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -109,8 +110,7 @@ func (r *connectionCatalogConfigResource) Read(
109110

110111
config, err := r.client.GetConnectionCatalogConfig(connectionID)
111112
if err != nil {
112-
if strings.Contains(err.Error(), "resource-not-found") {
113-
resp.State.RemoveResource(ctx)
113+
if helper.HandleResourceNotFound(ctx, err, &resp.Diagnostics, &resp.State, "connection catalog config") {
114114
return
115115
}
116116
resp.Diagnostics.AddError(

pkg/framework/objects/databricks_credential/resource_acceptance_test.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -209,55 +209,6 @@ func testAccCheckDbtCloudDatabricksCredentialDestroy(s *terraform.State) error {
209209
return nil
210210
}
211211

212-
func getBasicConfigTestStep(projectName, catalogName, targetName, token string) resource.TestStep {
213-
return resource.TestStep{
214-
Config: testAccDbtCloudDatabricksCredentialResourceBasicConfigGlobConn(
215-
projectName,
216-
catalogName,
217-
targetName,
218-
token,
219-
),
220-
Check: resource.ComposeTestCheckFunc(
221-
testAccCheckDbtCloudDatabricksCredentialExists(
222-
"dbtcloud_databricks_credential.test_credential",
223-
),
224-
resource.TestCheckResourceAttr(
225-
"dbtcloud_databricks_credential.test_credential",
226-
"target_name",
227-
targetName,
228-
),
229-
),
230-
}
231-
}
232-
233-
func getModifyConfigTestStep(projectName, catalogName, targetName, targetName2, token, token2 string) resource.TestStep {
234-
return resource.TestStep{
235-
Config: testAccDbtCloudDatabricksCredentialResourceBasicConfigGlobConn(
236-
projectName,
237-
catalogName,
238-
targetName2,
239-
token2,
240-
),
241-
Check: resource.ComposeTestCheckFunc(
242-
testAccCheckDbtCloudDatabricksCredentialExists(
243-
"dbtcloud_databricks_credential.test_credential",
244-
),
245-
resource.TestCheckResourceAttr(
246-
"dbtcloud_databricks_credential.test_credential",
247-
"target_name",
248-
targetName2,
249-
),
250-
resource.TestCheckResourceAttr(
251-
"dbtcloud_databricks_credential.test_credential",
252-
"token",
253-
token2,
254-
),
255-
),
256-
}
257-
}
258-
259-
// Mock server utilities for bug fix regression tests
260-
261212
// TestDatabricksCredential_UpdateBugRegression tests the bug fix for credential updates
262213
func TestDatabricksCredential_UpdateBugRegression(t *testing.T) {
263214
originalTFAcc := os.Getenv("TF_ACC")

pkg/framework/objects/environment_variable/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
10+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
1011
"github.com/hashicorp/terraform-plugin-framework/path"
1112
"github.com/hashicorp/terraform-plugin-framework/resource"
1213
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -142,8 +143,7 @@ func (r *environmentVariableResource) Read(
142143

143144
envVar, err := r.client.GetEnvironmentVariable(projectID, name)
144145
if err != nil {
145-
if strings.Contains(err.Error(), "resource-not-found") {
146-
resp.State.RemoveResource(ctx)
146+
if helper.HandleResourceNotFound(ctx, err, &resp.Diagnostics, &resp.State, "environment variable") {
147147
return
148148
}
149149

0 commit comments

Comments
 (0)