-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vdc network isolated ress/data
- Loading branch information
Showing
21 changed files
with
1,412 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/cloudavenue_vdc_network_isolated/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
2
examples/resources/cloudavenue_vdc_network_isolated/import.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
examples/resources/cloudavenue_vdc_network_isolated/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)...) | ||
} |
Oops, something went wrong.