inwx / terraform-provider-inwx

INWX Terraform Provider plugin for Terraform
MIT License
19 stars 5 forks source link

Wrong type for `id` when modifying or destroying a `nameserver_record` resource #7

Closed ygabuev closed 1 year ago

ygabuev commented 1 year ago

Hello!

I am getting errors when trying to modify the inwx_nameserver_record resource that was created by using this plugin. The error implies that the id parameter that is sent to the INWX API doesn't have the correct type, which should be int or maybe an array of ints for some cases.

My versions are

[~/terraform_project] terraform version
Terraform v1.3.9
on linux_amd64
+ provider registry.terraform.io/inwx/inwx v1.2.0

To reproduce, do the following. We create a CNAME record for hello.domain.com with value example.org. 1) Have a configuration similar to this:

provider "inwx" {
  username = "user@domain.com"
  password = "password"
}

resource "inwx_nameserver_record" "record" {
  domain  = "domain.com"
  type    = "CNAME"
  name    = "hello"
  content = "example.org"
}

2) Run terraform apply, verify that the record is created. 3) Modify the record resource or remove it from configuration, run terraform apply again.

I am getting the following error when destroying the resource:

inwx_nameserver_record.record: Destroying... [id=domain.com:1012250634]
╷
│ Error: Could not delete nameserver record
│
│ API response not status code 1000 pr 1001. Got response:
│ {"code":2005,"msg":"Parameter value syntax error","reason":"The given parameter
│ value for 'id' does not match the expected parameter type
│ 'int'","reasonCode":"The given parameter value for 'id' does not match the
│ expected parameter type 'int'"}

When changing the name (suggests an in-place update):

inwx_nameserver_record.record: Modifying... [id=domain.com:1012250634]
╷
│ Error: Could not update nameserver record
│
│   with inwx_nameserver_record.record,
│   on main.tf line 792, in resource "inwx_nameserver_record" "record":
│  792: resource "inwx_nameserver_record" "record" {
│
│ API response not status code 1000. Got response: {"code":2005,"msg":"Parameter
│ value syntax error","reason":"The given parameter value for 'id' does not match
│ the expected parameter type 'array_int'","reasonCode":"The given parameter value
│ for 'id' does not match the expected parameter type 'array_int'"}

When changing the content, the error message is that same as when changing the name.

Thank you!

ygabuev commented 1 year ago

It seems to me that this is the result of a bug in the code - when modifying a resource, the client doesn't process the id field that is stored in the resource state and sends the id as domain.com:12345678 instead of 12345678.