-
Notifications
You must be signed in to change notification settings - Fork 178
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
fix: avoid diff in state after import for undefined optional attribute in alert config notification #1412
fix: avoid diff in state after import for undefined optional attribute in alert config notification #1412
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 |
---|---|---|
|
@@ -291,6 +291,10 @@ func (r *AlertConfigurationRS) Schema(ctx context.Context, req resource.SchemaRe | |
}, | ||
"interval_min": schema.Int64Attribute{ | ||
Optional: true, | ||
Computed: true, | ||
PlanModifiers: []planmodifier.Int64{ | ||
int64planmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"mobile_number": schema.StringAttribute{ | ||
Optional: true, | ||
|
@@ -709,9 +713,6 @@ func newTFNotificationModelList(matlasSlice []matlas.Notification, currStateNoti | |
if !currState.EmailAddress.IsNull() { | ||
newState.EmailAddress = conversion.StringNullIfEmpty(value.EmailAddress) | ||
} | ||
if !currState.IntervalMin.IsNull() { | ||
newState.IntervalMin = types.Int64Value(int64(value.IntervalMin)) | ||
} | ||
Comment on lines
-712
to
-714
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. I was reading this plan-modification#plan-modification-process
I am wondering if 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. Yes your statement is correct, I could verify that the attribute in In this case, since it is a value that is always defined in the api request/response (defined as an int in manual sdk), we can simply define the value in the model. This is what solves the inconsistency issue when doing the import operation, because when importing you have no state/config to verify if field was defined by the user, so value coming from the api is set directly. |
||
if !currState.MobileNumber.IsNull() { | ||
newState.MobileNumber = conversion.StringNullIfEmpty(value.MobileNumber) | ||
} | ||
|
@@ -728,6 +729,7 @@ func newTFNotificationModelList(matlasSlice []matlas.Notification, currStateNoti | |
newState.Username = conversion.StringNullIfEmpty(value.Username) | ||
} | ||
|
||
newState.IntervalMin = types.Int64Value(int64(value.IntervalMin)) | ||
newState.DelayMin = types.Int64Value(int64(*value.DelayMin)) | ||
newState.EmailEnabled = types.BoolValue(value.EmailEnabled != nil && *value.EmailEnabled) | ||
newState.SMSEnabled = types.BoolValue(value.SMSEnabled != nil && *value.SMSEnabled) | ||
|
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.
Why is this modifier needed?
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.
Essentially to simplify the terraform plan output. The
interval_min
attribute will only change its value when modified by the user.As a counter example, alert configuration has an
updated
attribute that is computed and is not set with this modifier. In this case is seems appropriate to have the message(known after apply)
shown on the terraform plan because on every apply it will be modified.