-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename CustomStringValue and CustomStringType to AAPCustomStringValue…
… and AAPCustomStringType Signed-off-by: Alina Buzachis <[email protected]>
- Loading branch information
1 parent
6e3256b
commit b756aa4
Showing
19 changed files
with
208 additions
and
211 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 |
---|---|---|
|
@@ -73,4 +73,4 @@ output "group_abc" { | |
|
||
output "group_xyz" { | ||
value = aap_group.sample_xyz | ||
} | ||
} |
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 |
---|---|---|
|
@@ -77,4 +77,4 @@ output "host_abc" { | |
} | ||
output "host_xyz" { | ||
value = aap_host.sample_xyz | ||
} | ||
} |
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 |
---|---|---|
|
@@ -77,4 +77,4 @@ output "inventory_abc" { | |
|
||
output "inventory_xyz" { | ||
value = aap_inventory.sample_xyz | ||
} | ||
} |
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
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
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,93 @@ | ||
package customtypes | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
) | ||
|
||
var ( | ||
_ = basetypes.StringValuable(&AAPCustomStringValue{}) | ||
_ = basetypes.StringValuableWithSemanticEquals(&AAPCustomStringValue{}) | ||
) | ||
|
||
// AAPCustomStringValue implements a custom Terraform value. | ||
type AAPCustomStringValue struct { | ||
basetypes.StringValue | ||
} | ||
|
||
// NewAAPCustomStringNull creates a AAPCustomStringValue with a null value. Determine | ||
// whether the value is null via the AAPCustomStringValue type IsNull method. | ||
func NewAAPCustomStringNull() AAPCustomStringValue { | ||
return AAPCustomStringValue{ | ||
StringValue: basetypes.NewStringNull(), | ||
} | ||
} | ||
|
||
// NewAAPCustomStringUnknown creates a AAPCustomStringValue with an unknown value. | ||
func NewAAPCustomStringUnknown() AAPCustomStringValue { | ||
return AAPCustomStringValue{ | ||
StringValue: basetypes.NewStringUnknown(), | ||
} | ||
} | ||
|
||
// NewAAPCustomStringValue creates a AAPCustomStringValue with a known value. | ||
func NewAAPCustomStringValue(value string) AAPCustomStringValue { | ||
return AAPCustomStringValue{ | ||
StringValue: basetypes.NewStringValue(value), | ||
} | ||
} | ||
|
||
// NewAAPCustomStringPointerValue creates a AAPCustomStringValue with a null value if | ||
// nil or a known value. | ||
func NewCustomStringPointerValue(value *string) AAPCustomStringValue { | ||
if value == nil { | ||
return NewAAPCustomStringNull() | ||
} | ||
|
||
return NewAAPCustomStringValue(*value) | ||
} | ||
|
||
// Equal returns true if the given value is equivalent. | ||
func (v AAPCustomStringValue) Equal(o attr.Value) bool { | ||
other, ok := o.(AAPCustomStringValue) | ||
if !ok { | ||
return false | ||
} | ||
|
||
return v.StringValue.Equal(other.StringValue) | ||
} | ||
|
||
// Type returns an instance of the type. | ||
func (v AAPCustomStringValue) Type(_ context.Context) attr.Type { | ||
return AAPCustomStringType{} | ||
} | ||
|
||
func (v AAPCustomStringValue) String() string { | ||
return "AAPCustomStringValue" | ||
} | ||
|
||
// StringSemanticEquals checks if two AAPCustomStringValue objects have | ||
// equivalent values, even if they are not equal. | ||
func (v AAPCustomStringValue) StringSemanticEquals(_ context.Context, newValuable basetypes.StringValuable) (bool, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
|
||
newValue, ok := newValuable.(AAPCustomStringValue) | ||
if !ok { | ||
diags.AddError( | ||
"Semantic Equality Check Error", | ||
fmt.Sprintf("Expected value type %T but got value type %T. Please report this to the provider developers.", v, newValuable), | ||
) | ||
|
||
return false, diags | ||
} | ||
|
||
priorValue := v.ValueString() | ||
currentValue := strings.TrimSpace(newValue.ValueString()) | ||
|
||
return priorValue == currentValue, nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.