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

datasource int overflow #507

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d4495b8
Merge branch 'terraform-routeros:main' into main
danielnachtrub May 10, 2024
5398c81
Merge branch 'terraform-routeros:main' into main
danielnachtrub May 13, 2024
7049e04
Merge branch 'terraform-routeros:main' into main
danielnachtrub May 13, 2024
f081bbf
Merge branch 'terraform-routeros:main' into main
danielnachtrub Jun 6, 2024
d2be7cf
Merge branch 'terraform-routeros:main' into main
danielnachtrub Jun 27, 2024
b2577aa
Merge branch 'terraform-routeros:main' into main
danielnachtrub Jul 10, 2024
a366afc
replace TypeInt with TypeFloat on data sources counters
danielnachtrub Jul 10, 2024
3572df0
clean interfaces.go
Ujstor Aug 7, 2024
78e5bb7
clean ip_routes.go
Ujstor Aug 7, 2024
5c8522a
clean system_resource.go
Ujstor Aug 7, 2024
0877c5e
clean firewalls
Ujstor Aug 7, 2024
9324583
docs update
Ujstor Aug 7, 2024
d729f5b
Merge branch 'terraform-routeros:main' into dn/datasource_int_overflow
danielnachtrub Aug 7, 2024
da095bb
add changes
Ujstor Aug 8, 2024
55bc2cb
docs
Ujstor Aug 8, 2024
3d575b4
Merge branch 'dn/datasource_int_overflow' into clean-nonstatic-ds
Ujstor Aug 8, 2024
07dc03e
Merge pull request #1 from Ujstor/clean-nonstatic-ds
danielnachtrub Aug 8, 2024
b5e19f7
PropSkipFields
Ujstor Aug 9, 2024
b324d79
remove TypeFolat
Ujstor Aug 9, 2024
5999414
float leftover
Ujstor Aug 9, 2024
99d5f05
Merge pull request #2 from Ujstor/clean-nonstatic-ds
danielnachtrub Aug 12, 2024
3fa5dd2
Merge branch 'main' into dn/datasource_int_overflow
danielnachtrub Aug 12, 2024
113cdb5
ingress_priority & random
Ujstor Aug 12, 2024
7f41906
Merge pull request #3 from Ujstor/clean-nonstatic-ds
danielnachtrub Aug 12, 2024
4a6d912
formating
Ujstor Aug 12, 2024
1e950a3
Merge pull request #4 from Ujstor/clean-nonstatic-ds
danielnachtrub Aug 12, 2024
3e2070a
fix(datasources): Add field skipping when processing input MT data
vaerh Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions docs/data-sources/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,16 @@ Read-Only:
- `comment` (String)
- `default_name` (String)
- `disabled` (Boolean)
- `fp_rx_byte` (Number)
- `fp_rx_packet` (Number)
- `fp_tx_byte` (Number)
- `fp_tx_packet` (Number)
- `id` (String)
- `l2mtu` (Number)
- `last_link_down_time` (String)
- `last_link_up_time` (String)
- `link_downs` (Number)
- `mac_address` (String)
- `max_l2mtu` (Number)
- `mtu` (String)
- `name` (String)
- `running` (Boolean)
- `rx_byte` (Number)
- `rx_drop` (Number)
- `rx_error` (Number)
- `rx_packet` (Number)
- `slave` (Boolean)
- `tx_byte` (Number)
- `tx_drop` (Number)
- `tx_error` (Number)
- `tx_packet` (Number)
- `tx_queue_drop` (Number)
- `type` (String)


