Skip to content

Commit 8ef4c92

Browse files
committed
chore: add validation
1 parent 273fef2 commit 8ef4c92

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

provider/resource_environment.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
910

1011
"github.com/bytebase/terraform-provider-bytebase/api"
1112
)
@@ -21,14 +22,17 @@ func resourceEnvironment() *schema.Resource {
2122
},
2223
Schema: map[string]*schema.Schema{
2324
"name": {
24-
Type: schema.TypeString,
25-
Required: true,
25+
Type: schema.TypeString,
26+
Required: true,
27+
Description: "The environment unique name.",
28+
ValidateFunc: validation.StringIsNotEmpty,
2629
},
2730
"order": {
28-
Type: schema.TypeInt,
29-
Optional: true,
30-
Computed: true,
31-
Default: nil,
31+
Type: schema.TypeInt,
32+
Optional: true,
33+
Computed: true,
34+
Default: nil,
35+
Description: "The environment sorting order.",
3236
},
3337
},
3438
}

provider/resource_instance.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
910

1011
"github.com/bytebase/terraform-provider-bytebase/api"
1112
)
@@ -21,13 +22,20 @@ func resourceInstance() *schema.Resource {
2122
},
2223
Schema: map[string]*schema.Schema{
2324
"name": {
24-
Type: schema.TypeString,
25-
Required: true,
25+
Type: schema.TypeString,
26+
Required: true,
27+
ValidateFunc: validation.StringIsNotEmpty,
2628
},
2729
"engine": {
28-
// TODO: validation
2930
Type: schema.TypeString,
3031
Required: true,
32+
ValidateFunc: validation.StringInSlice([]string{
33+
"MYSQL",
34+
"POSTGRES",
35+
"TIDB",
36+
"SNOWFLAKE",
37+
"CLICKHOUSE",
38+
}, false),
3139
},
3240
"engine_version": {
3341
Type: schema.TypeString,
@@ -39,17 +47,19 @@ func resourceInstance() *schema.Resource {
3947
Computed: true,
4048
},
4149
"host": {
42-
Type: schema.TypeString,
43-
Required: true,
50+
Type: schema.TypeString,
51+
Required: true,
52+
ValidateFunc: validation.StringIsNotEmpty,
53+
Description: "Host or socker for your instance, or the account name if the instance type is Snowflake.",
4454
},
4555
"port": {
4656
Type: schema.TypeString,
4757
Optional: true,
58+
Computed: true,
4859
},
4960
"username": {
5061
Type: schema.TypeString,
5162
Optional: true,
52-
Computed: false,
5363
},
5464
"password": {
5565
Type: schema.TypeString,
@@ -70,8 +80,10 @@ func resourceInstance() *schema.Resource {
7080
Optional: true,
7181
},
7282
"environment": {
73-
Type: schema.TypeString,
74-
Required: true,
83+
Type: schema.TypeString,
84+
Required: true,
85+
ValidateFunc: validation.StringIsNotEmpty,
86+
Description: "The environment name for your instance.",
7587
},
7688
},
7789
}

0 commit comments

Comments
 (0)