feat: add LaunchDarkly AI Config resource and data source#402
feat: add LaunchDarkly AI Config resource and data source#402tracisiebel wants to merge 5 commits intomainfrom
Conversation
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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…404, add ForceNew to mode Co-Authored-By: traci@launchdarkly.com <traci@launchdarkly.com>
|
tested CRUD locally |
…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>
There was a problem hiding this comment.
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 { |
| }, | ||
| 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 |
Wait!
evaluation_metric_key,is_inverted,maintainer_id,maintainer_team_key, andversion. Optional field removal is also tested.docs/resources/ai_config.mdanddocs/data-sources/ai_config.mdare generated and committed.Testing
For any changes you make, please ensure your acceptance test conform to the following:
ImportStateandImportStateVerifyare set to true.ImportStateVerifyIgnorecan be used if we explicitly expect a value to be different when imported, such as in the case of obfuscated values like API keysLaunchDarkly Employees
For more information on how to build, test, and release, see the internal provider runbook.
Summary
Adds a new
launchdarkly_ai_configresource and data source for managing AI Configs via Terraform. Uses the generatedapi-client-go/v22SDK 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 parserresource_launchdarkly_ai_config.go— resource with Create/Read/Update/Delete + Import usingldapi.AIConfigsApidata_source_launchdarkly_ai_config.go— read-only data sourceresource_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 sourcedocs/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 resourceexamples/data-sources/launchdarkly_ai_config/— example Terraform configs for data sourceModified files
keys.go— new constants:EVALUATION_METRIC_KEY,IS_INVERTED,MODEprovider.go— registerslaunchdarkly_ai_configin bothResourcesMapandDataSourcesMapgo.mod/go.sum— bumpsapi-client-go/v22to include AI Configs supportUpdates since initial commit
Initial review fixes (commits 2-4)
AI_CONFIG_KEYconstant — the resource usesKEYdirectlyForceNew: truetomode— changing mode requires resource recreationTestAccAiConfig_RemoveOptionalFields— tests that removing optional fields causes them to revert to empty/defaultsSDK refactor (commit 5)
Replaced raw HTTP calls with generated SDK client. The initial implementation used
client.fallbackClientwith raw HTTP, following the pattern from theviewresource. However, the AI Configs API is now available in the generatedapi-client-go/v22SDK.Changes:
api-client-go/v22fromv22.0.0tov22.0.1-0.20260305104810-a434796e8e64(pseudo-version pointing to latest commit with AI Configs)AiConfig,AiConfigPost,AiConfigPatch) and raw HTTP helpersldapi.AIConfigsApimethods (PostAIConfig,GetAIConfig,PatchAIConfig,DeleteAIConfig) with SDK types (ldapi.AIConfigPost,ldapi.AIConfigPatch,ldapi.AIConfig)AIConfigMaintaineroneOf union type for maintainer handlingBenefits:
Comprehensive tests and docs (commit 6)
Added complete test coverage and documentation.
Test additions:
TestAccAiConfig_WithMaintainer— testsmaintainer_idattribute with team memberTestAccAiConfig_WithTeamMaintainer— testsmaintainer_team_keyattribute with team (includesImportStateVerifyIgnoresince team key is write-only)TestAccAiConfig_WithEvaluationMetric— testsevaluation_metric_keyandis_invertedattributes (both create and update)versionattribute checks to all testsDocumentation:
docs/resources/ai_config.mdvia tfplugindocsdocs/data-sources/ai_config.mdvia tfplugindocsexamples/for both resource and data sourceHuman Review Checklist — items that need careful attention
1.⚠️ CRITICAL: Dependency on unreleased SDK version
The PR pins
api-client-go/v22to a pseudo-version (v22.0.1-0.20260305104810-a434796e8e64) pointing to an unreleased commit onmain. This could cause issues:Action needed:
v22.1.0release that includes AI Configs2. Tags removal behavior needs verification
The SDK's
AIConfigPatchtype hasTags []string json:"tags,omitempty". When tags are removed from config, the update handler callspatch.SetTags([]string{}). Theomitemptystruct tag may still cause empty slices to be omitted from the JSON payload, meaning the API might not clear the tags.Action needed:
TestAccAiConfig_RemoveOptionalFieldsthat tags actually get cleared when removed from config (test has been written but not yet run against live API)MarshalJSONimplementation and potentially file an SDK issue3. Boolean zero-value behavior on create
In
resourceAiConfigCreate, the code usesGetOkto check foris_inverted:Since
falseis the zero value for bool, explicitly settingis_inverted = falsein 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.Getso it correctly handlesis_inverted = falseon updates.4.
maintainer_team_keyis write-only_maintainerobject doesn't include the team key whenkind == "team", only the team IDImportStateVerifyto fail when importing a config with a team maintainerImportStateVerifyIgnore: []string{MAINTAINER_TEAM_KEY}for team maintainer scenariosmaintainer_team_keyto their Terraform config after importSession Info