-
Notifications
You must be signed in to change notification settings - Fork 61
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
Generate datasource code ? #278
Comments
no interesting for anyone, so I close it |
I apologize for such a long response! I use an idea similar to yours in part when adding resources. REST is used to request data (to check if the schema is filled correctly). From Wiki MT, data is extracted that describes the future schema. And a script is used to generate a skeleton that requires further validation. You can take a look #161 @maksym-nazarenko made such a code generator in a parallel project, but I haven't looked at it to see if it's applicable here. If you have any parts of the finished code I would be interested to see them. |
@vaerh our code-generator relies on the |
Maksym, thanks for the answer! |
@vaerh the issue is closed: ddelnano/terraform-provider-mikrotik#145 Maybe, we don't use functionality you mentioned, so it is not visible to us yet 😄 |
@maksym-nazarenko Of course working with all the data at work is just fine, but some points complicate development: impossibility of DiffSuppress as in SDK, impossibility to change data when saving to state file, very verbose validators, etc. |
yeah, missing |
That's the secret knowledge you need to remember 😎 Unfortunately some trivial things present in the SDK have to be implemented manually. Let's hang on until Hashi will not give up back support for old providers. I hope it will be not soon. |
I wanted to contribute to this project, but I can not write go, but I can copy/past it. I have made a python script to retrieve a JSON-sample from a mikrotik switch command, and generate a working datasource-go file. I tested it with "/ip/arp" and "/certificate". These mikrotik command's produce a list of objects. To generate datasource-go-code for singe object/dict samples, I am looking for an example with just one object/dict (eg. ./system/resource), so I can generate those also. If that succeeds, I will make some documentation for every datasource I make/generate. |
Ok, I need to see if there will be any problems when implementing data sources for system resources and will write a post. P. S. You can add the pythoncode in your Gist and provide a link or include in the post between pairs of three backquotes ``` |
I put my python code in my own repository https://github.com/tofkamp/Routeros_datasource_generator/tree/main |
Looks good. |
I have already a linux server and a CHR mikrotik switch running. I needed it to get a sample, in order to generate the code. On my work I have access to real mikrotik switches (routerboard). terraform {
required_providers {
routeros = {
source = "terraform-routeros/routeros"
}
}
}
provider "routeros" {
#alias = "bh1-k1-sw1"
hosturl = "https://bh1-k1-sw1.home.arpa"
username = "admin"
password = "admin"
ca_certificate = var.ca_certificate_path
insecure = false
}
data "routeros_ip_arps" "arps" {}
output "mikrotik_arps" {
description = "all known arps"
value = data.routeros_ip_arps.arps.iparps
}
data "routeros_certificates" "certs" {}
output "mikrotik_certificates" {
description = "all installed certificates"
value = data.routeros_certificates.certs.certificates
} |
That's great! Are you using any kind of IDE? Or is all debugging done in the console? |
I've tested the ARP records output option and there's something I want to do: since the main data field doesn't make any sense yet, I suggest calling it "data". data "routeros_ip_arp" "arp_records" {}
output "mikrotik_arp" {
description = "all known arp"
value = data.routeros_ip_arp.arp_records.data
} |
I changed it to 'data'. In the datasource_ip_routes it is not called "data". Which is an inconsistency. It is a choice. |
I only tested ARP. There are two ways to run it, either with the built-in tester in VSCode/Goland/etc. or with a command in the console. Which one should I describe? ... but a little later |
Is this still relevant ? |
And why not? |
I happen to have closed that issue. I'm gonna open it up. Maybe someone will need it. |
I don't have a lot of knowledge about the inner works of a mikrotik switch, but I have thought of something and wonder if it is possible.
Browsing through your go-code, I noticed that the datasource-interfaces.go is almost a copy of the output of the command: "curl -k -u admin:password https:///rest/interface/ether1".
I am not a go programmer, but I can read it. I can program in python. Would it be an idea we make something like this:
Because this is all done in code, it is easy to repeat it on a new firmware version of ROS. If there are schema changes between firmware version, it can be detected.
If the above is possible, is it also possible to generate terraform resource go-code automatically ?
If a human enriches the schema which tells if a field/attribute is mandatory,optional or readonly. Can it be possible to generate go-code for terraform resources ? Or even documentation, if a human provides some descriptive text about a field of structure ?
What do you think about this idea ?
The text was updated successfully, but these errors were encountered: