@@ -3,36 +3,46 @@ package provider
33
44import (
55 "context"
6+ "fmt"
67
78 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
1011 "github.com/bytebase/terraform-provider-bytebase/client"
1112)
1213
14+ const (
15+ envKeyForBytebaseURL = "BYTEBASE_URL"
16+ envKeyForyUserEmail = "BYTEBASE_USER_EMAIL"
17+ envKeyForyUserPassword = "BYTEBASE_USER_PASSWORD"
18+ )
19+
1320// NewProvider is the implement for Bytebase Terraform provider.
1421func NewProvider () * schema.Provider {
1522 return & schema.Provider {
1623 Schema : map [string ]* schema.Schema {
1724 "bytebase_url" : {
1825 Type : schema .TypeString ,
1926 Required : true ,
20- DefaultFunc : schema .EnvDefaultFunc ("BYTEBASE_URL" , nil ),
27+ DefaultFunc : schema .EnvDefaultFunc (envKeyForBytebaseURL , nil ),
2128 },
2229 "email" : {
2330 Type : schema .TypeString ,
2431 Required : true ,
25- DefaultFunc : schema .EnvDefaultFunc ("BYTEBASE_USER_EMAIL" , nil ),
32+ DefaultFunc : schema .EnvDefaultFunc (envKeyForyUserEmail , nil ),
2633 },
2734 "password" : {
2835 Type : schema .TypeString ,
2936 Required : true ,
3037 Sensitive : true ,
31- DefaultFunc : schema .EnvDefaultFunc ("BYTEBASE_USER_PASSWORD" , nil ),
38+ DefaultFunc : schema .EnvDefaultFunc (envKeyForyUserPassword , nil ),
3239 },
3340 },
3441 ConfigureContextFunc : providerConfigure ,
35- DataSourcesMap : map [string ]* schema.Resource {},
42+ DataSourcesMap : map [string ]* schema.Resource {
43+ "bytebase_instances" : dataSourceInstanceList (),
44+ "bytebase_environments" : dataSourceEnvironmentList (),
45+ },
3646 ResourcesMap : map [string ]* schema.Resource {
3747 "bytebase_environment" : resourceEnvironment (),
3848 "bytebase_instance" : resourceInstance (),
@@ -52,7 +62,7 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
5262 diags = append (diags , diag.Diagnostic {
5363 Severity : diag .Error ,
5464 Summary : "Unable to create HashiCups client" ,
55- Detail : "BYTEBASE_USER_EMAIL or BYTEBASE_USER_PASSWORD cannot be empty" ,
65+ Detail : fmt . Sprintf ( "%s or %s cannot be empty", envKeyForyUserEmail , envKeyForyUserPassword ) ,
5666 })
5767
5868 return nil , diags
@@ -62,7 +72,7 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
6272 diags = append (diags , diag.Diagnostic {
6373 Severity : diag .Error ,
6474 Summary : "Unable to create HashiCups client" ,
65- Detail : "BYTEBASE_URL cannot be empty" ,
75+ Detail : fmt . Sprintf ( "%s cannot be empty", envKeyForBytebaseURL ) ,
6676 })
6777
6878 return nil , diags
0 commit comments