@@ -116,11 +116,12 @@ func resourceInstance() *schema.Resource {
116116 Description : "The connection user name used by Bytebase to perform DDL and DML operations." ,
117117 },
118118 "password" : {
119- Type : schema .TypeString ,
120- Optional : true ,
121- Sensitive : true ,
122- Default : "" ,
123- Description : "The connection user password used by Bytebase to perform DDL and DML operations." ,
119+ Type : schema .TypeString ,
120+ Optional : true ,
121+ Sensitive : true ,
122+ Computed : true ,
123+ DiffSuppressFunc : suppressSensitiveFieldDiff ,
124+ Description : "The connection user password used by Bytebase to perform DDL and DML operations." ,
124125 },
125126 "external_secret" : {
126127 Type : schema .TypeList ,
@@ -234,26 +235,35 @@ func resourceInstance() *schema.Resource {
234235 },
235236 },
236237 },
237- "ssl_ca " : {
238- Type : schema .TypeString ,
238+ "use_ssl " : {
239+ Type : schema .TypeBool ,
239240 Optional : true ,
240- Default : "" ,
241- Sensitive : true ,
242- Description : "The CA certificate. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE." ,
241+ Default : false ,
242+ Description : "Enable SSL connection. Required to use SSL certificates." ,
243+ },
244+ "ssl_ca" : {
245+ Type : schema .TypeString ,
246+ Optional : true ,
247+ Sensitive : true ,
248+ Computed : true ,
249+ DiffSuppressFunc : suppressSensitiveFieldDiff ,
250+ Description : "The CA certificate. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE." ,
243251 },
244252 "ssl_cert" : {
245- Type : schema .TypeString ,
246- Optional : true ,
247- Default : "" ,
248- Sensitive : true ,
249- Description : "The client certificate. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE." ,
253+ Type : schema .TypeString ,
254+ Optional : true ,
255+ Sensitive : true ,
256+ Computed : true ,
257+ DiffSuppressFunc : suppressSensitiveFieldDiff ,
258+ Description : "The client certificate. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE." ,
250259 },
251260 "ssl_key" : {
252- Type : schema .TypeString ,
253- Optional : true ,
254- Default : "" ,
255- Sensitive : true ,
256- Description : "The client key. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE." ,
261+ Type : schema .TypeString ,
262+ Optional : true ,
263+ Sensitive : true ,
264+ Computed : true ,
265+ DiffSuppressFunc : suppressSensitiveFieldDiff ,
266+ Description : "The client key. Optional, you can set this if the engine type is MYSQL, POSTGRES, TIDB or CLICKHOUSE." ,
257267 },
258268 "host" : {
259269 Type : schema .TypeString ,
@@ -288,6 +298,17 @@ func resourceInstance() *schema.Resource {
288298 }
289299}
290300
301+ // suppressSensitiveFieldDiff suppresses diffs for write-only sensitive fields.
302+ func suppressSensitiveFieldDiff (_ string , oldValue , newValue string , _ * schema.ResourceData ) bool {
303+ // If the field was previously set (exists in state) and the new value is empty,
304+ // suppress the diff because the API doesn't return these fields
305+ if oldValue != "" && newValue == "" {
306+ return true
307+ }
308+ // If both are equal, suppress the diff
309+ return oldValue == newValue
310+ }
311+
291312func resourceInstanceCreate (ctx context.Context , d * schema.ResourceData , m interface {}) diag.Diagnostics {
292313 c := m .(api.Client )
293314
@@ -656,6 +677,7 @@ func flattenDataSourceList(d *schema.ResourceData, dataSourceList []*v1pb.DataSo
656677 raw ["host" ] = dataSource .Host
657678 raw ["port" ] = dataSource .Port
658679 raw ["database" ] = dataSource .Database
680+ raw ["use_ssl" ] = dataSource .UseSsl
659681
660682 // These sensitive fields won't returned in the API. Propagate state value.
661683 if ds , ok := oldDataSourceMap [dataSource .Id ]; ok {
@@ -722,7 +744,26 @@ func flattenDataSourceList(d *schema.ResourceData, dataSourceList []*v1pb.DataSo
722744
723745func dataSourceHash (rawDataSource interface {}) int {
724746 dataSource := rawDataSource .(map [string ]interface {})
725- return internal .ToHashcodeInt (dataSource ["id" ].(string ))
747+ // Include id and SSL-related field presence to detect configuration changes
748+ hashStr := dataSource ["id" ].(string )
749+
750+ // Include use_ssl in hash to detect SSL enablement changes
751+ if v , ok := dataSource ["use_ssl" ].(bool ); ok {
752+ hashStr = fmt .Sprintf ("%s-ssl_%t" , hashStr , v )
753+ }
754+
755+ // Include whether SSL certificates are present (not the values themselves)
756+ if v , ok := dataSource ["ssl_ca" ].(string ); ok && v != "" {
757+ hashStr = fmt .Sprintf ("%s-ca_present" , hashStr )
758+ }
759+ if v , ok := dataSource ["ssl_cert" ].(string ); ok && v != "" {
760+ hashStr = fmt .Sprintf ("%s-cert_present" , hashStr )
761+ }
762+ if v , ok := dataSource ["ssl_key" ].(string ); ok && v != "" {
763+ hashStr = fmt .Sprintf ("%s-key_present" , hashStr )
764+ }
765+
766+ return internal .ToHashcodeInt (hashStr )
726767}
727768
728769func convertDataSourceCreateList (d * schema.ResourceData , validate bool ) ([]* v1pb.DataSource , error ) {
@@ -797,6 +838,9 @@ func convertDataSourceCreateList(d *schema.ResourceData, validate bool) ([]*v1pb
797838 return nil , errors .Errorf ("cannot set both password and external_secret" )
798839 }
799840
841+ if v , ok := obj ["use_ssl" ].(bool ); ok {
842+ dataSource .UseSsl = v
843+ }
800844 if v , ok := obj ["ssl_ca" ].(string ); ok {
801845 dataSource .SslCa = v
802846 }
0 commit comments