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