Some information can be found in the docs for developing a new provider.
As a prerequisite, in aws-sdk-go-v2 ensure API calls exist to list/describe the desired resource, and make note of:
- to which aws service the resource belongs
- the schema of the returned object(s)
If the service to which the resource belongs has not been used before in cq-provider-aws, there are a few steps that need to be done to configure it.
- Create the service interface in client/services.go
- Add the service to the
Services
struct in the client/client.go - Init the service in the
initServices
function in client/client.go - Run
go generate client/services.go
to create a mock for your new service. This will update client/mocks/services.go automatically
- In client/services.go, update the service interface and add the method(s) that you will be using to fetch the data from the aws sdk.
- Run
go generate client/services.go
to create a mock for your new methods. This will update client/mocks/services.go automatically - Create a file under
resources/
that follows the pattern of<service>_<resource>
. - In that file, create a function that returns a
*schema.Table
- In resources/provider.go, add a mapping between the function you just created and the name of the resource that will be used in the config yml file.
- In client/config.go, add the key that you used in the map in the previous step to the config template
- Add a test in clients/mocks/mock_test.go for the resource following the existing examples
Now that the skeleton has been set up, you can start to actually implement the resource. This consists of two parts:
- Defining the schema
- Implementing resolver functions
It is recommended that you look at a few existing resources as examples and also read through the comments on the source code for the Table and Column implementations for details.
For noncomplex fields, the SDK can directly resolve them into Column
s for you, so all you need to do is specify the Name
and the Type
.
For complex fields or fields that require further API calls, you can defined your own Resolver
for the Column
.
A few important things to note when adding functions that call the AWS API:
- If possible, always use an API call that allows you to fetch many resources at once
- Take pagination into account. Ensure you fetch all of the resources