chore: refactor cmd
This commit is contained in:
parent
4a2819787d
commit
2aee47aa76
1 changed files with 11 additions and 22 deletions
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||||
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/{{.PackageName}}"
|
{{.PackageName}}PkgGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/{{.PackageName}}"
|
||||||
|
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||||
|
|
@ -35,12 +35,12 @@ func New{{.NamePascal}}Resource() resource.Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
type {{.NameCamel}}Resource struct{
|
type {{.NameCamel}}Resource struct{
|
||||||
client *{{.PackageName}}.APIClient
|
client *{{.PackageName}}PkgGen.APIClient
|
||||||
providerData core.ProviderData
|
providerData core.ProviderData
|
||||||
}
|
}
|
||||||
|
|
||||||
// resourceModel represents the Terraform resource state
|
// resourceModel represents the Terraform resource state
|
||||||
type resourceModel = {{.PackageName}}.{{.NamePascal}}Model
|
type resourceModel = {{.PackageName}}ResGen.{{.NamePascal}}Model
|
||||||
|
|
||||||
type {{.NamePascal}}ResourceIdentityModel struct {
|
type {{.NamePascal}}ResourceIdentityModel struct {
|
||||||
ProjectID types.String `tfsdk:"project_id"`
|
ProjectID types.String `tfsdk:"project_id"`
|
||||||
|
|
@ -59,15 +59,15 @@ var modifiersFileByte []byte
|
||||||
|
|
||||||
// Schema loads the schema from generated files and adds plan modifiers
|
// Schema loads the schema from generated files and adds plan modifiers
|
||||||
func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
schema = {{.PackageName}}ResGen.{{.NamePascal}}ResourceSchema(ctx)
|
schema := {{.PackageName}}ResGen.{{.NamePascal}}ResourceSchema(ctx)
|
||||||
|
|
||||||
fields, err := {{.PackageName}}Utils.ReadModifiersConfig(modifiersFileByte)
|
fields, err := utils.ReadModifiersConfig(modifiersFileByte)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError("error during read modifiers config file", err.Error())
|
resp.Diagnostics.AddError("error during read modifiers config file", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = {{.PackageName}}Utils.AddPlanModifiersToResourceSchema(fields, &schema)
|
err = utils.AddPlanModifiersToResourceSchema(fields, &schema)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError("error adding plan modifiers", err.Error())
|
resp.Diagnostics.AddError("error adding plan modifiers", err.Error())
|
||||||
return
|
return
|
||||||
|
|
@ -109,12 +109,14 @@ func (r *{{.NameCamel}}Resource) Configure(
|
||||||
config.WithCustomAuth(r.providerData.RoundTripper),
|
config.WithCustomAuth(r.providerData.RoundTripper),
|
||||||
utils.UserAgentConfigOption(r.providerData.Version),
|
utils.UserAgentConfigOption(r.providerData.Version),
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if r.providerData.{{.PackageNamePascal}}CustomEndpoint != "" {
|
if r.providerData.{{.PackageNamePascal}}CustomEndpoint != "" {
|
||||||
apiClientConfigOptions = append(apiClientConfigOptions, config.WithEndpoint(r.providerData.{{.PackageName}}CustomEndpoint))
|
apiClientConfigOptions = append(apiClientConfigOptions, config.WithEndpoint(r.providerData.{{.PackageName}}CustomEndpoint))
|
||||||
} else {
|
} else {
|
||||||
apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(r.providerData.GetRegion()))
|
apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(r.providerData.GetRegion()))
|
||||||
}
|
}
|
||||||
apiClient, err := {{.PackageName}}.NewAPIClient(apiClientConfigOptions...)
|
*/
|
||||||
|
apiClient, err := {{.PackageName}}PkgGen.NewAPIClient(apiClientConfigOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError(
|
resp.Diagnostics.AddError(
|
||||||
"Error configuring API client",
|
"Error configuring API client",
|
||||||
|
|
@ -293,18 +295,11 @@ func (r *{{.NameCamel}}Resource) Read(ctx context.Context, req resource.ReadRequ
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData {{.NamePascal}}ResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId := identityData.ProjectID.ValueString()
|
projectId := data.ProjectID.ValueString()
|
||||||
region := identityData.Region.ValueString()
|
region := data.Region.ValueString()
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
|
|
||||||
|
|
@ -330,12 +325,6 @@ func (r *{{.NameCamel}}Resource) Read(ctx context.Context, req resource.ReadRequ
|
||||||
func (r *{{.NameCamel}}Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
func (r *{{.NameCamel}}Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
|
||||||
var data {{.PackageName}}ResGen.{{.NamePascal}}Model
|
var data {{.PackageName}}ResGen.{{.NamePascal}}Model
|
||||||
|
|
||||||
// Read Terraform prior state data into the model
|
|
||||||
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId := data.ProjectId.ValueString()
|
projectId := data.ProjectId.ValueString()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue