-
Notifications
You must be signed in to change notification settings - Fork 205
feat: Long-running operation improvements for mongodbatlas_flex_cluster
resource
#3525
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: CLOUDP-320243-dev-2.0.0
Are you sure you want to change the base?
Changes from 6 commits
ecec0cd
09ea70c
4e57721
ab24521
69f0c40
3bed1db
9e51912
342d64a
3cfc917
bb7c257
56b6dc8
b0d39a8
55f67aa
8d2d1f0
37b192a
13b41ce
4ff82b3
d1d777c
66c72ef
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:enhancement | ||
resource/mongodbatlas_flex_cluster: Adds `timeouts` attribute for create, update and delete operations | ||
``` | ||
|
||
```release-note:enhancement | ||
resource/mongodbatlas_flex_cluster: Adds `delete_on_create_timeout` attribute to indicate whether to delete the resource if its creation times out | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package customplanmodifier | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
planmodifier "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
) | ||
|
||
// CreateOnlyStringPlanModifier creates a plan modifier that prevents updates to string attributes. | ||
func CreateOnlyStringPlanModifier() planmodifier.String { | ||
return &createOnlyAttributePlanModifier{} | ||
} | ||
|
||
// CreateOnlyBoolPlanModifier creates a plan modifier that prevents updates to boolean attributes. | ||
func CreateOnlyBoolPlanModifier() planmodifier.Bool { | ||
return &createOnlyAttributePlanModifier{} | ||
} | ||
|
||
// Plan modifier that implements create-only behavior for multiple attribute types | ||
type createOnlyAttributePlanModifier struct{} | ||
|
||
func (d *createOnlyAttributePlanModifier) Description(ctx context.Context) string { | ||
return d.MarkdownDescription(ctx) | ||
} | ||
|
||
func (d *createOnlyAttributePlanModifier) MarkdownDescription(ctx context.Context) string { | ||
return "Ensures that update operations fail when attempting to modify a create-only attribute." | ||
} | ||
|
||
func (d *createOnlyAttributePlanModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { | ||
validateCreateOnly(req.PlanValue, req.StateValue, req.Path, &resp.Diagnostics) | ||
} | ||
|
||
func (d *createOnlyAttributePlanModifier) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) { | ||
validateCreateOnly(req.PlanValue, req.StateValue, req.Path, &resp.Diagnostics) | ||
} | ||
|
||
// validateCreateOnly checks if an attribute value has changed and adds an error if it has | ||
func validateCreateOnly(planValue, stateValue attr.Value, attrPath path.Path, diagnostics *diag.Diagnostics, | ||
) { | ||
if !stateValue.IsNull() && !stateValue.Equal(planValue) { | ||
diagnostics.AddError( | ||
fmt.Sprintf("%s cannot be updated", attrPath), | ||
fmt.Sprintf("%s cannot be updated", attrPath), | ||
) | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package flexcluster | |||||
import ( | ||||||
"context" | ||||||
|
||||||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" | ||||||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||||||
"github.com/hashicorp/terraform-plugin-framework/types" | ||||||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/customplanmodifier" | ||||||
|
@@ -21,14 +22,14 @@ func ResourceSchema(ctx context.Context) schema.Schema { | |||||
"project_id": schema.StringAttribute{ | ||||||
Required: true, | ||||||
PlanModifiers: []planmodifier.String{ | ||||||
customplanmodifier.NonUpdatableStringAttributePlanModifier(), | ||||||
customplanmodifier.CreateOnlyStringPlanModifier(), | ||||||
}, | ||||||
MarkdownDescription: "Unique 24-hexadecimal character string that identifies the project.", | ||||||
}, | ||||||
"name": schema.StringAttribute{ | ||||||
Required: true, | ||||||
PlanModifiers: []planmodifier.String{ | ||||||
customplanmodifier.NonUpdatableStringAttributePlanModifier(), | ||||||
customplanmodifier.CreateOnlyStringPlanModifier(), | ||||||
}, | ||||||
MarkdownDescription: "Human-readable label that identifies the instance.", | ||||||
}, | ||||||
|
@@ -37,7 +38,7 @@ func ResourceSchema(ctx context.Context) schema.Schema { | |||||
"backing_provider_name": schema.StringAttribute{ | ||||||
Required: true, | ||||||
PlanModifiers: []planmodifier.String{ | ||||||
customplanmodifier.NonUpdatableStringAttributePlanModifier(), | ||||||
customplanmodifier.CreateOnlyStringPlanModifier(), | ||||||
}, | ||||||
MarkdownDescription: "Cloud service provider on which MongoDB Cloud provisioned the flex cluster.", | ||||||
}, | ||||||
|
@@ -58,7 +59,7 @@ func ResourceSchema(ctx context.Context) schema.Schema { | |||||
"region_name": schema.StringAttribute{ | ||||||
Required: true, | ||||||
PlanModifiers: []planmodifier.String{ | ||||||
customplanmodifier.NonUpdatableStringAttributePlanModifier(), | ||||||
customplanmodifier.CreateOnlyStringPlanModifier(), | ||||||
}, | ||||||
MarkdownDescription: "Human-readable label that identifies the geographic location of your MongoDB flex cluster. The region you choose can affect network latency for clients accessing your databases. For a complete list of region names, see [AWS](https://docs.atlas.mongodb.com/reference/amazon-aws/#std-label-amazon-aws), [GCP](https://docs.atlas.mongodb.com/reference/google-gcp/), and [Azure](https://docs.atlas.mongodb.com/reference/microsoft-azure/).", | ||||||
}, | ||||||
|
@@ -145,24 +146,39 @@ func ResourceSchema(ctx context.Context) schema.Schema { | |||||
}, | ||||||
MarkdownDescription: "Method by which the cluster maintains the MongoDB versions.", | ||||||
}, | ||||||
"delete_on_create_timeout": schema.BoolAttribute{ | ||||||
Optional: true, | ||||||
PlanModifiers: []planmodifier.Bool{ | ||||||
customplanmodifier.CreateOnlyBoolPlanModifier(), | ||||||
}, | ||||||
|
||||||
MarkdownDescription: "Indicates whether to delete the resource if creation times out. Default is `true`. When Terraform apply fails, it returns immediately without waiting for cleanup to complete. If you suspect a transient error, wait before retrying to allow resource deletion to finish.", | ||||||
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.
Suggested change
The 3rd sentence was confusing to me, would just leave as one description. 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. This is following the description in https://github.com/mongodb/terraform-provider-mongodbatlas/pull/3515/files#diff-e9d48cdf6bde5c047a1a852d6c3275175fe0a3d47f7ab543facdf8663b57fc57R334 which was reviewed by docs team. |
||||||
}, | ||||||
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{ | ||||||
Create: true, | ||||||
Update: true, | ||||||
Delete: true, | ||||||
}), | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
type TFModel struct { | ||||||
ProviderSettings types.Object `tfsdk:"provider_settings"` | ||||||
ConnectionStrings types.Object `tfsdk:"connection_strings"` | ||||||
Tags types.Map `tfsdk:"tags"` | ||||||
CreateDate types.String `tfsdk:"create_date"` | ||||||
ProjectId types.String `tfsdk:"project_id"` | ||||||
Id types.String `tfsdk:"id"` | ||||||
MongoDbversion types.String `tfsdk:"mongo_db_version"` | ||||||
Name types.String `tfsdk:"name"` | ||||||
ClusterType types.String `tfsdk:"cluster_type"` | ||||||
StateName types.String `tfsdk:"state_name"` | ||||||
VersionReleaseSystem types.String `tfsdk:"version_release_system"` | ||||||
BackupSettings types.Object `tfsdk:"backup_settings"` | ||||||
TerminationProtectionEnabled types.Bool `tfsdk:"termination_protection_enabled"` | ||||||
Tags types.Map `tfsdk:"tags"` | ||||||
MongoDbversion types.String `tfsdk:"mongo_db_version"` | ||||||
ClusterType types.String `tfsdk:"cluster_type"` | ||||||
CreateDate types.String `tfsdk:"create_date"` | ||||||
ProjectId types.String `tfsdk:"project_id"` | ||||||
Id types.String `tfsdk:"id"` | ||||||
ProviderSettings types.Object `tfsdk:"provider_settings"` | ||||||
Name types.String `tfsdk:"name"` | ||||||
ConnectionStrings types.Object `tfsdk:"connection_strings"` | ||||||
StateName types.String `tfsdk:"state_name"` | ||||||
VersionReleaseSystem types.String `tfsdk:"version_release_system"` | ||||||
BackupSettings types.Object `tfsdk:"backup_settings"` | ||||||
Timeouts timeouts.Value `tfsdk:"timeouts"` | ||||||
DeleteOnCreateTimeout types.Bool `tfsdk:"delete_on_create_timeout"` | ||||||
TerminationProtectionEnabled types.Bool `tfsdk:"termination_protection_enabled"` | ||||||
} | ||||||
|
||||||
type TFBackupSettings struct { | ||||||
|
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.
[nit] Would improve the details by showing the plan & stateValue.