Skip to content

Commit 53c99d4

Browse files
authored
Merge pull request #561 from dbt-labs/tomighita/env-schema-validation
Add schema validation following the cloud-ui logic
2 parents 46df47d + 26a554f commit 53c99d4

13 files changed

Lines changed: 206 additions & 6 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Changes
2+
body: Add validation to schema names to follow the same rules as in the cloud UI
3+
time: 2025-11-19T17:31:45.917757+02:00

pkg/framework/objects/athena_credential/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package athena_credential
22

33
import (
4+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
45
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
56
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
67
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -53,6 +54,9 @@ var resourceSchema = resource_schema.Schema{
5354
"schema": resource_schema.StringAttribute{
5455
Required: true,
5556
Description: "The schema where to create models",
57+
Validators: []validator.String{
58+
helper.SchemaNameValidator(),
59+
},
5660
},
5761
},
5862
}

pkg/framework/objects/bigquery_credential/schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package bigquery_credential
22

33
import (
4+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
45
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
56
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
67
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
78
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
89
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
11+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1012
)
1113

1214
var BigQueryResourceSchema = resource_schema.Schema{
@@ -42,6 +44,9 @@ var BigQueryResourceSchema = resource_schema.Schema{
4244
"dataset": resource_schema.StringAttribute{
4345
Required: true,
4446
Description: "Default dataset name",
47+
Validators: []validator.String{
48+
helper.SchemaNameValidator(),
49+
},
4550
},
4651
"num_threads": resource_schema.Int64Attribute{
4752
Required: true,

pkg/framework/objects/databricks_credential/schema.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package databricks_credential
22

33
import (
4-
sl_cred_validator "github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
4+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
55
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
66
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
77
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -99,7 +99,8 @@ var DatabricksResourceSchema = resource_schema.Schema{
9999
Computed: true,
100100
Default: stringdefault.StaticString("default_schema"),
101101
Validators: []validator.String{
102-
sl_cred_validator.SemanticLayerCredentialValidator{FieldName: "schema"},
102+
helper.SemanticLayerCredentialValidator{FieldName: "schema"},
103+
helper.SchemaNameValidator(),
103104
},
104105
},
105106
"adapter_type": resource_schema.StringAttribute{
@@ -113,7 +114,7 @@ var DatabricksResourceSchema = resource_schema.Schema{
113114
},
114115
Validators: []validator.String{
115116
stringvalidator.OneOf("databricks", "spark"),
116-
sl_cred_validator.SemanticLayerCredentialValidator{FieldName: "adapter_type"},
117+
helper.SemanticLayerCredentialValidator{FieldName: "adapter_type"},
117118
},
118119
},
119120
"semantic_layer_credential": resource_schema.BoolAttribute{

pkg/framework/objects/fabric_credential/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
78
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
89
"github.com/hashicorp/terraform-plugin-framework/path"
910
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -99,6 +100,9 @@ var resourceSchema = resource_schema.Schema{
99100
"schema": resource_schema.StringAttribute{
100101
Required: true,
101102
Description: "The schema where to create the dbt models",
103+
Validators: []validator.String{
104+
helper.SchemaNameValidator(),
105+
},
102106
},
103107
"schema_authorization": resource_schema.StringAttribute{
104108
Optional: true,

pkg/framework/objects/postgres_credential/schema.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package postgres_credential
22

33
import (
4-
sl_cred_validator "github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
4+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
55
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
66
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
77
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -83,7 +83,7 @@ var PostgresResourceSchema = resource_schema.Schema{
8383
stringvalidator.OneOf(
8484
warehouseTypes...,
8585
),
86-
sl_cred_validator.SemanticLayerCredentialValidator{FieldName: "type"},
86+
helper.SemanticLayerCredentialValidator{FieldName: "type"},
8787
},
8888
},
8989
"default_schema": resource_schema.StringAttribute{
@@ -92,7 +92,8 @@ var PostgresResourceSchema = resource_schema.Schema{
9292
Default: stringdefault.StaticString("default_schema"),
9393
Description: "Default schema name. Optional only when semantic_layer_credential is set to true; otherwise, this field is required.",
9494
Validators: []validator.String{
95-
sl_cred_validator.SemanticLayerCredentialValidator{FieldName: "default_schema"},
95+
helper.SemanticLayerCredentialValidator{FieldName: "default_schema"},
96+
helper.SchemaNameValidator(),
9697
},
9798
},
9899
"target_name": resource_schema.StringAttribute{

pkg/framework/objects/redshift_credential/schema.go

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

33
import (
4+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
45
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
56
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
67
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
78
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
89
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
1011
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
12+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1113
)
1214

1315
var RedshiftResourceSchema = resource_schema.Schema{
@@ -57,6 +59,9 @@ var RedshiftResourceSchema = resource_schema.Schema{
5759
"default_schema": resource_schema.StringAttribute{
5860
Required: true,
5961
Description: "Default schema name",
62+
Validators: []validator.String{
63+
helper.SchemaNameValidator(),
64+
},
6065
},
6166
"num_threads": resource_schema.Int64Attribute{
6267
Required: true,

pkg/framework/objects/snowflake_credential/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package snowflake_credential
22

33
import (
44
snowflake_credential "github.com/dbt-labs/terraform-provider-dbtcloud/pkg/framework/objects/snowflake_credential/validators"
5+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
56
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
67
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
78
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -105,6 +106,9 @@ var SnowflakeCredentialResourceSchema = resource_schema.Schema{
105106
Computed: true,
106107
Default: stringdefault.StaticString("default_schema"),
107108
Description: "The schema where to create models. This is an optional field ONLY if the credential is used for Semantic Layer configuration, otherwise it is required.",
109+
Validators: []validator.String{
110+
helper.SchemaNameValidator(),
111+
},
108112
},
109113
"user": resource_schema.StringAttribute{
110114
Optional: true,

pkg/framework/objects/starburst_credential/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package starburst_credential
22

33
import (
4+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
45
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
56
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
67
resource_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -56,6 +57,9 @@ var resourceSchema = resource_schema.Schema{
5657
"schema": resource_schema.StringAttribute{
5758
Required: true,
5859
Description: "The schema where to create models",
60+
Validators: []validator.String{
61+
helper.SchemaNameValidator(),
62+
},
5963
},
6064
},
6165
}

pkg/framework/objects/synapse_credential/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper"
78
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
89
datasource_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
910
"github.com/hashicorp/terraform-plugin-framework/path"
@@ -153,6 +154,9 @@ var resourceSchema = resource_schema.Schema{
153154
"schema": resource_schema.StringAttribute{
154155
Required: true,
155156
Description: "The schema where to create the dbt models",
157+
Validators: []validator.String{
158+
helper.SchemaNameValidator(),
159+
},
156160
},
157161
"schema_authorization": resource_schema.StringAttribute{
158162
Optional: true,

0 commit comments

Comments
 (0)