Skip to content

Commit

Permalink
Add missed plan request modifiers for resources
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprogrammr committed Jun 15, 2024
1 parent ecb2244 commit 232983e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/resources/achievement.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ resource "appstore_achievement" "test" {

### Required

- `game_center_id` (String) Identifier of the game center to associate the achievement with.
- `game_center_id` (String) Identifier of the game center to associate the achievement with. Resource will be re-created if this value is changed.
- `points` (Number) The points that each achievement is worth.
- `reference_name` (String) An internal name of the achievement.
- `repeatable` (Boolean) An indication of whether the player can earn the achievement multiple times.
- `show_before_earned` (Boolean) An indication of whether the achievement is visible to the player before it is earned.
- `vendor_id` (String) A chosen alphanumeric identifier of the achievement.
- `vendor_id` (String) A chosen alphanumeric identifier of the achievement. Resource will be re-created if this value is changed.

### Read-Only

Expand Down
6 changes: 3 additions & 3 deletions docs/resources/achievement_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ resource "appstore_achievement_image" "en-US" {

### Required

- `achievement_localization_id` (String) Identifier of the achievement localization to associate the image with.
- `file` (String) Path to the image file.
- `achievement_localization_id` (String) Identifier of the achievement localization to associate the image with. Resource will be re-created if this value is changed.
- `file` (String) Path to the image file. Resource will be re-created if this value is changed.

### Read-Only

- `checksum` (String) MD5 checksum of the image.
- `checksum` (String) MD5 checksum of the image. Resource will be re-created if this value is changed.
- `id` (String) Identifier of the achievement image.
4 changes: 2 additions & 2 deletions docs/resources/achievement_localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ resource "appstore_achievement_localization" "en-US" {

### Required

- `achievement_id` (String) Identifier of the achievement to associate the localization with.
- `achievement_id` (String) Identifier of the achievement to associate the localization with. Resource will be re-created if this value is changed.
- `after_earned_description` (String) Description of the achievement after it is earned.
- `before_earned_description` (String) Description of the achievement before it is earned.
- `locale` (String) Locale of the achievement localization.
- `locale` (String) Locale of the achievement localization. Resource will be re-created if this value is changed.
- `name` (String) Name of the achievement.

### Read-Only
Expand Down
23 changes: 18 additions & 5 deletions internal/provider/achievement_image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ func (r *achievementImageResource) Schema(_ context.Context, _ resource.SchemaRe
Computed: true,
},
"achievement_localization_id": schema.StringAttribute{
Description: "Identifier of the achievement localization to associate the image with.",
Description: "Identifier of the achievement localization to associate the image with. Resource will be re-created if this value is changed.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"file": schema.StringAttribute{
Description: "Path to the image file.",
Description: "Path to the image file. Resource will be re-created if this value is changed.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"checksum": schema.StringAttribute{
Description: "MD5 checksum of the image.",
Description: "MD5 checksum of the image. Resource will be re-created if this value is changed.",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
Expand Down Expand Up @@ -139,6 +145,13 @@ func (r *achievementImageResource) Read(ctx context.Context, req resource.ReadRe
return
}

file := state.File.ValueString()
if _, err := os.Stat(file); os.IsNotExist(err) {
state.File = types.StringValue("")
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
return
}

image, err := os.ReadFile(state.File.ValueString())
if err != nil {
resp.Diagnostics.AddError(
Expand All @@ -150,9 +163,9 @@ func (r *achievementImageResource) Read(ctx context.Context, req resource.ReadRe

if state.Checksum.ValueString() != checksum(image) {
state.File = types.StringValue("")
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
return
}

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r *achievementImageResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down
12 changes: 10 additions & 2 deletions internal/provider/achievement_localization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/alexprogrammr/appstore-go"
"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"
)

Expand Down Expand Up @@ -52,12 +54,18 @@ func (r *achievementLocalizationResource) Schema(_ context.Context, _ resource.S
Computed: true,
},
"achievement_id": schema.StringAttribute{
Description: "Identifier of the achievement to associate the localization with.",
Description: "Identifier of the achievement to associate the localization with. Resource will be re-created if this value is changed.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"locale": schema.StringAttribute{
Description: "Locale of the achievement localization.",
Description: "Locale of the achievement localization. Resource will be re-created if this value is changed.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"name": schema.StringAttribute{
Description: "Name of the achievement.",
Expand Down
12 changes: 10 additions & 2 deletions internal/provider/achievement_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/alexprogrammr/appstore-go"
"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"
)

Expand Down Expand Up @@ -53,16 +55,22 @@ func (r *achievementResource) Schema(_ context.Context, _ resource.SchemaRequest
Computed: true,
},
"game_center_id": schema.StringAttribute{
Description: "Identifier of the game center to associate the achievement with.",
Description: "Identifier of the game center to associate the achievement with. Resource will be re-created if this value is changed.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"reference_name": schema.StringAttribute{
Description: "An internal name of the achievement.",
Required: true,
},
"vendor_id": schema.StringAttribute{
Description: "A chosen alphanumeric identifier of the achievement.",
Description: "A chosen alphanumeric identifier of the achievement. Resource will be re-created if this value is changed.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"points": schema.Int64Attribute{
Description: "The points that each achievement is worth.",
Expand Down

0 comments on commit 232983e

Please sign in to comment.