Closed aneesfaraz closed 3 years ago
Hi, @aneesfaraz. This seems strange because I took another read of the code since I recall a bug in an older release that had applied to path/method overrides, but everything seems on the up-and-up.
Can you share your config and perhaps some debug output? The error you provide makes it look like the request is invalid (400
) rather than against the wrong location (404
).
Here is the config
resource "restapi_object" "logstream" {
path = "/${var.org}/_apis/audit/streams?daysToBackfill=30&api-version=6.1-preview.1"
destroy_path = "/${var.org}}/_apis/audit/streams/{id}?api-version=6.1-preview.1"
data = "{\"consumerInputs\": {\"EventGridTopicHostname\": \"https://xyz.eastus2-1.eventgrid.azure.net/api/events\", \"EventGridTopicAccessKey\": \"REPLACED\" }, \"consumerType\": \"AzureEventGrid\",\"createdTime\": \"2020-11-09T13:55:05.893Z\", \"displayName\": \"Test ADO Stream\", \"id\" : -1,\"status\": 1,\"statusReason\": \"Disabled by the system\",\"updateTime\": \"2020-11-09T13:55:05.893Z\" }"
}
I think whats the problem is its appending /{id} at the end of the url but its modifying that url due to which its not liking. I'm adding that destroy path so that it won't use the default thing but its not liking it.
Thanks, @aneesfaraz - sorry for the slow reply. Can you take a quick look at the debug logging output of the request that fails? Looking at the config pasted, it looks like you may have an extra }
character in the destroy_path (for var.org
). That could be the cause of the 400 error.
It's been a while since this issue has had any activity so I'm going to close it for now. Please feel free to reply if you have more info to share.
Hi. I had the same problem.
resource "restapi_object" "azure_devops_elastic_pool" {
path = "/_apis/distributedtask/elasticpools"
# GET
read_path = "/_apis/distributedtask/elasticpools/{id}?api-version=${local.apiVersion}"
# PUT
update_path = "/_apis/distributedtask/elasticpools/{id}?api-version=${local.apiVersion}"
# POST
create_path = "/_apis/distributedtask/elasticpools?poolName=${local.poolName}&authorizeAllPipelines=${local.authorizeAllPipelines}&autoProvisionProjectPools=${local.autoProvisionProjectPools}&projectId=${local.projectId}&api-version=${local.apiVersion}"
# DELETE
destroy_path = "/_apis/distributedtask/pools/{id}?api-version=${local.apiVersion}"
data = ".."
id_attribute = "elasticPool/poolId"
}
Error:
unexpected response code '400': {"$id":"1","innerException":null,"message":"Invalid api version string: \"7.1-preview.1/373\". Api version string must be in the format: {Major}.{Minor}[-preview[.{ResourceVersion}]].","typeName":"Microsoft.VisualStudio.Services.WebApi.VssInvalidApiResourceVersionException, Microsoft.VisualStudio.Services.WebApi","typeKey":"VssInvalidApiResourceVersionException","errorCode":0,"eventId":3000}
Constructed address:
2022-03-25T15:34:34.754+0100 [DEBUG] provider.terraform-provider-restapi_v1.16.1: 2022/03/25 15:34:34 api_client.go: method='GET', path='/_apis/distributedtask/elasticpools/373?api-version=7.1-preview.1/373', full uri (derived)='https://dev.azure.com/xxxxx/_apis/distributedtask/elasticpools/373?api-version=7.1-preview.1/373', data=''
Id is at the end
Solution: I had before
path = "/_apis/distributedtask/elasticpools"
Then I added this after first apply:
# GET
read_path = "/_apis/distributedtask/elasticpools/{id}?api-version=${local.apiVersion}"
# PUT
update_path = "/_apis/distributedtask/elasticpools/{id}?api-version=${local.apiVersion}"
I had to remove from the state that resource and run again and its working.
@DRuggeri Could you please reopen this issue because the problem is not solved. i have the config like:
resource "restapi_object" "service_hook" {
# provider = restapi.restapi_headers
path = "/_apis/hooks/subscriptions/{id}?api-version=7.1-preview.1"
# POST
create_path = "/_apis/hooks/subscriptions?api-version=7.1-preview.1"
update_path = "/_apis/hooks/subscriptions/{id}?api-version=7.1-preview.1"
destroy_path = "/_apis/hooks/subscriptions/{id}?api-version=7.1-preview.1"
}
and error: "Invalid api version string: \"7.1-preview.1/2b73390d-d68c-43b1-9a52-58ebaf301ed2\" it`s because when you create a resource and after trying to delete them he puts the id at the end of the URL, not in the correct path.
Try putting query_string = "api-version=7.1-preview.1"
and removing from the paths.
See https://registry.terraform.io/providers/Mastercard/restapi/latest/docs/resources/object
I want to use Microsoft Log Stream API and their deleted endpoint is different that api/{id}. I try to set destroy_path but still it doesn't like it and i'm getting this below error. Is there any way to override the destroy path.
https://docs.microsoft.com/en-us/rest/api/azure/devops/audit/streams/delete?view=azure-devops-rest-6.1
Error:
Error: Unexpected response code '400': {"$id":"1","innerException":null,"message":"Invalid api version string: \"6.1-preview.1/-1\". Api version string must be in the format: {Major}.{Minor}[-preview[.{ResourceVersion}]].","typeName":"Microsoft.VisualStudio.Services.WebApi.VssInvalidApiResourceVersionException, Microsoft.VisualStudio.Services.WebApi","typeKey":"VssInvalidApiResourceVersionException","errorCode":0,"eventId":3000}