From e0a7105ab78ba8cfe28ad34e02c3debaf73b0182 Mon Sep 17 00:00:00 2001 From: Mickael Stanislas Date: Wed, 29 Jan 2025 15:23:43 +0100 Subject: [PATCH 1/2] docs: improve doc for the edgegateway resource --- .changelog/954.txt | 3 + cmd/edgegateway-doc/main.go | 59 +++++++++++++++++++ docs/data-sources/edgegateway.md | 2 +- docs/resources/edgegateway.md | 26 +++++++- go.mod | 2 + go.sum | 2 - .../provider/edgegw/edgegateway_datasource.go | 2 +- .../provider/edgegw/edgegateway_resource.go | 4 +- .../provider/edgegw/edgegateway_schema.go | 4 +- main.go | 1 + templates/resources/edgegateway.md.tmpl | 18 ++++++ 11 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 .changelog/954.txt create mode 100644 cmd/edgegateway-doc/main.go diff --git a/.changelog/954.txt b/.changelog/954.txt new file mode 100644 index 00000000..db638ba4 --- /dev/null +++ b/.changelog/954.txt @@ -0,0 +1,3 @@ +```release-note:note +`resource/cloudavenue_edgegateway` - Improve the documentation of the `bandwidth` attribute in the edge gateway resource. +``` \ No newline at end of file diff --git a/cmd/edgegateway-doc/main.go b/cmd/edgegateway-doc/main.go new file mode 100644 index 00000000..2d802dab --- /dev/null +++ b/cmd/edgegateway-doc/main.go @@ -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 = "" +) + +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) +} diff --git a/docs/data-sources/edgegateway.md b/docs/data-sources/edgegateway.md index 93c23781..4e37bc31 100644 --- a/docs/data-sources/edgegateway.md +++ b/docs/data-sources/edgegateway.md @@ -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. diff --git a/docs/resources/edgegateway.md b/docs/resources/edgegateway.md index fd515422..0cf95ae4 100644 --- a/docs/resources/edgegateway.md +++ b/docs/resources/edgegateway.md @@ -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. @@ -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 : + + +* `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: diff --git a/go.mod b/go.mod index f03e7112..52720d5d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 0589079b..cabe6bfa 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/provider/edgegw/edgegateway_datasource.go b/internal/provider/edgegw/edgegateway_datasource.go index 79929361..e24be6eb 100644 --- a/internal/provider/edgegw/edgegateway_datasource.go +++ b/internal/provider/edgegw/edgegateway_datasource.go @@ -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)...) diff --git a/internal/provider/edgegw/edgegateway_resource.go b/internal/provider/edgegw/edgegateway_resource.go index f9da140c..74ce496d 100644 --- a/internal/provider/edgegw/edgegateway_resource.go +++ b/internal/provider/edgegw/edgegateway_resource.go @@ -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()) @@ -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 } diff --git a/internal/provider/edgegw/edgegateway_schema.go b/internal/provider/edgegw/edgegateway_schema.go index 68bb8cee..99051814 100644 --- a/internal/provider/edgegw/edgegateway_schema.go +++ b/internal/provider/edgegw/edgegateway_schema.go @@ -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).", }, }, }, diff --git a/main.go b/main.go index 226bc0cb..bfadc57a 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/templates/resources/edgegateway.md.tmpl b/templates/resources/edgegateway.md.tmpl index 3ddaf9c4..27c9576e 100644 --- a/templates/resources/edgegateway.md.tmpl +++ b/templates/resources/edgegateway.md.tmpl @@ -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 : + + + +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 From 98cb4d6386b0df4dbc89be913e76a127ac706f90 Mon Sep 17 00:00:00 2001 From: Mickael Stanislas Date: Fri, 31 Jan 2025 17:48:28 +0100 Subject: [PATCH 2/2] fix: documentation --- cmd/edgegateway-doc/main.go | 14 +++++++++++--- docs/resources/edgegateway.md | 10 +++++----- go.mod | 4 +--- go.sum | 4 ++++ internal/provider/edgegw/edgegateway_schema.go | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cmd/edgegateway-doc/main.go b/cmd/edgegateway-doc/main.go index 2d802dab..d5f53522 100644 --- a/cmd/edgegateway-doc/main.go +++ b/cmd/edgegateway-doc/main.go @@ -15,6 +15,7 @@ import ( "fmt" "log" "os" + "slices" "strings" v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1" @@ -39,10 +40,17 @@ func main() { // * Retrieve the rules for the edgegateway and construct a markdown table - rules := []string{} + keys := []string{} + + for key := range v1.EdgeGatewayAllowedBandwidth { + keys = append(keys, string(key)) + } - for key, value := range v1.EdgeGatewayAllowedBandwidth { - rules = append(rules, fmt.Sprintf("* `%s` %s\n", key, strings.Trim(strings.ReplaceAll(fmt.Sprint(value.T1AllowedBandwidth), " ", ", "), "[]"))) + 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 diff --git a/docs/resources/edgegateway.md b/docs/resources/edgegateway.md index 0cf95ae4..f35cad69 100644 --- a/docs/resources/edgegateway.md +++ b/docs/resources/edgegateway.md @@ -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. More information can be found [here](#bandwidth-attribute). +- `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. @@ -68,10 +68,10 @@ The `bandwidth` attribute is optional. If no value is specified, the bandwidth i The following values are supported depending on the service class of the Tier-0 : -* `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 +* `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]} diff --git a/go.mod b/go.mod index 52720d5d..41870f92 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,6 @@ 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 @@ -21,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 diff --git a/go.sum b/go.sum index cabe6bfa..d662f75f 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -262,6 +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.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= diff --git a/internal/provider/edgegw/edgegateway_schema.go b/internal/provider/edgegw/edgegateway_schema.go index 99051814..50b7af02 100644 --- a/internal/provider/edgegw/edgegateway_schema.go +++ b/internal/provider/edgegw/edgegateway_schema.go @@ -145,7 +145,7 @@ func edgegwSchema() superschema.Schema { }, 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. More information can be found [here](#bandwidth-attribute).", + 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).", }, }, },