tofkamp / Routeros_datasource_generator

Sample and generate datasource code for terraform/OpenToFu provider Routeros
GNU General Public License v3.0
0 stars 0 forks source link

/system/resource format #1

Open vaerh opened 10 months ago

vaerh commented 10 months ago

The output file format should be as in the example below. I need to move some changes to the main branch for it to work correctly.

package routeros

// Script generated from sampled device MikroTik 7.10 (stable) on CHR QEMU-x86_64

import (
    "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DatasourceSystemResource() *schema.Resource {
    resSchema := map[string]*schema.Schema{
        MetaResourcePath: PropResourcePath("/system/resource"),
        MetaId:           PropId(Id),
        "architecture_name": { // Sample = architecture-name: "x86_64"
            Type:     schema.TypeString,
            Computed: true,
        },
        "board_name": { // Sample = board-name: "CHR"
            Type:     schema.TypeString,
            Computed: true,
        },
        "build_time": { // Sample = build-time: "Jun/15/2023 05:17:29"
            Type:     schema.TypeString,
            Computed: true,
        },
        "cpu": { // Sample = cpu: "QEMU"
            Type:     schema.TypeString,
            Computed: true,
        },
        "cpu_count": { // Sample = cpu-count: "4"
            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,
        },
        "total_hdd_space": { // Sample = total-hdd-space: "93564928"
            Type:     schema.TypeInt,
            Computed: true,
        },
        "total_memory": { // Sample = total-memory: "469762048"
            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{
        ReadContext: DefaultSystemDatasourceRead(resSchema),
        Schema:      resSchema,
    }
}
tofkamp commented 10 months ago

Solved, but where do I have to put the reference to the filenames/function ? Also in provider.go, or somewhere else ? Introduced cache response from routeros, but missed the sample_id of the switch... Cache is for generating datasource go code, of hardware types you do not own, or have no access to any more. Example /system/routerboard

tofkamp commented 10 months ago

I made some improvements, but while searching for a list of all mikrotik commands, I found the following: https://www.hashicorp.com/blog/terraform-provider-code-generation-now-in-tech-preview https://forum.mikrotik.com/viewtopic.php?p=859379&hilit=openapi https://tikoci.github.io/restraml/routeros-openapi3.json

vaerh commented 10 months ago

Interesting information, thank you! Code generation for the framework is not suitable in our case, as the provider uses the SDK that came before it.