From 3e90220e4729031da72b47b8f8451a22257d756b Mon Sep 17 00:00:00 2001 From: danischm Date: Tue, 15 Oct 2024 11:26:59 +0200 Subject: [PATCH] Add use_af_group attribute to router bgp neighbor group resource --- CHANGELOG.md | 1 + docs/data-sources/router_bgp_neighbor_group.md | 1 + docs/guides/changelog.md | 1 + docs/resources/router_bgp_neighbor_group.md | 1 + gen/definitions/router_bgp_neighbor_group.yaml | 3 +++ ...a_source_iosxr_router_bgp_neighbor_group.go | 4 ++++ .../model_iosxr_router_bgp_neighbor_group.go | 18 ++++++++++++++++++ ...resource_iosxr_router_bgp_neighbor_group.go | 7 +++++++ templates/guides/changelog.md.tmpl | 1 + 9 files changed, 37 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6ec9037..fb017ee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.5.2 (unreleased) - Implement workaround for issue related to interpreting dotted decimal AS number notation, [link](https://github.com/CiscoDevNet/terraform-provider-iosxr/issues/263) +- Add `use_af_group` attribute to `iosxr_router_bgp_neighbor_group` resource and data source ## 0.5.1 diff --git a/docs/data-sources/router_bgp_neighbor_group.md b/docs/data-sources/router_bgp_neighbor_group.md index f660b911..9937e375 100644 --- a/docs/data-sources/router_bgp_neighbor_group.md +++ b/docs/data-sources/router_bgp_neighbor_group.md @@ -68,3 +68,4 @@ Read-Only: - `route_reflector_client` (Boolean) Configure a neighbor as Route Reflector client - `route_reflector_client_inheritance_disable` (Boolean) Prevent route-reflector-client from being inherited from the parent - `soft_reconfiguration_inbound_always` (Boolean) Always use soft reconfig, even if route refresh is supported +- `use_af_group` (String) Inherit configuration for this address-family from an af-group diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index e24e82af..83d1dab8 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -10,6 +10,7 @@ description: |- ## 0.5.2 (unreleased) - Implement workaround for issue related to interpreting dotted decimal AS number notation, [link](https://github.com/CiscoDevNet/terraform-provider-iosxr/issues/263) +- Add `use_af_group` attribute to `iosxr_router_bgp_neighbor_group` resource and data source ## 0.5.1 diff --git a/docs/resources/router_bgp_neighbor_group.md b/docs/resources/router_bgp_neighbor_group.md index 3bdf3fe5..e13bc5e6 100644 --- a/docs/resources/router_bgp_neighbor_group.md +++ b/docs/resources/router_bgp_neighbor_group.md @@ -103,6 +103,7 @@ Optional: - `route_reflector_client` (Boolean) Configure a neighbor as Route Reflector client - `route_reflector_client_inheritance_disable` (Boolean) Prevent route-reflector-client from being inherited from the parent - `soft_reconfiguration_inbound_always` (Boolean) Always use soft reconfig, even if route refresh is supported +- `use_af_group` (String) Inherit configuration for this address-family from an af-group ## Import diff --git a/gen/definitions/router_bgp_neighbor_group.yaml b/gen/definitions/router_bgp_neighbor_group.yaml index f8f21f1d..733d2a6a 100644 --- a/gen/definitions/router_bgp_neighbor_group.yaml +++ b/gen/definitions/router_bgp_neighbor_group.yaml @@ -79,6 +79,9 @@ attributes: example: ROUTE_POLICY_1 - yang_name: route-policy/out example: ROUTE_POLICY_1 + - yang_name: use/af-group + example: ROUTE_POLICY_1 + exclude_test: true - yang_name: timers/keepalive-interval optional: true delete_parent: true diff --git a/internal/provider/data_source_iosxr_router_bgp_neighbor_group.go b/internal/provider/data_source_iosxr_router_bgp_neighbor_group.go index eee518d1..b870b934 100644 --- a/internal/provider/data_source_iosxr_router_bgp_neighbor_group.go +++ b/internal/provider/data_source_iosxr_router_bgp_neighbor_group.go @@ -171,6 +171,10 @@ func (d *RouterBGPNeighborGroupDataSource) Schema(ctx context.Context, req datas MarkdownDescription: "Apply route policy to outbound routes", Computed: true, }, + "use_af_group": schema.StringAttribute{ + MarkdownDescription: "Inherit configuration for this address-family from an af-group", + Computed: true, + }, }, }, }, diff --git a/internal/provider/model_iosxr_router_bgp_neighbor_group.go b/internal/provider/model_iosxr_router_bgp_neighbor_group.go index 80f7470f..9a3e6f1e 100644 --- a/internal/provider/model_iosxr_router_bgp_neighbor_group.go +++ b/internal/provider/model_iosxr_router_bgp_neighbor_group.go @@ -93,6 +93,7 @@ type RouterBGPNeighborGroupAddressFamilies struct { RouteReflectorClientInheritanceDisable types.Bool `tfsdk:"route_reflector_client_inheritance_disable"` RoutePolicyIn types.String `tfsdk:"route_policy_in"` RoutePolicyOut types.String `tfsdk:"route_policy_out"` + UseAfGroup types.String `tfsdk:"use_af_group"` } func (data RouterBGPNeighborGroup) getPath() string { @@ -216,6 +217,9 @@ func (data RouterBGPNeighborGroup) toBody(ctx context.Context) string { if !item.RoutePolicyOut.IsNull() && !item.RoutePolicyOut.IsUnknown() { body, _ = sjson.Set(body, "address-families.address-family"+"."+strconv.Itoa(index)+"."+"route-policy.out", item.RoutePolicyOut.ValueString()) } + if !item.UseAfGroup.IsNull() && !item.UseAfGroup.IsUnknown() { + body, _ = sjson.Set(body, "address-families.address-family"+"."+strconv.Itoa(index)+"."+"use.af-group", item.UseAfGroup.ValueString()) + } } } return body @@ -413,6 +417,11 @@ func (data *RouterBGPNeighborGroup) updateFromBody(ctx context.Context, res []by } else { data.AddressFamilies[i].RoutePolicyOut = types.StringNull() } + if value := r.Get("use.af-group"); value.Exists() && !data.AddressFamilies[i].UseAfGroup.IsNull() { + data.AddressFamilies[i].UseAfGroup = types.StringValue(value.String()) + } else { + data.AddressFamilies[i].UseAfGroup = types.StringNull() + } } if value := gjson.GetBytes(res, "timers.keepalive-interval"); value.Exists() && !data.TimersKeepaliveInterval.IsNull() { data.TimersKeepaliveInterval = types.Int64Value(value.Int()) @@ -532,6 +541,9 @@ func (data *RouterBGPNeighborGroup) fromBody(ctx context.Context, res []byte) { if cValue := v.Get("route-policy.out"); cValue.Exists() { item.RoutePolicyOut = types.StringValue(cValue.String()) } + if cValue := v.Get("use.af-group"); cValue.Exists() { + item.UseAfGroup = types.StringValue(cValue.String()) + } data.AddressFamilies = append(data.AddressFamilies, item) return true }) @@ -648,6 +660,9 @@ func (data *RouterBGPNeighborGroupData) fromBody(ctx context.Context, res []byte if cValue := v.Get("route-policy.out"); cValue.Exists() { item.RoutePolicyOut = types.StringValue(cValue.String()) } + if cValue := v.Get("use.af-group"); cValue.Exists() { + item.UseAfGroup = types.StringValue(cValue.String()) + } data.AddressFamilies = append(data.AddressFamilies, item) return true }) @@ -757,6 +772,9 @@ func (data *RouterBGPNeighborGroup) getDeletedItems(ctx context.Context, state R if !state.AddressFamilies[i].RoutePolicyOut.IsNull() && data.AddressFamilies[j].RoutePolicyOut.IsNull() { deletedItems = append(deletedItems, fmt.Sprintf("%v/address-families/address-family%v/route-policy/out", state.getPath(), keyString)) } + if !state.AddressFamilies[i].UseAfGroup.IsNull() && data.AddressFamilies[j].UseAfGroup.IsNull() { + deletedItems = append(deletedItems, fmt.Sprintf("%v/address-families/address-family%v/use/af-group", state.getPath(), keyString)) + } break } } diff --git a/internal/provider/resource_iosxr_router_bgp_neighbor_group.go b/internal/provider/resource_iosxr_router_bgp_neighbor_group.go index 7c17e8bc..fa773e89 100644 --- a/internal/provider/resource_iosxr_router_bgp_neighbor_group.go +++ b/internal/provider/resource_iosxr_router_bgp_neighbor_group.go @@ -224,6 +224,13 @@ func (r *RouterBGPNeighborGroupResource) Schema(ctx context.Context, req resourc stringvalidator.LengthBetween(1, 255), }, }, + "use_af_group": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Inherit configuration for this address-family from an af-group").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 1024), + }, + }, }, }, }, diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index e24e82af..83d1dab8 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -10,6 +10,7 @@ description: |- ## 0.5.2 (unreleased) - Implement workaround for issue related to interpreting dotted decimal AS number notation, [link](https://github.com/CiscoDevNet/terraform-provider-iosxr/issues/263) +- Add `use_af_group` attribute to `iosxr_router_bgp_neighbor_group` resource and data source ## 0.5.1