Skip to content

Commit 3b2d997

Browse files
committed
Add ImportState functions for Teams/ServiceAccounts
1 parent 7075658 commit 3b2d997

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

internal/provider/service_account_resource.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import (
99

1010
"terraform-provider-tlspc/internal/tlspc"
1111

12+
"github.com/hashicorp/terraform-plugin-framework/path"
1213
"github.com/hashicorp/terraform-plugin-framework/resource"
1314
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1415
"github.com/hashicorp/terraform-plugin-framework/types"
1516
)
1617

1718
var (
18-
_ resource.Resource = &serviceAccountResource{}
19-
_ resource.ResourceWithConfigure = &serviceAccountResource{}
19+
_ resource.Resource = &serviceAccountResource{}
20+
_ resource.ResourceWithConfigure = &serviceAccountResource{}
21+
_ resource.ResourceWithImportState = &serviceAccountResource{}
2022
)
2123

2224
type serviceAccountResource struct {
@@ -218,3 +220,8 @@ func (r *serviceAccountResource) Delete(ctx context.Context, req resource.Delete
218220
return
219221
}
220222
}
223+
224+
func (r *serviceAccountResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
225+
// Retrieve import ID and save to id attribute
226+
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
227+
}

internal/provider/team_resource.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import (
99

1010
"terraform-provider-tlspc/internal/tlspc"
1111

12+
"github.com/hashicorp/terraform-plugin-framework/path"
1213
"github.com/hashicorp/terraform-plugin-framework/resource"
1314
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1415
"github.com/hashicorp/terraform-plugin-framework/types"
1516
)
1617

1718
var (
18-
_ resource.Resource = &teamResource{}
19-
_ resource.ResourceWithConfigure = &teamResource{}
19+
_ resource.Resource = &teamResource{}
20+
_ resource.ResourceWithConfigure = &teamResource{}
21+
_ resource.ResourceWithImportState = &teamResource{}
2022
)
2123

2224
type teamResource struct {
@@ -235,3 +237,8 @@ func (r *teamResource) Delete(ctx context.Context, req resource.DeleteRequest, r
235237
return
236238
}
237239
}
240+
241+
func (r *teamResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
242+
// Retrieve import ID and save to id attribute
243+
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
244+
}

0 commit comments

Comments
 (0)