Skip to content

Commit 296dfaa

Browse files
authored
Fix - Clean up some of the state variables
2 parents f369046 + 28b2c9e commit 296dfaa

13 files changed

+30
-43
lines changed

examples/providers.tf

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ terraform {
22
required_providers {
33
dbt = {
44
source = "GtheSheep/dbt-cloud"
5-
version = "0.0.40"
5+
version = "0.0.75"
66
}
77
}
88
}
99

10-
//provider "dbt" {
11-
// account_id = <ACCOUNT_ID>
12-
// token = "<TOKEN>>"
13-
//}
10+
provider "dbt" {
11+
account_id = var.dbt_cloud_account_id
12+
token = var.dbt_cloud_token
13+
}

examples/variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
variable "dbt_cloud_account_id" {
2+
type = number
3+
description = "DBT Cloud Account ID"
4+
}
5+
6+
variable "dbt_cloud_token" {
7+
type = string
8+
description = "DBT Cloud Token"
9+
}
10+
111
variable "dbt_cloud_environment_id" {
212
type = number
313
description = "DBT Cloud Environment ID"

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/aws/aws-sdk-go v1.37.0 // indirect
88
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
99
github.com/hashicorp/terraform-exec v0.15.0 // indirect
10-
github.com/hashicorp/terraform-plugin-docs v0.5.1 // indirect
1110
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1
1211
github.com/mattn/go-colorable v0.1.11 // indirect
1312
github.com/zclconf/go-cty v1.10.0 // indirect

go.sum

-13
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3636
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3737
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3838
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
39-
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
4039
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
41-
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
4240
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
43-
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
4441
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
4542
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
4643
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
@@ -67,7 +64,6 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0 h1:bNEQyAGak9tojivJNkoqWErVCQbj
6764
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
6865
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
6966
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
70-
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=
7167
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
7268
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
7369
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
@@ -77,7 +73,6 @@ github.com/aws/aws-sdk-go v1.37.0 h1:GzFnhOIsrGyQ69s7VgqtrG2BG8v7X7vwB3Xpbd/DBBk
7773
github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
7874
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
7975
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
80-
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
8176
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
8277
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
8378
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
@@ -167,7 +162,6 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
167162
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
168163
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
169164
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
170-
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
171165
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
172166
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
173167
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
@@ -213,16 +207,13 @@ github.com/hashicorp/terraform-exec v0.15.0/go.mod h1:H4IG8ZxanU+NW0ZpDRNsvh9f0u
213207
github.com/hashicorp/terraform-json v0.12.0/go.mod h1:pmbq9o4EuL43db5+0ogX10Yofv1nozM+wskr/bGFJpI=
214208
github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY=
215209
github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk=
216-
github.com/hashicorp/terraform-plugin-docs v0.5.1 h1:WwrUcamix9x0TqfTw/WGHMRqoTe1QPZKaeWJPuFb4lQ=
217-
github.com/hashicorp/terraform-plugin-docs v0.5.1/go.mod h1:SQwEgy0/B0UPQ07rNEG1Wpt6E3jvRcCwkVHPNybGgc0=
218210
github.com/hashicorp/terraform-plugin-go v0.3.0 h1:AJqYzP52JFYl9NABRI7smXI1pNjgR5Q/y2WyVJ/BOZA=
219211
github.com/hashicorp/terraform-plugin-go v0.3.0/go.mod h1:dFHsQMaTLpON2gWhVWT96fvtlc/MF1vSy3OdMhWBzdM=
220212
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1 h1:vpzKKP2dIFb9n89AG8Wxl758/5JSZWZH0OuKdlq0M38=
221213
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1/go.mod h1:o3pdss6ynDZW9FfiZ+rETUH5LEVufrXdhwLU+5OiRo0=
222214
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
223215
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
224216
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
225-
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
226217
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
227218
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
228219
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
@@ -271,7 +262,6 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
271262
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
272263
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
273264
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
274-
github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw=
275265
github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4=
276266
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
277267
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
@@ -301,12 +291,9 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
301291
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
302292
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
303293
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
304-
github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w=
305294
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
306295
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
307296
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
308-
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
309-
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
310297
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
311298
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
312299
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=

pkg/dbt_cloud/connection.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ func (c *Client) GetConnection(connectionID, projectID string) (*Connection, err
6262
}
6363

6464
func (c *Client) CreateConnection(projectID int, name string, connectionType string, isActive bool, account string, database string, warehouse string, role string, allowSSO bool, clientSessionKeepAlive bool) (*Connection, error) {
65-
state := 1
65+
state := STATE_ACTIVE
6666
if !isActive {
67-
state = 2
67+
state = STATE_DELETED
6868
}
6969

7070
connectionDetails := ConnectionDetails{

pkg/dbt_cloud/environment.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func (c *Client) GetEnvironment(projectId int, environmentId int) (*Environment,
5555
}
5656

5757
func (c *Client) CreateEnvironment(isActive bool, projectId int, name string, dbtVersion string, type_ string, useCustomBranch bool, customBranch string, credentialId int) (*Environment, error) {
58-
state := 1
58+
state := STATE_ACTIVE
5959
if !isActive {
60-
state = 2
60+
state = STATE_DELETED
6161
}
6262

6363
newEnvironment := Environment{

pkg/dbt_cloud/job.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ func (c *Client) GetJob(jobID string) (*Job, error) {
8080
}
8181

8282
func (c *Client) CreateJob(projectId int, environmentId int, name string, executeSteps []string, dbtVersion string, isActive bool, triggers map[string]interface{}, numThreads int, targetName string, generateDocs bool, runGenerateSources bool, scheduleType string, scheduleInterval int, scheduleHours []int, scheduleDays []int, scheduleCron string) (*Job, error) {
83-
state := 1
83+
state := STATE_ACTIVE
8484
if !isActive {
85-
state = 2
85+
state = STATE_DELETED
8686
}
8787
github_webhook, gw_found := triggers["github_webhook"]
8888
if !gw_found {

pkg/dbt_cloud/project.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (c *Client) GetProject(projectID string) (*Project, error) {
5252
func (c *Client) CreateProject(name string, dbtProjectSubdirectory string, connectionID int, repositoryID int) (*Project, error) {
5353
newProject := Project{
5454
Name: name,
55-
State: 1,
55+
State: STATE_ACTIVE,
5656
AccountID: c.AccountID,
5757
}
5858
if dbtProjectSubdirectory != "" {

pkg/dbt_cloud/repository.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ func (c *Client) GetRepository(repositoryID, projectID string) (*Repository, err
4747
}
4848

4949
func (c *Client) CreateRepository(projectID int, remoteUrl string, isActive bool) (*Repository, error) {
50-
state := 1
50+
state := STATE_ACTIVE
5151
if !isActive {
52-
state = 2
52+
state = STATE_DELETED
5353
}
5454

5555
newRepository := Repository{

pkg/dbt_cloud/snowflake_credential.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (c *Client) CreateSnowflakeCredential(projectId int, type_ string, isActive
6161
Account_Id: c.AccountID,
6262
Project_Id: projectId,
6363
Type: type_,
64-
State: 1, // TODO: make variable
64+
State: STATE_ACTIVE, // TODO: make variable
6565
Schema: schema,
6666
User: user,
6767
Password: password,

pkg/resources/connection.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1212
)
1313

14-
const CONNECTION_STATE_ACTIVE = 1
15-
const CONNECTION_STATE_DELETED = 2
16-
1714
var (
1815
connectionTypes = []string{
1916
"snowflake",
@@ -132,7 +129,7 @@ func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, m inter
132129
return diag.FromErr(err)
133130
}
134131

135-
if err := d.Set("is_active", connection.State == CONNECTION_STATE_ACTIVE); err != nil {
132+
if err := d.Set("is_active", connection.State == dbt_cloud.STATE_ACTIVE); err != nil {
136133
return diag.FromErr(err)
137134
}
138135
if err := d.Set("project_id", connection.ProjectID); err != nil {

pkg/resources/environment.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212
)
1313

14-
const ENVIRONMENT_STATE_ACTIVE = 1
15-
const ENVIRONMENT_STATE_DELETED = 2
16-
1714
func ResourceEnvironment() *schema.Resource {
1815
return &schema.Resource{
1916
CreateContext: resourceEnvironmentCreate,
@@ -136,7 +133,7 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, m inte
136133
return diag.FromErr(err)
137134
}
138135

139-
if err := d.Set("is_active", environment.State == ENVIRONMENT_STATE_ACTIVE); err != nil {
136+
if err := d.Set("is_active", environment.State == dbt_cloud.STATE_ACTIVE); err != nil {
140137
return diag.FromErr(err)
141138
}
142139
if err := d.Set("project_id", environment.Project_Id); err != nil {

pkg/resources/repository.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
)
1212

13-
const REPOSITORY_STATE_ACTIVE = 1
14-
const REPOSITORY_STATE_DELETED = 2
15-
1613
func ResourceRepository() *schema.Resource {
1714
return &schema.Resource{
1815
CreateContext: resourceRepositoryCreate,
@@ -79,7 +76,7 @@ func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, m inter
7976
return diag.FromErr(err)
8077
}
8178

82-
if err := d.Set("is_active", repository.State == REPOSITORY_STATE_ACTIVE); err != nil {
79+
if err := d.Set("is_active", repository.State == dbt_cloud.STATE_ACTIVE); err != nil {
8380
return diag.FromErr(err)
8481
}
8582
if err := d.Set("project_id", repository.ProjectID); err != nil {
@@ -113,9 +110,9 @@ func resourceRepositoryUpdate(ctx context.Context, d *schema.ResourceData, m int
113110
if d.HasChange("is_active") {
114111
isActive := d.Get("is_active").(bool)
115112
if isActive {
116-
repository.State = REPOSITORY_STATE_ACTIVE
113+
repository.State = dbt_cloud.STATE_ACTIVE
117114
} else {
118-
repository.State = REPOSITORY_STATE_DELETED
115+
repository.State = dbt_cloud.STATE_DELETED
119116
}
120117
}
121118

0 commit comments

Comments
 (0)