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 ress/data cloudavenue_vdcg_network_isolated #885

Open
wants to merge 1 commit into
base: network-isolated
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
7 changes: 7 additions & 0 deletions .changelog/878.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
`resource/cloudavenue_vdcg_network_isolated` - Added a new resource to manage isolated networks in a VDC Group.
```

```release-note:new-data-source
`datasource/cloudavenue_vdcg_network_isolated` - Added a new data source to fetch information about an isolated network in a VDC Group.
```
44 changes: 44 additions & 0 deletions docs/data-sources/vdcg_network_isolated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
page_title: "cloudavenue_vdcg_network_isolated Data Source - cloudavenue"
subcategory: "vDC Group (Virtual Datacenter Group)"
description: |-
The cloudavenue_vdcg_network_isolated data source allows you to retrieve information about an isolated network in a VDC Group.
---

# cloudavenue_vdcg_network_isolated (Data Source)

The `cloudavenue_vdcg_network_isolated` data source allows you to retrieve information about an isolated network in a `VDC Group`.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the network. This value must be unique within the `VDC` that owns the network.

### Optional

- `vdc_group_id` (String) The ID of vDC group that owns the network. Ensure that at least one attribute from this collection is set: [vdc_group_name,vdc_group_id].
- `vdc_group_name` (String) The name of vDC group that owns the network. Ensure that at least one attribute from this collection is set: [vdc_group_name,vdc_group_id].

### Read-Only

- `description` (String) A description of the network.
- `dns1` (String) The primary DNS server IP address for the network.
- `dns2` (String) The secondary DNS server IP address for the network.
- `dns_suffix` (String) The DNS suffix for the network.
- `gateway` (String) The gateway IP address for the network. This value define also the network IP range with the prefix length.
- `guest_vlan_allowed` (Boolean) Indicates if the network allows guest VLANs.
- `id` (String) The ID of the isolated network.
- `prefix_length` (Number) The prefix length for the network. This value must be a valid prefix length for the network IP range. (e.g. /24 for netmask 255.255.255.0).
- `static_ip_pool` (Attributes Set) A set of static IP pools to be used for this network. (see [below for nested schema](#nestedatt--static_ip_pool))

<a id="nestedatt--static_ip_pool"></a>
### Nested Schema for `static_ip_pool`

Read-Only:

- `end_address` (String) The end address of the IP pool. This value must be a valid IP address in the network IP range.
- `start_address` (String) The start address of the IP pool. This value must be a valid IP address in the network IP range.
66 changes: 66 additions & 0 deletions docs/resources/vdcg_network_isolated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
page_title: "cloudavenue_vdcg_network_isolated Resource - cloudavenue"
subcategory: "vDC Group (Virtual Datacenter Group)"
description: |-
The cloudavenue_vdcg_network_isolated resource allows you to manage an isolated network in a VDC Group.
---

# cloudavenue_vdcg_network_isolated (Resource)

The `cloudavenue_vdcg_network_isolated` resource allows you to manage an isolated network in a `VDC Group`.

## Example Usage

```terraform
resource "cloudavenue_vdcg_network_isolated" "example" {
name = "my-isolated-network"
vdc_group_name = cloudavenue_vdcg.example.name

gateway = "192.168.0.1"
prefix_length = 24

dns1 = "192.168.0.2"
dns2 = "192.168.0.3"
dns_suffix = "example.local"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `gateway` (String) (ForceNew) The gateway IP address for the network. This value define also the network IP range with the prefix length. Must be a valid IP with net.ParseIP.
- `name` (String) The name of the network. This value must be unique within the `VDC` that owns the network.
- `prefix_length` (Number) (ForceNew) The prefix length for the network. This value must be a valid prefix length for the network IP range. (e.g. /24 for netmask 255.255.255.0). Value must be between 1 and 32.

### Optional

- `description` (String) A description of the network.
- `dns1` (String) The primary DNS server IP address for the network. Must be a valid IP with net.ParseIP.
- `dns2` (String) The secondary DNS server IP address for the network. Must be a valid IP with net.ParseIP.
- `dns_suffix` (String) The DNS suffix for the network.
- `guest_vlan_allowed` (Boolean) Indicates if the network allows guest VLANs. Value defaults to `false`.
- `static_ip_pool` (Attributes Set) A set of static IP pools to be used for this network. (see [below for nested schema](#nestedatt--static_ip_pool))
- `vdc_group_id` (String) (ForceNew) The ID of vDC group that owns the network. Ensure that at least one attribute from this collection is set: [vdc_group_name,vdc_group_id].
- `vdc_group_name` (String) (ForceNew) The name of vDC group that owns the network. Ensure that at least one attribute from this collection is set: [vdc_group_name,vdc_group_id].

### Read-Only

- `id` (String) The ID of the isolated network.

<a id="nestedatt--static_ip_pool"></a>
### Nested Schema for `static_ip_pool`

Required:

- `end_address` (String) The end address of the IP pool. This value must be a valid IP address in the network IP range. Must be a valid IP with net.ParseIP.
- `start_address` (String) The start address of the IP pool. This value must be a valid IP address in the network IP range. Must be a valid IP with net.ParseIP.

## Import

Import is supported using the following syntax:
```shell
# VDC Network isolated can be imported using the VDC Groupe name or ID and the network name or ID.
terraform import cloudavenue_vdcg_network_isolated.example vdcGroupNameOrId.networkNameOrId
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# VDC Network isolated can be imported using the VDC Groupe name or ID and the network name or ID.
terraform import cloudavenue_vdcg_network_isolated.example vdcGroupNameOrId.networkNameOrId
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "cloudavenue_vdcg_network_isolated" "example" {
name = "my-isolated-network"
vdc_group_name = cloudavenue_vdcg.example.name

gateway = "192.168.0.1"
prefix_length = 24

dns1 = "192.168.0.2"
dns2 = "192.168.0.3"
dns_suffix = "example.local"
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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.15.1
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.14.1-0.20241212084109-0015a69a610a
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339
github.com/rs/zerolog v1.33.0
github.com/thanhpk/randstr v1.0.6
Expand All @@ -45,6 +45,7 @@ require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/avast/retry-go/v4 v4.6.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/avast/retry-go/v4 v4.6.0 h1:K9xNA+KeB8HHc2aWFuLb25Offp+0iVRXEvFx8IinRJA=
github.com/avast/retry-go/v4 v4.6.0/go.mod h1:gvWlPhBVsvBbLkVGDg/KwvBv0bEkCOLRRSHKIr2PyOE=
github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
Expand Down Expand Up @@ -250,8 +252,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.15.1 h1:8KZ2/hWbuDTY9KZqr0TBgwD0r702KcVXBC/FOW1opM8=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.15.1/go.mod h1:nUx8sNedkNajCoMo+oAEgBmcUnSJcxezoqhhliqKmMs=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.14.1-0.20241212084109-0015a69a610a h1:z2os66FLZiYX+SogPZUwlRALepmnx4HE3Nf9JM7is6Q=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.14.1-0.20241212084109-0015a69a610a/go.mod h1:c/V9npNz22QjlTXEsx0GWoxhzMFYiLynlCUPQOImd2w=
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339 h1:DEKcWLGbEhu/I6kn9NAXhVCFrbPhR+Ef7oLmpLVnnPM=
github.com/orange-cloudavenue/common-go/utils v0.0.0-20240119163616-66b473d92339/go.mod h1:11JAFfGWVmhoT4AAORKsIC5M6nI+uDGSEOScMzavgPA=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider_datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (p *cloudavenueProvider) DataSources(_ context.Context) []func() datasource

// * VDC GROUP
vdcg.NewVDCGDataSource,
vdcg.NewNetworkIsolatedDataSource,

// * VAPP
vapp.NewVappDataSource,
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (p *cloudavenueProvider) Resources(_ context.Context) []func() resource.Res

// * VDC Group
vdcg.NewVDCGResource,
vdcg.NewNetworkIsolatedResource,

// * VCDA
vcda.NewVCDAIPResource,
Expand Down
113 changes: 113 additions & 0 deletions internal/provider/vdcg/network_isolated_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package vdcg

import (
"context"
"fmt"

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

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

v1 "github.com/orange-cloudavenue/cloudavenue-sdk-go/v1"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/metrics"
)

var (
_ datasource.DataSource = &NetworkIsolatedDataSource{}
_ datasource.DataSourceWithConfigure = &NetworkIsolatedDataSource{}
)

func NewNetworkIsolatedDataSource() datasource.DataSource {
return &NetworkIsolatedDataSource{}
}

type NetworkIsolatedDataSource struct {
client *client.CloudAvenue
vdcg *v1.VDCGroup
}

func (d *NetworkIsolatedDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + categoryName + "_network_isolated"
}

// Init Initializes the resource.
func (d *NetworkIsolatedDataSource) Init(ctx context.Context, rm *networkIsolatedModel) (diags diag.Diagnostics) {
var err error

// Get the VDC Group
if rm.VDCGroupID.IsKnown() {
d.vdcg, err = d.client.CAVSDK.V1.VDC().GetVDCGroup(rm.VDCGroupID.Get())
} else {
d.vdcg, err = d.client.CAVSDK.V1.VDC().GetVDCGroup(rm.VDCGroupName.Get())
}
if err != nil {
diags.AddError("Error retrieving VDC Group", err.Error())
return
}
return
}

func (d *NetworkIsolatedDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = networkIsolatedSchema(ctx).GetDataSource(ctx)
}

func (d *NetworkIsolatedDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}

client, ok := req.ProviderData.(*client.CloudAvenue)

if !ok {
resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type",
fmt.Sprintf("Expected *client.CloudAvenue, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
}

d.client = client
}

func (d *NetworkIsolatedDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
defer metrics.New("data.cloudavenue_vdcg_network_isolated", d.client.GetOrgName(), metrics.Read)()

config := &networkIsolatedModel{}

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

/*
Implement the data source read logic here.
*/

s := &NetworkIsolatedResource{
client: d.client,
vdcg: d.vdcg,
}

// Read data from the API
data, found, diags := s.read(ctx, config)
if !found {
resp.Diagnostics.AddError("Resource not found", fmt.Sprintf("The isolated network '%s' was not found.", config.Name.Get()))
return
}
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Loading
Loading