Skip to content

Commit

Permalink
r/switch_options: add service_id argument
Browse files Browse the repository at this point in the history
Fix #575
  • Loading branch information
jeremmfr committed Dec 11, 2023
1 parent 841c214 commit 0408639
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changes/issue-575.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ ENHANCEMENTS:
* resource now use new [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework)
optional boolean attributes doesn't accept value *false*
optional string attributes doesn't accept *empty* value
* add `service_id` argument (Fix [#575](https://github.com/jeremmfr/terraform-provider-junos/issues/575))
2 changes: 2 additions & 0 deletions docs/resources/switch_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The following arguments are supported:

- **clean_on_destroy** (Optional, Boolean)
Clean supported lines when destroy this resource.
- **service_id** (Optional, Number)
Service ID required if multi-chassis AE is part of a bridge-domain (1..65535).
- **vtep_source_interface** (Optional, String)
Source layer-3 IFL for VXLAN.

Expand Down
24 changes: 23 additions & 1 deletion internal/providerfwk/resource_switch_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"strings"

"github.com/jeremmfr/terraform-provider-junos/internal/junos"
"github.com/jeremmfr/terraform-provider-junos/internal/tfdata"
"github.com/jeremmfr/terraform-provider-junos/internal/tfvalidator"
"github.com/jeremmfr/terraform-provider-junos/internal/utils"

"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -87,6 +90,13 @@ func (rsc *switchOptions) Schema(
tfvalidator.BoolTrue(),
},
},
"service_id": schema.Int64Attribute{
Optional: true,
Description: "Service ID required if multi-chassis AE is part of a bridge-domain.",
Validators: []validator.Int64{
int64validator.Between(1, 65535),
},
},
"vtep_source_interface": schema.StringAttribute{
Optional: true,
Description: "Source layer-3 IFL for VXLAN.",
Expand All @@ -103,6 +113,7 @@ func (rsc *switchOptions) Schema(
type switchOptionsData struct {
CleanOnDestroy types.Bool `tfsdk:"clean_on_destroy"`
ID types.String `tfsdk:"id"`
ServiceID types.Int64 `tfsdk:"service_id"`
VTEPSourceInterface types.String `tfsdk:"vtep_source_interface"`
}

Expand Down Expand Up @@ -217,6 +228,10 @@ func (rscData *switchOptionsData) set(
configSet := make([]string, 0)
setPrefix := "set switch-options "

if !rscData.ServiceID.IsNull() {
configSet = append(configSet, setPrefix+"service-id "+
utils.ConvI64toa(rscData.ServiceID.ValueInt64()))
}
if v := rscData.VTEPSourceInterface.ValueString(); v != "" {
configSet = append(configSet, setPrefix+"vtep-source-interface "+v)
}
Expand Down Expand Up @@ -244,7 +259,13 @@ func (rscData *switchOptionsData) read(
break
}
itemTrim := strings.TrimPrefix(item, junos.SetLS)
if balt.CutPrefixInString(&itemTrim, "vtep-source-interface ") {
switch {
case balt.CutPrefixInString(&itemTrim, "service-id "):
rscData.ServiceID, err = tfdata.ConvAtoi64Value(itemTrim)
if err != nil {
return err
}
case balt.CutPrefixInString(&itemTrim, "vtep-source-interface "):
rscData.VTEPSourceInterface = types.StringValue(itemTrim)
}
}
Expand All @@ -257,6 +278,7 @@ func (rscData *switchOptionsData) del(
_ context.Context, junSess *junos.Session,
) error {
listLinesToDelete := []string{
"service-id",
"vtep-source-interface",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ resource "junos_interface_logical" "testacc_switchOpts" {
}
}
resource "junos_switch_options" "testacc_switchOpts" {
service_id = 111
vtep_source_interface = junos_interface_logical.testacc_switchOpts.name
}

0 comments on commit 0408639

Please sign in to comment.