Skip to content

Commit

Permalink
Fix backup configuration and config_version state handling (#38)
Browse files Browse the repository at this point in the history
* moved to custom backups plan modifier

* removed updated_at field and added plan modifier in backupstore and cloud-account provider, updated backupstore planmodifier state change checks

* added additional nested backups key validations
  • Loading branch information
KnockOutEZ authored Nov 8, 2024
1 parent f684123 commit 8e824d4
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 118 deletions.
5 changes: 0 additions & 5 deletions internals/provider/backup-store/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ type BackupStoreModel struct {
CloudAccountID types.String `tfsdk:"cloud_account_id"`
CloudAccountType types.String `tfsdk:"cloud_account_type"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
Status types.String `tfsdk:"status"`
Name types.String `tfsdk:"name"`
Properties types.Map `tfsdk:"properties"`
Expand All @@ -81,9 +80,6 @@ func (d *backupStoresDataSource) Schema(_ context.Context, _ datasource.SchemaRe
"created_at": schema.StringAttribute{
Computed: true,
},
"updated_at": schema.StringAttribute{
Computed: true,
},
"status": schema.StringAttribute{
Computed: true,
},
Expand Down Expand Up @@ -120,7 +116,6 @@ func (d *backupStoresDataSource) Read(ctx context.Context, req datasource.ReadRe
CloudAccountID: types.StringPointerValue(store.CloudAccountID),
CloudAccountType: types.StringPointerValue(store.CloudAccountType),
CreatedAt: types.StringPointerValue(store.CreatedAt),
UpdatedAt: types.StringPointerValue(store.UpdatedAt),
Status: types.StringPointerValue(store.Status),
Name: types.StringPointerValue(store.Name),
Properties: d.convertPropertiesToMap(store.Properties),
Expand Down
13 changes: 6 additions & 7 deletions internals/provider/backup-store/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type backupStoreResourceModel struct {
CloudAccountID types.String `tfsdk:"cloud_account_id"`
CloudAccountType types.String `tfsdk:"cloud_account_type"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
Status types.String `tfsdk:"status"`
Name types.String `tfsdk:"name"`
Properties types.Map `tfsdk:"properties"`
Expand All @@ -62,12 +61,15 @@ func (r *backupStoreResource) Schema(_ context.Context, _ resource.SchemaRequest
},
"cloud_account_type": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"created_at": schema.StringAttribute{
Computed: true,
},
"updated_at": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"status": schema.StringAttribute{
Computed: true,
Expand Down Expand Up @@ -130,7 +132,6 @@ func (r *backupStoreResource) Create(ctx context.Context, req resource.CreateReq
plan.ID = types.StringValue(backupStore.ID.String())
plan.CloudAccountType = types.StringPointerValue(backupStore.CloudAccountType)
plan.CreatedAt = types.StringPointerValue(backupStore.CreatedAt)
plan.UpdatedAt = types.StringPointerValue(backupStore.UpdatedAt)
plan.Status = types.StringPointerValue(backupStore.Status)
plan.ClusterIDs = types.ListValueMust(types.StringType, []attr.Value{types.StringValue("")})
plan.Properties = r.convertPropertiesToMap(backupStore.Properties)
Expand All @@ -144,7 +145,6 @@ func (r *backupStoreResource) Create(ctx context.Context, req resource.CreateReq
plan.ID = types.StringValue(backupStore.ID.String())
plan.CloudAccountType = types.StringPointerValue(backupStore.CloudAccountType)
plan.CreatedAt = types.StringPointerValue(backupStore.CreatedAt)
plan.UpdatedAt = types.StringPointerValue(backupStore.UpdatedAt)
plan.Status = types.StringPointerValue(backupStore.Status)

// Handle Properties
Expand Down Expand Up @@ -186,7 +186,6 @@ func (r *backupStoreResource) Read(ctx context.Context, req resource.ReadRequest
state.CloudAccountID = types.StringPointerValue(backupStore.CloudAccountID)
state.CloudAccountType = types.StringPointerValue(backupStore.CloudAccountType)
state.CreatedAt = types.StringPointerValue(backupStore.CreatedAt)
state.UpdatedAt = types.StringPointerValue(backupStore.UpdatedAt)
state.Status = types.StringPointerValue(backupStore.Status)
state.Name = types.StringPointerValue(backupStore.Name)

Expand Down
6 changes: 0 additions & 6 deletions internals/provider/cloud-account/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ type CloudAccountDetails struct {
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
Description types.String `tfsdk:"description"`
Properties types.Map `tfsdk:"properties"`
}
Expand Down Expand Up @@ -83,10 +82,6 @@ func (d *cloudAccountsDataSource) Schema(_ context.Context, _ datasource.SchemaR
Computed: true,
Description: "Creation time of the cloud account",
},
"updated_at": schema.StringAttribute{
Computed: true,
Description: "Last update time of the cloud account",
},
"description": schema.StringAttribute{
Computed: true,
Description: "Description of the cloud account",
Expand Down Expand Up @@ -134,7 +129,6 @@ func (d *cloudAccountsDataSource) Read(ctx context.Context, req datasource.ReadR
Name: types.StringValue(*account.Name),
Type: types.StringValue(*account.Type),
CreatedAt: types.StringValue(*account.CreatedAt),
UpdatedAt: types.StringValue(*account.UpdatedAt),
Description: types.StringValue(account.Description),
Properties: propertiesMap,
}
Expand Down
18 changes: 10 additions & 8 deletions internals/provider/cloud-account/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/go-openapi/strfmt"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
pgEdge "github.com/pgEdge/terraform-provider-pgedge/client"
"github.com/pgEdge/terraform-provider-pgedge/client/models"
Expand Down Expand Up @@ -53,7 +55,6 @@ type CloudAccountResourceModel struct {
Type types.String `tfsdk:"type"`
Description types.String `tfsdk:"description"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
Credentials types.Map `tfsdk:"credentials"`
}

Expand All @@ -62,6 +63,9 @@ func (r *cloudAccountResource) Schema(_ context.Context, _ resource.SchemaReques
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"name": schema.StringAttribute{
Required: true,
Expand All @@ -74,9 +78,9 @@ func (r *cloudAccountResource) Schema(_ context.Context, _ resource.SchemaReques
},
"created_at": schema.StringAttribute{
Computed: true,
},
"updated_at": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"credentials": schema.MapAttribute{
Required: true,
Expand All @@ -100,9 +104,9 @@ func (r *cloudAccountResource) Create(ctx context.Context, req resource.CreateRe
}

createInput := &models.CreateCloudAccountInput{
Name: *plan.Name.ValueStringPointer(),
Name: plan.Name.ValueString(),
Type: plan.Type.ValueStringPointer(),
Description: *plan.Description.ValueStringPointer(),
Description: plan.Description.ValueString(),
Credentials: credentials,
}

Expand All @@ -114,7 +118,6 @@ func (r *cloudAccountResource) Create(ctx context.Context, req resource.CreateRe

plan.ID = types.StringValue(account.ID.String())
plan.CreatedAt = types.StringValue(*account.CreatedAt)
plan.UpdatedAt = types.StringValue(*account.UpdatedAt)

diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -146,7 +149,6 @@ func (r *cloudAccountResource) Read(ctx context.Context, req resource.ReadReques
state.Type = types.StringValue(*account.Type)
state.Description = types.StringValue(account.Description)
state.CreatedAt = types.StringValue(*account.CreatedAt)
state.UpdatedAt = types.StringValue(*account.UpdatedAt)

// Note: We don't update the credentials here as they are not returned by the API for security reasons

Expand Down
Loading

0 comments on commit 8e824d4

Please sign in to comment.