Skip to content

Commit

Permalink
fix(serialize): Fix the transformation of attribute names.
Browse files Browse the repository at this point in the history
It looks like the transformation was done incorrectly. In `zerotier` the order of names was reversed. In serialization functions the order of map filling was mixed up.
Added ability to transform common attribute names, since the wifi interface contains a `basic-rates-a/g` parameter.
  • Loading branch information
vaerh committed Sep 27, 2024
1 parent 909b4c7 commit 9796820
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions routeros/mikrotik_serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
var transformSet map[string]string
var skipFields, setUnsetFields map[string]struct{}

// {"channel.config": "channel", "schema-field-name": "mikrotik-field-name"}
// {"channel: channel.config", "datapath: datapath.config", "schema-field-name": "mikrotik-field-name"}
if ts, ok := s[MetaTransformSet]; ok {
transformSet = loadTransformSet(ts.Default.(string), true)
transformSet = loadTransformSet(ts.Default.(string), false)
}

// "field_first", "field_second", "field_third"
Expand Down Expand Up @@ -196,6 +196,13 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso
mikrotikKebabName := SnakeToKebab(terraformSnakeName)
value := d.Get(terraformSnakeName)

// WiFi basic_rates_ag -> basic-rates-a/g
if transformSet != nil && terraformMetadata.Type != schema.TypeMap {
if new, ok := transformSet[terraformSnakeName]; ok {
mikrotikKebabName = SnakeToKebab(new)
}
}

switch terraformMetadata.Type {
case schema.TypeString:
if _, ok := setUnsetFields[terraformSnakeName]; ok && value.(string) == "" {
Expand Down Expand Up @@ -322,7 +329,7 @@ func MikrotikResourceDataToTerraform(item MikrotikItem, s map[string]*schema.Sch

// {"channel": "channel.config", "mikrotik-field-name": "schema-field-name"}
if ts, ok := s[MetaTransformSet]; ok {
transformSet = loadTransformSet(ts.Default.(string), false)
transformSet = loadTransformSet(ts.Default.(string), true)
}

// "field_first", "field_second", "field_third"
Expand Down
2 changes: 1 addition & 1 deletion routeros/resource_zerotier.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ResourceZerotier() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/zerotier"),
MetaId: PropId(Id),
MetaTransformSet: PropTransformSet("identity.public: identity_public"),
MetaTransformSet: PropTransformSet("identity_public: identity.public"),

KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
Expand Down

0 comments on commit 9796820

Please sign in to comment.