Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve doc for the edgegateway resource #968

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/954.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:note
`resource/cloudavenue_edgegateway` - Improve the documentation of the `bandwidth` attribute in the edge gateway resource.
```
67 changes: 67 additions & 0 deletions cmd/edgegateway-doc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 Orange
* SPDX-License-Identifier: Mozilla Public License 2.0
*
* This software is distributed under the MPL-2.0 license.
* the text of which is available at https://www.mozilla.org/en-US/MPL/2.0/
* or see the "LICENSE" file for more details.
*/

// edgegateway doc is a tool to generate documentation for the edgegateway resource.

package main

import (
"fmt"
"log"
"os"
"slices"
"strings"

v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1"
)

const (
bandwidthMarker = "<!-- TABLE BANDWIDTH VALUES -->"
)

func main() {
// Read the content of the file into a string
filePath := "docs/resources/edgegateway.md"
content, err := os.ReadFile(filePath)
if err != nil {
log.Default().Printf("Failed to read file: %v", err)
os.Exit(1)
}

// Get the content before and after the markers
before := strings.Split(string(content), bandwidthMarker)[0]
after := strings.Split(string(content), bandwidthMarker)[1]

// * Retrieve the rules for the edgegateway and construct a markdown table

keys := []string{}

for key := range v1.EdgeGatewayAllowedBandwidth {
keys = append(keys, string(key))
}

slices.Sort(keys)

rules := []string{}
for _, value := range keys {
rules = append(rules, fmt.Sprintf("* `%s` %s\n", value, strings.Trim(strings.ReplaceAll(fmt.Sprint(v1.EdgeGatewayAllowedBandwidth[v1.ClassService(value)]), " ", ", "), "[]")))
}

// Generate the content of the file
newContent := before + bandwidthMarker + "\n" + strings.Join(rules, "") + "\n" + after

// Write the content to the file
err = os.WriteFile(filePath, []byte(newContent), 0o600)
if err != nil {
log.Default().Printf("Failed to write file: %v", err)
os.Exit(1)
}

os.Exit(0)
}
2 changes: 1 addition & 1 deletion docs/data-sources/edgegateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output "gateway" {

### Read-Only

- `bandwidth` (Number) The bandwidth in Mbps of the Edge Gateway.
- `bandwidth` (Number) The bandwidth in `Mbps` of the Edge Gateway.
- `description` (String) The description of the Edge Gateway.
- `id` (String) The ID of the Edge Gateway.
- `owner_name` (String) The name of the Edge Gateway owner. It can be a VDC or a VDC Group name.
Expand Down
26 changes: 25 additions & 1 deletion docs/resources/edgegateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ resource "cloudavenue_edgegateway" "example" {

### Optional

- `bandwidth` (Number) The bandwidth in Mbps of the Edge Gateway. If no value is not specified, the bandwidth is automatically calculated based on the remaining bandwidth of the Tier-0 VRF.
- `bandwidth` (Number) The bandwidth in `Mbps` of the Edge Gateway. If no value is specified, the bandwidth is automatically calculated based on the remaining bandwidth of the Tier-0 VRF. More information can be found [here](#bandwidth-attribute).
- `owner_type` (String, Deprecated) The type of the Edge Gateway owner. Value must be one of : `vdc`, `vdc-group`.

~> **Attribute deprecated** Remove the `owner_type` attribute configuration, it will be removed in the version [`v0.32.0`](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/milestone/20) of the provider. See the [GitHub issue](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/952) for more information.
Expand All @@ -61,6 +61,30 @@ Optional:
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).

## Bandwidth Attribute

The `bandwidth` attribute is optional. If no value is specified, the bandwidth is automatically calculated based on the remaining bandwidth of the Tier-0 VRF. For more information, see the [documentation of edge gateway](https://wiki.cloudavenue.orange-business.com/wiki/Network).

The following values are supported depending on the service class of the Tier-0 :

<!-- TABLE BANDWIDTH VALUES -->
* `VRF_DEDICATED_LARGE` {10000, [5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000]}
* `VRF_DEDICATED_MEDIUM` {3500, [5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000]}
* `VRF_PREMIUM` {1000, [5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000]}
* `VRF_STANDARD` {300, [5, 25, 50, 75, 100, 150, 200, 250, 300]}



Example with bandwidth:

```hcl
resource "cloudavenue_edgegateway" "example" {
owner_name = cloudavenue_vdc.example.name
tier0_vrf_name = data.cloudavenue_tier0_vrf.example.name
bandwidth = 100
}
```

## Import

Import is supported using the following syntax:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/iancoleman/strcase v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.1
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.2
github.com/orange-cloudavenue/common-go/print v0.0.0-20250109171729-2be550d5d3ac
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339
github.com/orange-cloudavenue/terraform-plugin-framework-planmodifiers v1.4.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ github.com/influxdata/influxdb-client-go/v2 v2.12.3 h1:28nRlNMRIV4QbtIUvxhWqaxn0
github.com/influxdata/influxdb-client-go/v2 v2.12.3/go.mod h1:IrrLUbCjjfkmRuaCiGQg4m2GbkaeJDcuWoxiWdQEbA0=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
Expand Down Expand Up @@ -262,8 +264,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.1 h1:Uy/AkLQM/KQzDMFBCVR7vh4BppgROa/GK5UNfXbP7e0=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.1/go.mod h1:1jc0W7Me1Oq0kSPoJNYcH6emJ5HruIIsh1//Wp26AJQ=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.2 h1:DHDMiRYqFNMuBakn062ysRgkEWhpjII7uRlWgRUewLM=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.21.2/go.mod h1:qijxgnnyB2JBkHWslCPD45NhJk5UVrVrm//Vq6qQ1c8=
github.com/orange-cloudavenue/common-go/print v0.0.0-20250109171729-2be550d5d3ac h1:f1Fd70+PMDTK6FE4gHdNfoHSQHLn5pfJMTjZPzOWZtc=
github.com/orange-cloudavenue/common-go/print v0.0.0-20250109171729-2be550d5d3ac/go.mod h1:IYtCusqpEGS0dhC6F8X9GHrrt1gp1zHaNhSKGYV59Xg=
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339 h1:DEKcWLGbEhu/I6kn9NAXhVCFrbPhR+Ef7oLmpLVnnPM=
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/edgegw/edgegateway_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (d *edgeGatewayDataSource) Read(ctx context.Context, req datasource.ReadReq
data.OwnerName.Set(edgegw.GetOwnerName())
data.OwnerType.Set(string(edgegw.GetOwnerType()))
data.Description.Set(edgegw.GetDescription())
data.Bandwidth.SetInt(int(edgegw.GetBandwidth()))
data.Bandwidth.SetInt(edgegw.GetBandwidth())

// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/edgegw/edgegateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (r *edgeGatewayResource) Create(ctx context.Context, req resource.CreateReq
return
}

if int(edgegwNew.GetBandwidth()) != plan.Bandwidth.GetInt() {
if edgegwNew.GetBandwidth() != plan.Bandwidth.GetInt() {
job, err = edgegwNew.UpdateBandwidth(plan.Bandwidth.GetInt())
if err != nil {
resp.Diagnostics.AddError("Error setting Bandwidth", err.Error())
Expand Down Expand Up @@ -518,7 +518,7 @@ func (r *edgeGatewayResource) read(_ context.Context, planOrState *edgeGatewayRe
stateRefreshed.Tier0VrfID.Set(edgegw.GetTier0VrfID())
stateRefreshed.OwnerName.Set(edgegw.GetOwnerName())
stateRefreshed.Description.Set(edgegw.GetDescription())
stateRefreshed.Bandwidth.SetInt(int(edgegw.GetBandwidth()))
stateRefreshed.Bandwidth.SetInt(edgegw.GetBandwidth())

return stateRefreshed, true, nil
}
4 changes: 2 additions & 2 deletions internal/provider/edgegw/edgegateway_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ func edgegwSchema() superschema.Schema {
},
"bandwidth": &superschema.SuperInt64Attribute{
Common: &schemaR.Int64Attribute{
MarkdownDescription: "The bandwidth in Mbps of the Edge Gateway.",
MarkdownDescription: "The bandwidth in `Mbps` of the Edge Gateway.",
Computed: true,
},
Resource: &schemaR.Int64Attribute{
Optional: true,
MarkdownDescription: "If no value is not specified, the bandwidth is automatically calculated based on the remaining bandwidth of the Tier-0 VRF.",
MarkdownDescription: "If no value is specified, the bandwidth is automatically calculated based on the remaining bandwidth of the Tier-0 VRF. More information can be found [here](#bandwidth-attribute).",
},
},
},
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var version = "dev"
// Provider documentation generation.
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --provider-name cloudavenue
//go:generate go run github.com/orange-cloudavenue/terraform-provider-cloudavenue/cmd/vdc-doc
//go:generate go run github.com/orange-cloudavenue/terraform-provider-cloudavenue/cmd/edgegateway-doc

func main() {
var debug bool
Expand Down
18 changes: 18 additions & 0 deletions templates/resources/edgegateway.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ resource "cloudavenue_edgegateway" "example" {

{{ .SchemaMarkdown | trimspace }}

## Bandwidth Attribute

The `bandwidth` attribute is optional. If no value is specified, the bandwidth is automatically calculated based on the remaining bandwidth of the Tier-0 VRF. For more information, see the [documentation of edge gateway](https://wiki.cloudavenue.orange-business.com/wiki/Network).

The following values are supported depending on the service class of the Tier-0 :

<!-- TABLE BANDWIDTH VALUES -->

Example with bandwidth:

```hcl
resource "cloudavenue_edgegateway" "example" {
owner_name = cloudavenue_vdc.example.name
tier0_vrf_name = data.cloudavenue_tier0_vrf.example.name
bandwidth = 100
}
```

{{ if .HasImport -}}
## Import

Expand Down
Loading