@@ -40,8 +40,36 @@ func ResourceSystemCertificate() *schema.Resource {
40
40
resSchema := map [string ]* schema.Schema {
41
41
MetaResourcePath : PropResourcePath ("/certificate" ),
42
42
MetaId : PropId (Id ),
43
- MetaSkipFields : PropSkipFields ("import" , "sign" , "sign_via_scep" ),
43
+ MetaSkipFields : PropSkipFields ("acme_ssl_certificate" , " import" , "sign" , "sign_via_scep" ),
44
44
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
+ },
45
73
"authority" : {
46
74
Type : schema .TypeString ,
47
75
Computed : true ,
@@ -126,7 +154,7 @@ func ResourceSystemCertificate() *schema.Resource {
126
154
Type : schema .TypeSet ,
127
155
Optional : true ,
128
156
ForceNew : true ,
129
- ConflictsWith : []string {"sign" , "sign_via_scep" },
157
+ ConflictsWith : []string {"acme_ssl_certificate" , " sign" , "sign_via_scep" },
130
158
Elem : & schema.Resource {
131
159
Schema : map [string ]* schema.Schema {
132
160
"cert_file_name" : {
@@ -249,7 +277,7 @@ func ResourceSystemCertificate() *schema.Resource {
249
277
Type : schema .TypeSet ,
250
278
Optional : true ,
251
279
ForceNew : true ,
252
- ConflictsWith : []string {"sign_via_scep" },
280
+ ConflictsWith : []string {"acme_ssl_certificate" , " sign_via_scep" },
253
281
Elem : & schema.Resource {
254
282
Schema : map [string ]* schema.Schema {
255
283
"ca" : {
@@ -282,7 +310,7 @@ func ResourceSystemCertificate() *schema.Resource {
282
310
Type : schema .TypeSet ,
283
311
Optional : true ,
284
312
ForceNew : true ,
285
- ConflictsWith : []string {"sign" },
313
+ ConflictsWith : []string {"acme_ssl_certificate" , " sign" },
286
314
Elem : & schema.Resource {
287
315
Schema : map [string ]* schema.Schema {
288
316
"scep_url" : {
@@ -426,11 +454,13 @@ func ResourceSystemCertificate() *schema.Resource {
426
454
var command string // MikroTik command to sign certificate
427
455
var ok bool
428
456
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
+ }
434
464
}
435
465
}
436
466
@@ -447,6 +477,11 @@ func ResourceSystemCertificate() *schema.Resource {
447
477
crudMethod = crudSignViaScep
448
478
// https://router/rest/certificate/add-scep
449
479
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"
450
485
} else if cmdBlock , ok = d .GetOk ("import" ); ok {
451
486
return certImport (ctx , cmdBlock , d , m )
452
487
} else {
@@ -481,6 +516,17 @@ func ResourceSystemCertificate() *schema.Resource {
481
516
return diag .FromErr (err )
482
517
}
483
518
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
+
484
530
return ResourceRead (ctx , resSchema , d , m )
485
531
}
486
532
0 commit comments