Skip to content

Commit

Permalink
implement missing import state functions
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Sep 11, 2024
1 parent aec39c8 commit c050864
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 1 addition & 3 deletions internal/resource/group_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (r *GroupMemberResource) Delete(ctx context.Context, req resource.DeleteReq
}
}

func (r *GroupMemberResource) ImportState(
ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse,
) {
func (r *GroupMemberResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}
25 changes: 19 additions & 6 deletions internal/resource/pr_automation_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package resource
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"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/planmodifier"
Expand Down Expand Up @@ -38,9 +40,7 @@ func (in *prAutomationTriggerResource) Schema(_ context.Context, _ resource.Sche
Description: "ID of the PR Automation that should be triggered.",
MarkdownDescription: "ID of the PR Automation that should be triggered.",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
Validators: []validator.String{stringvalidator.LengthAtLeast(1)},
},
"repo_slug": schema.StringAttribute{
Description: "Repo slug of the repository PR Automation should be triggered against. If not provided PR Automation repo will be used. Example format for a github repository: <userOrOrg>/<repoName>",
Expand All @@ -51,9 +51,7 @@ func (in *prAutomationTriggerResource) Schema(_ context.Context, _ resource.Sche
Description: "Branch that should be created against PR Automation base branch.",
MarkdownDescription: "Branch that should be created against PR Automation base branch.",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
Validators: []validator.String{stringvalidator.LengthAtLeast(1)},
},
"context": schema.MapAttribute{
Description: "PR Automation configuration context.",
Expand Down Expand Up @@ -142,3 +140,18 @@ func (in *prAutomationTriggerResource) Update(ctx context.Context, req resource.
func (in *prAutomationTriggerResource) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) {
// Since this is only a trigger, there is no delete API. Ignore.
}

func (in *prAutomationTriggerResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
idParts := strings.Split(req.ID, ",")

if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
resp.Diagnostics.AddError(
"Unexpected Import Identifier",
fmt.Sprintf("Expected import identifier with format: pr_automation_id,pr_automation_branch. Got: %q", req.ID),
)
return
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("pr_automation_id"), idParts[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("pr_automation_branch"), idParts[1])...)
}
5 changes: 5 additions & 0 deletions internal/resource/stack_run_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"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/planmodifier"
Expand Down Expand Up @@ -116,3 +117,7 @@ func (in *stackRunTriggerResource) Update(ctx context.Context, req resource.Upda
func (in *stackRunTriggerResource) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) {
// Since this is only a trigger, there is no delete API. Ignore.
}

func (in *stackRunTriggerResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

0 comments on commit c050864

Please sign in to comment.