diff --git a/routeros/mikrotik_serialize.go b/routeros/mikrotik_serialize.go
index a939c8f1..1734114a 100644
--- a/routeros/mikrotik_serialize.go
+++ b/routeros/mikrotik_serialize.go
@@ -115,7 +115,7 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
meta := &MikrotikItemMetadata{}
rawConfig := d.GetRawConfig()
var transformSet map[string]string
- var skipFields map[string]struct{}
+ var skipFields, setUnsetFields map[string]struct{}
// {"channel.config": "channel", "schema-field-name": "mikrotik-field-name"}
if ts, ok := s[MetaTransformSet]; ok {
@@ -126,6 +126,9 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
if sf, ok := s[MetaSkipFields]; ok {
skipFields = loadSkipFields(sf.Default.(string))
}
+ if suf, ok := s[MetaSetUnsetFields]; ok {
+ setUnsetFields = loadSkipFields(suf.Default.(string))
+ }
// Schema map iteration.
for terraformSnakeName, terraformMetadata := range s {
@@ -136,7 +139,7 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
meta.IdType = IdType(terraformMetadata.Default.(int))
case MetaResourcePath:
meta.Path = terraformMetadata.Default.(string)
- case MetaTransformSet, MetaSkipFields:
+ case MetaTransformSet, MetaSkipFields, MetaSetUnsetFields:
continue
default:
meta.Meta[terraformSnakeName] = terraformMetadata.Default.(string)
@@ -195,6 +198,17 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
case schema.TypeInt:
item[mikrotikKebabName] = strconv.Itoa(value.(int))
case schema.TypeBool:
+ // true: {...,"interfaces":"ether3","passive":"","priority":"128",...}
+ // false: {...,"interfaces":"ether3", "priority":"128",...}
+ if _, ok := setUnsetFields[terraformSnakeName]; ok {
+ if value.(bool) {
+ item[mikrotikKebabName] = ""
+ } else {
+ // Unset
+ item["!"+mikrotikKebabName] = ""
+ }
+ continue
+ }
item[mikrotikKebabName] = BoolToMikrotikJSON(value.(bool))
// Used to represent an ordered collection of items.
case schema.TypeList:
@@ -269,12 +283,18 @@ func MikrotikResourceDataToTerraform(item MikrotikItem, s map[string]*schema.Sch
var diags diag.Diagnostics
var err error
var transformSet map[string]string
+ var setUnsetFields map[string]struct{}
// {"channel": "channel.config", "mikrotik-field-name": "schema-field-name"}
if ts, ok := s[MetaTransformSet]; ok {
transformSet = loadTransformSet(ts.Default.(string), false)
}
+ // "field_first", "field_second", "field_third"
+ if suf, ok := s[MetaSetUnsetFields]; ok {
+ setUnsetFields = loadSkipFields(suf.Default.(string))
+ }
+
// TypeMap,TypeSet initialization information storage.
var maps = make(map[string]map[string]interface{})
var nestedLists = make(map[string]map[string]interface{})
@@ -340,6 +360,10 @@ func MikrotikResourceDataToTerraform(item MikrotikItem, s map[string]*schema.Sch
err = d.Set(terraformSnakeName, i)
case schema.TypeBool:
+ if _, ok := setUnsetFields[terraformSnakeName]; ok {
+ err = d.Set(terraformSnakeName, true)
+ break
+ }
err = d.Set(terraformSnakeName, BoolFromMikrotikJSON(mikrotikValue))
case schema.TypeList, schema.TypeSet:
@@ -532,6 +556,7 @@ func MikrotikResourceDataToTerraformDatasource(items *[]MikrotikItem, resourceDa
propValue = i
case schema.TypeBool:
+ // TODO Add support for set/unset fields?
propValue = BoolFromMikrotikJSON(mikrotikValue)
case schema.TypeList:
diff --git a/routeros/provider_schema_helpers.go b/routeros/provider_schema_helpers.go
index 7d35064f..772c3153 100644
--- a/routeros/provider_schema_helpers.go
+++ b/routeros/provider_schema_helpers.go
@@ -14,10 +14,11 @@ import (
// All metadata fields must be present in each resource schema, and the field type must be string.
const (
- MetaId = "___id___"
- MetaResourcePath = "___path___"
- MetaTransformSet = "___ts___"
- MetaSkipFields = "___skip___"
+ MetaId = "___id___"
+ MetaResourcePath = "___path___"
+ MetaTransformSet = "___ts___"
+ MetaSkipFields = "___skip___"
+ MetaSetUnsetFields = "___unset___"
)
const (
@@ -92,6 +93,19 @@ func PropSkipFields(s string) *schema.Schema {
}
}
+// PropSetUnsetFields
+func PropSetUnsetFields(s string) *schema.Schema {
+ return &schema.Schema{
+ Type: schema.TypeString,
+ Optional: true,
+ Default: s,
+ Description: "A set of fields that require setting/unsetting. This is an internal service field, setting a value is not required.",
+ DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
+ return true
+ },
+ }
+}
+
// PropName
func PropName(description string) *schema.Schema {
return &schema.Schema{
diff --git a/routeros/resource_routing_ospf_area.go b/routeros/resource_routing_ospf_area.go
index e60ea650..adc267f2 100644
--- a/routeros/resource_routing_ospf_area.go
+++ b/routeros/resource_routing_ospf_area.go
@@ -21,8 +21,9 @@ import (
// ResourceRoutingOspfArea https://help.mikrotik.com/docs/display/ROS/OSPF
func ResourceRoutingOspfArea() *schema.Resource {
resSchema := map[string]*schema.Schema{
- MetaResourcePath: PropResourcePath("/routing/ospf/area"),
- MetaId: PropId(Id),
+ MetaResourcePath: PropResourcePath("/routing/ospf/area"),
+ MetaId: PropId(Id),
+ MetaSetUnsetFields: PropSetUnsetFields(`"no_summaries"`),
"area_id": {
Type: schema.TypeString,
@@ -45,9 +46,11 @@ func ResourceRoutingOspfArea() *schema.Resource {
},
KeyName: PropNameForceNewRw,
"no_summaries": {
- Type: schema.TypeBool,
- Optional: true,
- Description: "If set then the area will not flood summary LSAs in the stub area.",
+ Type: schema.TypeBool,
+ Optional: true,
+ Description: "If set then the area will not flood summary LSAs in the stub area. " +
+ "The correct value of this attribute may not be displayed in Winbox. " +
+ "Please check the parameters in the console!",
},
"nssa_translate": {
Type: schema.TypeString,
diff --git a/routeros/resource_routing_ospf_interface_template.go b/routeros/resource_routing_ospf_interface_template.go
index 2894f701..9ab8edb7 100644
--- a/routeros/resource_routing_ospf_interface_template.go
+++ b/routeros/resource_routing_ospf_interface_template.go
@@ -34,8 +34,9 @@ import (
// ResourceRoutingOspfInterfaceTemplate https://help.mikrotik.com/docs/display/ROS/OSPF
func ResourceRoutingOspfInterfaceTemplate() *schema.Resource {
resSchema := map[string]*schema.Schema{
- MetaResourcePath: PropResourcePath("/routing/ospf/interface-template"),
- MetaId: PropId(Id),
+ MetaResourcePath: PropResourcePath("/routing/ospf/interface-template"),
+ MetaId: PropId(Id),
+ MetaSetUnsetFields: PropSetUnsetFields(`"passive"`),
"area": {
Type: schema.TypeString,
@@ -107,10 +108,12 @@ func ResourceRoutingOspfInterfaceTemplate() *schema.Resource {
Description: "The network prefix associated with the area.",
},
"passive": {
- Type: schema.TypeBool,
- Optional: true,
- Default: false,
- Description: "If enabled, then do not send or receive OSPF traffic on the matching interfaces",
+ Type: schema.TypeBool,
+ Optional: true,
+ Default: false,
+ Description: "If enabled, then do not send or receive OSPF traffic on the matching interfaces. " +
+ "The correct value of this attribute may not be displayed in Winbox. " +
+ "Please check the parameters in the console!",
},
"prefix_list": {
Type: schema.TypeString,
diff --git a/routeros/resource_routing_ospf_interface_template_test.go b/routeros/resource_routing_ospf_interface_template_test.go
index 5446ee87..7f8f2dd6 100644
--- a/routeros/resource_routing_ospf_interface_template_test.go
+++ b/routeros/resource_routing_ospf_interface_template_test.go
@@ -54,6 +54,7 @@ resource "routeros_routing_ospf_area" "test_routing_ospf_area" {
resource "routeros_routing_ospf_interface_template" "test_routing_ospf_interface_template" {
area = routeros_routing_ospf_area.test_routing_ospf_area.name
interfaces = ["ether3"]
+ passive = true
}
`