3 changes: 0 additions & 3 deletions docs/data-sources/ip_firewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ Read-Only:
- `out_interface_list` (String)
- `packet_mark` (String)
- `packet_size` (String)
- `packets` (Number)
- `passthrough` (Boolean)
- `per_connection_classifier` (String)
- `port` (String)
Expand Down Expand Up @@ -210,7 +209,6 @@ Read-Only:
- `out_interface_list` (String)
- `packet_mark` (String)
- `packet_size` (String)
- `packets` (Number)
- `per_connection_classifier` (String)
- `port` (String)
- `priority` (Number)
Expand Down Expand Up @@ -286,7 +284,6 @@ Read-Only:
- `out_interface_list` (String)
- `packet_mark` (String)
- `packet_size` (String)
- `packets` (Number)
- `per_connection_classifier` (String)
- `port` (String)
- `priority` (Number)
Expand Down
1 change: 0 additions & 1 deletion docs/data-sources/ipv6_firewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Read-Only:
- `out_interface_list` (String)
- `packet_mark` (String)
- `packet_size` (String)
- `packets` (Number)
- `per_connection_classifier` (String)
- `port` (String)
- `priority` (Number)
Expand Down
7 changes: 0 additions & 7 deletions docs/data-sources/system_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ data "routeros_system_resource" "data" {}
- `build_time` (String)
- `cpu` (String)
- `cpu_count` (Number)
- `cpu_frequency` (Number)
- `cpu_load` (Number)
- `factory_software` (String)
- `free_hdd_space` (Number)
- `free_memory` (Number)
- `id` (String) The ID of this resource.
- `platform` (String)
- `total_hdd_space` (Number)
- `total_memory` (Number)
- `uptime` (String)
- `version` (String)
- `write_sect_since_reboot` (Number)
- `write_sect_total` (Number)


10 changes: 5 additions & 5 deletions docs/resources/tool_bandwidth_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

## Example Usage
```terraform
resource "routeros_tool_bandwidth_server" "test" {
enabled = true
authenticate = false
max_sessions = 100
allocate_udp_ports_from = 2000
resource "routeros_tool_bandwidth_server" "test" {
enabled = true
authenticate = false
max_sessions = 100
allocate_udp_ports_from = 2000
}
```

