-
Notifications
You must be signed in to change notification settings - Fork 29
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
Code generation #150
Code generation #150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for revamping this and I'm very excited to have this capability soon! I haven't reviewed everything yet (inner part of the code generation to go still).
I should be able to get through the rest of it this week. I intend to go through workflow end to end as I review the rest of this as well. I think I need to see it in action in order to effectively review the more involved parts of this change.
I tried out this PR against the client and terraform test changes in #153. I didn't get completely through that testing, but I added comments for the things I uncovered so far. From performing that testing, it made me wonder if we could test that the output of It would be very useful to be able to add unit tests for a give struct definition to ensure things like |
fix resource name case, use Field's type name for UseStateForUnknown() fix func name in template
@ddelnano I addressed all the comments in the latest commits.
To fix types issues, I want to introduce some generic function that uses reflection, so it could be properly tested and just used in code generation. To wrap-up: my intention is to ease the creation of new resources (by auto-generation boilerplate). Once we have enough use cases, we can proceed with enhancements. |
Yep, completely understand that this is meant to ease the creation of the boilerplate. The current implementation lgtm. Sorry for the long turn around time on the latest review 🚢 |
Closes #47
This PR replaces #104.
Complete before merge:
[ ] errors typing(don't have a clear vision, so skipping atm)What is the value of this PR?
It introduces new tool
mikrotik-codegen
, that supportscodegen
struct tag to generate Terraform resource based of struct definition inclient/
file.The main purpose of this tool is to provide a fast and easy way to start working on new resource.
How to use new feature?
Example usage might look like:
with further code generation:
$ go run ./cmd/mikrotik-codegen -src client/resource.go -struct MikrotikResource > mikrotik/resource_new.go
Next steps
As further improvement for this codebase, I see these useful features:
client
API resource as well (based on struct definition only).... -only={client,client_test,terraform_resource,terraform_test}