logzio / terraform-provider-logzio

Terraform provider for logz.io alerts, endpoints and users
Apache License 2.0
19 stars 17 forks source link

Errors apply on update of resource logzio_metrics_account #192

Closed michelmorin closed 10 hours ago

michelmorin commented 1 month ago

Getting errors on apply using resource logzio_metrics_account https://registry.terraform.io/providers/logzio/logzio/latest/docs/resources/metrics_account

Reproducible steps. From an existing metrics account in logzio, import the resource where xxxxx is the metrics account id terraform import metrics_account xxxxx

This above steps works and verify all the fields are populated in the state of account name, plan uts, authorized_account, account_token

Changing the value of the plant_uts causes errors running with:

Error: All attempts fail: │ #1: API call UpdateMetricsAccount failed with status code 400, data: {"errorCode":"METRICS_ACCOUNT/SUB_ACCOUNT_NOT_OWNED","message":"Sub account is not found for the owner account (948339). Reason: Account is not found (or not owned): [xxxxxx]","requestId":"172a0d40-1fbc-4b45-8b26-c1604b07537e","parameters":{"accountId":xxxxxx,"reason":"Account is not found (or not owned): [xxxxxx]"}}

The same happens in the UI using https://api-docs.logz.io/docs/logz/update-a-metrics-account when you provide account_name. When contacting support, this works when account_name is remove and only include plan_uts when updating, but it doesn't work with terraform as I believe all fields are passed

The same error occurs if I create a new Metrics Account using the resource, see example below, which is successful, but if I change the plan_uts from say 100 to 200, I get the same error

example resource "logzio_metrics_account" "metrics_account" { email = email@example.com account_name = METRICS_ACCOUNT_NAME plan_uts = 100 authorized_accounts = [] }

yotamloe commented 3 weeks ago

Hey @michelmorin Thanks for reporting this issue, we are investigating.

yotamloe commented 3 weeks ago

@michelmorin There is an issue with this public API endpoint. We are working on it

ralongit commented 1 week ago

Hello @michelmorin, we have applied changes to our API. Can you please check if the error still occurs?

michelmorin commented 1 week ago

@ralongit - I have tested and still getting the same error. Here is example resource I am using to reproduce

terraform { required_providers { logzio = { source = "logzio/logzio" version = "~> 1.15.0" } } }

provider "logzio" { api_token = "APITOKEN" region = "au" }

resource "logzio_metrics_account" "metrics_account" { email = "EMAIL" account_name = "TEST_AUTOMATION_ACCOUNT" plan_uts = 100 authorized_accounts = [] }

After above is created, I change the plan_uts property from 100 to 200 and get the following error, but the plan_uts did change

logzio_metrics_account.metrics_account: Modifying... [id=1174985] ╷ │ Error: All attempts fail: │ #1: API call UpdateMetricsAccount failed with status code 409, data: {"errorCode":"METRICS_ACCOUNT/SUB_ACCOUNT_NAME_NOT_UNIQUE","message":"Sub account with name (TEST_AUTOMATION_ACCOUNT) already exists on account","requestId":"5e854db5-96b2-4789-bae9-7ec820c9f4fa","parameters":{"name":"TEST_AUTOMATION_ACCOUNT"}}

If I change both the plan_uts to 200 and the account_name, then it no errors is produced. Changing the account name shouldn't be required to update the plan_uts

The other error, we are getting is with the use of authorized_accounts. We keep this as blank, then the plan_uts does change though with error, but if we created the account with the auhorized_account with a value which we would want so users can see this metric account, there is an error during change of plan_uts and noticed the plan_uts has not been modified in this case.

error: │ Error: All attempts fail: │ #1: API call UpdateMetricsAccount failed with status code 400, data: {"errorCode":"METRICS_ACCOUNT/SUB_ACCOUNT_NOT_OWNED","message":"Sub account is not found for the owner account (*******). Reason: Account is not found (or not owned): [****]","requestId":"44da996b-e348-4c61-afc1-8e93b23a6b6b","parameters":{"accountId":*****,"reason":"Account is not found (or not owned): [****]"}}

yotamloe commented 2 days ago

Hey @michelmorin We just published a new release: https://github.com/logzio/terraform-provider-logzio/releases/tag/v1.16.0 that should solve this issue. Can you try it?

michelmorin commented 12 hours ago

@yotamloe I have tested the version 1.16.0 logzio provider and everything worked without error. Thank you so much

yotamloe commented 10 hours ago

@michelmorin Thank you for reporting this bug. Closing this issue