Skip to content

Commit 90bbf41

Browse files
authored
Merge pull request #164 from patientsknowbest/token-introspector-import
Support import for TokenIntrospector
2 parents 06a3a5e + b587f0c commit 90bbf41

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

internal/provider/resource_token_introspector.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ func resourceTokenIntrospector() *schema.Resource {
1717
ReadContext: resourceTokenIntrospectorRead,
1818
UpdateContext: resourceTokenIntrospectorUpdate,
1919
DeleteContext: resourceTokenIntrospectorDelete,
20-
Schema: resourceFullSchema(resourceSchemaTokenIntrospector()),
20+
Importer: &schema.ResourceImporter{
21+
StateContext: resourceTokenIntrospectorImport,
22+
},
23+
Schema: resourceFullSchema(resourceSchemaTokenIntrospector()),
2124
}
2225
}
2326

@@ -182,3 +185,13 @@ func resourceTokenIntrospectorDelete(ctx context.Context, d *schema.ResourceData
182185
}
183186
return nil
184187
}
188+
189+
func resourceTokenIntrospectorImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
190+
apiClient := meta.(*aidbox.ApiClient)
191+
res, err := apiClient.GetTokenIntrospector(ctx, d.Id())
192+
if err != nil {
193+
return nil, err
194+
}
195+
mapTokenIntrospectorToData(res, d)
196+
return []*schema.ResourceData{d}, nil
197+
}

internal/provider/resource_token_introspector_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ func TestAccResourceTokenIntrospector_opaque(t *testing.T) {
5454
})
5555
}
5656

57+
func TestAccResourceTokenIntrospector_import(t *testing.T) {
58+
resource.Test(t, resource.TestCase{
59+
PreCheck: func() { testAccPreCheck(t) },
60+
ProviderFactories: testProviderFactories,
61+
Steps: []resource.TestStep{
62+
{
63+
Config: testAccResourceTokenIntrospector_jwt,
64+
Check: resource.ComposeTestCheckFunc(
65+
resource.TestCheckResourceAttr("aidbox_token_introspector.example", "type", "jwt"),
66+
),
67+
},
68+
{
69+
ResourceName: "aidbox_token_introspector.example",
70+
ImportState: true,
71+
ImportStateVerify: true,
72+
},
73+
},
74+
})
75+
}
76+
5777
const testAccResourceTokenIntrospector_jwt = `
5878
resource "aidbox_token_introspector" "example" {
5979
type = "jwt"

0 commit comments

Comments
 (0)