FlexibleEngineCloud / terraform-provider-flexibleengine

Terraform flexibleengine provider
https://www.terraform.io/docs/providers/flexibleengine/
Mozilla Public License 2.0
30 stars 53 forks source link

[flexibleengine_elb_listener] tags management when no changes on the resource itself #680

Closed bsibaud closed 2 years ago

bsibaud commented 2 years ago

Terraform Version

Terraform v1.0.11 on linux_amd64

flexibleenginecloud/flexibleengine v1.26.0

Affected Resource(s)

Terraform Configuration Files

resource "flexibleengine_lb_listener_v2" "listener" {
  count           = var.deploy_trigger ? length(var.protocol_ports) : 0
  protocol        = var.protocol
  protocol_port   = var.protocol_ports[count.index]
  loadbalancer_id = flexibleengine_lb_loadbalancer_v2.elb[0].id
  tags            = var.tags # works without this line
}

(note: there are no "name" or "description" here)

Debug Output

"error_msg":"Invalid request body: Empty body '{}' is meaningless.","error_code":"SYS.0400"

Panic Output

N/A

Expected Behavior

Tags should be manageable even when no changes are performed on the lb_listener_v2 resource itself.

Actual Behavior

Tags can't be managed through Terraform IF there is no change on the lb_listener_v2 resource itself (because the first request will fails due to empty body, before even starting to add/remove tags)

I think the current tests in https://github.com/FlexibleEngineCloud/terraform-provider-flexibleengine/blob/master/flexibleengine/resource_flexibleengine_lb_listener_v2_test.go worked because there always is at least a "name" change at the same time. So the body is not empty during the first request.

Steps to Reproduce

Trying to add the first tag on a given flexibleengine_lb_listener_v2 resource (plan-target):

  # module.lb_public_bastion.flexibleengine_lb_listener_v2.listener[0] will be updated in-place
  ~ resource "flexibleengine_lb_listener_v2" "listener" {
        id                           = "(snip)"
      ~ tags                         = {
          + "billing" = "Infrastructure"
        }
        # (13 unchanged attributes hidden)
    }
Error: Error updating listener xxxxx: Bad request with: [PUT https://elb.eu-west-0.prod-cloud-ocb.orange-business.com/v3/xxxxx/elb/listeners/xxxxx], error message: {"error_msg":"Invalid request body: Empty body '{}' is meaningless.","error_code":"SYS.0400","request_id":"xxxxx"}

Terraform.log , request on the resource itself:

API Request Body:
 {
  "listener": {}
}

If the code is changed to add a new field "description" for example:

resource "flexibleengine_lb_listener_v2" "listener" {
  count           = var.deploy_trigger ? length(var.protocol_ports) : 0
  protocol        = var.protocol
  protocol_port   = var.protocol_ports[count.index]
  loadbalancer_id = flexibleengine_lb_loadbalancer_v2.elb[0].id
  tags            = var.tags
  description     = "tagged"
}

The new 'plan' is:

  # module.lb_public_bastion.flexibleengine_lb_listener_v2.listener[0] will be updated in-place
  ~ resource "flexibleengine_lb_listener_v2" "listener" {
      + description                  = "tagged"
        id                           = "(snip)"
      ~ tags                         = {
          + "billing" = "Infrastructure"
        }
        # (13 unchanged attributes hidden)
    }

Request on the resource itself:

API Request Body: {
  "listener": {
    "description": "tagged"
  }

Request to add the tag:

API Request Body: {
  "action": "create",
  "tags": [
    {
      "key": "billing",
      "value": "Infrastructure"
    }
  ]
}

Important Factoids

Requests go through a proxy. Test on Orange Cloud for Business / Flexible Engine, region eu-west-0

References

N/A

ShiChangkuo commented 2 years ago

@bsibaud thanks for reporting this problem. the provider manges tags with another API, so we have to add a judgment when only tags was changed.