This guide will help you add a new resource to an existing source plugin (a.k.a. "provider", such as AWS, GCP, Azure or K8s). If you wish to support a completely new cloud platform, first see creating a new plugin.
If the service to which the resource belongs has not been used before in the plugin, there are a few steps that need to be done to configure it.
- Create the service interface in
client/services.go
- Don't forget to add the new service interface name to the go:generate comment.
- Add the service to the
Services
struct in theclient/client.go
- Init the service in the
initServices
function inclient/client.go
- Run
go generate client/services.go
to create a mock for your new service. This will updateclient/mocks/mock_\<service\>.go
automatically
If you get an error about not being able to find
mockgen
, runmake install-tools
to install it. If it still fails, runexport PATH=${PATH}:
go env GOPATH/bin
in you shell to set up yourPATH
environment properly You might need to update an existing client by runninggo get <path to client>@latest
and thengo mod tidy
We use code generation to generate the code from a source SDK. This functionality is provided by the CloudQuery plugin-sdk. It will read all the fields on a given struct and generate the necessary structures and transformations to load it into a destination database. The configuration is done via "recipe" files, contained in the codegen/recipes
directory for each source plugin.
The only code that needs to be written by you are the SDK calls to list or describe the resources. Such glue functions are called "resolvers".
Here are the general steps to follow:
- Find an appropriate Go SDK function that fetches the resource you are interested in.
- Note the type of the return type that contains the information you want to read. This will be passed to
codegen
via theStruct
property. - Create a new recipe file for the resource, if one does not exist already.
- Add the resource to the recipe file.
- Run
go run main.go
in thecodegen
directory. The generated table will be inplugins/source/<plugin>/resources/services/<service>/<resource>.go
. - To regenerate from updated config, re-run
go run main.go
from thecodegen
directory again. - Implement one or more resolver functions (as referenced by the generated file) in
plugins/source/<plugin>/resources/services/<service>/<resource>_fetch.go
. - Add a mock test for the resource in
plugins/source/<plugin>/resources/services/<service>/<resource>_mock_test.go
See the following guides for deep-dives into adding resources for specific source plugins: