From 034a8788fb38ef6bdd2256f12254b438e58c6781 Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:41:42 +0100 Subject: [PATCH 1/5] Change to the data source instead of non existing resource --- docs/resources/user_groups.md | 2 +- examples/resources/dbtcloud_user_groups/resource.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/user_groups.md b/docs/resources/user_groups.md index 26c06e66..5a40ac20 100644 --- a/docs/resources/user_groups.md +++ b/docs/resources/user_groups.md @@ -25,7 +25,7 @@ If you would like a different behavior, please open an issue on GitHub. To remov ```terraform // we can assign groups to users resource "dbtcloud_user_groups" "my_user_groups" { - user_id = dbtcloud_user.my_user.id + user_id = data.dbtcloud_user.my_user.id group_ids = [ // the group_id can be written directly 1234, diff --git a/examples/resources/dbtcloud_user_groups/resource.tf b/examples/resources/dbtcloud_user_groups/resource.tf index 764f43bb..3486de05 100644 --- a/examples/resources/dbtcloud_user_groups/resource.tf +++ b/examples/resources/dbtcloud_user_groups/resource.tf @@ -1,6 +1,6 @@ // we can assign groups to users resource "dbtcloud_user_groups" "my_user_groups" { - user_id = dbtcloud_user.my_user.id + user_id = data.dbtcloud_user.my_user.id group_ids = [ // the group_id can be written directly 1234, From 4657c8d20583d956ff4d9c222a5f5dec7ba8e1b0 Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:42:08 +0100 Subject: [PATCH 2/5] Update modules version --- go.mod | 6 +++--- go.sum | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 0bb63f0e..75997d41 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect - github.com/cloudflare/circl v1.3.3 // indirect + github.com/cloudflare/circl v1.3.7 // indirect github.com/fatih/color v1.13.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect @@ -59,11 +59,11 @@ require ( github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.14.1 // indirect - golang.org/x/crypto v0.15.0 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.13.0 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sys v0.14.0 // indirect + golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect diff --git a/go.sum b/go.sum index 7456136d..7f4eecfe 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,9 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= -github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -202,8 +203,8 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= -golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -240,15 +241,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= -golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= From a25ccba88f0e543f34fd5c95481b51ab43d6e395 Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:42:21 +0100 Subject: [PATCH 3/5] Fix secret env variables --- docs/resources/environment_variable.md | 2 +- pkg/resources/environment_variable.go | 22 ++-- .../environment_variable_acceptance_test.go | 115 +++++++++++++++--- 3 files changed, 115 insertions(+), 24 deletions(-) diff --git a/docs/resources/environment_variable.md b/docs/resources/environment_variable.md index 9baa306a..3626b4fb 100644 --- a/docs/resources/environment_variable.md +++ b/docs/resources/environment_variable.md @@ -40,7 +40,7 @@ resource "dbtcloud_environment_variable" "dbt_my_env_var" { ### Required -- `environment_values` (Map of String) Map from environment names to respective variable value, a special key `project` should be set for the project default variable value +- `environment_values` (Map of String) Map from environment names to respective variable value, a special key `project` should be set for the project default variable value. This field is not set as sensitive so take precautions when using secret environment variables. - `name` (String) Name for the variable, must be unique within a project, must be prefixed with 'DBT_' - `project_id` (Number) Project for the variable to be created in diff --git a/pkg/resources/environment_variable.go b/pkg/resources/environment_variable.go index d79e66a9..f5e55c71 100644 --- a/pkg/resources/environment_variable.go +++ b/pkg/resources/environment_variable.go @@ -26,15 +26,17 @@ func ResourceEnvironmentVariable() *schema.Resource { Description: "Project for the variable to be created in", }, "name": &schema.Schema{ - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + // as the name is used as the ID, we need to force a new resource if the name changes + ForceNew: true, Description: "Name for the variable, must be unique within a project, must be prefixed with 'DBT_'", ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { v := val.(string) if !(strings.HasPrefix(v, "DBT_")) { errs = append( errs, - fmt.Errorf("%q must be between 0 and 10 inclusive, got: %s", key, v), + fmt.Errorf("The env var must start with DBT_ , got: %s", v), ) } return @@ -43,7 +45,7 @@ func ResourceEnvironmentVariable() *schema.Resource { "environment_values": &schema.Schema{ Type: schema.TypeMap, Required: true, - Description: "Map from environment names to respective variable value, a special key `project` should be set for the project default variable value", + Description: "Map from environment names to respective variable value, a special key `project` should be set for the project default variable value. This field is not set as sensitive so take precautions when using secret environment variables.", }, }, @@ -137,15 +139,21 @@ func resourceEnvironmentVariableRead( } return diag.FromErr(err) } - if err := d.Set("project_id", environmentVariable.ProjectID); err != nil { return diag.FromErr(err) } if err := d.Set("name", environmentVariable.Name); err != nil { return diag.FromErr(err) } - if err := d.Set("environment_values", environmentVariable.EnvironmentNameValues); err != nil { - return diag.FromErr(err) + + if !strings.HasPrefix(environmentVariable.Name, "DBT_ENV_SECRET_") { + if err := d.Set("environment_values", environmentVariable.EnvironmentNameValues); err != nil { + return diag.FromErr(err) + } + } else { + if err := d.Set("environment_values", d.Get("environment_values")); err != nil { + return diag.FromErr(err) + } } return diags diff --git a/pkg/resources/environment_variable_acceptance_test.go b/pkg/resources/environment_variable_acceptance_test.go index ac4cb9c1..49b0de53 100644 --- a/pkg/resources/environment_variable_acceptance_test.go +++ b/pkg/resources/environment_variable_acceptance_test.go @@ -17,33 +17,112 @@ func TestAccDbtCloudEnvironmentVariableResource(t *testing.T) { environmentName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) projectName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) - environmentVariableName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)) + environmentVariableName := strings.ToUpper( + acctest.RandStringFromCharSet(10, acctest.CharSetAlpha), + ) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckDbtCloudEnvironmentVariableDestroy, Steps: []resource.TestStep{ + // SECRET ENV VAR { - Config: testAccDbtCloudEnvironmentVariableResourceBasicConfig(projectName, environmentName, environmentVariableName), + Config: testAccDbtCloudEnvironmentVariableResourceBasicConfig( + projectName, + environmentName, + fmt.Sprintf("ENV_SECRET_%s", environmentVariableName), + ), Check: resource.ComposeTestCheckFunc( - testAccCheckDbtCloudEnvironmentVariableExists("dbtcloud_environment_variable.test_env_var"), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", "name", fmt.Sprintf("DBT_%s", environmentVariableName)), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", "environment_values.%", "2"), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", "environment_values.project", "Baa"), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", fmt.Sprintf("environment_values.%s", environmentName), "Moo"), + testAccCheckDbtCloudEnvironmentVariableExists( + "dbtcloud_environment_variable.test_env_var", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "name", + fmt.Sprintf("DBT_ENV_SECRET_%s", environmentVariableName), + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "environment_values.%", + "2", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "environment_values.project", + "Baa", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + fmt.Sprintf("environment_values.%s", environmentName), + "Moo", + ), + ), + }, + // NON SECRET ENV VAR + { + Config: testAccDbtCloudEnvironmentVariableResourceBasicConfig( + projectName, + environmentName, + environmentVariableName, + ), + Check: resource.ComposeTestCheckFunc( + testAccCheckDbtCloudEnvironmentVariableExists( + "dbtcloud_environment_variable.test_env_var", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "name", + fmt.Sprintf("DBT_%s", environmentVariableName), + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "environment_values.%", + "2", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "environment_values.project", + "Baa", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + fmt.Sprintf("environment_values.%s", environmentName), + "Moo", + ), ), }, - // RENAME // MODIFY { - Config: testAccDbtCloudEnvironmentVariableResourceModifiedConfig(projectName, environmentName, environmentVariableName), + Config: testAccDbtCloudEnvironmentVariableResourceModifiedConfig( + projectName, + environmentName, + environmentVariableName, + ), Check: resource.ComposeTestCheckFunc( - testAccCheckDbtCloudEnvironmentVariableExists("dbtcloud_environment_variable.test_env_var"), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", "name", fmt.Sprintf("DBT_%s", environmentVariableName)), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", "environment_values.%", "2"), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", "environment_values.project", "Oink"), - resource.TestCheckResourceAttr("dbtcloud_environment_variable.test_env_var", fmt.Sprintf("environment_values.%s", environmentName), "Neigh"), + testAccCheckDbtCloudEnvironmentVariableExists( + "dbtcloud_environment_variable.test_env_var", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "name", + fmt.Sprintf("DBT_%s", environmentVariableName), + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "environment_values.%", + "2", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + "environment_values.project", + "Oink", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment_variable.test_env_var", + fmt.Sprintf("environment_values.%s", environmentName), + "Neigh", + ), ), }, // IMPORT @@ -57,7 +136,9 @@ func TestAccDbtCloudEnvironmentVariableResource(t *testing.T) { }) } -func testAccDbtCloudEnvironmentVariableResourceBasicConfig(projectName, environmentName, environmentVariableName string) string { +func testAccDbtCloudEnvironmentVariableResourceBasicConfig( + projectName, environmentName, environmentVariableName string, +) string { return fmt.Sprintf(` resource "dbtcloud_project" "test_project" { name = "%s" @@ -85,7 +166,9 @@ resource "dbtcloud_environment_variable" "test_env_var" { `, projectName, environmentName, DBT_CLOUD_VERSION, environmentVariableName, environmentName) } -func testAccDbtCloudEnvironmentVariableResourceModifiedConfig(projectName, environmentName, environmentVariableName string) string { +func testAccDbtCloudEnvironmentVariableResourceModifiedConfig( + projectName, environmentName, environmentVariableName string, +) string { return fmt.Sprintf(` resource "dbtcloud_project" "test_project" { name = "%s" From 1f82a80ab348bad34514276c7b29a00e932b37e7 Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:42:37 +0100 Subject: [PATCH 4/5] New release! --- CHANGELOG.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9687df67..0dce732e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,21 @@ All notable changes to this project will be documented in this file. -## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.17...HEAD) +## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.18...HEAD) + +## [0.2.18](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.17...v0.2.18) + +## Changes + +- #229 - fix logic for secret environment variables + +## Documentations + +- #228 - update docs to replace the non existing `dbtcloud_user` resource by the existing `data.dbtcloud_user` data source + +## Behind the scenes + +- update third party module version following security report ## [0.2.17](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.16...v0.2.17) From 3730fae692c6a77cf11e1a127d0a58467f644e4a Mon Sep 17 00:00:00 2001 From: Benoit Perigaud <8754100+b-per@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:16:13 +0100 Subject: [PATCH 5/5] Update test following API change --- pkg/resources/environment_acceptance_test.go | 106 +++++++++++++++---- 1 file changed, 88 insertions(+), 18 deletions(-) diff --git a/pkg/resources/environment_acceptance_test.go b/pkg/resources/environment_acceptance_test.go index 00173a40..96fc6eb1 100644 --- a/pkg/resources/environment_acceptance_test.go +++ b/pkg/resources/environment_acceptance_test.go @@ -28,41 +28,108 @@ func TestAccDbtCloudEnvironmentResource(t *testing.T) { Config: testAccDbtCloudEnvironmentResourceBasicConfig(projectName, environmentName), Check: resource.ComposeTestCheckFunc( testAccCheckDbtCloudEnvironmentExists("dbtcloud_environment.test_env"), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "name", environmentName), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "deployment_type", "production"), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "name", + environmentName, + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "deployment_type", + "production", + ), ), }, // RENAME { - Config: testAccDbtCloudEnvironmentResourceBasicConfig(projectName, environmentName2), + Config: testAccDbtCloudEnvironmentResourceBasicConfig( + projectName, + environmentName2, + ), Check: resource.ComposeTestCheckFunc( testAccCheckDbtCloudEnvironmentExists("dbtcloud_environment.test_env"), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "name", environmentName2), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "name", + environmentName2, + ), ), }, // MODIFY ADDING CRED { - Config: testAccDbtCloudEnvironmentResourceModifiedConfig(projectName, environmentName2, "", "false"), + Config: testAccDbtCloudEnvironmentResourceModifiedConfig( + projectName, + environmentName2, + "", + "false", + ), Check: resource.ComposeTestCheckFunc( testAccCheckDbtCloudEnvironmentExists("dbtcloud_environment.test_env"), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "name", environmentName2), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "dbt_version", DBT_CLOUD_VERSION), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "custom_branch", ""), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "use_custom_branch", "false"), - resource.TestCheckResourceAttrSet("dbtcloud_environment.test_env", "credential_id"), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "deployment_type", ""), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "name", + environmentName2, + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "dbt_version", + DBT_CLOUD_VERSION, + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "custom_branch", + "", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "use_custom_branch", + "false", + ), + resource.TestCheckResourceAttrSet( + "dbtcloud_environment.test_env", + "credential_id", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "deployment_type", + "production", + ), ), }, // MODIFY CUSTOM BRANCH { - Config: testAccDbtCloudEnvironmentResourceModifiedConfig(projectName, environmentName2, "main", "true"), + Config: testAccDbtCloudEnvironmentResourceModifiedConfig( + projectName, + environmentName2, + "main", + "true", + ), Check: resource.ComposeTestCheckFunc( testAccCheckDbtCloudEnvironmentExists("dbtcloud_environment.test_env"), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "name", environmentName2), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "dbt_version", DBT_CLOUD_VERSION), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "custom_branch", "main"), - resource.TestCheckResourceAttr("dbtcloud_environment.test_env", "use_custom_branch", "true"), - resource.TestCheckResourceAttrSet("dbtcloud_environment.test_env", "credential_id"), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "name", + environmentName2, + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "dbt_version", + DBT_CLOUD_VERSION, + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "custom_branch", + "main", + ), + resource.TestCheckResourceAttr( + "dbtcloud_environment.test_env", + "use_custom_branch", + "true", + ), + resource.TestCheckResourceAttrSet( + "dbtcloud_environment.test_env", + "credential_id", + ), ), }, // IMPORT @@ -92,7 +159,9 @@ resource "dbtcloud_environment" "test_env" { `, projectName, environmentName, DBT_CLOUD_VERSION) } -func testAccDbtCloudEnvironmentResourceModifiedConfig(projectName, environmentName, customBranch, useCustomBranch string) string { +func testAccDbtCloudEnvironmentResourceModifiedConfig( + projectName, environmentName, customBranch, useCustomBranch string, +) string { return fmt.Sprintf(` resource "dbtcloud_project" "test_project" { name = "%s" @@ -106,6 +175,7 @@ resource "dbtcloud_environment" "test_env" { use_custom_branch = %s project_id = dbtcloud_project.test_project.id credential_id = dbtcloud_bigquery_credential.test_credential.credential_id + deployment_type = "production" } resource "dbtcloud_bigquery_credential" "test_credential" {