Skip to content

Commit

Permalink
chore: update CHANGELOG.md for #265
Browse files Browse the repository at this point in the history
  • Loading branch information
changelogbot authored and David MICHENEAU committed Apr 12, 2023
1 parent 3e39b4a commit d31462b
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 94 deletions.
23 changes: 19 additions & 4 deletions docs/data-sources/network_routed.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,31 @@ Provides a Cloud Avenue vDC routed Network data source to read data or reference
## Example Usage

```terraform
data "cloudavenue_edgegateway" "example" {
name = "tn01e02ocb0006205spt101"
}
resource "cloudavenue_network_routed" "example" {
name = "ExampleNetworkRouted"
gateway = "192.168.10.254"
prefix_length = 24
edge_gateway_id = "urn:vcloud:gateway:dde5d31a-2f32-43ef-b3b3-127245958298"
edge_gateway_id = data.cloudavenue_edgegateway.example.id
dns1 = "1.1.1.1"
dns2 = "8.8.8.8"
dns_suffix = "example"
static_ip_pool = [
{
start_address = "192.168.10.10"
end_address = "192.168.10.20"
}
]
}
data "cloudavenue_network_routed" "example" {
name = "ExampleNetworkRouted"
edge_gateway_id = "urn:vcloud:gateway:dde5d31a-2f32-43ef-b3b3-127245958298"
name = cloudavenue_network_routed.example.name
edge_gateway_id = cloudavenue_network_routed.example.edge_gateway_id
}
```

