"Adding a new resource type" in readme.md file is confusing
Closed this issue · 3 comments
In the readme.md file there is a section called "### Adding a new resource type" which has many steps. Step 3 says "3. Add the resource name along with the schema method to the ResourcesMap
found in provider.go
. This will make the resource available to the plugin." but there is no list of resources or schemas in the ResourcesMap in the provider.go file (it looks to me like it finds all of them automatically). But since I didn't do that step my resource is not available to the plugin. I get "Error: string genesyscloud_xxxx not in slice" So is the readme.md file wrong and I don't need to do that step or do I just not understand what it is saying?
Hi Jerry
Thanks for raising this issue. The docs are outdated so I've created a ticket to update them.
Here is a quick description that hopefully will make things clearer for you:
- Create new package inside
genesyscloud
with the following files:resource_genesyscloud_{resource_name}_schema.go
- The file containing the schema definition for the resource, data source, and exporter. It also contains a constant variable which defines the resource name, and a public function calledSetRegistrar
, which will be called from outside the package to register the resource with the provider.resource_genesyscloud_{resource_name}.go
- Contains the create, read, update and delete functions for the resource (the functions that are referenced in the schema definition.) It also contains the getAll function to be used by the exporter. If you have a few helper functions present in this file, that is fine, but if there are more than 1-2 helper functions you should create aresource_genesyscloud_{resource_name}_utils.go
to contain the business logic.resource_genesyscloud_{resource_name}_test.go
- Contains the resource tests.data_source_genesyscloud_{resource_name}.go
- This file contains all of the data source logic for a resource. The data source should call any Genesys Cloud APIs through its API proxy class. All functions and variables in this class should be private.data_source_genesyscloud_{resource_name}_test.go
- Contains the data source tests.genesyscloud_{resource_name}_proxy.go
- This contains all of the API logic for interacting with the Genesys Cloud APIs. This is meant to be an isolated layer from Terraform, so know Terraform objects should be passed back and forth to this code. All functions and variables in this class should be private.genesyscloud_{resource_name}_init_test.go
- This file contains all of the logic needed to initialize a test case for your resource. All functions and variables in this class should be private.
- Add a new folder for the resource and data source under the
/examples
folder. An exampleresource.tf
file for the resource should be added to the folder along with anapis.md
file listing all of the APIs the resource uses. To generate or update documentation, rungo generate
. - Import your package to
main.go
at the root of the project and, from theregisterResources
function, call the SetRegistrar function passing in theregInstance
variable.
If you want to go off of an example, we recommend using the external contacts package. It follows the format we're going for perfectly.
Hope this helps
-Charlie
I am trying to make an external organizations resource and I did copy the external contacts one to start it.
The details above are really helpful - thank you.
We have a project that might help speed up your development a little. This resource https://github.com/MyPureCloud/cxascode-resource-generator can generate boilderplate code for your resource, all details on how to use it are in it's README. Just bear in mind that the code won't be perfect and will most likely require some small changes.
Regards,
Declan