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

Segment keys not created when title and comments are required #184

Closed squalliram closed 3 months ago

squalliram commented 5 months ago

Hi there,

Terraform Version

v.1.7.3

HerokuX Provider Version

Terraform v1.7.3 on darwin_arm64 provider registry.terraform.io/davidji99/split v0.12.3

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

Provided below

Copy-paste your Terraform configurations here

resource "split_workspace" "foobar" {
  name = "Terraform Test"
  require_title_comments = true
}

data "split_workspace" "foobar" {
  name = "Terraform Test"
}

resource "split_environment" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  name = "staging-canary"
  production = false
}

resource "split_traffic_type" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  name = "terraform"
}

data "split_traffic_type" "foobar" {
    workspace_id = data.split_workspace.foobar.id
    name = "terraform"
}

resource "split_split" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  traffic_type_id = data.split_traffic_type.foobar.id
  name = "my_terraform_split"
  description = "my terraform split description"
}

resource "split_split_definition" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  split_name = split_split.foobar.name
  environment_id = split_environment.foobar.id

  default_treatment = "treatment_123"
  treatment {
    name = "treatment_123"
    configurations = "{\"key\":\"value\"}"
    description = "my treatment 123"
  }
  treatment {
    name = "treatment_456"
    configurations = "{\"key2\":\"value2\"}"
    description = "my treatment 456"
  }

  default_rule {
    treatment = "treatment_123"
    size = 100
  }
  rule {
    bucket {
      treatment = "treatment_123"
      size = 100
    }
    condition {
      combiner = "AND"
      matcher {
        type = "EQUAL_SET"
        attribute = "test_string"
        strings = ["test_string"]
      }
    }
  }
}

resource "split_segment" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  traffic_type_id = data.split_traffic_type.foobar.id
  name = "terraform_segment"
  description = "description_of_my_terraform_segment"
}

resource "split_segment_environment_association" "foobar" {
    workspace_id = data.split_workspace.foobar.id
    environment_id = split_environment.foobar.id
    segment_name = split_segment.foobar.name
}

resource "split_environment_segment_keys" "foobar" {
    environment_id = split_environment.foobar.id
    segment_name = split_segment_environment_association.foobar.segment_name
    keys = ["mytestkey1", "mytestkey2"]
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: run-nea3BckLYRchxeVz-apply-log.txt

Expected Behavior

The segment should have been created for the respective environment with the keys mentioned with a title and comment.

Actual Behavior

The last resource call gave an error with the segment update call not having the title and comments available and failed to associate the keys on that segment.

Steps to Reproduce

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

  1. terraform plan
  2. terraform apply

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

davidji99 commented 4 months ago

Thanks for attaching the log output. From the output, the error is

400 {\"code\":400,\"message\":\"Comment/title combination invalid for workspace\",\"details\":\"\",

which is odd because the associated API doesn't accept comment/title. Perhaps, you can open a support ticket with Split to understand why the segments API is throwing an error regarding the workspace?

squalliram commented 4 months ago

Hello @davidji99 I checked this with our support team and the API does actually accept comment/title in this format below. I'll ask the team to update the API documentation to reflect that but the curl command for this is below.

curl -v -X PUT -H 'Content-Type:application/json' -d '{"keys":["id1", "id2", "id3"], "comment":"a comment", "title":"a title"}' -H 'Authorization: Bearer mer3vihxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' https://api.split.io/internal/api/v2/segments/<environment-id>/<segment-name>/uploadKeys

So, the JSON format should be:

{
    "keys": [
        "id1",
        "id2",
        "id3"
    ],
    "comment": "a comment",
    "title": "a title"
}

Can you please add support for title and comments within the segment update call?

davidji99 commented 4 months ago

@squalliram Should comment and title be required when uploading segment keys?