Skip to content

feat: add LaunchDarkly AI Config resource and data source#402

Open
tracisiebel wants to merge 5 commits intomainfrom
devin/1773079106-add-ai-config-resource
Open

feat: add LaunchDarkly AI Config resource and data source#402
tracisiebel wants to merge 5 commits intomainfrom
devin/1773079106-add-ai-config-resource

Conversation

@tracisiebel
Copy link
Copy Markdown

@tracisiebel tracisiebel commented Mar 9, 2026

Wait!

  • Have you added comprehensive tests? ✅ Yes — all attributes are tested including evaluation_metric_key, is_inverted, maintainer_id, maintainer_team_key, and version. Optional field removal is also tested.
  • Have you updated relevant data sources as well as resources? Yes
  • Have you updated the docs? Yes — docs/resources/ai_config.md and docs/data-sources/ai_config.md are generated and committed.

Testing

For any changes you make, please ensure your acceptance test conform to the following:

  • every single new attribute is tested
  • optional attributes revert to null or default values if removed
  • attributes that interact interact as expected
  • block values behave as expected when reordered
  • nested fields on maps or list/set items function as expected. Terraform does not actually enforce most schema attributes on nested items
  • each test step for a configuration is followed by a test step where ImportState and ImportStateVerify are set to true. ImportStateVerifyIgnore can be used if we explicitly expect a value to be different when imported, such as in the case of obfuscated values like API keys

LaunchDarkly Employees

For more information on how to build, test, and release, see the internal provider runbook.


Summary

Adds a new launchdarkly_ai_config resource and data source for managing AI Configs via Terraform. Uses the generated api-client-go/v22 SDK client (ldapi.AIConfigsApi), following the same pattern as other resources in the provider (metrics, projects, etc.).

New files

  • ai_config_helper.go — schema definition, shared read logic using SDK, ID parser
  • resource_launchdarkly_ai_config.go — resource with Create/Read/Update/Delete + Import using ldapi.AIConfigsApi
  • data_source_launchdarkly_ai_config.go — read-only data source
  • resource_launchdarkly_ai_config_test.go — acceptance tests for resource (create, update, import, optional field removal, maintainer handling, evaluation metrics)
  • data_source_launchdarkly_ai_config_test.go — acceptance test for data source
  • docs/resources/ai_config.md — resource documentation (generated via tfplugindocs)
  • docs/data-sources/ai_config.md — data source documentation (generated via tfplugindocs)
  • examples/resources/launchdarkly_ai_config/ — example Terraform configs for resource
  • examples/data-sources/launchdarkly_ai_config/ — example Terraform configs for data source

Modified files

  • keys.go — new constants: EVALUATION_METRIC_KEY, IS_INVERTED, MODE
  • provider.go — registers launchdarkly_ai_config in both ResourcesMap and DataSourcesMap
  • go.mod / go.sum — bumps api-client-go/v22 to include AI Configs support

Updates since initial commit

Initial review fixes (commits 2-4)

  • Removed unused AI_CONFIG_KEY constant — the resource uses KEY directly
  • Fixed data source 404 handling — data sources now return an explicit error when the AI Config is not found
  • Added ForceNew: true to mode — changing mode requires resource recreation
  • Added TestAccAiConfig_RemoveOptionalFields — tests that removing optional fields causes them to revert to empty/defaults

SDK refactor (commit 5)

Replaced raw HTTP calls with generated SDK client. The initial implementation used client.fallbackClient with raw HTTP, following the pattern from the view resource. However, the AI Configs API is now available in the generated api-client-go/v22 SDK.

Changes:

  • Bump api-client-go/v22 from v22.0.0 to v22.0.1-0.20260305104810-a434796e8e64 (pseudo-version pointing to latest commit with AI Configs)
  • Remove all custom types (AiConfig, AiConfigPost, AiConfigPatch) and raw HTTP helpers
  • Use ldapi.AIConfigsApi methods (PostAIConfig, GetAIConfig, PatchAIConfig, DeleteAIConfig) with SDK types (ldapi.AIConfigPost, ldapi.AIConfigPatch, ldapi.AIConfig)
  • Use SDK's AIConfigMaintainer oneOf union type for maintainer handling
  • Update test helpers to use SDK client directly

