-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,55 @@ | ||
package setplanmodifier | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/airbytehq/terraform-provider-airbyte/internal/planmodifiers/utils" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
// UniqueByKey returnsa plan modifier that identifies each item in a set by a primary key (e.g name) | ||
func UniqueByKey(key string) planmodifier.Set { | ||
return uniqueByKey{ | ||
key: key, | ||
} | ||
} | ||
|
||
// uniqueByKey implements the plan modifier. | ||
type uniqueByKey struct { | ||
key string | ||
} | ||
|
||
// Description returns a human-readable description of the plan modifier. | ||
func (m uniqueByKey) Description(_ context.Context) string { | ||
return "Once set, the value of this attribute in state will not change." | ||
} | ||
|
||
// MarkdownDescription returns a markdown description of the plan modifier. | ||
func (m uniqueByKey) MarkdownDescription(_ context.Context) string { | ||
return "Once set, the value of this attribute in state will not change." | ||
} | ||
|
||
// PlanModifySet implements the plan modification logic. | ||
func (m uniqueByKey) PlanModifySet(ctx context.Context, req planmodifier.SetRequest, resp *planmodifier.SetResponse) { | ||
// Do nothing if there is an unknown configuration value | ||
if req.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
if utils.IsAllStateUnknown(ctx, req.State) { | ||
return | ||
} | ||
|
||
planList := req.PlanValue.Elements() | ||
//planItemsByKey := make(map[string]types.Object) | ||
for i := 0; i < len(planList); i++ { | ||
var set types.Set | ||
diags := req.Plan.GetAttribute(ctx, req.Path, &set) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} | ||
} |
This file contains 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