Skip to content

Commit 5c02e2e

Browse files
committed
feat(codegen): add Custom structure for custom resources that can be used to store extra state
1 parent e99c0a9 commit 5c02e2e

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

assets/terraform/internal/provider/api_key_crud.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/types"
88
)
99

10+
type ApiKeyCustom struct{}
11+
12+
func NewApiKeyCustom(provider *ProviderData) (*ApiKeyCustom, error) {
13+
return &ApiKeyCustom{}, nil
14+
}
15+
1016
func (o *ApiKeyResource) OpenCustom(ctx context.Context, req ephemeral.OpenRequest, resp *ephemeral.OpenResponse) {
1117
var data ApiKeyResourceModel
1218
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

assets/terraform/internal/provider/device_group_parent_crud.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import (
1313
"github.com/hashicorp/terraform-plugin-framework/types"
1414
)
1515

16+
type DeviceGroupParentCustom struct{}
17+
18+
func NewDeviceGroupParentCustom(provider *ProviderData) (*DeviceGroupParentCustom, error) {
19+
return &DeviceGroupParentCustom{}, nil
20+
}
21+
1622
type dgpReq struct {
1723
XMLName xml.Name `xml:"show"`
1824
Cmd string `xml:"dg-hierarchy"`

assets/terraform/internal/provider/vm_auth_key_crud.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import (
1010
"github.com/hashicorp/terraform-plugin-framework/types"
1111
)
1212

13+
type VmAuthKeyCustom struct{}
14+
15+
func NewVmAuthKeyCustom(data *ProviderData) (*VmAuthKeyCustom, error) {
16+
return &VmAuthKeyCustom{}, nil
17+
}
18+
1319
type vmAuthKeyRequest struct {
1420
XMLName xml.Name `xml:"request"`
1521
Lifetime int64 `xml:"bootstrap>vm-auth-key>generate>lifetime"`

pkg/translate/terraform_provider/template.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func New{{ resourceStructName }}() resource.Resource {
252252
type {{ resourceStructName }} struct {
253253
client *pango.Client
254254
{{- if IsCustom }}
255-
255+
custom *{{ structName }}Custom
256256
{{- else if and IsEntry HasImports }}
257257
manager *sdkmanager.ImportableEntryObjectManager[*{{ resourceSDKName }}.Entry, {{ resourceSDKName }}.Location, {{ resourceSDKName }}.ImportLocation, *{{ resourceSDKName }}.Service]
258258
{{- else if IsEntry }}
@@ -367,7 +367,12 @@ func (o *{{ resourceStructName }}) Configure(ctx context.Context, req {{ tfresou
367367
o.client = providerData.Client
368368
369369
{{- if IsCustom }}
370-
370+
custom, err := New{{ structName }}Custom(providerData)
371+
if err != nil {
372+
resp.Diagnostics.AddError("Failed to configure SDK client", err.Error())
373+
return
374+
}
375+
o.custom = custom
371376
{{- else if and IsEntry HasImports }}
372377
specifier, _, err := {{ resourceSDKName }}.Versioning(o.client.Versioning())
373378
if err != nil {
@@ -2016,7 +2021,7 @@ type {{ dataSourceStructName }} struct {
20162021
client *pango.Client
20172022
20182023
{{- if IsCustom }}
2019-
2024+
custom *{{ structName }}Custom
20202025
{{- else if and IsEntry HasImports }}
20212026
manager *sdkmanager.ImportableEntryObjectManager[*{{ resourceSDKName }}.Entry, {{ resourceSDKName }}.Location, {{ resourceSDKName }}.ImportLocation, *{{ resourceSDKName }}.Service]
20222027
{{- else if IsEntry }}
@@ -2070,7 +2075,12 @@ func (d *{{ dataSourceStructName }}) Configure(_ context.Context, req datasource
20702075
d.client = providerData.Client
20712076
20722077
{{- if IsCustom }}
2073-
2078+
custom, err := New{{ structName }}Custom(providerData)
2079+
if err != nil {
2080+
resp.Diagnostics.AddError("Failed to configure SDK client", err.Error())
2081+
return
2082+
}
2083+
d.custom = custom
20742084
{{- else if and IsEntry HasImports }}
20752085
specifier, _, err := {{ resourceSDKName }}.Versioning(d.client.Versioning())
20762086
if err != nil {

0 commit comments

Comments
 (0)