davidji99 / terraform-provider-split

Terraform Split provider
https://registry.terraform.io/providers/davidji99/split/latest
Mozilla Public License 2.0
23 stars 8 forks source link

Type error on split tags #114

Closed bulju closed 1 year ago

bulju commented 1 year ago

Hi there,

I'm facing issues when importing split_split, when the split has tags.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

HerokuX Provider Version

Terraform v1.3.2
on darwin_arm64
+ provider registry.terraform.io/davidji99/split v0.6.2
+ provider registry.terraform.io/hashicorp/aws v4.8.0

Note: I've tested with split v0.7.0, and I'm getting another error, and I will also put a solution in place for that.

Affected Resource(s)

Terraform Configuration Files

resource "split_split" "this" {
  for_each        = var.splits
  workspace_id    = each.value.workspace
  traffic_type_id = each.value.traffic_type
  name            = each.value.name
  description     = each.value.description
}

splits = {
  1 = {
    name          = "name"
    description   = "description"
    workspace     = "workspace_id"
    traffic_type  = "traffic_type_id"
  },

  2 = {
    name          = "name"
    description   = "description"
    workspace     = "workspace_id"
    traffic_type  = "traffic_type_id"
  },
}

Expected Behavior

What should have happened? The split should be imported

Actual Behavior

What actually happened? Terraform crashed because of a type error.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create a split containing tags
  2. Create the terraform code to import it
  3. terraform import <resource_name> <workspace_id>:<split_id>

Important mentions

Tags is being defined as a list of strings, but the response from the API is returning a list of key/value, as I detail:

> curl -X GET \
  -H 'Content-Type:application/json' \
  -H 'Authorization: Bearer <redacted>' \
  https://api.split.io/internal/api/v2/splits/ws/<redacted>/<redacted>
{"id":"<redacted>","name":<redacted>","description":"<redacted>","trafficType":{"id":"<redacted>","name":"<redacted>"},"creationTime":1604662508084,"tags":[{"name":"<redacted>"}],"owners":[{"id":"<redacted>","type":"<redacted>"},{"id":"<redacted>","type":"<redacted>"}]}%  
bulju commented 1 year ago

Hi @davidji99 , I'll work on a solution for this, and also add a missing check in checkRateLimit, which should check if response.statusCode is not empty (I got invalid memory address or nil pointer dereference) Probably tomorrow I'll raise a PR about this 😄

davidji99 commented 1 year ago

Thanks!