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

feat: add bandwidth and deprecate lb_enabled attributes on _edgegateway #573

Merged
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
8 changes: 8 additions & 0 deletions .changelog/567.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```release-note:note
`resource/cloudavenue_edgegateway` - The `lb_enabled` attribute is now deprecated and will be removed in the version [`v0.16.0`](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/milestone/8) of the provider. See the [GitHub issue](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/567) for more information.
```

```release-note:note
`datasource/cloudavenue_edgegateway` - The `lb_enabled` attribute is now deprecated and will be removed in the version [`v0.16.0`](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/milestone/8) of the provider.
```

12 changes: 12 additions & 0 deletions .changelog/568.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```release-note:dependency
deps: bumps github.com/orange-cloudavenue/cloudavenue-sdk-go from 0.0.4 to 0.1.0
```

```release-note:enhancement
`resource/cloudavenue_edgegateway` - Add new `bandwidth` attribute to manage bandwidth of the edge gateway (in Mbps).
```

```release-note:enhancement
`datasource/cloudavenue_edgegateway` - Add new `bandwidth` attribute to retrieve bandwidth of the edge gateway (in Mbps).
```

7 changes: 5 additions & 2 deletions docs/data-sources/edgegateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ output "gateway" {

### Read-Only

- `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.
- `lb_enabled` (Boolean) Load Balancing state on the Edge Gateway.
- `lb_enabled` (Boolean, Deprecated) Load Balancing state on the Edge Gateway.

~> **Attribute deprecated** Remove the `lb_enabled` attribute configuration, it will be removed in the version [`v0.16.0`](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/milestone/8) of the provider. See the [GitHub issue](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/567) for more information.
- `owner_name` (String) The name of the Edge Gateway owner.
dmicheneau marked this conversation as resolved.
Show resolved Hide resolved
- `owner_type` (String) The type of the Edge Gateway owner. Must be vdc or vdc-group.
- `owner_type` (String) The type of the Edge Gateway owner. Value must be one of : `vdc`, `vdc-group`.
- `tier0_vrf_name` (String) The name of the Tier-0 VRF to which the Edge Gateway is attached.

12 changes: 7 additions & 5 deletions docs/resources/edgegateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ The Edge Gateway resource allows you to create and delete Edge Gateways in Cloud
```terraform
data "cloudavenue_tier0_vrfs" "example_with_vdc" {}

resource "cloudavenue_edgegateway" "example_with_vdc" {
owner_name = "MyVDC"
resource "cloudavenue_edgegateway" "example" {
tier0_vrf_name = data.cloudavenue_tier0_vrfs.example_with_vdc.names.0
owner_name = "MyVDC"
owner_type = "vdc"
lb_enabled = false
}
```

Expand All @@ -28,12 +27,15 @@ resource "cloudavenue_edgegateway" "example_with_vdc" {
### Required

- `owner_name` (String) (ForceNew) The name of the Edge Gateway owner.
- `owner_type` (String) (ForceNew) The type of the Edge Gateway owner. Must be vdc or vdc-group.
- `owner_type` (String) (ForceNew) The type of the Edge Gateway owner. Value must be one of : `vdc`, `vdc-group`.
- `tier0_vrf_name` (String) (ForceNew) The name of the Tier-0 VRF to which the Edge Gateway is attached.

### Optional

- `lb_enabled` (Boolean) Load Balancing state on the Edge Gateway. Value defaults to `true`.
- `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.
- `lb_enabled` (Boolean, Deprecated) Load Balancing state on the Edge Gateway.

~> **Attribute deprecated** Remove the `lb_enabled` attribute configuration, it will be removed in the version [`v0.16.0`](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/milestone/8) of the provider. See the [GitHub issue](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/567) for more information.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only
Expand Down
7 changes: 3 additions & 4 deletions examples/resources/cloudavenue_edgegateway/resource.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
data "cloudavenue_tier0_vrfs" "example_with_vdc" {}

resource "cloudavenue_edgegateway" "example_with_vdc" {
owner_name = "MyVDC"
resource "cloudavenue_edgegateway" "example" {
tier0_vrf_name = data.cloudavenue_tier0_vrfs.example_with_vdc.names.0
owner_name = "MyVDC"
owner_type = "vdc"
lb_enabled = false
}
}
4 changes: 2 additions & 2 deletions 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.29.0
github.com/iancoleman/strcase v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.0.4-0.20231010202218-e3886106bffa
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.2.0
github.com/orange-cloudavenue/infrapi-sdk-go v0.1.4-0.20231005074857-89878ea119fb
github.com/rs/zerolog v1.31.0
github.com/thanhpk/randstr v1.0.6
Expand Down Expand Up @@ -48,7 +48,7 @@ require (
github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/go-chi/render v1.0.3 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-resty/resty/v2 v2.9.1 // indirect
github.com/go-resty/resty/v2 v2.10.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down
16 changes: 7 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-resty/resty/v2 v2.9.1 h1:PIgGx4VrHvag0juCJ4dDv3MiFRlDmP0vicBucwf+gLM=
github.com/go-resty/resty/v2 v2.9.1/go.mod h1:4/GYJVjh9nhkhGR6AUNW3XhpDYNUr+Uvy9gV/VGZIy4=
github.com/go-resty/resty/v2 v2.10.0 h1:Qla4W/+TMmv0fOeeRqzEpXPLfTUnR5HZ1+lGs+CkiCo=
github.com/go-resty/resty/v2 v2.10.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
Expand Down Expand Up @@ -216,8 +216,8 @@ github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.0.4-0.20231010202218-e3886106bffa h1:98Mkhxg3OOqP66+S55oMVZnSichMsmiRH2kXc9NJAWU=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.0.4-0.20231010202218-e3886106bffa/go.mod h1:DWBIS3DJtS5ZiZzblCwYNo123RaxO+UrGyfqsVQbFb0=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.2.0 h1:pNCOlxzCX7Q2/8zNApgWP8VeZFwNXABNVELWElqsxQE=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.2.0/go.mod h1:8HtVSQVDVoW1pk/pFUTTOOQ2TL1SErMxV7fmke2+acg=
github.com/orange-cloudavenue/infrapi-sdk-go v0.1.4-0.20231005074857-89878ea119fb h1:1/Wc21Tp9RnDOUTjKBm9x3wi+UgUkDc2bv0fHJc5f2o=
github.com/orange-cloudavenue/infrapi-sdk-go v0.1.4-0.20231005074857-89878ea119fb/go.mod h1:pGa9mB6s+weCi5QtNe5nicp7yL0C/e+i+3wHRh4cjBE=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
Expand Down Expand Up @@ -287,7 +287,6 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
Expand All @@ -307,7 +306,6 @@ golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.7.0 h1:qe6s0zUXlPX80/dITx3440hWZ7GwMwgDDyrSGTPJG/g=
Expand Down Expand Up @@ -349,7 +347,7 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -363,8 +361,8 @@ golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 h1:GZokNIeuVkl3aZHJchRrr13WCsols02MLUcz1U9is6M=
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
16 changes: 7 additions & 9 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type CloudAvenue struct {
urlVmware *url.URL
VCDVersion string

// API Backup of NetBackup
BackupClient *clientca.Client
BackupOpts *clientca.ClientOpts
// SDK CLOUDAVENUE
CAVSDK *clientca.Client
CAVSDKOpts *clientca.ClientOpts
}

// New creates a new CloudAvenue client.
Expand Down Expand Up @@ -78,12 +78,10 @@ func (c *CloudAvenue) New() (*CloudAvenue, error) {
return nil, fmt.Errorf("%w : %w", ErrConfigureVmware, err)
}

// API Backup of NetBackup
if c.BackupOpts.Netbackup.Username != "" && c.BackupOpts.Netbackup.Password != "" {
c.BackupClient, err = clientca.New(*c.BackupOpts)
if err != nil {
return nil, fmt.Errorf("%w : %w", ErrConfigureNetBackup, err)
}
// New SDK CloudAvenue
c.CAVSDK, err = clientca.New(*c.CAVSDKOpts)
if err != nil {
return nil, fmt.Errorf("%w : %w", ErrConfigureNetBackup, err)
}

return c, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/backup/backup_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (d *backupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
}

// Refresh data NetBackup from the API
job, err := d.client.BackupClient.V1.Netbackup.Inventory.Refresh()
job, err := d.client.CAVSDK.V1.Netbackup.Inventory.Refresh()
if err != nil {
resp.Diagnostics.AddError("Error refreshing NetBackup inventory", err.Error())
return
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/backup/backup_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *backupResource) Create(ctx context.Context, req resource.CreateRequest,
}

// Refresh data NetBackup from the API
job, err := r.client.BackupClient.V1.Netbackup.Inventory.Refresh()
job, err := r.client.CAVSDK.V1.Netbackup.Inventory.Refresh()
if err != nil {
resp.Diagnostics.AddError("Error refreshing NetBackup inventory", err.Error())
return
Expand Down Expand Up @@ -297,7 +297,7 @@ func (r *backupResource) ImportState(ctx context.Context, req resource.ImportSta
}

// Refresh data NetBackup from the API
job, err := r.client.BackupClient.V1.Netbackup.Inventory.Refresh()
job, err := r.client.CAVSDK.V1.Netbackup.Inventory.Refresh()
if err != nil {
resp.Diagnostics.AddError("Error refreshing NetBackup inventory", err.Error())
return
Expand Down Expand Up @@ -459,11 +459,11 @@ func (r *backupResource) getTarget(data *backupModel) (typeTarget target, d diag
var err error
switch data.Type.Get() {
case vdc:
typeTarget, err = r.client.BackupClient.V1.Netbackup.VCloud.GetVdcByNameOrIdentifier(data.getTargetIDOrName())
typeTarget, err = r.client.CAVSDK.V1.Netbackup.VCloud.GetVdcByNameOrIdentifier(data.getTargetIDOrName())
case vapp:
typeTarget, err = r.client.BackupClient.V1.Netbackup.VCloud.GetVAppByNameOrIdentifier(data.getTargetIDOrName())
typeTarget, err = r.client.CAVSDK.V1.Netbackup.VCloud.GetVAppByNameOrIdentifier(data.getTargetIDOrName())
case vm:
typeTarget, err = r.client.BackupClient.V1.Netbackup.Machines.GetMachineByNameOrIdentifier(data.getTargetIDOrName())
typeTarget, err = r.client.CAVSDK.V1.Netbackup.Machines.GetMachineByNameOrIdentifier(data.getTargetIDOrName())
}
if err != nil {
d.AddError(fmt.Sprintf("Error getting vCloud Director %s", data.Type.Get()), err.Error())
Expand Down
71 changes: 18 additions & 53 deletions internal/provider/edgegw/edgegateway_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ package edgegw

import (
"context"
"errors"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/hashicorp/terraform-plugin-framework/datasource"

apiclient "github.com/orange-cloudavenue/infrapi-sdk-go"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/helpers"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/metrics"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/pkg/uuid"
)
Expand Down Expand Up @@ -60,67 +55,37 @@ func (d *edgeGatewayDataSource) Configure(ctx context.Context, req datasource.Co
}

func (d *edgeGatewayDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var (
data edgeGatewayDataSourceModel
gateway apiclient.EdgeGateway
)
defer metrics.New("data.cloudavenue_edgegateway", d.client.GetOrgName(), metrics.Read)()

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
config := &edgeGatewayDatasourceModel{}

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, config)...)
if resp.Diagnostics.HasError() {
return
}

gateways, httpR, err := d.client.APIClient.EdgeGatewaysApi.GetEdges(d.client.Auth)

if httpR != nil {
defer func() {
err = errors.Join(err, httpR.Body.Close())
}()
}
data := config.Copy()

if apiErr := helpers.CheckAPIError(err, httpR); apiErr != nil {
resp.Diagnostics.Append(apiErr.GetTerraformDiagnostic())
// Read data from the API
edgegw, err := d.client.CAVSDK.V1.EdgeGateway.GetByName(config.Name.Get())
if err != nil {
resp.Diagnostics.AddError("Error retrieving edge gateway", err.Error())
return
}

found := false
for _, gateway = range gateways {
if data.Name.Equal(types.StringValue(gateway.EdgeName)) {
found = true
break
}
}
data.ID.Set(uuid.Normalize(uuid.Gateway, edgegw.GetID()).String())
data.Tier0VrfID.Set(edgegw.GetTier0VrfID())
data.OwnerName.Set(edgegw.GetOwnerName())
data.OwnerType.Set(string(edgegw.GetOwnerType()))
data.Description.Set(edgegw.GetDescription())
data.Bandwidth.SetInt(int(edgegw.GetBandwidth()))

if !found {
data.ID = types.StringValue("")
} else {
// Get LoadBalancing state.
gatewaysLoadBalancing, httpR, err := d.client.APIClient.EdgeGatewaysApi.GetEdgeLoadBalancing(d.client.Auth, gateway.EdgeId)
if apiErr := helpers.CheckAPIError(err, httpR); apiErr != nil {
defer httpR.Body.Close()
resp.Diagnostics.Append(apiErr.GetTerraformDiagnostic())
if resp.Diagnostics.HasError() {
return
}
}

data = edgeGatewayDataSourceModel{
Tier0VrfID: types.StringValue(gateway.Tier0VrfId),
Name: types.StringValue(gateway.EdgeName),
ID: types.StringValue(uuid.Normalize(uuid.Gateway, gateway.EdgeId).String()),
OwnerType: types.StringValue(gateway.OwnerType),
OwnerName: types.StringValue(gateway.OwnerName),
Description: types.StringValue(gateway.Description),
EnableLoadBalancing: types.BoolValue((gatewaysLoadBalancing.Enabled)),
}
// EnableLoadBalancing is now deprecated, but we still need to set it to false if it is unknown
if !data.EnableLoadBalancing.IsKnown() {
data.EnableLoadBalancing.Set(false)
}

// Save data into Terraform state
// Set refreshed state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}
}
Loading
Loading