-
Notifications
You must be signed in to change notification settings - Fork 82
fix(rabbitmq, redis): add modify plan functions #1684
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ var ( | |
| _ resource.Resource = &instanceResource{} | ||
| _ resource.ResourceWithConfigure = &instanceResource{} | ||
| _ resource.ResourceWithImportState = &instanceResource{} | ||
| _ resource.ResourceWithModifyPlan = &instanceResource{} | ||
| ) | ||
|
|
||
| type Model struct { | ||
|
|
@@ -105,6 +106,35 @@ func (r *instanceResource) Metadata(_ context.Context, req resource.MetadataRequ | |
| resp.TypeName = req.ProviderTypeName + "_rabbitmq_instance" | ||
| } | ||
|
|
||
| // ModifyPlan implements resource.ResourceWithModifyPlan. | ||
|
Contributor
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. Let's remove these comments, we usually don't have these on the functions
Contributor
Author
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. hmm, many resources have this comment in the modifyPlan function, that is why I also kept. |
||
| func (r *instanceResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { //nolint:gocritic // defined by terraform api | ||
| var configModel Model | ||
| // skip initial empty configuration to avoid follow-up errors | ||
| if req.Config.Raw.IsNull() { | ||
| return | ||
| } | ||
| resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| var planModel Model | ||
| resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // Configure adds the provider configured client to the resource. | ||
| func (r *instanceResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { | ||
| var ok bool | ||
|
|
@@ -517,7 +547,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques | |
| return | ||
| } | ||
| // Update existing instance | ||
| err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, instanceId, region).PartialUpdateInstancePayload(*payload).Execute() | ||
| err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(*payload).Execute() | ||
| if err != nil { | ||
| core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Calling API: %v", err)) | ||
| return | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ var ( | |
| _ resource.Resource = &credentialResource{} | ||
| _ resource.ResourceWithConfigure = &credentialResource{} | ||
| _ resource.ResourceWithImportState = &credentialResource{} | ||
| _ resource.ResourceWithModifyPlan = &credentialResource{} | ||
| ) | ||
|
|
||
| type Model struct { | ||
|
|
@@ -72,6 +73,36 @@ func (r *credentialResource) Metadata(_ context.Context, req resource.MetadataRe | |
| resp.TypeName = req.ProviderTypeName + "_redis_credential" | ||
| } | ||
|
|
||
| // ModifyPlan implements resource.ResourceWithModifyPlan. | ||
|
Contributor
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. here as well |
||
| // Use the modifier to set the effective region in the current plan. | ||
| func (r *credentialResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform | ||
| var configModel Model | ||
| // skip initial empty configuration to avoid follow-up errors | ||
| if req.Config.Raw.IsNull() { | ||
| return | ||
| } | ||
| resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| var planModel Model | ||
| resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // Configure adds the provider configured client to the resource. | ||
| func (r *credentialResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { | ||
| var ok bool | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ var ( | |
| _ resource.Resource = &instanceResource{} | ||
| _ resource.ResourceWithConfigure = &instanceResource{} | ||
| _ resource.ResourceWithImportState = &instanceResource{} | ||
| _ resource.ResourceWithModifyPlan = &instanceResource{} | ||
| ) | ||
|
|
||
| type Model struct { | ||
|
|
@@ -124,6 +125,35 @@ func (r *instanceResource) Metadata(_ context.Context, req resource.MetadataRequ | |
| resp.TypeName = req.ProviderTypeName + "_redis_instance" | ||
| } | ||
|
|
||
| // ModifyPlan implements resource.ResourceWithModifyPlan. | ||
|
Contributor
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. And here as well 😄 |
||
| func (r *instanceResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { //nolint:gocritic // defined by terraform api | ||
| var configModel Model | ||
| // skip initial empty configuration to avoid follow-up errors | ||
| if req.Config.Raw.IsNull() { | ||
| return | ||
| } | ||
| resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| var planModel Model | ||
| resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
|
|
||
| resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...) | ||
| if resp.Diagnostics.HasError() { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // Configure adds the provider configured client to the resource. | ||
| func (r *instanceResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { | ||
| var ok bool | ||
|
|
@@ -586,7 +616,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques | |
| return | ||
| } | ||
| // Update existing instance | ||
| err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, instanceId, region).PartialUpdateInstancePayload(*payload).Execute() | ||
| err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(*payload).Execute() | ||
| if err != nil { | ||
| core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Calling API: %v", err)) | ||
| return | ||
|
|
||
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.
here as well remove