Skip to content

Commit

Permalink
Fix - Clean up some of the state variables
Browse files Browse the repository at this point in the history
  • Loading branch information
GtheSheep authored Feb 5, 2022
2 parents f369046 + 28b2c9e commit 296dfaa
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 43 deletions.
10 changes: 5 additions & 5 deletions examples/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ terraform {
required_providers {
dbt = {
source = "GtheSheep/dbt-cloud"
version = "0.0.40"
version = "0.0.75"
}
}
}

//provider "dbt" {
// account_id = <ACCOUNT_ID>
// token = "<TOKEN>>"
//}
provider "dbt" {
account_id = var.dbt_cloud_account_id
token = var.dbt_cloud_token
}
10 changes: 10 additions & 0 deletions examples/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
variable "dbt_cloud_account_id" {
type = number
description = "DBT Cloud Account ID"
}

variable "dbt_cloud_token" {
type = string
description = "DBT Cloud Token"
}

variable "dbt_cloud_environment_id" {
type = number
description = "DBT Cloud Environment ID"
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/aws/aws-sdk-go v1.37.0 // indirect
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
github.com/hashicorp/terraform-exec v0.15.0 // indirect
github.com/hashicorp/terraform-plugin-docs v0.5.1 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
Expand Down
13 changes: 0 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
Expand All @@ -67,7 +64,6 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0 h1:bNEQyAGak9tojivJNkoqWErVCQbj
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
Expand All @@ -77,7 +73,6 @@ 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/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
Expand Down Expand Up @@ -167,7 +162,6 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
Expand Down Expand Up @@ -213,16 +207,13 @@ github.com/hashicorp/terraform-exec v0.15.0/go.mod h1:H4IG8ZxanU+NW0ZpDRNsvh9f0u
github.com/hashicorp/terraform-json v0.12.0/go.mod h1:pmbq9o4EuL43db5+0ogX10Yofv1nozM+wskr/bGFJpI=
github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY=
github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk=
github.com/hashicorp/terraform-plugin-docs v0.5.1 h1:WwrUcamix9x0TqfTw/WGHMRqoTe1QPZKaeWJPuFb4lQ=
github.com/hashicorp/terraform-plugin-docs v0.5.1/go.mod h1:SQwEgy0/B0UPQ07rNEG1Wpt6E3jvRcCwkVHPNybGgc0=
github.com/hashicorp/terraform-plugin-go v0.3.0 h1:AJqYzP52JFYl9NABRI7smXI1pNjgR5Q/y2WyVJ/BOZA=
github.com/hashicorp/terraform-plugin-go v0.3.0/go.mod h1:dFHsQMaTLpON2gWhVWT96fvtlc/MF1vSy3OdMhWBzdM=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1 h1:vpzKKP2dIFb9n89AG8Wxl758/5JSZWZH0OuKdlq0M38=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1/go.mod h1:o3pdss6ynDZW9FfiZ+rETUH5LEVufrXdhwLU+5OiRo0=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down Expand Up @@ -271,7 +262,6 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw=
github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
Expand Down Expand Up @@ -301,12 +291,9 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbt_cloud/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func (c *Client) GetConnection(connectionID, projectID string) (*Connection, err
}

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) {
state := 1
state := STATE_ACTIVE
if !isActive {
state = 2
state = STATE_DELETED
}

connectionDetails := ConnectionDetails{
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbt_cloud/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (c *Client) GetEnvironment(projectId int, environmentId int) (*Environment,
}

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

newEnvironment := Environment{
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbt_cloud/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func (c *Client) GetJob(jobID string) (*Job, error) {
}

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) {
state := 1
state := STATE_ACTIVE
if !isActive {
state = 2
state = STATE_DELETED
}
github_webhook, gw_found := triggers["github_webhook"]
if !gw_found {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dbt_cloud/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Client) GetProject(projectID string) (*Project, error) {
func (c *Client) CreateProject(name string, dbtProjectSubdirectory string, connectionID int, repositoryID int) (*Project, error) {
newProject := Project{
Name: name,
State: 1,
State: STATE_ACTIVE,
AccountID: c.AccountID,
}
if dbtProjectSubdirectory != "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/dbt_cloud/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func (c *Client) GetRepository(repositoryID, projectID string) (*Repository, err
}

func (c *Client) CreateRepository(projectID int, remoteUrl string, isActive bool) (*Repository, error) {
state := 1
state := STATE_ACTIVE
if !isActive {
state = 2
state = STATE_DELETED
}

newRepository := Repository{
Expand Down
2 changes: 1 addition & 1 deletion pkg/dbt_cloud/snowflake_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *Client) CreateSnowflakeCredential(projectId int, type_ string, isActive
Account_Id: c.AccountID,
Project_Id: projectId,
Type: type_,
State: 1, // TODO: make variable
State: STATE_ACTIVE, // TODO: make variable
Schema: schema,
User: user,
Password: password,
Expand Down
5 changes: 1 addition & 4 deletions pkg/resources/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const CONNECTION_STATE_ACTIVE = 1
const CONNECTION_STATE_DELETED = 2

var (
connectionTypes = []string{
"snowflake",
Expand Down Expand Up @@ -132,7 +129,7 @@ func resourceConnectionRead(ctx context.Context, d *schema.ResourceData, m inter
return diag.FromErr(err)
}

if err := d.Set("is_active", connection.State == CONNECTION_STATE_ACTIVE); err != nil {
if err := d.Set("is_active", connection.State == dbt_cloud.STATE_ACTIVE); err != nil {
return diag.FromErr(err)
}
if err := d.Set("project_id", connection.ProjectID); err != nil {
Expand Down
5 changes: 1 addition & 4 deletions pkg/resources/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const ENVIRONMENT_STATE_ACTIVE = 1
const ENVIRONMENT_STATE_DELETED = 2

func ResourceEnvironment() *schema.Resource {
return &schema.Resource{
CreateContext: resourceEnvironmentCreate,
Expand Down Expand Up @@ -136,7 +133,7 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, m inte
return diag.FromErr(err)
}

if err := d.Set("is_active", environment.State == ENVIRONMENT_STATE_ACTIVE); err != nil {
if err := d.Set("is_active", environment.State == dbt_cloud.STATE_ACTIVE); err != nil {
return diag.FromErr(err)
}
if err := d.Set("project_id", environment.Project_Id); err != nil {
Expand Down
9 changes: 3 additions & 6 deletions pkg/resources/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const REPOSITORY_STATE_ACTIVE = 1
const REPOSITORY_STATE_DELETED = 2

func ResourceRepository() *schema.Resource {
return &schema.Resource{
CreateContext: resourceRepositoryCreate,
Expand Down Expand Up @@ -79,7 +76,7 @@ func resourceRepositoryRead(ctx context.Context, d *schema.ResourceData, m inter
return diag.FromErr(err)
}

if err := d.Set("is_active", repository.State == REPOSITORY_STATE_ACTIVE); err != nil {
if err := d.Set("is_active", repository.State == dbt_cloud.STATE_ACTIVE); err != nil {
return diag.FromErr(err)
}
if err := d.Set("project_id", repository.ProjectID); err != nil {
Expand Down Expand Up @@ -113,9 +110,9 @@ func resourceRepositoryUpdate(ctx context.Context, d *schema.ResourceData, m int
if d.HasChange("is_active") {
isActive := d.Get("is_active").(bool)
if isActive {
repository.State = REPOSITORY_STATE_ACTIVE
repository.State = dbt_cloud.STATE_ACTIVE
} else {
repository.State = REPOSITORY_STATE_DELETED
repository.State = dbt_cloud.STATE_DELETED
}
}

Expand Down

0 comments on commit 296dfaa

Please sign in to comment.