Benefits:

  • Consistent with other resources (metrics, projects, etc.)
  • Leverages SDK's built-in error handling, auth, retries, and type safety
  • Reduces technical debt and maintenance burden

Comprehensive tests and docs (commit 6)

Added complete test coverage and documentation.

Test additions:

  • TestAccAiConfig_WithMaintainer — tests maintainer_id attribute with team member
  • TestAccAiConfig_WithTeamMaintainer — tests maintainer_team_key attribute with team (includes ImportStateVerifyIgnore since team key is write-only)
  • TestAccAiConfig_WithEvaluationMetric — tests evaluation_metric_key and is_inverted attributes (both create and update)
  • Added version attribute checks to all tests

Documentation:

  • Generated docs/resources/ai_config.md via tfplugindocs
  • Generated docs/data-sources/ai_config.md via tfplugindocs
  • Added example files in examples/ for both resource and data source

Human Review Checklist — items that need careful attention

1. ⚠️ CRITICAL: Dependency on unreleased SDK version

The PR pins api-client-go/v22 to a pseudo-version (v22.0.1-0.20260305104810-a434796e8e64) pointing to an unreleased commit on main. This could cause issues:

  • Go module proxy may not resolve this pseudo-version reliably
  • Downstream users may have trouble pulling this dependency
  • CI/CD may fail if the commit becomes unavailable

Action needed:

  • Verify this is the intended approach, or wait for an official v22.1.0 release that includes AI Configs
  • If pseudo-version is acceptable, ensure it's documented and that the commit is stable

2. Tags removal behavior needs verification

The SDK's AIConfigPatch type has Tags []string json:"tags,omitempty". When tags are removed from config, the update handler calls patch.SetTags([]string{}). The omitempty struct tag may still cause empty slices to be omitted from the JSON payload, meaning the API might not clear the tags.

Action needed:

  • Verify via TestAccAiConfig_RemoveOptionalFields that tags actually get cleared when removed from config (test has been written but not yet run against live API)
  • If the test fails, investigate SDK's MarshalJSON implementation and potentially file an SDK issue

3. Boolean zero-value behavior on create

In resourceAiConfigCreate, the code uses GetOk to check for is_inverted:

if isInverted, ok := d.GetOk(IS_INVERTED); ok {
    post.SetIsInverted(isInverted.(bool))
}

Since false is the zero value for bool, explicitly setting is_inverted = false in Terraform config won't trigger this condition, so the value won't be sent to the API on create. This is likely fine since false is the default, but it means there's a subtle difference between not setting the field vs. explicitly setting it to false.

The update path uses d.HasChange + d.Get so it correctly handles is_inverted = false on updates.

4. maintainer_team_key is write-only

  • The API response _maintainer object doesn't include the team key when kind == "team", only the team ID
  • This causes ImportStateVerify to fail when importing a config with a team maintainer
  • Resolution: Tests now use ImportStateVerifyIgnore: []string{MAINTAINER_TEAM_KEY} for team maintainer scenarios
  • Note: Users importing AI Configs with team maintainers will need to manually add maintainer_team_key to their Terraform config after import

Session Info

Add comprehensive support for managing AI Configs via Terraform:
- New resource: launchdarkly_ai_config (CRUD operations)
- New data source: launchdarkly_ai_config (read-only)
- Helper functions for schema definitions and API interactions
- Acceptance tests for both resource and data source
- New constants in keys.go for AI Config fields
- Registered resource and data source in provider.go

Co-Authored-By: traci@launchdarkly.com <traci@launchdarkly.com>
@devin-ai-integration
Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…404, add ForceNew to mode

Co-Authored-By: traci@launchdarkly.com <traci@launchdarkly.com>
@tracisiebel
Copy link
Copy Markdown
Author

tested CRUD locally

devin-ai-integration bot and others added 3 commits March 9, 2026 21:53
…n to defaults

