Skip to content

feat: Add flagsmith_feature and flagsmith_segment data sources - #244

Merged
matthewelwell merged 1 commit into
mainfrom
feat/feature-and-segment-data-sources
Aug 26, 2026
Merged

feat: Add flagsmith_feature and flagsmith_segment data sources#244
matthewelwell merged 1 commit into
mainfrom
feat/feature-and-segment-data-sources

Conversation

@matthewelwell

@matthewelwell matthewelwell commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Closes #153.

Adds data sources so features and segments created outside of Terraform can be referenced. Without them, a pipeline that manages only environment-specific flagsmith_feature_state overrides has no way to get at the feature it needs to override — the use case in the issue.

data "flagsmith_feature" "my_feature" {
  uuid = "10421b1f-5f29-4da9-abe2-30f88c07c9e8"
}

data "flagsmith_segment" "mobile_users" {
  uuid = "f6c714d3-94e7-4b14-9117-8dd9db91bc19"
}

resource "flagsmith_feature_state" "mobile_override" {
  feature_id       = data.flagsmith_feature.my_feature.id
  environment_key  = var.environment_key
  segment_id       = data.flagsmith_segment.mobile_users.id
  segment_priority = 0
  enabled          = true
  feature_state_value = {
    type         = "unicode"
    string_value = "mobile-value"
  }
}

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
📝 Walkthrough

Walkthrough

Added flagsmith_feature and flagsmith_segment Terraform data sources. Each data source reads a Flagsmith object by UUID and writes computed attributes to state. Segment support includes nested rules and conditions. The provider registers both data sources. Acceptance and schema consistency tests cover successful reads, missing objects, nested data, and feature-state usage. Documentation, examples, and an Unreleased changelog entry were added.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 8f080

The PR adds the requested data sources; the only noted issue is a minor changelog formatting problem that does not affect runtime behavior. It is otherwise merge-ready after normal review, with a small documentation fix recommended.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d9d1f3fa-4664-4cdd-9033-840e3ff91674

📥 Commits

Reviewing files that changed from the base of the PR and between efa883e and 8f080f2.

📒 Files selected for processing (11)
  • CHANGELOG.md
  • docs/data-sources/feature.md
  • docs/data-sources/segment.md
  • examples/data-sources/flagsmith_feature/data-source.tf
  • examples/data-sources/flagsmith_segment/data-source.tf
  • flagsmith/data_source_feature.go
  • flagsmith/data_source_feature_test.go
  • flagsmith/data_source_schema_test.go
  • flagsmith/data_source_segment.go
  • flagsmith/data_source_segment_test.go
  • flagsmith/provider.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread CHANGELOG.md Outdated
@matthewelwell
matthewelwell force-pushed the feat/feature-and-segment-data-sources branch from 8f080f2 to c4a3508 Compare August 25, 2026 18:58
Adds data sources so that features and segments created outside of Terraform can
be referenced, which is what issue #153 asks for. Without them a pipeline that
manages only environment specific flagsmith_feature_state overrides has no way
to get at the feature it needs to override.

Both are keyed on `uuid`, matching the existing flagsmith_project and
flagsmith_organisation data sources. UUIDs are also stable across renames, and
GetFeature and GetSegment already exist in the API client, so this needs no
client changes.

Looking entities up by name would be friendlier, but the API's name filters are
case insensitive "contains" matches, which means client side filtering, and
segment names are not unique within a project. If that turns out to be wanted,
adding `project_uuid` plus a name behind ExactlyOneOf later is additive and
breaks no existing configuration.

Both reuse the existing FeatureResourceData and SegmentResourceData structs, as
the three existing data sources do. That avoids forking the recursive segment
rules converter, but it means req.Config.Get needs the schema attributes and the
tfsdk tags to stay in step, and a mismatch only shows up at runtime. The new
reflection based tests in data_source_schema_test.go turn that into a build
failure instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@matthewelwell
matthewelwell force-pushed the feat/feature-and-segment-data-sources branch from c4a3508 to 63fdc61 Compare August 25, 2026 19:02
@matthewelwell
matthewelwell marked this pull request as ready for review August 25, 2026 19:28
@matthewelwell
matthewelwell requested a review from a team as a code owner August 25, 2026 19:28
@matthewelwell
matthewelwell requested review from khvn26 and removed request for a team August 25, 2026 19:28
@matthewelwell
matthewelwell merged commit 8e76226 into main Aug 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement data sources to reference externally managed resources

2 participants