@@ -40,8 +40,36 @@ func ResourceSystemCertificate() *schema.Resource {
4040 resSchema := map [string ]* schema.Schema {
4141 MetaResourcePath : PropResourcePath ("/certificate" ),
4242 MetaId : PropId (Id ),
43- MetaSkipFields : PropSkipFields ("import" , "sign" , "sign_via_scep" ),
43+ MetaSkipFields : PropSkipFields ("acme_ssl_certificate" , " import" , "sign" , "sign_via_scep" ),
4444
45+ "acme_ssl_certificate" : {
46+ Type : schema .TypeSet ,
47+ Optional : true ,
48+ Description : "Enable SSL certificate. This will generate a new certificate using ACME protocol." ,
49+ ConflictsWith : []string {"import" , "sign" , "sign_via_scep" },
50+ Elem : & schema.Resource {
51+ Schema : map [string ]* schema.Schema {
52+ "directory_url" : {
53+ Type : schema .TypeString ,
54+ Optional : true ,
55+ Description : "ACME directory url." ,
56+ DiffSuppressFunc : AlwaysPresentNotUserProvided ,
57+ },
58+ "eab_hmac_key" : {
59+ Type : schema .TypeString ,
60+ Optional : true ,
61+ Description : "HMAC key for ACME External Account Binding (optional)." ,
62+ DiffSuppressFunc : AlwaysPresentNotUserProvided ,
63+ },
64+ "eab_kid" : {
65+ Type : schema .TypeString ,
66+ Optional : true ,
67+ Description : "Key identifier." ,
68+ DiffSuppressFunc : AlwaysPresentNotUserProvided ,
69+ },
70+ },
71+ },
72+ },
4573 "authority" : {
4674 Type : schema .TypeString ,
4775 Computed : true ,
@@ -126,7 +154,7 @@ func ResourceSystemCertificate() *schema.Resource {
126154 Type : schema .TypeSet ,
127155 Optional : true ,
128156 ForceNew : true ,
129- ConflictsWith : []string {"sign" , "sign_via_scep" },
157+ ConflictsWith : []string {"acme_ssl_certificate" , " sign" , "sign_via_scep" },
130158 Elem : & schema.Resource {
131159 Schema : map [string ]* schema.Schema {
132160 "cert_file_name" : {
@@ -249,7 +277,7 @@ func ResourceSystemCertificate() *schema.Resource {
249277 Type : schema .TypeSet ,
250278 Optional : true ,
251279 ForceNew : true ,
252- ConflictsWith : []string {"sign_via_scep" },
280+ ConflictsWith : []string {"acme_ssl_certificate" , " sign_via_scep" },
253281 Elem : & schema.Resource {
254282 Schema : map [string ]* schema.Schema {
255283 "ca" : {
@@ -282,7 +310,7 @@ func ResourceSystemCertificate() *schema.Resource {
282310 Type : schema .TypeSet ,
283311 Optional : true ,
284312 ForceNew : true ,
285- ConflictsWith : []string {"sign" },
313+ ConflictsWith : []string {"acme_ssl_certificate" , " sign" },
286314 Elem : & schema.Resource {
287315 Schema : map [string ]* schema.Schema {
288316 "scep_url" : {
@@ -426,11 +454,13 @@ func ResourceSystemCertificate() *schema.Resource {
426454 var command string // MikroTik command to sign certificate
427455 var ok bool
428456
429- if _ , ok = d .GetOk ("import" ); ! ok {
430- // Run DefaultCreate.
431- diags = ResourceCreate (ctx , resSchema , d , m )
432- if diags .HasError () {
433- return diags
457+ if _ , ok = d .GetOk ("acme_ssl_certificate" ); ! ok {
458+ if _ , ok = d .GetOk ("import" ); ! ok {
459+ // Run DefaultCreate.
460+ diags = ResourceCreate (ctx , resSchema , d , m )
461+ if diags .HasError () {
462+ return diags
463+ }
434464 }
435465 }
436466
@@ -447,6 +477,11 @@ func ResourceSystemCertificate() *schema.Resource {
447477 crudMethod = crudSignViaScep
448478 // https://router/rest/certificate/add-scep
449479 command = "/add-scep"
480+ } else if cmdBlock , ok = d .GetOk ("acme_ssl_certificate" ); ok {
481+ params = MikrotikItem {"dns-name" : d .Get ("common_name" ).(string )}
482+ crudMethod = crudEnableSslCertificate
483+ // https://router/rest/certificate/enable-ssl-certificate
484+ command = "/enable-ssl-certificate"
450485 } else if cmdBlock , ok = d .GetOk ("import" ); ok {
451486 return certImport (ctx , cmdBlock , d , m )
452487 } else {
@@ -481,6 +516,17 @@ func ResourceSystemCertificate() *schema.Resource {
481516 return diag .FromErr (err )
482517 }
483518
519+ if command == "/enable-ssl-certificate" {
520+ d .SetId (d .Get ("name" ).(string ))
521+ id , err := dynamicIdLookup (Name , resSchema [MetaResourcePath ].Default .(string ), m .(Client ), d )
522+
523+ if err != nil {
524+ return diag .FromErr (err )
525+ }
526+
527+ d .SetId (id )
528+ }
529+
484530 return ResourceRead (ctx , resSchema , d , m )
485531 }
486532
0 commit comments