Co-Authored-By: traci@launchdarkly.com <traci@launchdarkly.com>
…calls

Replaces custom types and raw HTTP calls with the generated
api-client-go/v22 SDK client (ldapi.AIConfigsApi). This uses the same
pattern as other resources in the provider (metrics, projects, etc.)
and benefits from the SDK's built-in error handling, auth, and type safety.

Changes:
- Bump api-client-go/v22 to include AI Configs support
- Remove custom AiConfig/AiConfigPost/AiConfigPatch types
- Remove raw HTTP helpers (createAiConfig, getAiConfig, patchAiConfig,
  deleteAiConfig, setAiConfigRequestHeaders, aiConfigAPIURL)
- Use ldapi.AIConfigsApi methods (PostAIConfig, GetAIConfig,
  PatchAIConfig, DeleteAIConfig) with proper SDK types
- Use SDK AIConfigMaintainer oneOf union type for maintainer handling
- Update test helpers to use SDK client directly

Co-Authored-By: traci@launchdarkly.com <traci@launchdarkly.com>
- Add TestAccAiConfig_WithMaintainer: tests maintainer_id with team member
- Add TestAccAiConfig_WithTeamMaintainer: tests maintainer_team_key with team
- Add TestAccAiConfig_WithEvaluationMetric: tests evaluation_metric_key and
  is_inverted (create + update)
- Add version checks to BasicCreateAndUpdate test
- Add docs/resources/ai_config.md and docs/data-sources/ai_config.md
- Add example files for doc generation

Co-Authored-By: traci@launchdarkly.com <traci@launchdarkly.com>
@tracisiebel tracisiebel marked this pull request as ready for review March 17, 2026 23:40
@tracisiebel tracisiebel requested review from a team as code owners March 17, 2026 23:40
@monsagri monsagri requested a review from Copilot March 18, 2026 11:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Terraform support for LaunchDarkly AI Configs by introducing a new launchdarkly_ai_config resource and matching data source, backed by the generated api-client-go/v22 AIConfigsApi, plus acceptance tests, docs, and examples.

Changes:

  • Introduces AI Config resource CRUD + import and shared schema/read helper.
  • Adds AI Config data source and acceptance tests for both resource and data source.
  • Registers the new resource/data source with the provider and updates constants + SDK dependency version; generates docs/examples.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
launchdarkly/ai_config_helper.go Shared schema + read/import parsing helper for AI Configs
launchdarkly/resource_launchdarkly_ai_config.go AI Config Terraform resource implementation (CRUD + import)
launchdarkly/resource_launchdarkly_ai_config_test.go Acceptance tests for AI Config resource (update/import/optionals/maintainers/metrics)
launchdarkly/data_source_launchdarkly_ai_config.go AI Config data source implementation
launchdarkly/data_source_launchdarkly_ai_config_test.go Acceptance test for AI Config data source
launchdarkly/provider.go Registers launchdarkly_ai_config resource + data source
launchdarkly/keys.go Adds schema key constants for new AI Config attributes
go.mod Bumps LaunchDarkly SDK dependency to include AI Config support
go.sum Updates dependency checksums for the SDK bump
examples/resources/launchdarkly_ai_config/resource.tf Resource usage examples
examples/resources/launchdarkly_ai_config/import.sh Import example for AI Config resource
examples/data-sources/launchdarkly_ai_config/data-source.tf Data source usage example
docs/resources/ai_config.md Generated resource documentation
docs/data-sources/ai_config.md Generated data source documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

post.SetEvaluationMetricKey(evaluationMetricKey.(string))
}

if isInverted, ok := d.GetOk(IS_INVERTED); ok {
Comment on lines +59 to +64
},
MAINTAINER_TEAM_KEY: {
Type: schema.TypeString,
Optional: !isDataSource,
Computed: isDataSource,
Description: "The key of the team that will maintain the AI Config.",

require (
github.com/launchdarkly/api-client-go/v22 v22.0.0
github.com/launchdarkly/api-client-go/v22 v22.0.1-0.20260305104810-a434796e8e64
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.

3 participants