Skip to content

Commit

Permalink
Implement page import
Browse files Browse the repository at this point in the history
  • Loading branch information
kjschubert committed Jul 12, 2023
1 parent be36298 commit 90d5c31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/resources/auth_strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Optional:
- `auto_enroll_groups` (List of Number) When self_registration is set to true, this list must contain the group ids the newly created account is added to.
- `domain_whitelist` (List of String) When self_registration is set to true, this list must contain the allowed domains
- `enabled` (Boolean) Whether to enable this auth strategy instance
- `key` (String) Unique Key for this instance of the auth strategy
- `key` (String) Unique Key for this instance of the auth strategy. This resource can generate a unique key for you, but when you change the order of your auth strategies you have to explicitly set this key by yourself.
- `self_registration` (Boolean) Automatically create user accounts for people who successfully login via this auth strategie


15 changes: 13 additions & 2 deletions internal/provider/page_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package provider
import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
Expand All @@ -18,8 +20,9 @@ import (

// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &pageResource{}
_ resource.ResourceWithConfigure = &pageResource{}
_ resource.Resource = &pageResource{}
_ resource.ResourceWithConfigure = &pageResource{}
_ resource.ResourceWithImportState = &pageResource{}
)

// NewPageResource is a helper function to simplify the provider implementation.
Expand Down Expand Up @@ -436,3 +439,11 @@ func (r *pageResource) Delete(ctx context.Context, req resource.DeleteRequest, r
return
}
}

func (r *pageResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
if id, err := strconv.Atoi(req.ID); err != nil {
resp.Diagnostics.AddAttributeError(path.Root("id"), "Could not parse id", err.Error())
} else {
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), int64(id))...)
}
}

0 comments on commit 90d5c31

Please sign in to comment.