I’m fooling around with two new custom types with semantic equality in my provider:
StringWithAltValues
is a custom string type which contains semantically equal alternate values:
type StringWithAltValues struct {
basetypes.StringValue
altValues []attr.Value
}
func NewStringWithAltValuesValue(value string, alt ...string) StringWithAltValues {
altValues := make([]attr.Value, len(alt))
for i, a := range alt {
altValues[i] = StringWithAltValues{StringValue: basetypes.NewStringValue(a)}
}
return StringWithAltValues{
StringValue: basetypes.NewStringValue(value),
altValues: altValues,
}
}
The idea is that values passed to Terraform during Read()
might wind up like this:
someVal := NewStringWithAltValuesValue("Space Cowboy", "Gangster of Love", "Maurice")
This way, I won’t have to care which exact string is in the configuration.
I’ve also got this other custom type:
type SetWithSemanticEquals struct {
basetypes.SetValue
ignoreLength bool // currently unused
}
This thing expects elements to implement semantic equality and relies on it in SetSemanticEquals()
The idea, then is that these two sets might be considered semantically equal:
["Maurice", "red"]
["#ff0000", "Midnight Toker", "rojo", "rouge"]
I’m probably doing something obviously wrong, but I can’t see it right now. terraform validate
is telling me:
panic: SetValueMust received error(s): Error | Invalid Set Element Type | While creating a Set value, an invalid element was detected. A Set must use the single, given element type. This is always an issue with the provider and should be reported to the provider developers.
Set Element Type: types.ObjectType["access_ids":types.SetType[customtypes.StringWithAltValues], "leaf_id":customtypes.StringWithAltValues, "vlan_id":basetypes.Int64Type]
Set Index (0) Element Type: types.ObjectType["access_ids":types.SetType[customtypes.StringWithAltValues], "leaf_id":customtypes.StringWithAltValues, "vlan_id":basetypes.Int64Type]
…which… Those types match, so what’s the problem?
Steps to reproduce:
git clone https://github.com/Juniper/terraform-provider-apstra.git
cd terraform-provider-apstra
git checkout 1373852
go install
curl https://pastebin.com/raw/NTEhgAK7 > main.tf
- Set up
~/.terraformrc
(below), and then runterraform validate
:
# ~/.terraformrc example
provider_installation {
dev_overrides {
"Juniper/apstra" = "/path/to/go/bin"
}
direct {}
}