segmentio / terraform-provider-segment

Terraform provider for Segment, using the Public API
https://registry.terraform.io/providers/segmentio/segment/latest
MIT License
25 stars 3 forks source link

Unable to create resources when Source contains schema settings #73

Closed sco-at-scg closed 8 months ago

sco-at-scg commented 8 months ago

Issue

Provider version: 0.7.0

When trying to create resources (source, tracking_plan, etc), if the Source has a schema settings defined, the provider was unable to successfully create the resources.

Error: Unable to update Source schema settings

{
  "errors": [
    {
      "type": "bad-request",
      "message": "Source is not connected to a tracking plan: fields '???', '???', '???' cannot be updated"
    }
  ]
}
resource "segment_source" "my_source_with_schema_settings" {
  slug    = "my_source_slug"
  name    = "My Source"
  enabled = true
  metadata = {
    id = "abc123"
  }
  settings = jsonencode({
    "token" : "xyz321",
  })
  labels = [
    {
      key   = "env"
      value = "dev"
    },
  ]
  schema_settings = {
    forwarding_blocked_events_to = segment_source.my_source.id
    track = {
      allow_unplanned_events           = true
      allow_unplanned_event_properties = true
      allow_event_on_violations        = false
      allow_properties_on_violations   = true
      common_event_on_violations       = "ALLOW"
    }
    identify = {
      allow_traits_on_violations = false
      allow_unplanned_traits     = false
      common_event_on_violations = "ALLOW"
    }
    group = {
      allow_traits_on_violations = true
      allow_unplanned_traits     = true
      common_event_on_violations = "ALLOW"
    }
  }
}

The current workaround is to split the resources into 2 steps:

  1. Create a source, tracking plan, tracking plan connection, etc
  2. Once created, update the source with the `schema_settings`

Ideal:

  1. Can we define the source with schema settings and other resources in one step process?
cv commented 8 months ago

Thank you for reporting this issue, @sco-at-scg! Looks like an issue with how we order the operations when creating sources. We'll post a PR with a potential fix here shortly.

deanhuynh commented 8 months ago

This is fixed in the newest release. Unfortunately a breaking change was required where the schema_settings had to be moved to the segment_source_tracking_plan_connection resource in order for the resources to be created in the correct order naturally.