Skip to content

Commit

Permalink
feat: add vdc network isolated ress/data
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod committed Dec 12, 2024
1 parent 299e9c0 commit 464fc0f
Show file tree
Hide file tree
Showing 21 changed files with 1,412 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changelog/879.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
`resource/cloudavenue_vdc_network_isolated` - Added a new resource to manage isolated networks in a VDC. This resource replace the deprecated `cloudavenue_network_isolated` resource.
```

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

# cloudavenue_vdc_network_isolated (Data Source)

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

## Example Usage

```terraform
data "cloudavenue_vdc_network_isolated" "example" {
vdc = cloudavenue_vdc.example.name
name = "my-isolated-network"
}
```

<!-- 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.
- `vdc` (String) The name of vDC to use.

### 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.

95 changes: 95 additions & 0 deletions docs/resources/vdc_network_isolated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
page_title: "cloudavenue_vdc_network_isolated Resource - cloudavenue"
subcategory: "vDC (Virtual Datacenter)"
description: |-
The cloudavenue_vdc_network_isolated resource allows you to manage an isolated network in a VDC.
---

# cloudavenue_vdc_network_isolated (Resource)

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

## Example Usage

```terraform
resource "cloudavenue_vdc_network_isolated" "example" {
name = "my-isolated-network"
vdc = cloudavenue_vdc.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.
- `vdc` (String) (ForceNew) The name of vDC to use.

### 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))

### 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.

## Advanced Usage

Define `static_ip_pool` as a list of objects to create multiple IP pools.

```hcl
resource "cloudavenue_vdc_network_isolated" "example" {
name = "my-isolated-network"
vdc = cloudavenue_vdc.example.name
gateway = "192.168.0.1"
prefix_length = 24
dns1 = "192.168.0.2"
dns2 = "192.168.0.3"
dns_suffix = "example.local"
static_ip_pool = [
{
start_address = "192.168.0.10"
end_address = "192.168.0.20"
},
{
start_address = "192.168.0.100"
end_address = "192.168.0.130"
}
]
}
```

## Import

Import is supported using the following syntax:
```shell
# VDC Network isolated can be imported using the VDC name and the network name or ID.
terraform import cloudavenue_vdc_network_isolated.example vdc.networkNameOrId
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "cloudavenue_vdc_network_isolated" "example" {
vdc = cloudavenue_vdc.example.name
name = "my-isolated-network"
}
2 changes: 2 additions & 0 deletions examples/resources/cloudavenue_vdc_network_isolated/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# VDC Network isolated can be imported using the VDC name and the network name or ID.
terraform import cloudavenue_vdc_network_isolated.example vdc.networkNameOrId
11 changes: 11 additions & 0 deletions examples/resources/cloudavenue_vdc_network_isolated/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "cloudavenue_vdc_network_isolated" "example" {
name = "my-isolated-network"
vdc = cloudavenue_vdc.example.name

gateway = "192.168.0.1"
prefix_length = 24

dns1 = "192.168.0.2"
dns2 = "192.168.0.3"
dns_suffix = "example.local"
}
5 changes: 3 additions & 2 deletions 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.14.0
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 All @@ -56,7 +57,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.16.0 // indirect
github.com/go-resty/resty/v2 v2.16.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/cli v1.1.6 // indirect
Expand Down
10 changes: 6 additions & 4 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 @@ -93,8 +95,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.16.0 h1:qpKalHWI2bpp9BIKlyT8TYWEJXOk1NuKbfiT3RRnzWc=
github.com/go-resty/resty/v2 v2.16.0/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
github.com/go-resty/resty/v2 v2.16.2 h1:CpRqTjIzq/rweXUt9+GxzzQdlkqMdt8Lm/fuK/CAbAg=
github.com/go-resty/resty/v2 v2.16.2/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
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.14.0 h1:IHqwdPRAEfw/xP6I0COzE9hsju7Hk+TLjd3xzJ6AOqM=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.14.0/go.mod h1:CTQO1VIVFvImvmKoR4ntL3HxBi5REm6ssLzUj3kv1sc=
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 @@ -51,6 +51,7 @@ func (p *cloudavenueProvider) DataSources(_ context.Context) []func() datasource
vdc.NewVDCsDataSource,
vdc.NewVDCDataSource,
vdc.NewGroupDataSource,
vdc.NewNetworkIsolatedDataSource,

// * VDC GROUP
vdcg.NewVDCGDataSource,
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 @@ -41,6 +41,7 @@ func (p *cloudavenueProvider) Resources(_ context.Context) []func() resource.Res
vdc.NewVDCResource,
vdc.NewACLResource,
vdc.NewGroupResource,
vdc.NewNetworkIsolatedResource,

// * VDC Group
vdcg.NewVDCGResource,
Expand Down
102 changes: 102 additions & 0 deletions internal/provider/vdc/network_isolated_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package vdc

import (
"context"
"fmt"

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

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

"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/metrics"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/vdc"
)

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

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

type NetworkIsolatedDataSource struct {
client *client.CloudAvenue
vdc vdc.VDC
}

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) {
d.vdc, diags = vdc.Init(d.client, rm.VDC.StringValue)
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_vdc_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,
vdc: d.vdc,
}

// 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 in the VDC '%s'.", config.Name.Get(), config.VDC.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

0 comments on commit 464fc0f

Please sign in to comment.