Skip to content

Commit

Permalink
chore(code): re-organize and cleanup "fwk provider"'s code (#568)
Browse files Browse the repository at this point in the history
* chore(code): code cleanup / renaming

* chore(code): flatten and rename fw provider package

* chore(code): refactor & update network tests
  • Loading branch information
bpg authored Sep 17, 2023
1 parent 0a37dfd commit 7d064a8
Show file tree
Hide file tree
Showing 43 changed files with 457 additions and 380 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ test:

.PHONY: testacc
testacc:
TF_ACC=1 go test ./...
# env vars required for acceptance tests
# - PROXMOX_VE_ENDPOINT
# - PROXMOX_VE_USERNAME
# - PROXMOX_VE_PASSWORD
TF_ACC=1 go test ./...

.PHONY: lint
lint:
Expand Down
6 changes: 3 additions & 3 deletions docs/resources/virtual_environment_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ output "ubuntu_container_public_key" {
- `unmanaged` - Unmanaged.
- `pool_id` - (Optional) The identifier for a pool to assign the container to.
- `started` - (Optional) Whether to start the container (defaults to `true`).
- `tags` - (Optional) A list of tags of the container. This is only meta
- `tags` - (Optional) A list of tags the container tags. This is only meta
information (defaults to `[]`). Note: Proxmox always sorts the container tags.
If the list in template is not sorted, then Proxmox will always report a
difference on the resource. You may use the `ignore_changes` lifecycle
Expand All @@ -202,8 +202,8 @@ output "ubuntu_container_public_key" {
to `false`)
- `fuse` - (Optional) Whether the container supports FUSE mounts (defaults
to `false`)
- `keyctl` - (Optional) Whether the container supports `keyctl()` system call (defaults
to `false`)
- `keyctl` - (Optional) Whether the container supports `keyctl()` system
call (defaults to `false`)

## Attribute Reference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package cluster
package fwprovider

import (
"context"
Expand All @@ -14,30 +14,31 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/internal/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"

"github.com/bpg/terraform-provider-proxmox/proxmox"
hagroups "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/groups"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &hagroupDatasource{}
_ datasource.DataSourceWithConfigure = &hagroupDatasource{}
_ datasource.DataSource = &haGroupDatasource{}
_ datasource.DataSourceWithConfigure = &haGroupDatasource{}
)

// NewHAGroupDataSource is a helper function to simplify the provider implementation.
func NewHAGroupDataSource() datasource.DataSource {
return &hagroupDatasource{}
return &haGroupDatasource{}
}

// hagroupDatasource is the data source implementation for full information about
// haGroupDatasource is the data source implementation for full information about
// specific High Availability groups.
type hagroupDatasource struct {
type haGroupDatasource struct {
client *hagroups.Client
}

// Metadata returns the data source type name.
func (d *hagroupDatasource) Metadata(
func (d *haGroupDatasource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
Expand All @@ -46,7 +47,7 @@ func (d *hagroupDatasource) Metadata(
}

// Schema returns the schema for the data source.
func (d *hagroupDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *haGroupDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Retrieves information about a specific High Availability group.",
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -79,7 +80,7 @@ func (d *hagroupDatasource) Schema(_ context.Context, _ datasource.SchemaRequest
}

// Configure adds the provider-configured client to the data source.
func (d *hagroupDatasource) Configure(
func (d *haGroupDatasource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
Expand All @@ -103,8 +104,8 @@ func (d *hagroupDatasource) Configure(
}

// Read fetches the list of HA groups from the Proxmox cluster then converts it to a list of strings.
func (d *hagroupDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var state hagroupModel
func (d *haGroupDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var state haGroupModel

resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package cluster
package fwprovider

import (
"context"
Expand All @@ -15,35 +15,36 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/internal/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"

"github.com/bpg/terraform-provider-proxmox/proxmox"
hagroups "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/groups"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &hagroupsDatasource{}
_ datasource.DataSourceWithConfigure = &hagroupsDatasource{}
_ datasource.DataSource = &haGroupsDatasource{}
_ datasource.DataSourceWithConfigure = &haGroupsDatasource{}
)

// NewHAGroupsDataSource is a helper function to simplify the provider implementation.
func NewHAGroupsDataSource() datasource.DataSource {
return &hagroupsDatasource{}
return &haGroupsDatasource{}
}

// hagroupsDatasource is the data source implementation for High Availability groups.
type hagroupsDatasource struct {
// haGroupsDatasource is the data source implementation for High Availability groups.
type haGroupsDatasource struct {
client *hagroups.Client
}

// hagroupsModel maps the schema data for the High Availability groups data source.
type hagroupsModel struct {
// haGroupsModel maps the schema data for the High Availability groups data source.
type haGroupsModel struct {
Groups types.Set `tfsdk:"group_ids"`
ID types.String `tfsdk:"id"`
}

// Metadata returns the data source type name.
func (d *hagroupsDatasource) Metadata(
func (d *haGroupsDatasource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
Expand All @@ -52,7 +53,7 @@ func (d *hagroupsDatasource) Metadata(
}

// Schema returns the schema for the data source.
func (d *hagroupsDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *haGroupsDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Retrieves the list of High Availability groups.",
Attributes: map[string]schema.Attribute{
Expand All @@ -67,7 +68,7 @@ func (d *hagroupsDatasource) Schema(_ context.Context, _ datasource.SchemaReques
}

// Configure adds the provider-configured client to the data source.
func (d *hagroupsDatasource) Configure(
func (d *haGroupsDatasource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
Expand All @@ -91,8 +92,8 @@ func (d *hagroupsDatasource) Configure(
}

// Read fetches the list of HA groups from the Proxmox cluster then converts it to a list of strings.
func (d *hagroupsDatasource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
var state hagroupsModel
func (d *haGroupsDatasource) Read(ctx context.Context, _ datasource.ReadRequest, resp *datasource.ReadResponse) {
var state haGroupsModel

list, err := d.client.List(ctx)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package cluster
package fwprovider

import (
"context"
Expand All @@ -14,31 +14,32 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/bpg/terraform-provider-proxmox/internal/structure"
"github.com/bpg/terraform-provider-proxmox/internal/validators"
"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/validators"

"github.com/bpg/terraform-provider-proxmox/proxmox"
haresources "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/resources"
proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &haresourceDatasource{}
_ datasource.DataSourceWithConfigure = &haresourceDatasource{}
_ datasource.DataSource = &haResourceDatasource{}
_ datasource.DataSourceWithConfigure = &haResourceDatasource{}
)

// NewHAResourceDataSource is a helper function to simplify the provider implementation.
func NewHAResourceDataSource() datasource.DataSource {
return &haresourceDatasource{}
return &haResourceDatasource{}
}

// haresourceDatasource is the data source implementation for High Availability resources.
type haresourceDatasource struct {
// haResourceDatasource is the data source implementation for High Availability resources.
type haResourceDatasource struct {
client *haresources.Client
}

// Metadata returns the data source type name.
func (d *haresourceDatasource) Metadata(
func (d *haResourceDatasource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
Expand All @@ -47,7 +48,7 @@ func (d *haresourceDatasource) Metadata(
}

// Schema returns the schema for the data source.
func (d *haresourceDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *haResourceDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Retrieves the list of High Availability resources.",
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -88,7 +89,7 @@ func (d *haresourceDatasource) Schema(_ context.Context, _ datasource.SchemaRequ
}

// Configure adds the provider-configured client to the data source.
func (d *haresourceDatasource) Configure(
func (d *haResourceDatasource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
Expand All @@ -110,8 +111,8 @@ func (d *haresourceDatasource) Configure(
}

// Read fetches the specified HA resource.
func (d *haresourceDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data haresourceModel
func (d *haResourceDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data haResourceModel

resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package cluster
package fwprovider

import (
"context"
Expand All @@ -17,30 +17,31 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/bpg/terraform-provider-proxmox/internal/structure"
"github.com/bpg/terraform-provider-proxmox/fwprovider/structure"

"github.com/bpg/terraform-provider-proxmox/proxmox"
haresources "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/resources"
proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &haresourcesDatasource{}
_ datasource.DataSourceWithConfigure = &haresourcesDatasource{}
_ datasource.DataSource = &haResourcesDatasource{}
_ datasource.DataSourceWithConfigure = &haResourcesDatasource{}
)

// NewHAResourcesDataSource is a helper function to simplify the provider implementation.
func NewHAResourcesDataSource() datasource.DataSource {
return &haresourcesDatasource{}
return &haResourcesDatasource{}
}

// haresourcesDatasource is the data source implementation for High Availability resources.
type haresourcesDatasource struct {
// haResourcesDatasource is the data source implementation for High Availability resources.
type haResourcesDatasource struct {
client *haresources.Client
}

// haresourcesModel maps the schema data for the High Availability resources data source.
type haresourcesModel struct {
// haResourcesModel maps the schema data for the High Availability resources data source.
type haResourcesModel struct {
// The Terraform resource identifier
ID types.String `tfsdk:"id"`
// The type of HA resources to fetch. If unset, all resources will be fetched.
Expand All @@ -50,7 +51,7 @@ type haresourcesModel struct {
}

// Metadata returns the data source type name.
func (d *haresourcesDatasource) Metadata(
func (d *haResourcesDatasource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
Expand All @@ -59,7 +60,7 @@ func (d *haresourcesDatasource) Metadata(
}

// Schema returns the schema for the data source.
func (d *haresourcesDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *haResourcesDatasource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Retrieves the list of High Availability resources.",
Attributes: map[string]schema.Attribute{
Expand All @@ -82,7 +83,7 @@ func (d *haresourcesDatasource) Schema(_ context.Context, _ datasource.SchemaReq
}

// Configure adds the provider-configured client to the data source.
func (d *haresourcesDatasource) Configure(
func (d *haResourcesDatasource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
Expand All @@ -104,9 +105,9 @@ func (d *haresourcesDatasource) Configure(
}

// Read fetches the list of HA resources from the Proxmox cluster then converts it to a list of strings.
func (d *haresourcesDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *haResourcesDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var (
data haresourcesModel
data haResourcesModel
fetchType *proxmoxtypes.HAResourceType
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package provider
package fwprovider

import (
"context"
Expand Down
Loading

0 comments on commit 7d064a8

Please sign in to comment.