-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
), | ||
) | ||
|
@@ -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", | ||
) | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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"