Hello,
I am trying to use a validator on a bool argument so that it requires at least one of other 2 attributes to be set. I am trying to use AtLeastOneOf
, but it’s not working.
Schema:
Attributes: map[string]schema.Attribute{
"enabled": schema.BoolAttribute{
Description: fmt.Sprintf("Whether the DHCP server is enabled. Defaults to `%t`", CONFIG_DHCP_ENABLED),
Computed: true,
Optional: true,
Default: booldefault.StaticBool(CONFIG_DHCP_ENABLED),
Validators: []validator.Bool{
boolvalidator.AtLeastOneOf(path.Expressions{
path.MatchRelative().AtParent().AtName("ipv4_settings"),
path.MatchRelative().AtParent().AtName("ipv6_settings"),
}...),
},
},
If I replace AtLeastOneOf
with AlsoRequires
, the validation works, but that means I need to supply both attributes, which is not the case:
│ Error: Invalid Attribute Combination
│
│ with adguard_config.test,
│ on main.tf line 79, in resource "adguard_config" "test":
│ 79: resource "adguard_config" "test" {
│
│ Attribute "dhcp.ipv4_settings" must be specified when "dhcp.enabled" is specified
╵
╷
│ Error: Invalid Attribute Combination
│
│ with adguard_config.test,
│ on main.tf line 79, in resource "adguard_config" "test":
│ 79: resource "adguard_config" "test" {
│
│ Attribute "dhcp.ipv6_settings" must be specified when "dhcp.enabled" is specified
What am I doing wrong here?
Thank you