Expand Down
63 changes: 6 additions & 57 deletions routeros/datasource_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routeros

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -12,7 +13,11 @@ func DatasourceInterfaces() *schema.Resource {
Schema: map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface"),
MetaId: PropId(Id),

MetaSkipFields: PropSkipFields(
"fp_rx_byte", "fp_rx_packet", "fp_tx_byte", "fp_tx_packet", "link_downs",
"rx_byte", "rx_drop", "rx_error", "rx_packet", "tx_byte",
"tx_drop", "tx_error", "tx_packet", "tx_queue_drop",
),
KeyFilter: PropFilterRw,
"interfaces": {
Type: schema.TypeList,
Expand All @@ -39,22 +44,6 @@ func DatasourceInterfaces() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"fp_rx_byte": {
Type: schema.TypeInt,
Computed: true,
},
"fp_rx_packet": {
Type: schema.TypeInt,
Computed: true,
},
"fp_tx_byte": {
Type: schema.TypeInt,
Computed: true,
},
"fp_tx_packet": {
Type: schema.TypeInt,
Computed: true,
},
"l2mtu": {
Type: schema.TypeInt,
Computed: true,
Expand All @@ -67,10 +56,6 @@ func DatasourceInterfaces() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"link_downs": {
Type: schema.TypeInt,
Computed: true,
},
"mac_address": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -92,46 +77,10 @@ func DatasourceInterfaces() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"rx_byte": {
Type: schema.TypeInt,
Computed: true,
},
"rx_drop": {
Type: schema.TypeInt,
Computed: true,
},
"rx_error": {
Type: schema.TypeInt,
Computed: true,
},
"rx_packet": {
Type: schema.TypeInt,
Computed: true,
},
"slave": {
Type: schema.TypeBool,
Computed: true,
},
"tx_byte": {
Type: schema.TypeInt,
Computed: true,
},
"tx_drop": {
Type: schema.TypeInt,
Computed: true,
},
"tx_error": {
Type: schema.TypeInt,
Computed: true,
},
"tx_packet": {
Type: schema.TypeInt,
Computed: true,
},
"tx_queue_drop": {
Type: schema.TypeInt,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
Expand Down
2 changes: 2 additions & 0 deletions routeros/datasource_ip_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func DatasourceIPFirewall() *schema.Resource {
- rules (aka filter)
`,
Schema: map[string]*schema.Schema{
MetaSkipFields: PropSkipFields("packets"),

"address_list": getIPFirewallAddrListSchema(),
"mangle": getIPFirewallMangleSchema(),
"nat": getIPFirewallNatSchema(),
Expand Down
4 changes: 0 additions & 4 deletions routeros/datasource_ip_firewall_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ func getIPFirewallFilterSchema() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"packets": {
Type: schema.TypeInt,
Computed: true,
},
"packet_mark": {
Type: schema.TypeString,
Computed: true,
Expand Down
4 changes: 0 additions & 4 deletions routeros/datasource_ip_firewall_mangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ func getIPFirewallMangleSchema() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"packets": {
Type: schema.TypeInt,
Computed: true,
},
"packet_mark": {
Type: schema.TypeString,
Computed: true,
Expand Down
5 changes: 0 additions & 5 deletions routeros/datasource_ip_firewall_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ func getIPFirewallNatSchema() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"packets": {
Type: schema.TypeInt,
Computed: true,
},
"packet_mark": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -216,7 +212,6 @@ func getIPFirewallNatSchema() *schema.Schema {
Type: schema.TypeInt,
Computed: true,
},

"routing_mark": {
Type: schema.TypeString,
Computed: true,
Expand Down
2 changes: 2 additions & 0 deletions routeros/datasource_ipv6_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func DatasourceIPv6Firewall() *schema.Resource {
- rules (aka filter)
`,
Schema: map[string]*schema.Schema{
MetaSkipFields: PropSkipFields("packets"),

"rules": getIPv6FirewallFilterSchema(),
},
}
Expand Down
4 changes: 0 additions & 4 deletions routeros/datasource_ipv6_firewall_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ func getIPv6FirewallFilterSchema() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"packets": {
Type: schema.TypeInt,
Computed: true,
},
"packet_mark": {
Type: schema.TypeString,
Computed: true,
Expand Down
32 changes: 4 additions & 28 deletions routeros/datasource_system_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ func DatasourceSystemResource() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/system/resource"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(
"cpu_frequency", "cpu_load", "free_hdd_space", "free_memory",
"uptime", "write_sect_since_reboot", "write_sect_total",
),
"architecture_name": { // Sample = architecture-name: "x86_64"
Type: schema.TypeString,
Computed: true,
Expand All @@ -30,26 +34,10 @@ func DatasourceSystemResource() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"cpu_frequency": { // Sample = cpu-frequency: "2396"
Type: schema.TypeInt,
Computed: true,
},
"cpu_load": { // Sample = cpu-load: "3"
Type: schema.TypeInt,
Computed: true,
},
"factory_software": { // Sample = factory-software: "7.1"
Type: schema.TypeString,
Computed: true,
},
"free_hdd_space": { // Sample = free-hdd-space: "74567680"
Type: schema.TypeInt,
Computed: true,
},
"free_memory": { // Sample = free-memory: "393805824"
Type: schema.TypeInt,
Computed: true,
},
"platform": { // Sample = platform: "MikroTik"
Type: schema.TypeString,
Computed: true,
Expand All @@ -62,22 +50,10 @@ func DatasourceSystemResource() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"uptime": { // Sample = uptime: "21h43m21s"
Type: schema.TypeString,
Computed: true,
},
"version": { // Sample = version: "7.10 (stable)"
Type: schema.TypeString,
Computed: true,
},
"write_sect_since_reboot": { // Sample = write-sect-since-reboot: "6936"
Type: schema.TypeInt,
Computed: true,
},
"write_sect_total": { // Sample = write-sect-total: "6936"
Type: schema.TypeInt,
Computed: true,
},
}

return &schema.Resource{
Expand Down
12 changes: 12 additions & 0 deletions routeros/mikrotik_serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ func MikrotikResourceDataToTerraformDatasource(items *[]MikrotikItem, resourceDa
var dsItems []map[string]interface{}
// System resource have an empty 'resourceDataKeyName'.
var isSystemDatasource bool = (resourceDataKeyName == "")
var skipFields map[string]struct{}

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

// Checking the schema.
if !isSystemDatasource {
Expand Down Expand Up @@ -598,6 +603,13 @@ func MikrotikResourceDataToTerraformDatasource(items *[]MikrotikItem, resourceDa

// field-name => field_name
terraformSnakeName := KebabToSnake(mikrotikKebabName)

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

if _, ok := s[terraformSnakeName]; !ok {
// For development.
//panic("[MikrotikResourceDataToTerraformDatasource] the field was lost during development.: " + terraformSnakeName)
Expand Down