Skip to content

Commit

Permalink
Merge pull request #231 from dbt-labs/release-0.2.18
Browse files Browse the repository at this point in the history
Release 0.2.18
  • Loading branch information
b-per authored Jan 10, 2024
2 parents 6becd00 + 3730fae commit dcb68b1
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 55 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/environment_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/user_groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/dbtcloud_user_groups/resource.tf
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
106 changes: 88 additions & 18 deletions pkg/resources/environment_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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" {
Expand Down
22 changes: 15 additions & 7 deletions pkg/resources/environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.",
},
},

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit dcb68b1

Please sign in to comment.