Skip to content

Commit

Permalink
Add plan modifiers to stop showing values that didn't change on TF plan
Browse files Browse the repository at this point in the history
  • Loading branch information
posriniv committed Jan 30, 2025
1 parent b3f3ac1 commit b89da0f
Showing 1 changed file with 123 additions and 8 deletions.
131 changes: 123 additions & 8 deletions managed/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,25 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Description: "The ID of the account this cluster belongs to.",
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"project_id": {
Description: "The ID of the project this cluster belongs to.",
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"cluster_id": {
Description: "The ID of the cluster. Created automatically when a cluster is created. Used to get a specific cluster.",
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"cluster_name": {
Description: "The name of the cluster.",
Expand All @@ -72,7 +81,10 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.StringType,
Optional: true,
Computed: true,
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("AWS", "GCP", "AZURE")},
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("AWS", "GCP", "AZURE")},
},
"cluster_region_info": {
Required: true,
Expand All @@ -90,6 +102,9 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.Int64Type,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
schemavalidator.ExactlyOneOf(
path.MatchRelative().AtParent().AtParent().AtParent().AtName("node_config").AtName("num_cores"),
Expand All @@ -102,6 +117,9 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.Int64Type,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
schemavalidator.ConflictsWith(
path.MatchRelative().AtParent().AtParent().AtParent().AtName("node_config").AtName("disk_size_gb"),
Expand All @@ -113,6 +131,9 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.Int64Type,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
schemavalidator.ConflictsWith(
path.MatchRelative().AtParent().AtParent().AtParent().AtName("node_config").AtName("disk_iops"),
Expand All @@ -123,6 +144,9 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.StringType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
schemavalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("vpc_name")),
},
Expand All @@ -131,69 +155,97 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.StringType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"public_access": {
Type: types.BoolType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"is_preferred": {
Type: types.BoolType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"is_default": {
Type: types.BoolType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
}),
},
"backup_schedules": {
Optional: true,
Attributes: tfsdk.ListNestedAttributes(map[string]tfsdk.Attribute{

"state": {

Description: "The state of the backup schedule. Used to pause or resume the backup schedule. Valid values are ACTIVE or PAUSED.",
Type: types.StringType,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},

"cron_expression": {
Description: "The cron expression for the backup schedule",
Type: types.StringType,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},

"time_interval_in_days": {
Description: "The time interval in days for the backup schedule.",
Type: types.Int64Type,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},

"retention_period_in_days": {
Description: "The retention period of the backup schedule.",
Type: types.Int64Type,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},

"backup_description": {
Description: "The description of the backup schedule.",
Type: types.StringType,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},

"schedule_id": {
Description: "The ID of the backup schedule. Created automatically when the backup schedule is created. Used to get a specific backup schedule.",
Type: types.StringType,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"incremental_interval_in_mins": {
Description: "The time interval in minutes for the incremental backup schedule.",
Expand Down Expand Up @@ -370,14 +422,20 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.StringType,
Optional: true,
Computed: true,
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("NONE", "NODE", "ZONE", "REGION")},
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("NONE", "NODE", "ZONE", "REGION")},
},
"num_faults_to_tolerate": {
Description: "The number of domain faults the cluster can tolerate. 0 for NONE, 1 for ZONE and [1-3] for NODE and REGION",
Type: types.Int64Type,
Optional: true,
Computed: true,
Validators: []tfsdk.AttributeValidator{int64validator.OneOf(0, 1, 2, 3)},
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{int64validator.OneOf(0, 1, 2, 3)},
},
"cluster_allow_list_ids": {
Description: "List of IDs of the allow lists assigned to the cluster.",
Expand All @@ -394,18 +452,27 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
"node_config": {
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
"num_cores": {
Description: "Number of CPU cores in the node.",
Type: types.Int64Type,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"disk_size_gb": {
Description: "Disk size of the node.",
Type: types.Int64Type,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
schemavalidator.ConflictsWith(
path.MatchRelative().AtParent().AtParent().AtName("cluster_region_info").AtAnyListIndex().AtName("disk_size_gb"),
Expand All @@ -417,6 +484,9 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.Int64Type,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
schemavalidator.ConflictsWith(
path.MatchRelative().AtParent().AtParent().AtName("cluster_region_info").AtAnyListIndex().AtName("disk_iops"),
Expand Down Expand Up @@ -469,40 +539,64 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
},
"cluster_info": {
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
"state": {
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"software_version": {
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"created_time": {
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"updated_time": {
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
}),
},
"cluster_version": {
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"database_track": {
Description: "The track of the database. Production or Innovation or Preview.",
Type: types.StringType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"desired_state": {
Description: "The desired state of the cluster, Active or Paused. This parameter can be used to pause/resume a cluster.",
Type: types.StringType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
// Validate string value must be "Active" or "Paused"
stringvalidator.OneOfCaseInsensitive([]string{"Active", "Paused"}...),
Expand All @@ -513,6 +607,9 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Type: types.StringType,
Optional: true,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Validators: []tfsdk.AttributeValidator{
// Validate string value must be "Enabled" or "Disabled"
stringvalidator.OneOfCaseInsensitive([]string{"Enabled", "Disabled"}...),
Expand All @@ -525,6 +622,9 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
ElemType: types.StringType,
},
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"endpoints": {
Description: "The endpoints used to connect to the cluster.",
Expand All @@ -533,27 +633,42 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
Description: "The accessibility type of the endpoint. PUBLIC or PRIVATE.",
Type: types.StringType,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Optional: true,
},
"host": {
Description: "The host of the endpoint.",
Type: types.StringType,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Optional: true,
},
"region": {
Description: "The region of the endpoint.",
Type: types.StringType,
Computed: true,
Optional: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
Optional: true,
},
}),
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
"cluster_certificate": {
Description: "The certificate used to connect to the cluster.",
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
},
}
// Remove once feature flag is enabled
Expand Down

0 comments on commit b89da0f

Please sign in to comment.