-
Notifications
You must be signed in to change notification settings - Fork 197
fix: Sets default value for WithDefaultAlertsSettings during state import #3105
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
Open
EspenAlbert
wants to merge
14
commits into
master
Choose a base branch
from
CLOUDP-302586_fix_project_no_plan_change_for_with_default_alert_settings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
53de463
fix: Sets default value for WithDefaultAlertsSettings during state im…
EspenAlbert 26f7353
chore: Adds release note
EspenAlbert 5e67e14
fix: Removes 'with_default_alerts_settings' from ImportStateVerifyIgn…
EspenAlbert 57ddae6
doc: update changelog message
EspenAlbert 7bc763e
doc: Add back reference based on comments
EspenAlbert de2589d
revert changes of old implementation
EspenAlbert 7934ad0
refactor: Introduce Modifier interface and enhance non-updatable attr…
EspenAlbert af84e38
refactor: Mark with_default_alerts_settings as NonUpdateable
EspenAlbert 66e55e9
refactor:Rename NonUpdatableAttributePlanModifier with CreateOnlyAttr…
EspenAlbert e11fc3f
Merge branch 'master' into CLOUDP-302586_fix_project_no_plan_change_f…
EspenAlbert bd76a93
feat: Implement CreateOnlyAttributePlanModifier with default boolean …
EspenAlbert d0cb772
chore: small fix to planModifier using state value when Unknown in th…
EspenAlbert 57f8e64
test: Support testing plan error after importing
EspenAlbert 4ae2ccc
doc: Update error message in addDiags to clarify import restrictions
EspenAlbert 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
resource/mongodbatlas_project: Fixes import when `with_default_alerts_settings` is set | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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" | ||
) | ||
|
||
type Modifier interface { | ||
planmodifier.String | ||
planmodifier.Bool | ||
} | ||
|
||
func CreateOnlyAttributePlanModifier() Modifier { | ||
return &createOnlyAttributePlanModifier{} | ||
} | ||
|
||
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 fails when updating an attribute." | ||
} | ||
|
||
func (d *createOnlyAttributePlanModifier) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) { | ||
if d.isUpdated(req.PlanValue, req.StateValue) { | ||
d.addDiags(&resp.Diagnostics, req.Path) | ||
} | ||
} | ||
|
||
func (d *createOnlyAttributePlanModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { | ||
if d.isUpdated(req.PlanValue, req.StateValue) { | ||
d.addDiags(&resp.Diagnostics, req.Path) | ||
} | ||
} | ||
|
||
func (d *createOnlyAttributePlanModifier) isUpdated(planValue, stateValue attr.Value) bool { | ||
return !stateValue.IsNull() && !planValue.Equal(stateValue) | ||
} | ||
|
||
func (d *createOnlyAttributePlanModifier) addDiags(diags *diag.Diagnostics, attrPath path.Path) { | ||
message := fmt.Sprintf("%s cannot be updated", attrPath) | ||
diags.AddError(message, message) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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.
Can we add a comment on what this plan modifier does & why it's needed?