Skip to content

Commit

Permalink
Merge pull request #136 from simplebitlabs/fix-invalid-result-object
Browse files Browse the repository at this point in the history
Ensure attributes aren't unknown after apply
  • Loading branch information
BarnabyShearer authored Sep 27, 2024
2 parents b56ac06 + fc38145 commit 85a93f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/resources/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ resource "slack-app_manifest" "example" {

- `credentials` (Attributes) (see [below for nested schema](#nestedatt--credentials))
- `id` (String) The ID of the app.
- `oauth_authorize_url` (String) Full URL for athorization.
- `oauth_authorize_url` (String) Full URL for authorization.

<a id="nestedatt--credentials"></a>
### Nested Schema for `credentials`
Expand Down
23 changes: 16 additions & 7 deletions internal/provider/manifest_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *manifestResource) Schema(_ context.Context, _ resource.SchemaRequest, r
},
"oauth_authorize_url": schema.StringAttribute{
Computed: true,
MarkdownDescription: "Full URL for athorization.",
MarkdownDescription: "Full URL for authorization.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Expand Down Expand Up @@ -119,8 +119,8 @@ type manifestResourceModel struct {
OAuthAuthorizeUrl types.String `tfsdk:"oauth_authorize_url"`
}

type createManifestReqest struct {
AppID string `json:"app_id,omit_empty"`
type createManifestRequest struct {
AppID string `json:"app_id,omitempty"`
Manifest string `json:"manifest"`
}

Expand All @@ -147,7 +147,7 @@ func (r *manifestResource) Create(ctx context.Context, req resource.CreateReques
return
}

request, _ := json.Marshal(createManifestReqest{
request, _ := json.Marshal(createManifestRequest{
Manifest: plan.Manifest.ValueString(),
})
var resultJson createManifestResponse
Expand Down Expand Up @@ -178,7 +178,7 @@ func (r *manifestResource) Read(ctx context.Context, req resource.ReadRequest, r
return
}

request, _ := json.Marshal(createManifestReqest{
request, _ := json.Marshal(createManifestRequest{
AppID: state.ID.ValueString(),
})
var resultJson exportManifestResponse
Expand All @@ -205,7 +205,7 @@ func (r *manifestResource) Update(ctx context.Context, req resource.UpdateReques
return
}

request, _ := json.Marshal(createManifestReqest{
request, _ := json.Marshal(createManifestRequest{
AppID: plan.ID.ValueString(),
Manifest: plan.Manifest.ValueString(),
})
Expand All @@ -215,6 +215,15 @@ func (r *manifestResource) Update(ctx context.Context, req resource.UpdateReques
return
}

// Slack only returns `credentials` and `oauth_authorize_url` on create, not update. If this was an imported
// app, just mark these value as null to avoid "Error: Provider returned invalid result object after apply".
if plan.Credentials.IsUnknown() {
plan.Credentials = types.ObjectNull(plan.Credentials.AttributeTypes(ctx))
}
if plan.OAuthAuthorizeUrl.IsUnknown() {
plan.OAuthAuthorizeUrl = types.StringNull()
}

diags = resp.State.Set(ctx, &plan)
resp.Diagnostics.Append(diags...)
}
Expand All @@ -229,7 +238,7 @@ func (r *manifestResource) Delete(ctx context.Context, req resource.DeleteReques
return
}

request, _ := json.Marshal(createManifestReqest{
request, _ := json.Marshal(createManifestRequest{
AppID: state.ID.ValueString(),
})
err := r.client.Request(ctx, "apps.manifest.delete", request, nil)
Expand Down

0 comments on commit 85a93f5

Please sign in to comment.