Skip to content

Commit

Permalink
refactor(vapp): enhancement 'cloudavenue_vapp_isolated_network_dataso…
Browse files Browse the repository at this point in the history
…urce'
  • Loading branch information
David MICHENEAU committed Apr 26, 2023
1 parent 5b51373 commit 09481b0
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 21 deletions.
80 changes: 80 additions & 0 deletions docs/data-sources/vapp_isolated_network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
page_title: "cloudavenue_vapp_isolated_network Data Source - cloudavenue"
subcategory: "vApp (Virtual Appliance)"
description: |-
---

# cloudavenue_vapp_isolated_network (Data Source)



## Example Usage

```terraform
resource "cloudavenue_vapp" "example" {
name = "MyVapp"
description = "This is an example vApp"
}
resource "cloudavenue_vapp_isolated_network" "example" {
name = "MyVappNet"
vapp_name = cloudavenue_vapp.example.name
gateway = "192.168.10.1"
netmask = "255.255.255.0"
dns1 = "192.168.10.1"
dns2 = "192.168.10.3"
dns_suffix = "myvapp.biz"
guest_vlan_allowed = true
retain_ip_mac_enabled = true
static_ip_pool = [{
start_address = "192.168.10.51"
end_address = "192.168.10.101"
},
{
start_address = "192.168.10.10"
end_address = "192.168.10.30"
}]
}
data "cloudavenue_vapp_isolated_network" "example" {
vapp_name = cloudavenue_vapp.example.name
name = cloudavenue_vapp_isolated_network.example.name
}
```

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

### Required

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

### Optional

- `vapp_id` (String) ID of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_name`, `vapp_id`.
- `vapp_name` (String) Name of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_id`, `vapp_name`.
- `vdc` (String) The name of vDC to use, optional if defined at provider level.

### 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) Return True if Network allows guest VLAN.
- `id` (String) The ID of the network.
- `netmask` (String) The netmask of the network.
- `retain_ip_mac_enabled` (Boolean) Return network resources such as IP/MAC of router will be retained across deployments.
- `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.

4 changes: 2 additions & 2 deletions docs/data-sources/vapp_org_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ data "cloudavenue_vapp_org_network" "example" {
### Required

- `network_name` (String) Organization network name to which vApp network is connected to.
- `vapp_name` (String) Name of the vApp.

### Optional

- `vapp_id` (String) ID of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_name`, `vapp_id`.
- `vapp_name` (String) Name of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_id`, `vapp_name`.
- `vdc` (String) The name of vDC to use, optional if defined at provider level.

### Read-Only

- `id` (String) The ID of the network.
- `is_fenced` (Boolean) Defines if the network is fenced. Fencing allows identical virtual machines in different vApp networks connect to organization VDC networks that are accessed in this vApp.
- `retain_ip_mac_enabled` (Boolean) Specifies whether the network resources such as IP/MAC of router will be retained across deployments.
- `vapp_id` (String) ID of the vApp.


82 changes: 82 additions & 0 deletions docs/data-sources/vapp_org_network.md copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
page_title: "cloudavenue_vapp_org_network Data Source - cloudavenue"
subcategory: "vApp (Virtual Appliance)"
description: |-
Provides a Cloud Avenue routed vAPP Org Network data source to read data or reference existing network.
---

# cloudavenue_vapp_org_network (Data Source)

Provides a Cloud Avenue routed vAPP Org Network data source to read data or reference existing network.

## Example Usage

```terraform
data "cloudavenue_tier0_vrfs" "example" {}

resource "cloudavenue_edgegateway" "example" {
owner_name = "MyVDC"
tier0_vrf_name = data.cloudavenue_tier0_vrfs.example.names.0
owner_type = "vdc"
}

resource "cloudavenue_network_routed" "example" {
name = "MyOrgNet"
description = "This is an example Net"

edge_gateway_id = cloudavenue_edgegateway.example.id

gateway = "192.168.1.254"
prefix_length = 24

dns1 = "1.1.1.1"
dns2 = "8.8.8.8"

dns_suffix = "example"

static_ip_pool = [
{
start_address = "192.168.1.10"
end_address = "192.168.1.20"
}
]
}

resource "cloudavenue_vapp" "example" {
name = "MyVapp"
vdc = "MyVDC"
description = "This is an example vApp"
}

resource "cloudavenue_vapp_org_network" "example" {
vapp_name = cloudavenue_vapp.example.name
vdc = cloudavenue_vapp.example.vdc
network_name = cloudavenue_network_routed.example.name
}

