Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements on the resource routeros_interface_ethernet #266

Merged
merged 11 commits into from
Oct 1, 2023
3 changes: 3 additions & 0 deletions examples/resources/routeros_interface_ethernet/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/interface/ethernet get [print show-ids]]
terraform import routeros_interface_ethernet.test "*0"
5 changes: 5 additions & 0 deletions examples/resources/routeros_interface_ethernet/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "routeros_interface_ethernet" "test" {
factory_name = "sfp-sfpplus8"
name = "swtich-eth0"
mtu = 9000
}
12 changes: 12 additions & 0 deletions routeros/mikrotik_serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,18 @@ func MikrotikResourceDataToTerraform(item MikrotikItem, s map[string]*schema.Sch
var diags diag.Diagnostics
var err error
var transformSet map[string]string
var skipFields 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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaerh this 3 lines are a bit structural change. heads up, double check if you think it makes sense.
What I am trying to do here is be able to skip fields from being passed to terraform as it throws warnings about fields being missing in the schema.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks logical and good. In my opinion it should work without errors.

if sf, ok := s[MetaSkipFields]; ok {
skipFields = loadSkipFields(sf.Default.(string))
}

// TypeMap,TypeSet initialization information storage.
var maps = make(map[string]map[string]interface{})
var nestedLists = make(map[string]map[string]interface{})
Expand Down Expand Up @@ -305,6 +311,12 @@ func MikrotikResourceDataToTerraform(item MikrotikItem, s map[string]*schema.Sch
// field-name => field_name
terraformSnakeName := KebabToSnake(mikrotikKebabName)

if skipFields != nil {
if _, ok := skipFields[terraformSnakeName]; ok {
continue
}
}

// Composite fields.
var subFieldSnakeName string
if strings.Contains(terraformSnakeName, ".") {
Expand Down
2 changes: 1 addition & 1 deletion routeros/resource_default_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func SystemResourceRead(ctx context.Context, s map[string]*schema.Schema, d *sch
return diag.FromErr(err)
}

// We make a unique Id, it does not affect the work with the Mikrotik.
// We make a unique Id, it does not affect the work with the Mikrotik.
// Id: /caps-man/manager -> caps-man.manager
d.SetId(strings.ReplaceAll(strings.TrimLeft(metadata.Path, "/"), "/", "."))

Expand Down
Loading
Loading