Skip to content

Commit

Permalink
Fix Import for OIDC Scope resource (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay-gopalan authored Jul 25, 2022
1 parent 8cb55c1 commit 060ccf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vault/resource_identity_oidc_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vault
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand All @@ -17,6 +18,9 @@ func identityOIDCScopeResource() *schema.Resource {
Update: identityOIDCScopeCreateUpdate,
Read: identityOIDCScopeRead,
Delete: identityOIDCScopeDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -106,6 +110,11 @@ func identityOIDCScopeRead(d *schema.ResourceData, meta interface{}) error {
}
}

name := strings.Trim(strings.TrimPrefix(path, identityOIDCScopePathPrefix), "/")
if err := d.Set("name", name); err != nil {
return fmt.Errorf("error setting state key %q on OIDC Scope %q, err=%w", "name", path, err)
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions vault/resource_identity_oidc_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func TestAccIdentityOIDCScope(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "template", updatedScope),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down

0 comments on commit 060ccf8

Please sign in to comment.