Closed maksym-nazarenko closed 1 year ago
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 go run ./cmd/mikrotik-codegen
results code that compiles. The parser_test
seems to already leverage the go parser and AST, so maybe that wouldn't be too difficult to do?
It would be very useful to be able to add unit tests for a give struct definition to ensure things like bool
and int64
types use the correct ${TYPE}planmodifier.UseStateForUnknown()
. The verification I did so far was time consuming, so being able to have an end to end test for that would be useful. Curious to hear your thoughts on this.
@ddelnano I addressed all the comments in the latest commits. however, I would like to emphasize, that current implementation is not intended to be fully automatic. I see at least these issues:
Computed
field, UseStateForUnknown()
is not used, so the import also should be skipped). I have something in my head, but I don't think I can implement it right away due to lack of time.int
field, the generator should wrap it in int64()
and vice-versa for modelTo...()
and ...ToModel()
funcs.MikrotikDuration
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 :ship:
Closes #47
This PR replaces #104.
Complete before merge:
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:
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}