Repository navigation
feat: add Anthropic integration resource and data source [ENG-8433] #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
internal/acceptance_tests/anthropic_integration_data_source_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright Stacklet, Inc. 2025, 2026 | ||
|
|
||
| package acceptance_tests | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| ) | ||
|
|
||
| func TestAccAnthropicIntegrationDataSource(t *testing.T) { | ||
| steps := []resource.TestStep{ | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "` + testAnthropicAdminKey + `" | ||
| admin_key_wo_version = "1" | ||
| } | ||
|
|
||
| data "stacklet_anthropic_integration" "test" { | ||
| org_id = stacklet_anthropic_integration.test.org_id | ||
| } | ||
| `, | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttrPair("data.stacklet_anthropic_integration.test", "id", "stacklet_anthropic_integration.test", "id"), | ||
| resource.TestCheckResourceAttr("data.stacklet_anthropic_integration.test", "org_id", testAnthropicOrgID), | ||
| resource.TestCheckResourceAttr("data.stacklet_anthropic_integration.test", "configured", "true"), | ||
| ), | ||
| }, | ||
| } | ||
| runRecordedAccTest(t, "TestAccAnthropicIntegrationDataSource", steps) | ||
| } |
163 changes: 163 additions & 0 deletions
163
internal/acceptance_tests/anthropic_integration_resource_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| // Copyright Stacklet, Inc. 2025, 2026 | ||
|
|
||
| package acceptance_tests | ||
|
|
||
| import ( | ||
| "regexp" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| ) | ||
|
|
||
| // The recordings come from the platform's local development stack, whose fake | ||
| // Anthropic Admin API accepts these keys. testAnthropicAdminKey belongs to | ||
| // testAnthropicOrgID, and otherAnthropicAdminKey to another organization. | ||
| const ( | ||
| testAnthropicOrgID = "org-functest" | ||
| testAnthropicAdminKey = "sk-ant-admin01-fake-test" | ||
| otherAnthropicAdminKey = "sk-ant-admin01-fake" | ||
| ) | ||
|
|
||
| func TestAccAnthropicIntegrationResource(t *testing.T) { | ||
| steps := []resource.TestStep{ | ||
| // Create and Read testing | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "` + testAnthropicAdminKey + `" | ||
| admin_key_wo_version = "1" | ||
| } | ||
| `, | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttrSet("stacklet_anthropic_integration.test", "id"), | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "org_id", testAnthropicOrgID), | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "configured", "true"), | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "admin_key_wo_version", "1"), | ||
| // The key is write-only, so it isn't in state. | ||
| resource.TestCheckNoResourceAttr("stacklet_anthropic_integration.test", "admin_key_wo"), | ||
| ), | ||
| }, | ||
| // ImportState testing | ||
| { | ||
| ResourceName: "stacklet_anthropic_integration.test", | ||
| ImportState: true, | ||
| ImportStateId: testAnthropicOrgID, | ||
| ImportStateVerify: true, | ||
| ImportStateVerifyIdentifierAttribute: "org_id", | ||
| ImportStateVerifyIgnore: []string{ | ||
| // The key is never returned, so an import can't know which | ||
| // version the stored one corresponds to. | ||
| "admin_key_wo_version", | ||
| }, | ||
| }, | ||
| } | ||
| runRecordedAccTest(t, "TestAccAnthropicIntegrationResource", steps) | ||
| } | ||
|
|
||
| // TestAccAnthropicIntegrationResource_KeyRotation checks that bumping the | ||
| // version sends the key again, which the API checks with Anthropic before it | ||
| // replaces the stored one. | ||
| func TestAccAnthropicIntegrationResource_KeyRotation(t *testing.T) { | ||
| steps := []resource.TestStep{ | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "` + testAnthropicAdminKey + `" | ||
| admin_key_wo_version = "1" | ||
| } | ||
| `, | ||
| Check: resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "configured", "true"), | ||
| }, | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "` + testAnthropicAdminKey + `" | ||
| admin_key_wo_version = "2" | ||
| } | ||
| `, | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "admin_key_wo_version", "2"), | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "configured", "true"), | ||
| ), | ||
| }, | ||
| } | ||
| runRecordedAccTest(t, "TestAccAnthropicIntegrationResource_KeyRotation", steps) | ||
| } | ||
|
|
||
| // TestAccAnthropicIntegrationResource_RejectedKey checks that a key the API | ||
| // rejects when it checks it with Anthropic fails the apply with the reason. | ||
| func TestAccAnthropicIntegrationResource_RejectedKey(t *testing.T) { | ||
| steps := []resource.TestStep{ | ||
| // A key that doesn't authenticate. | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "sk-ant-admin01-invalid" | ||
| admin_key_wo_version = "1" | ||
| } | ||
| `, | ||
| ExpectError: regexp.MustCompile(`Failed to connect to Anthropic`), | ||
| }, | ||
| // Another organization's key. | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "` + otherAnthropicAdminKey + `" | ||
| admin_key_wo_version = "1" | ||
| } | ||
| `, | ||
| ExpectError: regexp.MustCompile(`The admin key belongs to Anthropic organization`), | ||
| }, | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "` + testAnthropicAdminKey + `" | ||
| admin_key_wo_version = "1" | ||
| } | ||
| `, | ||
| Check: resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "configured", "true"), | ||
| }, | ||
| // A rotation to a bad key fails too, and leaves the stored key alone. | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "sk-ant-admin01-invalid" | ||
| admin_key_wo_version = "2" | ||
| } | ||
| `, | ||
| ExpectError: regexp.MustCompile(`Failed to connect to Anthropic`), | ||
| }, | ||
| // The failed rotation left state at the first version, and the API | ||
| // still holds the first key. | ||
| { | ||
| Config: ` | ||
| resource "stacklet_anthropic_integration" "test" { | ||
| org_id = "` + testAnthropicOrgID + `" | ||
|
|
||
| admin_key_wo = "` + testAnthropicAdminKey + `" | ||
| admin_key_wo_version = "1" | ||
| } | ||
| `, | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "org_id", testAnthropicOrgID), | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "configured", "true"), | ||
| resource.TestCheckResourceAttr("stacklet_anthropic_integration.test", "admin_key_wo_version", "1"), | ||
| ), | ||
| }, | ||
| } | ||
| runRecordedAccTest(t, "TestAccAnthropicIntegrationResource_RejectedKey", steps) | ||
| } | ||
128 changes: 128 additions & 0 deletions
128
internal/acceptance_tests/recordings/TestAccAnthropicIntegrationDataSource.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| { | ||
| "mutation ($input:RemoveAnthropicIntegrationInput!){removeAnthropicIntegration(input: $input){problems{__typename,message}}}:{\"input\":{\"orgId\":\"org-functest\"}}": [ | ||
| { | ||
| "request": { | ||
| "query": "mutation ($input:RemoveAnthropicIntegrationInput!){removeAnthropicIntegration(input: $input){problems{__typename,message}}}", | ||
| "variables": { | ||
| "input": { | ||
| "orgId": "org-functest" | ||
| } | ||
| } | ||
| }, | ||
| "response": { | ||
| "data": { | ||
| "removeAnthropicIntegration": { | ||
| "problems": [] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "mutation ($input:UpsertAnthropicIntegrationInput!){upsertAnthropicIntegration(input: $input){anthropicIntegration{id,orgId,configured},problems{__typename,message}}}:{\"input\":{\"adminKey\":\"sk-ant-admin01-fake-test\",\"orgId\":\"org-functest\"}}": [ | ||
| { | ||
| "request": { | ||
| "query": "mutation ($input:UpsertAnthropicIntegrationInput!){upsertAnthropicIntegration(input: $input){anthropicIntegration{id,orgId,configured},problems{__typename,message}}}", | ||
| "variables": { | ||
| "input": { | ||
| "adminKey": "sk-ant-admin01-fake-test", | ||
| "orgId": "org-functest" | ||
| } | ||
| } | ||
| }, | ||
| "response": { | ||
| "data": { | ||
| "upsertAnthropicIntegration": { | ||
| "anthropicIntegration": { | ||
| "configured": true, | ||
| "id": "WyJhbnRocm9waWMtaW50ZWdyYXRpb24iLCAib3JnLWZ1bmN0ZXN0Il0=", | ||
| "orgId": "org-functest" | ||
| }, | ||
| "problems": [] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "query ($orgId:String!){anthropicIntegration(orgId: $orgId){anthropicIntegration{id,orgId,configured},problems{__typename,message}}}:{\"orgId\":\"org-functest\"}": [ | ||
| { | ||
| "request": { | ||
| "query": "query ($orgId:String!){anthropicIntegration(orgId: $orgId){anthropicIntegration{id,orgId,configured},problems{__typename,message}}}", | ||
| "variables": { | ||
| "orgId": "org-functest" | ||
| } | ||
| }, | ||
| "response": { | ||
| "data": { | ||
| "anthropicIntegration": { | ||
| "anthropicIntegration": { | ||
| "configured": true, | ||
| "id": "WyJhbnRocm9waWMtaW50ZWdyYXRpb24iLCAib3JnLWZ1bmN0ZXN0Il0=", | ||
| "orgId": "org-functest" | ||
| }, | ||
| "problems": [] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "request": { | ||
| "query": "query ($orgId:String!){anthropicIntegration(orgId: $orgId){anthropicIntegration{id,orgId,configured},problems{__typename,message}}}", | ||
| "variables": { | ||
| "orgId": "org-functest" | ||
| } | ||
| }, | ||
| "response": { | ||
| "data": { | ||
| "anthropicIntegration": { | ||
| "anthropicIntegration": { | ||
| "configured": true, | ||
| "id": "WyJhbnRocm9waWMtaW50ZWdyYXRpb24iLCAib3JnLWZ1bmN0ZXN0Il0=", | ||
| "orgId": "org-functest" | ||
| }, | ||
| "problems": [] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "request": { | ||
| "query": "query ($orgId:String!){anthropicIntegration(orgId: $orgId){anthropicIntegration{id,orgId,configured},problems{__typename,message}}}", | ||
| "variables": { | ||
| "orgId": "org-functest" | ||
| } | ||
| }, | ||
| "response": { | ||
| "data": { | ||
| "anthropicIntegration": { | ||
| "anthropicIntegration": { | ||
| "configured": true, | ||
| "id": "WyJhbnRocm9waWMtaW50ZWdyYXRpb24iLCAib3JnLWZ1bmN0ZXN0Il0=", | ||
| "orgId": "org-functest" | ||
| }, | ||
| "problems": [] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "request": { | ||
| "query": "query ($orgId:String!){anthropicIntegration(orgId: $orgId){anthropicIntegration{id,orgId,configured},problems{__typename,message}}}", | ||
| "variables": { | ||
| "orgId": "org-functest" | ||
| } | ||
| }, | ||
| "response": { | ||
| "data": { | ||
| "anthropicIntegration": { | ||
| "anthropicIntegration": { | ||
| "configured": true, | ||
| "id": "WyJhbnRocm9waWMtaW50ZWdyYXRpb24iLCAib3JnLWZ1bmN0ZXN0Il0=", | ||
| "orgId": "org-functest" | ||
| }, | ||
| "problems": [] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.