这是indexloc提供的服务,不要输入任何密码
Skip to content

Allow updating Deployment delete_on_destroy field #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions vercel/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ func (r resourceDeployment) Read(ctx context.Context, req tfsdk.ReadResourceRequ
if err != nil {
resp.Diagnostics.AddError(
"Error reading deployment",
fmt.Sprintf("Could not get project %s %s, unexpected error: %s",
fmt.Sprintf("Could not get deployment %s %s, unexpected error: %s",
state.TeamID.Value,
state.URL.Value,
state.ID.Value,
err,
),
)
Expand All @@ -303,15 +303,40 @@ func (r resourceDeployment) Read(ctx context.Context, req tfsdk.ReadResourceRequ
}
}

// Update is a noop as it is not possible to update an existing deployment. Instead, all
// attributes must be set to force recreation.
// This method has to exist, however, to satisfy the resource interface.
// Update updates the deployment state.
// Note that only the `delete_on_destroy` field is updatable, and this does not affect Vercel. So it is just a case
// of setting terraform state.
func (r resourceDeployment) Update(ctx context.Context, req tfsdk.UpdateResourceRequest, resp *tfsdk.UpdateResourceResponse) {
// Nothing to do here - we can't update deployments
var plan Deployment
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
resp.Diagnostics.AddError(
"Error getting deployment plan",
"Error getting deployment plan",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing else worth adding here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy-pasted from the Create function. Might have a play and see what the output looks like 🤔. I suspect it might be one of those errors that's really hard to actually see, just because the schema validation kicks in before this point.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's worth figuring out if the errors raised here are actually useful for output, or if they're pretty much just flags to say "stop now, it didn't work"

)
return
}

var state Deployment
diags = req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Copy over the planned field only
state.DeleteOnDestroy = plan.DeleteOnDestroy
diags = resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two bare returns that don't surface the error

}
}

// Delete conditionally deletes a Deployment.
// Typically, Vercel users do not delete old Deployments so deployments will be deleted only if delete_on_destroy parameter is set to true
// Typically, Vercel users do not delete old Deployments so deployments will be deleted only if delete_on_destroy
// parameter is set to true.
func (r resourceDeployment) Delete(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) {
var state Deployment
diags := req.State.Get(ctx, &state)
Expand All @@ -335,7 +360,7 @@ func (r resourceDeployment) Delete(ctx context.Context, req tfsdk.DeleteResource
}
tflog.Trace(ctx, fmt.Sprintf("deleted deployment %s", dResp.UID))
} else {
tflog.Trace(ctx, fmt.Sprintf("deplyment %s deleted from the Terraform state", state.ID.Value))
tflog.Trace(ctx, fmt.Sprintf("deployment %s deleted from the Terraform state", state.ID.Value))
}
resp.State.RemoveResource(ctx)
}
Expand Down