-
Notifications
You must be signed in to change notification settings - Fork 2
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
🤖 auto-generate resources for Mondoo integrations #195
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Salim Afiune Maya <[email protected]>
59002ac
to
4150dbb
Compare
Nice step to auto-generate the integrations! If I understand the code right now, we would generate it only once. Do you think we can run this in the next step as a go generate task and replace all existing integrations with that approach as well? I would like to ensure integrations do not drift away over time. |
// {{.ResourceClassName}} options | ||
} | ||
|
||
func (m integration{{.ResourceClassName}}ResourceModel) GetConfigurationOptions() *mondoov1.{{.ResourceClassName}}ConfigurationOptionsInput { |
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.
For best practices, we should also add generated comments here so that its easier to understand what the methods are doing
"strings" | ||
"text/template" | ||
|
||
"github.com/fatih/structs" |
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.
We should not include unmaintained go modules.
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.
I couldn't find any other go module that does this. I we ok copying the code and NOT use the import?
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.
Would the alternative solution not to use mapstructure? github.com/go-viper/mapstructure/v2. In case we need to change the tags for mondoo-go, we need touch the templates here https://github.com/mondoohq/mondoo-go/blob/main/gen/gen.go#L260
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.
Good call! 🌟
} | ||
|
||
// Ensure the output directory exists | ||
outputDirPath := filepath.Join("gen", "generated") |
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.
Couldn't we create this directly in the directory the other integrations are in?
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.
not yet. still need some more work but we will ultimately write it in the right directory.
|
||
for k := range m { | ||
// TODO we know the type and the struct associated to the type, we need | ||
// to look it (the struct) and use the same `structs.Map(v)` to list all |
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.
Something reads strange to me.
Perhaps:
// to look it (the struct) and use the same `structs.Map(v)` to list all | |
// to look at it (the struct) and use the same `structs.Map(v)` to list all |
return err | ||
} | ||
// Create example main.tf | ||
err = os.WriteFile(filepath.Join(examplesDirPath, "main.tf"), mainDotTFTestFile(), 0644) |
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.
Same here: Could we generate this directly in the final directory?
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.
not yet. still need some more work but we will ultimately write it in the right directory.
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.
Is this something for a follow-up or do you want to include it in this PR?
return nil | ||
} | ||
|
||
var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)") |
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.
I'm not sure this works as expected. Wouldn't the .
also match an upper case letter?
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.
I think, I'm missing something here.
Could you please add a comment or a test case to show how this works?
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.
What would we need in this auto generate PR to also be able to generate the docs, like in https://github.com/mondoohq/terraform-provider-mondoo/pull/194/files#diff-f9f43e36f94b402f6ad590eef25f3da2adbf02034de08d64aeb834510e3159e9
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.
docs will be auto generated too
First iteration to a generator that create Terraform resources for Mondoo Integrations.
Most of our integrations are very similar and the only thing that changes are the
ConfigurationOptions
per integration type. This generator iterates over all possible config options and generates the following
file:
Once the resource is generated, we run our auto-generation of documentation, which created the docs
for this resource. Though, today I am writing the generated files to
gen/generated/
and the idea is thatwe can start copying the example from there and adapt quickly with the specific configuration options.
The Sentinel One integration was generated with this generator. #194
Next up, we need to code the full generation so that we write directly to
internal/
andexamples/
only.