Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: orange-cloudavenue/terraform-provider-cloudavenue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8f85e1d16f11a822d5e6cf3129801e4eff7b2b87
Choose a base ref
..
head repository: orange-cloudavenue/terraform-provider-cloudavenue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9187dac8030fcf4c1354c641f83004808db7726e
Choose a head ref
3 changes: 3 additions & 0 deletions .changelog/428.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
`datasource/cloudavenue_edgegateway_static_route` - New data source to fetch static route details from Cloud Avenue Edge Gateway.
```
41 changes: 20 additions & 21 deletions cmd/listing/resource-ca.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Checking resources and datasources of Orange Cloud Avenue provider
- Found 28 resources in terraform
- Found 27 resources in terraform
- Found 32 datasources in terraform

# Checking resources and datasources of VMware Cloud Director provider (version: unset)
@@ -19,26 +19,25 @@
| (6) | cloudavenue_edgegateway_firewall | vcd_nsxt_firewall |
| (7) | cloudavenue_edgegateway_ip_set | vcd_nsxt_ip_set |
| (8) | cloudavenue_edgegateway_security_group | vcd_nsxt_security_group |
| (9) | cloudavenue_edgegateway_static_route |
| (10) | cloudavenue_iam_role | vcd_role |
| (11) | cloudavenue_iam_user | vcd_org_user |
| (12) | cloudavenue_network_dhcp | vcd_nsxt_network_dhcp |
| (13) | cloudavenue_network_dhcp_binding | vcd_nsxt_network_dhcp_binding |
| (14) | cloudavenue_network_isolated | vcd_network_isolated |
| (15) | cloudavenue_network_routed | vcd_network_routed |
| (16) | cloudavenue_publicip |
| (17) | cloudavenue_vapp | vcd_vapp |
| (18) | cloudavenue_vapp_acl | vcd_vapp_access_control |
| (19) | cloudavenue_vapp_isolated_network | vcd_vapp_network |
| (20) | cloudavenue_vapp_org_network | vcd_vapp_org_network |
| (21) | cloudavenue_vcda_ip |
| (22) | cloudavenue_vdc | vcd_org_vdc |
| (23) | cloudavenue_vdc_acl | vcd_org_vdc_access_control |
| (24) | cloudavenue_vm | vcd_vm |
| (25) | cloudavenue_vm_affinity_rule | vcd_vm_affinity_rule |
| (26) | cloudavenue_vm_disk | vcd_independent_disk |
| (27) | cloudavenue_vm_inserted_media | vcd_inserted_media |
| (28) | cloudavenue_vm_security_tag | vcd_security_tag |
| (9) | cloudavenue_iam_role | vcd_role |
| (10) | cloudavenue_iam_user | vcd_org_user |
| (11) | cloudavenue_network_dhcp | vcd_nsxt_network_dhcp |
| (12) | cloudavenue_network_dhcp_binding | vcd_nsxt_network_dhcp_binding |
| (13) | cloudavenue_network_isolated | vcd_network_isolated |
| (14) | cloudavenue_network_routed | vcd_network_routed |
| (15) | cloudavenue_publicip |
| (16) | cloudavenue_vapp | vcd_vapp |
| (17) | cloudavenue_vapp_acl | vcd_vapp_access_control |
| (18) | cloudavenue_vapp_isolated_network | vcd_vapp_network |
| (19) | cloudavenue_vapp_org_network | vcd_vapp_org_network |
| (20) | cloudavenue_vcda_ip |
| (21) | cloudavenue_vdc | vcd_org_vdc |
| (22) | cloudavenue_vdc_acl | vcd_org_vdc_access_control |
| (23) | cloudavenue_vm | vcd_vm |
| (24) | cloudavenue_vm_affinity_rule | vcd_vm_affinity_rule |
| (25) | cloudavenue_vm_disk | vcd_vm_internal_disk |
| (26) | cloudavenue_vm_inserted_media | vcd_inserted_media |
| (27) | cloudavenue_vm_security_tag | vcd_security_tag |

| Number | Datasources Orange Cloud Avenue | Datasources VMware VCD |
|:--:|:--:|:--:|
47 changes: 47 additions & 0 deletions docs/data-sources/edgegateway_static_route
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
page_title: "cloudavenue_edgegateway_static_route Data Source - cloudavenue"
subcategory: "Edge Gateway (Tier-1)"
description: |-
The cloudavenue_edgegateway_static_route data source allows you to retrieve information about a static route on an Edge Gateway.
---

# cloudavenue_edgegateway_static_route (Data Source)

The `cloudavenue_edgegateway_static_route` data source allows you to retrieve information about a static route on an Edge Gateway.

## Example Usage

```terraform
data "cloudavenue_edgegateway_static_route" "example" {
edge_gateway_name = "myEdgeName"
name = "example"
}
```

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

### Required

- `name` (String) The name of the Static Route.

### Optional

- `edge_gateway_id` (String) The ID of the Edge Gateway. Ensure that one and only one attribute from this collection is set : `edge_gateway_name`, `edge_gateway_id`.
- `edge_gateway_name` (String) The name of the Edge Gateway. Ensure that one and only one attribute from this collection is set : `edge_gateway_name`, `edge_gateway_id`.

### Read-Only

- `description` (String) The description of the Static Route.
- `id` (String) The ID of the Static Route.
- `network_cidr` (String) The network CIDR of the Static Route. (e.g. 192.168.1.0/24).
- `next_hops` (Attributes Set) A set of next hops to use within the static route. (see [below for nested schema](#nestedatt--next_hops))

<a id="nestedatt--next_hops"></a>
### Nested Schema for `next_hops`

Read-Only:

- `admin_distance` (Number) Admin distance is used to choose which route to use when there are multiple routes for a specific network. The lower the admin distance, the higher the preference for the route.
- `ip_address` (String) IP address for next hop gateway IP Address for the Static Route.

47 changes: 47 additions & 0 deletions docs/data-sources/edgegateway_static_route.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cloudavenue_edgegateway_static_route Data Source - cloudavenue"
subcategory: ""
description: |-
The cloudavenue_edgegateway_static_route data source allows you to retrieve information about a static route on an Edge Gateway.
---

# cloudavenue_edgegateway_static_route (Data Source)

The `cloudavenue_edgegateway_static_route` data source allows you to retrieve information about a static route on an Edge Gateway.

## Example Usage

```terraform
data "cloudavenue_edgegateway_static_route" "example" {
edge_gateway_name = "myEdgeName"
name = "example"
}
```

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

### Required

- `name` (String) The name of the Static Route.

### Optional

- `edge_gateway_id` (String) The ID of the Edge Gateway. Ensure that one and only one attribute from this collection is set : `edge_gateway_name`, `edge_gateway_id`.
- `edge_gateway_name` (String) The name of the Edge Gateway. Ensure that one and only one attribute from this collection is set : `edge_gateway_name`, `edge_gateway_id`.

### Read-Only

- `description` (String) The description of the Static Route.
- `id` (String) The ID of the Static Route.
- `network_cidr` (String) The network CIDR of the Static Route. (e.g. 192.168.1.0/24).
- `next_hops` (Attributes Set) A set of next hops to use within the static route. (see [below for nested schema](#nestedatt--next_hops))

<a id="nestedatt--next_hops"></a>
### Nested Schema for `next_hops`

Read-Only:

- `admin_distance` (Number) Admin distance is used to choose which route to use when there are multiple routes for a specific network. The lower the admin distance, the higher the preference for the route.
- `ip_address` (String) IP address for next hop gateway IP Address for the Static Route.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "cloudavenue_edgegateway_static_route" "example" {
edge_gateway_name = "myEdgeName"
name = "example"
}
114 changes: 114 additions & 0 deletions internal/provider/edgegw/static_route_datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Package edgegw provides a Terraform datasource.
package edgegw //nolint:dupl

import (
"context"
"fmt"

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

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

"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/edgegw"
"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/org"
)

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

func NewStaticRouteDataSource() datasource.DataSource {
return &staticRouteDataSource{}
}

type staticRouteDataSource struct {
client *client.CloudAvenue
org org.Org
edgegw edgegw.EdgeGateway
}

// Init Initializes the data source.
func (d *staticRouteDataSource) Init(ctx context.Context, dm *StaticRouteModel) (diags diag.Diagnostics) {
var err error

d.org, diags = org.Init(d.client)
if diags.HasError() {
return
}

d.edgegw, err = d.org.GetEdgeGateway(edgegw.BaseEdgeGW{
ID: types.StringValue(dm.EdgeGatewayID.Get()),
Name: types.StringValue(dm.EdgeGatewayName.Get()),
})
if err != nil {
diags.AddError("Error retrieving Edge Gateway", err.Error())
return
}

return
}

func (d *staticRouteDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + categoryName + "_static_route"
}

func (d *staticRouteDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = staticRouteSchema(ctx).GetDataSource(ctx)
}

func (d *staticRouteDataSource) 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 *staticRouteDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
config := &StaticRouteModel{}

// 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.
*/

// If read function is identical to the resource, you can use the following code:
s := &staticRouteResource{
client: d.client,
org: d.org,
edgegw: d.edgegw,
}

// Read data from the API
data, _, diags := s.read(ctx, config)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
14 changes: 10 additions & 4 deletions internal/provider/edgegw/static_route_resource.go
Original file line number Diff line number Diff line change
@@ -27,9 +27,6 @@ var (
_ resource.Resource = &staticRouteResource{}
_ resource.ResourceWithConfigure = &staticRouteResource{}
_ resource.ResourceWithImportState = &staticRouteResource{}
// _ resource.ResourceWithModifyPlan = &staticRouteResource{}
// _ resource.ResourceWithUpgradeState = &staticRouteResource{}
// _ resource.ResourceWithValidateConfig = &staticRouteResource{}.
)

// NewStaticRouteResource is a helper function to simplify the provider implementation.
@@ -343,7 +340,16 @@ func (r *staticRouteResource) ImportState(ctx context.Context, req resource.Impo
func (r *staticRouteResource) read(ctx context.Context, planOrState *StaticRouteModel) (stateRefreshed *StaticRouteModel, found bool, diags diag.Diagnostics) {
stateRefreshed = planOrState.Copy()

staticRoute, err := r.edgegw.GetStaticRouteById(planOrState.ID.Get())
var (
staticRoute *govcd.NsxtEdgeGatewayStaticRoute
err error
)

if planOrState.ID.IsKnown() {
staticRoute, err = r.edgegw.GetStaticRouteById(planOrState.ID.Get())
} else {
staticRoute, err = r.edgegw.GetStaticRouteByName(planOrState.Name.Get())
}
if err != nil {
if govcd.ContainsNotFound(err) {
return nil, false, nil
7 changes: 1 addition & 6 deletions internal/provider/edgegw/static_route_schema.go
Original file line number Diff line number Diff line change
@@ -72,12 +72,7 @@ func staticRouteSchema(_ context.Context) superschema.Schema {
"name": superschema.SuperStringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The name of the Static Route.",
},
Resource: &schemaR.StringAttribute{
Required: true,
},
DataSource: &schemaD.StringAttribute{
Computed: true,
Required: true,
},
},
"description": superschema.SuperStringAttribute{
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ func (p *cloudavenueProvider) DataSources(_ context.Context) []func() datasource
edgegw.NewSecurityGroupDataSource,
edgegw.NewIPSetDataSource,
edgegw.NewDhcpForwardingDataSource,
edgegw.NewStaticRouteDataSource,

// VDC
vdc.NewVDCsDataSource,
33 changes: 33 additions & 0 deletions internal/tests/edgegw/static_route_datasource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package edgegw

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

tests "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/tests/common"
)

const testAccStaticRouteDataSourceConfig = `
data "cloudavenue_edgegateway_static_route" "example" {
edge_gateway_id = cloudavenue_edgegateway.example_with_vdc.id
name = cloudavenue_edgegateway_static_route.example.name
}
`

func TestAccStaticRouteDataSource(t *testing.T) {
dataSourceName := "data.cloudavenue_edgegateway_static_route.example"

resource.Test(t, resource.TestCase{
PreCheck: func() { tests.TestAccPreCheck(t) },
ProtoV6ProviderFactories: tests.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
// Apply test
Config: tests.ConcatTests(testAccEdgeGatewayResourceConfig, testAccStaticRouteResourceConfig, testAccStaticRouteDataSourceConfig),
Check: staticRouteTestCheck(dataSourceName),
},
},
})
}
25 changes: 25 additions & 0 deletions templates/data-sources/edgegateway_static_route.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: "Edge Gateway (Tier-1)"
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.Name}} ({{.Type}})

{{ .Description | trimspace }}

{{ if .HasExample -}}
## Example Usage

{{ tffile .ExampleFile }}
{{- end }}

{{ .SchemaMarkdown | trimspace }}

{{ if .HasImport -}}
## Import

Import is supported using the following syntax:
{{ codefile "shell" .ImportFile }}
{{- end }}