data "cloudavenue_vapp_org_network" "example" {
vapp_name = cloudavenue_vapp.example.name
network_name = cloudavenue_network_routed.example.name
vdc = cloudavenue_vapp.example.vdc
}
```

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

### Required

- `network_name` (String) Organization network name to which vApp network is connected to.

### Optional

- `vapp_id` (String) ID of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_name`, `vapp_id`.
- `vapp_name` (String) Name of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_id`, `vapp_name`.
- `vdc` (String) The name of vDC to use, optional if defined at provider level.

### Read-Only

- `id` (String) The ID of the network.
- `is_fenced` (Boolean) Defines if the network is fenced. Fencing allows identical virtual machines in different vApp networks connect to organization VDC networks that are accessed in this vApp.
- `retain_ip_mac_enabled` (Boolean) Specifies whether the network resources such as IP/MAC of router will be retained across deployments.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource "cloudavenue_vapp" "example" {
name = "MyVapp"
description = "This is an example vApp"
}

resource "cloudavenue_vapp_isolated_network" "example" {
name = "MyVappNet"
vapp_name = cloudavenue_vapp.example.name
gateway = "192.168.10.1"
netmask = "255.255.255.0"
dns1 = "192.168.10.1"
dns2 = "192.168.10.3"
dns_suffix = "myvapp.biz"
guest_vlan_allowed = true
retain_ip_mac_enabled = true

static_ip_pool = [{
start_address = "192.168.10.51"
end_address = "192.168.10.101"
},
{
start_address = "192.168.10.10"
end_address = "192.168.10.30"
}]
}

data "cloudavenue_vapp_isolated_network" "example" {
vapp_name = cloudavenue_vapp.example.name
name = cloudavenue_vapp_isolated_network.example.name
}
31 changes: 29 additions & 2 deletions examples/data-sources/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
data "cloudavenue_vdc_group" "example" {
name = "MyVDCGroup"
resource "cloudavenue_vapp" "example" {
name = "MyVapp"
description = "This is an example vApp"
}

resource "cloudavenue_vapp_isolated_network" "example" {
name = "MyVappNet"
vapp_name = cloudavenue_vapp.example.name
gateway = "192.168.10.1"
netmask = "255.255.255.0"
dns1 = "192.168.10.1"
dns2 = "192.168.10.3"
dns_suffix = "myvapp.biz"
guest_vlan_allowed = true
retain_ip_mac_enabled = true

static_ip_pool = [{
start_address = "192.168.10.51"
end_address = "192.168.10.101"
},
{
start_address = "192.168.10.10"
end_address = "192.168.10.30"
}]
}

data "cloudavenue_vapp_isolated_network" "example" {
vapp_name = cloudavenue_vapp.example.name
name = cloudavenue_vapp_isolated_network.example.name
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.15.0
github.com/hashicorp/terraform-plugin-log v0.8.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/k0kubun/pp v3.0.1+incompatible
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.1.1
github.com/vmware/go-vcloud-director/v2 v2.19.0
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
Expand Down Expand Up @@ -52,6 +53,7 @@ require (
github.com/huandu/xstrings v1.4.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40=
github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck=
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
7 changes: 6 additions & 1 deletion internal/provider/common/network/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,12 @@ func GetSchema(opts ...networkSchemaOpts) superschema.Schema {
// Add isolated vApp network specific attributes to the schema
delete(_schema.Attributes, "prefix_length")
_schema.Attributes["netmask"] = superschema.StringAttribute{
Common: &schemaR.StringAttribute{
Computed: true,
},
Resource: &schemaR.StringAttribute{
MarkdownDescription: "The netmask for the network.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString("255.255.255.0"),
Validators: []validator.String{
fstringvalidator.IsNetmask(),
Expand All @@ -309,6 +311,9 @@ func GetSchema(opts ...networkSchemaOpts) superschema.Schema {
stringplanmodifier.RequiresReplace(),
},
},
DataSource: &schemaD.StringAttribute{
MarkdownDescription: "The netmask of the network.",
},
}

case ROUTEDVAPP:
Expand Down
23 changes: 8 additions & 15 deletions internal/provider/common/vapp/vapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand Down Expand Up @@ -89,35 +88,29 @@ func SuperSchema() map[string]superschema.Attribute {
"vapp_id": superschema.StringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "ID of the vApp.",
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("vapp_name"), path.MatchRoot("vapp_id")),
},
Optional: true,
},
Resource: &schemaR.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("vapp_name"), path.MatchRoot("vapp_id")),
},
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"vapp_name": superschema.StringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "Name of the vApp.",
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("vapp_id"), path.MatchRoot("vapp_name")),
},
Optional: true,
},
Resource: &schemaR.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("vapp_id"), path.MatchRoot("vapp_name")),
},
},
DataSource: &schemaD.StringAttribute{
Required: true,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (p *cloudavenueProvider) DataSources(_ context.Context) []func() datasource
// VAPP
vapp.NewVappDataSource,
vapp.NewOrgNetworkDataSource,

vapp.NewIsolatedNetworkDataSource,
// CATALOG
catalog.NewCatalogsDataSource,
catalog.NewCatalogDataSource,
Expand Down
Loading

0 comments on commit 09481b0

Please sign in to comment.