Skip to content
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

Support for simple listable data source #328

Open
2 tasks
arjunrajinstaclustr opened this issue Feb 24, 2022 · 2 comments
Open
2 tasks

Support for simple listable data source #328

arjunrajinstaclustr opened this issue Feb 24, 2022 · 2 comments

Comments

@arjunrajinstaclustr
Copy link

arjunrajinstaclustr commented Feb 24, 2022

Is your feature request related to a problem?

As a user of this plugin, I would like to define my APIs to return a single object containing a list of results as my data source so that I do not have to perform any hacky workarounds on my API to conform with the plugin's requirements.

Describe the solution you'd like

Non-CRUD data sources should be created for any GET endpoint that returns a single object, not just ones that return an array.

Acceptance criteria

  • Data sources are created from all GET endpoints that return a single object.
  • A meta attribute is introduced to exclude certain GET endpoints from being converted to data sources.

A data source should be creatable for the following API response for example -

{
  "id": "some_id",
  "results": [
    {
      "myProperty": "myValue"
    }
  ]
}

Describe alternatives you've considered

The alternative has been to return a single item array on my GET list requests.

Example -

[
  {
    "id": "some_kind_of_id",
    "results": [
      {
        "myProperty": "myValue"
      }
    ]
  }
]

As you can see, the above workaround is a bit hacky. Users using my API directly will be fairly confused why I've got such a strange structure - with an array containing a single object containing an array.

If I don't wrap my response in such a manner and directly return my list of results I get the following error - Error: your query returned contains more than one result. Please change your search criteria to make it more specific because the plugin only wants one result (I think it is so that it can set the ID of the data source).

Additional context

Bonus points if an id/x-terraform-id doesn't have to be defined on the API response. I'm not sure Terraform even meaningfully uses the ID of a data source so you could even just set it to some random GUID.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly:

  • I have added a corresponding label (feature request) to the issue (right side menu)
  • I have added this issue to the 'API Terraform Provider' GitHub project (right side menu)
@x7airworker
Copy link

Any updates on this issue?

@pl4nty
Copy link

pl4nty commented Mar 13, 2023

Wrapped responses are common, I'm surprised this hasn't been implemented (unless there's a workaround?). I'm using a public API so can't just change its responses:

{
  "success": true,
  "data": [
    {
      "id": 1
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants