profile
viewpoint

Ask questionsUnable to perform DELETE: ID is not expanding, being seen as literal and getting Invalid resource

I've seen some related issues but nothing specifically talking about ID being seen as a literal string which appears to be what's happening to me...

From the terraform side: state, output are both good (other than being the string "_ref" rather than the results; "id": "_ref"): tfstate (sample):

      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "api_data": {
              "result": "map[_ref:networkcontainer/ZG5zLm5l...]"
            },
          "api_response": "{\n    \"result\": {\n        \"_ref\": \"networkcontainer/ZG5zLm5l...]"

I'm able to use the following to output and/or use as input for something else:

output "cidr" {
    value = jsondecode(restapi_object.network_container.create_response).result.network
}

output "raw_data" {
    value = restapi_object.network_container.create_response
}

But I'm not able to DELETE, tried a bunch of different combinations of including and not including a variety of id_attribute/object_id, *_paths, etc., and have seen a bunch of varying errors but say I'm using something like:

resource "restapi_object" "network_container" {
    path = "/networkcontainer"
    create_path = "/networkcontainer?_return_fields%2B=network,comment&_return_as_object=1"
    data = "{\"network\": \"func:nextavailablenetwork:100.100.0.0/15,1234-TEST,23\",\"comment\": \"1234-TEST-VPC\",\"network_view\": \"1234-TEST\"}"
    id_attribute = "_ref"
    object_id = "_ref"
    debug = true
}

if then issuing a terraform destroy I'll get back:

restapi_object.network_container: Refreshing state... [id=_ref]

Error: Unexpected response code '400': { "Error": "AdmConProtoError: Invalid reference: networkcontainer/_ref", 
  "code": "Client.Ibap.Proto", 
  "text": "Invalid reference: networkcontainer/_ref"
}

...where I would assume it would be what it should be networkcontainer/ZG5zLm5l... but for some reason, it would appear the ID is being seen as the literal string rather than the generated return data.

Similar to other related issues, if I don't include object_id I get an error Internal validation failed error.

Any help would be appreciated.

Mastercard/terraform-provider-restapi

Answer questions TryTryAgain

This was an issue with the id_attribute, needed "result/_ref" and took out object_id and it worked as expected. Woohoo!

useful!
source:https://uonfu.com/
Github User Rank List