Skip to content

Commit

Permalink
doc: improve doc for the edgegateway resource
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod committed Jan 29, 2025
1 parent c5bed9b commit fd56a61
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 9 deletions.
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.
```
59 changes: 59 additions & 0 deletions cmd/edgegateway-doc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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"
"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

rules := []string{}

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

// 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 not 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_STANDARD` 5, 25, 50, 75, 100, 150, 200, 250, 300
* `VRF_PREMIUM` 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000
* `VRF_DEDICATED_MEDIUM` 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000
* `VRF_DEDICATED_LARGE` 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000



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: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.22.7

toolchain go1.23.3

replace github.com/orange-cloudavenue/cloudavenue-sdk-go => ../cloudavenue-sdk-go

require (
github.com/FrangipaneTeam/terraform-analytic-tool v0.0.12
github.com/aws/aws-sdk-go v1.55.6
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ 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/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 not 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

0 comments on commit fd56a61

Please sign in to comment.