Skip to content

Commit

Permalink
Housekeeping work for schema
Browse files Browse the repository at this point in the history
  • Loading branch information
simaotwx committed Aug 14, 2024
1 parent 876ea14 commit 1dda7ec
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion provider/resource_packer_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ type resourceImageTypeV0 struct {
Name types.String `tfsdk:"name"`
}

type resourceImageTypeV1 struct {
ID types.String `tfsdk:"id"`
Variables types.Dynamic `tfsdk:"variables"`
AdditionalParams []string `tfsdk:"additional_params"`
Directory types.String `tfsdk:"directory"`
File types.String `tfsdk:"file"`
Environment map[string]string `tfsdk:"environment"`
IgnoreEnvironment types.Bool `tfsdk:"ignore_environment"`
Triggers map[string]string `tfsdk:"triggers"`
Force types.Bool `tfsdk:"force"`
BuildUUID types.String `tfsdk:"build_uuid"`
Name types.String `tfsdk:"name"`
}

func (r resourceImageType) NewResource(_ context.Context, p provider.Provider) (resource.Resource, diag.Diagnostics) {
return resourceImage{
p: *(p.(*tfProvider)),
Expand Down Expand Up @@ -130,7 +144,7 @@ func (r resourceImage) Schema(_ context.Context, _ resource.SchemaRequest, respo
Computed: true,
},
},
Version: 1,
Version: 2,
},
}
}
Expand Down Expand Up @@ -205,6 +219,70 @@ func (r resourceImage) UpgradeState(ctx context.Context) map[int64]resource.Stat
resp.Diagnostics.Append(resp.State.Set(ctx, upgradedStateData)...)
},
},
1: {
PriorSchema: &schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"name": schema.StringAttribute{
Optional: true,
},
"variables": schema.DynamicAttribute{
Optional: true,
},
"additional_params": schema.SetAttribute{
ElementType: types.StringType,
Optional: true,
},
"directory": schema.StringAttribute{
Optional: true,
},
"file": schema.StringAttribute{
Optional: true,
},
"force": schema.BoolAttribute{
Optional: true,
},
"environment": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
},
"ignore_environment": schema.BoolAttribute{
Optional: true,
},
"triggers": schema.MapAttribute{
ElementType: types.StringType,
Optional: true,
},
"build_uuid": schema.StringAttribute{
Computed: true,
},
},
},
StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
var priorStateData resourceImageTypeV1
resp.Diagnostics.Append(req.State.Get(ctx, &priorStateData)...)
if resp.Diagnostics.HasError() {
return
}

upgradedStateData := resourceImageType{
Variables: priorStateData.Variables,
SensitiveVariables: types.DynamicNull(),
AdditionalParams: priorStateData.AdditionalParams,
Directory: priorStateData.Directory,
File: priorStateData.File,
Environment: priorStateData.Environment,
IgnoreEnvironment: priorStateData.IgnoreEnvironment,
Triggers: priorStateData.Triggers,
Force: priorStateData.Force,
BuildUUID: priorStateData.BuildUUID,
Name: priorStateData.Name,
}
resp.Diagnostics.Append(resp.State.Set(ctx, upgradedStateData)...)
},
},
}
}

Expand Down

0 comments on commit 1dda7ec

Please sign in to comment.