Skip to content

Commit

Permalink
r/forwardingoptions_dhcprelay_group: fix missing tests in config vali…
Browse files Browse the repository at this point in the history
…dation

- detection of conflict between dynamic_profile_aggregate_clients and dynamic_profile_use_primary arguments
- detection of empty overrides_v4 and overrides_v6 block arguments
  • Loading branch information
jeremmfr committed Jan 13, 2025
1 parent 69a7575 commit a310990
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .changes/latest-system-resources-with-fwk.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ BUG FIXES:
* **resource/junos_forwardingoptions_dhcprelay**:
* fix missing detection of conflict between `dynamic_profile_aggregate_clients` and `dynamic_profile_use_primary` arguments in config validation
* fix missing detection of empty `overrides_v4` and `overrides_v6` block arguments in config validation
* **resource/junos_forwardingoptions_dhcprelay_group**:
* fix missing detection of conflict between `dynamic_profile_aggregate_clients` and `dynamic_profile_use_primary` arguments in config validation
* fix missing detection of empty `overrides_v4` and `overrides_v6` block arguments in config validation
94 changes: 76 additions & 18 deletions internal/providerfwk/resource_forwardingoptions_dhcprelay_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,16 @@ func (rsc *forwardingoptionsDhcprelayGroup) ValidateConfig( //nolint:gocognit,go
}
}

if !config.DynamicProfileAggregateClients.IsNull() &&
!config.DynamicProfileAggregateClients.IsUnknown() &&
!config.DynamicProfileUsePrimary.IsNull() &&
!config.DynamicProfileUsePrimary.IsUnknown() {
resp.Diagnostics.AddAttributeError(
path.Root("dynamic_profile_aggregate_clients"),
tfdiag.ConflictConfigErrSummary,
"dynamic_profile_aggregate_clients and dynamic_profile_use_primary cannot be configured together",
)
}
if !config.DynamicProfileAggregateClients.IsNull() &&
!config.DynamicProfileAggregateClients.IsUnknown() &&
config.DynamicProfile.IsNull() {
Expand Down Expand Up @@ -1104,6 +1114,17 @@ func (rsc *forwardingoptionsDhcprelayGroup) ValidateConfig( //nolint:gocognit,go
interfaceName[name] = struct{}{}
}

if !block.DynamicProfileAggregateClients.IsNull() &&
!block.DynamicProfileAggregateClients.IsUnknown() &&
!block.DynamicProfileUsePrimary.IsNull() &&
!block.DynamicProfileUsePrimary.IsUnknown() {
resp.Diagnostics.AddAttributeError(
path.Root("interface"),
tfdiag.ConflictConfigErrSummary,
fmt.Sprintf("dynamic_profile_aggregate_clients and dynamic_profile_use_primary cannot be configured together"+
" in interface block %q", block.Name.ValueString()),
)
}
if !block.DynamicProfileAggregateClients.IsNull() &&
!block.DynamicProfileAggregateClients.IsUnknown() &&
block.DynamicProfile.IsNull() {
Expand All @@ -1118,7 +1139,7 @@ func (rsc *forwardingoptionsDhcprelayGroup) ValidateConfig( //nolint:gocognit,go
!block.DynamicProfileAggregateClientsAction.IsUnknown() &&
block.DynamicProfileAggregateClients.IsNull() {
resp.Diagnostics.AddAttributeError(
path.Root("dynamic_profile_aggregate_clients_action"),
path.Root("interface"),
tfdiag.MissingConfigErrSummary,
fmt.Sprintf("dynamic_profile_aggregate_clients must be specified with dynamic_profile_aggregate_clients_action"+
" in interface block %q", block.Name.ValueString()),
Expand All @@ -1128,29 +1149,48 @@ func (rsc *forwardingoptionsDhcprelayGroup) ValidateConfig( //nolint:gocognit,go
!block.DynamicProfileUsePrimary.IsUnknown() &&
block.DynamicProfile.IsNull() {
resp.Diagnostics.AddAttributeError(
path.Root("dynamic_profile_use_primary"),
path.Root("interface"),
tfdiag.MissingConfigErrSummary,
fmt.Sprintf("dynamic_profile must be specified with dynamic_profile_use_primary"+
" in interface block %q", block.Name.ValueString()),
)
}
if block.OverridesV4 != nil && block.OverridesV4.hasKnownValue() &&
version == "v6" {
resp.Diagnostics.AddAttributeError(
path.Root("interface"),
tfdiag.ConflictConfigErrSummary,
fmt.Sprintf("overrides_v4 cannot be configured when version = v6"+
" in interface block %q", block.Name.ValueString()),
)
if block.OverridesV4 != nil {
if block.OverridesV4.isEmpty() {
resp.Diagnostics.AddAttributeError(
path.Root("interface"),
tfdiag.MissingConfigErrSummary,
fmt.Sprintf("overrides_v4 block is empty"+
" in interface block %q", block.Name.ValueString()),
)
}
if block.OverridesV4.hasKnownValue() && version == "v6" {
resp.Diagnostics.AddAttributeError(
path.Root("interface"),
tfdiag.ConflictConfigErrSummary,
fmt.Sprintf("overrides_v4 cannot be configured when version = v6"+
" in interface block %q", block.Name.ValueString()),
)
}
}
if block.OverridesV6 != nil && block.OverridesV6.hasKnownValue() &&
(version == "v4" || config.Version.IsNull()) {
resp.Diagnostics.AddAttributeError(
path.Root("interface"),
tfdiag.ConflictConfigErrSummary,
fmt.Sprintf("overrides_v6 cannot be configured when version = v4"+
" in interface block %q", block.Name.ValueString()),
)
if block.OverridesV6 != nil {
if block.OverridesV6.isEmpty() {
resp.Diagnostics.AddAttributeError(
path.Root("interface"),
tfdiag.MissingConfigErrSummary,
fmt.Sprintf("overrides_v6 block is empty"+
" in interface block %q", block.Name.ValueString()),
)
}
if block.OverridesV6.hasKnownValue() &&
(version == "v4" || config.Version.IsNull()) {
resp.Diagnostics.AddAttributeError(
path.Root("interface"),
tfdiag.ConflictConfigErrSummary,
fmt.Sprintf("overrides_v6 cannot be configured when version = v4"+
" in interface block %q", block.Name.ValueString()),
)
}
}
}
}
Expand Down Expand Up @@ -1180,6 +1220,24 @@ func (rsc *forwardingoptionsDhcprelayGroup) ValidateConfig( //nolint:gocognit,go
)
}
}
if config.OverridesV4 != nil {
if config.OverridesV4.isEmpty() {
resp.Diagnostics.AddAttributeError(
path.Root("overrides_v4").AtName("*"),
tfdiag.MissingConfigErrSummary,
"overrides_v4 block is empty",
)
}
}
if config.OverridesV6 != nil {
if config.OverridesV6.isEmpty() {
resp.Diagnostics.AddAttributeError(
path.Root("overrides_v6").AtName("*"),
tfdiag.MissingConfigErrSummary,
"overrides_v6 block is empty",
)
}
}
if config.RelayOption != nil {
if config.RelayOption.Option15DefaultAction != nil &&
config.RelayOption.Option15DefaultAction.Action.IsNull() {
Expand Down

0 comments on commit a310990

Please sign in to comment.