magodo/terraform-provider-restful

data.restful_resource.output_attrs gjson filter is not working as expected on the returned attributes.

LaurentLesle opened this issue · 2 comments

Scenario 1 - The following example is working

data "restful_resource" "policy_definitions" {
  id = format("providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Authorization/policyDefinitions", var.root_id)
  query = {
    api-version = ["2021-06-01"]
    "$filter" = ["policyType eq 'Custom'"]
    "$top" = ["1"]
  }
  output_attrs = [
    "value"
  ]
}

returns as expected the value attribute:
image

Scenario 2 - Want to retrieve only id and name

data "restful_resource" "policy_definitions" {
  id = format("providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Authorization/policyDefinitions", var.root_id)
  query = {
    api-version = ["2021-06-01"]
    "$filter" = ["policyType eq 'Custom'"]
    "$top" = ["1"]
  }
  output_attrs = [
    "value.#.id",
    "value.#.name"
  ]
}

image

The "jsondecode(data.restful_resource.policy_definitions.output)" does not return the expected structure of the object.

Expected result:

Changes to Outputs:
  + policy_definitions = [
          + {
              + id         = "/providers/Microsoft.Management/managementGroups/xxxxx/providers/Microsoft.Authorization/policyDefinitions/Deploy-Diagnostics-EventGridTopic"
              + name       = "Deploy-Diagnostics-EventGridTopic"
            }
          ]
magodo commented

@LaurentLesle Would you mind test your use case based on #70?

Yes I can confirm it is now working
image