Skip to content

Conversation

orgads
Copy link
Contributor

@orgads orgads commented Apr 21, 2025

This PR includes 3 features in read_search, and 2 other changes, which are required for supporting voxbone api.

read_search features:

  • Support id_attribute
  • Support {id} substitution also for search_value in read_search
  • Support object_wrap

Other changes:

  • Support slash separator for ignore_changes_to
  • Strip null values when comparing read output if they're not set in the input.

Some providers use a different notation for the object on create/update and on read.

Full example for Voxbone voiceuri api follows.

Sample PUT request:

PUT /configuration/voiceuri

Data:

{
  "voiceUri": {
    "voiceUriProtocol": "SIP",
    "uri": "[email protected]",
    "description": "desc"
  }
}

Response is the same, but with voiceUriId in voiceUri.

GET sample:

GET /configuration/voiceuri/1234

{
  "voiceUris": [
    {
      "voiceUriId": 1234,
      "backupUriId": null,
      "backupUri": null,
      "voiceUriProtocol": "SIP",
      "uri": "[email protected]",
      "description": "desc"
    }
  ],
  "resultCount": 1
}

Notice that read doesn't have an internal voiceUri in voiceUris array.

Sample provider configuration:

provider "restapi" {
  uri                   = "https://api.voxbone.com/v1"
  create_method         = "PUT"
  update_method         = "PUT"
  create_returns_object = true
  write_returns_object  = true
}

resource "restapi_object" "voxbone_voice_uri" {
  path         = "/configuration/voiceuri"
  id_attribute = "voiceUri/voiceUriId"
  ignore_changes_to = ["voiceUri/voiceUriId"]

  read_search = {
    results_key = "voiceUris"
    search_key  = "voiceUriId"
    search_value = "{id}" # Support for this substitution is new
    id_attribute = "voiceUriId" # New
    object_wrap = "voiceUri" # New
  }

  data = jsonencode({
    voiceUri = {
      uri              = "[email protected]"
      voiceUriProtocol = "SIP"
      description      = "desc"
    }
  })
}

orgads added 5 commits April 21, 2025 22:10
This is the notation all over the provider. Keep dot for backward
compatibility.
Some providers use a different notation for the object on create/update
and on read. Allow specifying id_attribute for read.

For example, voiceuri in voxbone accepts this as input:
{
  "voiceUri": {
    "uri": "...",
    "description": "..."
  }
}

But in read, it returns:
{
  "voiceUris": [
    {
      "voiceUriId": 1743102,
      "uri": "...",
      "description": "..."
    }
  ]
}

Notice that read doesn't have an internal voiceUri in voiceUris array.
If they're not set in the input.
Can be useful for matching the expected data against the read value when
extra wrapping is needed.

For example, voiceuri in voxbone accepts this as input:
{
  "voiceUri": {
    "uri": "...",
    "description": "..."
  }
}

But in read, it returns:
{
  "voiceUris": [
    {
      "voiceUriId": 1743102,
      "uri": "...",
      "description": "..."
    }
  ]
}

Notice that read doesn't have an internal voiceUri in voiceUris array.

Usage example:
  read_search = {
    object_wrap = "voiceUri"
  }
@orgads
Copy link
Contributor Author

orgads commented Apr 21, 2025

I tried to write acceptance tests, but couldn't get it to work. Some guidance can be useful :)

I can split the separator commit to a separate PR if you prefer that. It's unrelated to the rest, just did it for consistency.

The id substitution can also be separated if you wish.

@orgads
Copy link
Contributor Author

orgads commented May 5, 2025

ping?

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

Successfully merging this pull request may close these issues.

1 participant