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 7b97f49 commit e8e1b20
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FEATURES:
DEPENDENCIES:

deps: bumps actions/checkout from 2 to 3 ([GH-263](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/263))
deps: bumps github.com/FrangipaneTeam/terraform-plugin-framework-superschema from 1.2.0 to 1.3.0 ([GH-265](https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/265))

## 0.1.1 (April 3, 2023)

Expand Down
17 changes: 14 additions & 3 deletions docs/data-sources/network_routed.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ resource "cloudavenue_network_routed" "example" {
gateway = "192.168.10.254"
prefix_length = 24
edge_gateway_id = "urn:vcloud:gateway:dde5d31a-2f32-43ef-b3b3-127245958298"
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 +46,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
15 changes: 13 additions & 2 deletions examples/data-sources/cloudavenue_network_routed/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ resource "cloudavenue_network_routed" "example" {
gateway = "192.168.10.254"
prefix_length = 24
edge_gateway_id = "urn:vcloud:gateway:dde5d31a-2f32-43ef-b3b3-127245958298"
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
17 changes: 11 additions & 6 deletions internal/provider/network/routed_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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 networkRoutedDataSourceModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
Expand All @@ -94,7 +94,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,9 +122,10 @@ func (d *networkRoutedDataSource) Read(ctx context.Context, req datasource.ReadR
return
}

plan := &networkRoutedDataSourceModel{
// Set data
data = networkRoutedDataSourceModel{
ID: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.ID),
Name: types.StringValue(data.Name.ValueString()),
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),
Expand All @@ -136,10 +137,14 @@ func (d *networkRoutedDataSource) Read(ctx context.Context, req datasource.ReadR
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)...)
}
10 changes: 6 additions & 4 deletions internal/provider/network/routed_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/edgegw"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/network"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/org"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/pkg/utils"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down Expand Up @@ -186,15 +187,15 @@ func (r *networkRoutedResource) Read(ctx context.Context, req resource.ReadReque
plan := &networkRoutedResourceModel{
ID: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.ID),
Name: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Name),
Description: types.StringValue(orgNetwork.OpenApiOrgVdcNetwork.Description),
Description: utils.StringValueOrNull(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),
DNS1: utils.StringValueOrNull(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer1),
DNS2: utils.StringValueOrNull(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSServer2),
DNSSuffix: utils.StringValueOrNull(orgNetwork.OpenApiOrgVdcNetwork.Subnets.Values[0].DNSSuffix),
}

// Set Static IP Pool
Expand Down Expand Up @@ -401,6 +402,7 @@ func (r *networkRoutedResource) SetNetworkAPIObject(ctx context.Context, plan an
StaticIPPool: p.StaticIPPool,
VDCIDOrVDCGroupID: types.StringValue(vdcOrVDCGroup.GetID()),
EdgeGatewayID: p.EdgeGatewayID,
EdgegatewayName: p.EdgeGatewayName,
InterfaceType: p.InterfaceType,
})
}
22 changes: 17 additions & 5 deletions internal/tests/network/routed_datasource_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package network

import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -15,11 +16,22 @@ resource "cloudavenue_network_routed" "example" {
gateway = "192.168.10.254"
prefix_length = 24
edge_gateway_id = "urn:vcloud:gateway:dde5d31a-2f32-43ef-b3b3-127245958298"
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,9 +47,9 @@ func TestAccNetworkRoutedDataSource(t *testing.T) {
// Apply test
Config: testAccNetworkRoutedDataSourceConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
resource.TestCheckResourceAttrPair(dataSourceName, "interface_type", resourceName, "interface_type"),
resource.TestCheckResourceAttrSet(dataSourceName, "name"),
resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile(`urn:vcloud:network:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}`)),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "static_ip_pool.#", resourceName, "static_ip_pool.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "gateway", resourceName, "gateway"),
),
},
Expand Down

0 comments on commit e8e1b20

Please sign in to comment.