Expand All @@ -35,14 +50,14 @@ data "cloudavenue_network_routed" "example" {
### Optional

- `edge_gateway_id` (String) The ID of the edge gateway in which the routed network should be located.
- `edge_gateway_name` (String) The name of the edge gateway in which the routed network should be located.

### 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.
- `edge_gateway_name` (String) The name of the edge gateway in which the routed network should be located.
- `gateway` (String) The gateway IP address for the network. This value define also the network IP range with the prefix length.
- `id` (String) The ID of the network.
- `interface_type` (String) An interface for the network.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/network_routed.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ resource "cloudavenue_network_routed" "example" {
- `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.
- `edge_gateway_id` (String) (ForceNew) The ID of the edge gateway in which the routed network should be located. Ensure that one and only one attribute from this collection is set : `edge_gateway_id`, `edge_gateway_name`.
- `edge_gateway_name` (String) (ForceNew) The name of the edge gateway in which the routed network should be located.
- `edge_gateway_name` (String) (ForceNew) The name of the edge gateway in which the routed network should be located. The name of the edge gateway in which the routed network should be located.
- `interface_type` (String) An interface for the network. Value must be one of : `INTERNAL`, `SUBINTERFACE`, `DISTRIBUTED`. Value defaults to `INTERNAL`.
- `static_ip_pool` (Attributes Set) A set of static IP pools to be used for this network. Set must contain at least 1 elements. (see [below for nested schema](#nestedatt--static_ip_pool))

Expand Down
21 changes: 18 additions & 3 deletions examples/data-sources/cloudavenue_network_routed/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
data "cloudavenue_edgegateway" "example" {
name = "tn01e02ocb0006205spt101"
}

resource "cloudavenue_network_routed" "example" {
name = "ExampleNetworkRouted"
gateway = "192.168.10.254"
prefix_length = 24
edge_gateway_id = "urn:vcloud:gateway:dde5d31a-2f32-43ef-b3b3-127245958298"
edge_gateway_id = data.cloudavenue_edgegateway.example.id
dns1 = "1.1.1.1"
dns2 = "8.8.8.8"

dns_suffix = "example"

static_ip_pool = [
{
start_address = "192.168.10.10"
end_address = "192.168.10.20"
}
]
}

data "cloudavenue_network_routed" "example" {
name = "ExampleNetworkRouted"
edge_gateway_id = "urn:vcloud:gateway:dde5d31a-2f32-43ef-b3b3-127245958298"
name = cloudavenue_network_routed.example.name
edge_gateway_id = cloudavenue_network_routed.example.edge_gateway_id
}
8 changes: 5 additions & 3 deletions internal/provider/common/network/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type GlobalResourceModel struct {
// ISOLATED

// ROUTED
EdgeGatewayID types.String
InterfaceType types.String
EdgeGatewayID types.String
EdgegatewayName types.String
InterfaceType types.String
}

type Network interface {
Expand Down Expand Up @@ -60,7 +61,8 @@ func (k Kind) SetNetworkAPIObject(ctx context.Context, data GlobalResourceModel)
apiObject.NetworkType = govcdtypes.OrgVdcNetworkTypeRouted
apiObject.Connection = &govcdtypes.Connection{
RouterRef: govcdtypes.OpenApiReference{
ID: data.EdgeGatewayID.ValueString(),
ID: data.EdgeGatewayID.ValueString(),
Name: data.EdgegatewayName.ValueString(),
},
// API requires interface type in upper case, but we accept any case
ConnectionType: data.InterfaceType.ValueString(),
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/common/network/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,11 @@ func GetSchema(opts ...networkSchemaOpts) superschema.Schema {
_schema.Attributes["edge_gateway_name"] = superschema.StringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The name of the edge gateway in which the routed network should be located.",
Optional: true,
Computed: true,
},
Resource: &schemaR.StringAttribute{
MarkdownDescription: "The name of the edge gateway in which the routed network should be located.",
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.UseStateForUnknown(),
Expand Down
47 changes: 40 additions & 7 deletions internal/provider/network/common_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/mutex"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/org"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/pkg/utils"
)

type staticIPPool struct {
Expand All @@ -34,8 +35,24 @@ type networkIsolatedModel struct {
StaticIPPool types.Set `tfsdk:"static_ip_pool"`
}

type networkRoutedModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
EdgeGatewayID types.String `tfsdk:"edge_gateway_id"`
EdgeGatewayName types.String `tfsdk:"edge_gateway_name"`
InterfaceType types.String `tfsdk:"interface_type"`
Gateway types.String `tfsdk:"gateway"`
PrefixLength types.Int64 `tfsdk:"prefix_length"`
DNS1 types.String `tfsdk:"dns1"`
DNS2 types.String `tfsdk:"dns2"`
DNSSuffix types.String `tfsdk:"dns_suffix"`
StaticIPPool types.Set `tfsdk:"static_ip_pool"`
}

var networkMutexKV = mutex.NewKV()

// Get parent edge gateway ID.
func GetParentEdgeGatewayID(org org.Org, edgeGatewayID string) (*string, diag.Diagnostic) {
anyEdgeGateway, err := org.GetAnyTypeEdgeGatewayById(edgeGatewayID)
if err != nil {
Expand All @@ -49,17 +66,33 @@ func GetParentEdgeGatewayID(org org.Org, edgeGatewayID string) (*string, diag.Di
return &id, nil
}

// Get IP Pool information data from network.
func GetIPRanges(network *govcd.OpenApiOrgVdcNetwork) []staticIPPool {
ipPools := []staticIPPool{}

if len(network.OpenApiOrgVdcNetwork.Subnets.Values[0].IPRanges.Values) > 0 {
for _, ipRange := range network.OpenApiOrgVdcNetwork.Subnets.Values[0].IPRanges.Values {
ipPool := staticIPPool{
StartAddress: types.StringValue(ipRange.StartAddress),
EndAddress: types.StringValue(ipRange.EndAddress),
}
ipPools = append(ipPools, ipPool)
for _, ipRange := range network.OpenApiOrgVdcNetwork.Subnets.Values[0].IPRanges.Values {
ipPool := staticIPPool{
StartAddress: types.StringValue(ipRange.StartAddress),
EndAddress: types.StringValue(ipRange.EndAddress),
}
ipPools = append(ipPools, ipPool)
}
return ipPools
}

// Set data to network routed model.
func SetDataToNetworkRoutedModel(network *govcd.OpenApiOrgVdcNetwork) networkRoutedModel {
return networkRoutedModel{
ID: types.StringValue(network.OpenApiOrgVdcNetwork.ID),
Name: types.StringValue(network.OpenApiOrgVdcNetwork.Name),
Description: utils.StringValueOrNull(network.OpenApiOrgVdcNetwork.Description),
EdgeGatewayID: types.StringValue(network.OpenApiOrgVdcNetwork.Connection.RouterRef.ID),
EdgeGatewayName: types.StringValue(network.OpenApiOrgVdcNetwork.Connection.RouterRef.Name),
InterfaceType: types.StringValue(network.OpenApiOrgVdcNetwork.Connection.ConnectionType),
Gateway: types.StringValue(network.OpenApiOrgVdcNetwork.Subnets.Values[0].Gateway),
PrefixLength: types.Int64Value(int64(network.OpenApiOrgVdcNetwork.Subnets.Values[0].PrefixLength)),
DNS1: utils.StringValueOrNull(network.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer1),
DNS2: utils.StringValueOrNull(network.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer2),
DNSSuffix: utils.StringValueOrNull(network.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSSuffix),
}
}
60 changes: 26 additions & 34 deletions internal/provider/network/routed_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ type networkRoutedDataSource struct {
network network.Kind
}

type networkRoutedDataSourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
EdgeGatewayID types.String `tfsdk:"edge_gateway_id"`
EdgeGatewayName types.String `tfsdk:"edge_gateway_name"`
InterfaceType types.String `tfsdk:"interface_type"`
Gateway types.String `tfsdk:"gateway"`
PrefixLength types.Int64 `tfsdk:"prefix_length"`
DNS1 types.String `tfsdk:"dns1"`
DNS2 types.String `tfsdk:"dns2"`
DNSSuffix types.String `tfsdk:"dns_suffix"`
StaticIPPool types.Set `tfsdk:"static_ip_pool"`
}

func (d *networkRoutedDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + categoryName + "_routed"
}
Expand All @@ -57,7 +42,7 @@ func (d *networkRoutedDataSource) Schema(ctx context.Context, req datasource.Sch
}

// Init resource used to initialize the resource.
func (d *networkRoutedDataSource) Init(_ context.Context, rm *networkRoutedDataSourceModel) (diags diag.Diagnostics) {
func (d *networkRoutedDataSource) Init(_ context.Context, rm *networkRoutedModel) (diags diag.Diagnostics) {
// Init Network
d.network.TypeOfNetwork = network.NAT_ROUTED
// Init Org
Expand Down Expand Up @@ -85,7 +70,7 @@ func (d *networkRoutedDataSource) Configure(ctx context.Context, req datasource.
}

func (d *networkRoutedDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data *networkRoutedDataSourceModel
var data networkRoutedModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
Expand All @@ -94,7 +79,7 @@ func (d *networkRoutedDataSource) Read(ctx context.Context, req datasource.ReadR
}

// Init resource
resp.Diagnostics.Append(d.Init(ctx, data)...)
resp.Diagnostics.Append(d.Init(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}
Expand Down Expand Up @@ -122,24 +107,31 @@ func (d *networkRoutedDataSource) Read(ctx context.Context, req datasource.ReadR
return
}

plan := &networkRoutedDataSourceModel{
ID: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.ID),
Name: types.StringValue(data.Name.ValueString()),
Description: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Description),
EdgeGatewayID: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Connection.RouterRef.ID),
EdgeGatewayName: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Connection.RouterRef.Name),
InterfaceType: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Connection.ConnectionType),
Gateway: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].Gateway),
PrefixLength: types.Int64Value(int64(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].PrefixLength)),
DNS1: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer1),
DNS2: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer2),
DNSSuffix: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSSuffix),
}

// Set data into the model
data = SetDataToNetworkRoutedModel(orgNetwork)

// data = networkRoutedModel{
// ID: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.ID),
// Name: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Name),
// Description: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Description),
// EdgeGatewayID: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Connection.RouterRef.ID),
// EdgeGatewayName: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Connection.RouterRef.Name),
// InterfaceType: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Connection.ConnectionType),
// Gateway: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].Gateway),
// PrefixLength: types.Int64Value(int64(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].PrefixLength)),
// DNS1: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer1),
// DNS2: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer2),
// DNSSuffix: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSSuffix),
// }

// Set static IP pool
var diags diag.Diagnostics
plan.StaticIPPool, diags = types.SetValueFrom(ctx, types.ObjectType{AttrTypes: staticIPPoolAttrTypes}, GetIPRanges(orgNetwork))
data.StaticIPPool, diags = types.SetValueFrom(ctx, types.ObjectType{AttrTypes: staticIPPoolAttrTypes}, GetIPRanges(orgNetwork))
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

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

0 comments on commit d31462b

Please sign in to comment.