Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 3.02 KB

adding_a_new_resource.md

File metadata and controls

51 lines (32 loc) · 3.02 KB

Adding a new resource

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)

Setting up the service

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.

  1. Create the service interface in client/services.go
  2. Add the service to the Services struct in the client/client.go
  3. Init the service in the initServices function in client/client.go
  4. Run go generate client/services.go to create a mock for your new service. This will update client/mocks/services.go automatically

Setting up the resource

Skeleton

  1. 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.
  2. Run go generate client/services.go to create a mock for your new methods. This will update client/mocks/services.go automatically
  3. Create a file under resources/ that follows the pattern of <service>_<resource>.
  4. In that file, create a function that returns a *schema.Table
  5. 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.
  6. In client/config.go, add the key that you used in the map in the previous step to the config template
  7. Add a test in clients/mocks/mock_test.go for the resource following the existing examples

Implementation

Now that the skeleton has been set up, you can start to actually implement the resource. This consists of two parts:

  1. Defining the schema
  2. Implementing resolver functions

Defining the schema

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 Columns 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.

Implementing Resolver Functions

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