From 7d064a8b27d78a1564c9da914f17340966d955d1 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 17 Sep 2023 18:50:24 -0400 Subject: [PATCH] chore(code): re-organize and cleanup "fwk provider"'s code (#568) * chore(code): code cleanup / renaming * chore(code): flatten and rename fw provider package * chore(code): refactor & update network tests --- Makefile | 6 +- .../virtual_environment_container.md | 6 +- .../datasource_hagroup.go | 25 ++-- .../datasource_hagroups.go | 29 ++-- .../datasource_haresource.go | 27 ++-- .../datasource_haresources.go | 29 ++-- .../datasource_version.go | 2 +- .../hagroup.go => fwprovider/hagroup_model.go | 12 +- .../haresource_model.go | 20 ++- {internal/provider => fwprovider}/provider.go | 22 ++- .../resource_hagroup.go | 19 +-- .../resource_haresource.go | 56 ++++---- .../resource_linux_bridge.go | 7 +- .../resource_linux_vlan.go | 8 +- .../resource_options.go | 9 +- .../structure/attribute.go | 0 .../tests}/datasource_version_test.go | 8 +- .../tests/resource_linux_bridge_test.go | 110 ++++++++++++++ fwprovider/tests/resource_linux_vlan_test.go | 136 ++++++++++++++++++ .../tests/resource_options_test.go | 9 +- .../test => fwprovider/tests}/test_support.go | 22 +-- {internal => fwprovider}/types/ip_addr.go | 0 .../types/ip_addr_test.go | 0 .../types/ip_addr_value.go | 0 {internal => fwprovider}/types/ip_cidr.go | 0 .../types/ip_cidr_test.go | 0 .../types/ip_cidr_value.go | 0 .../validators/ha_resource_validator.go | 0 {internal => fwprovider}/validators/i18n.go | 0 .../validators/parse_validator.go | 0 go.mod | 2 + go.sum | 5 +- internal/internal.go | 8 -- .../network/resource_linux_bridge_test.go | 105 -------------- .../test/network/resource_linux_vlan_test.go | 77 ---------- main.go | 4 +- proxmox/nodes/network.go | 43 ++++-- proxmox/nodes/vms/vms.go | 2 +- proxmoxtf/resource/validator/vm.go | 8 +- proxmoxtf/resource/validator/vm_test.go | 5 +- proxmoxtf/resource/vm.go | 2 +- proxmoxtf/resource/vm_test.go | 10 +- proxmoxtf/structure/schema.go | 4 +- 43 files changed, 457 insertions(+), 380 deletions(-) rename {internal/cluster => fwprovider}/datasource_hagroup.go (86%) rename {internal/cluster => fwprovider}/datasource_hagroups.go (81%) rename {internal/cluster => fwprovider}/datasource_haresource.go (85%) rename {internal/cluster => fwprovider}/datasource_haresources.go (86%) rename {internal/provider => fwprovider}/datasource_version.go (99%) rename internal/cluster/hagroup.go => fwprovider/hagroup_model.go (90%) rename {internal/cluster => fwprovider}/haresource_model.go (85%) rename {internal/provider => fwprovider}/provider.go (96%) rename {internal/cluster => fwprovider}/resource_hagroup.go (97%) rename {internal/cluster => fwprovider}/resource_haresource.go (88%) rename {internal/network => fwprovider}/resource_linux_bridge.go (98%) rename {internal/network => fwprovider}/resource_linux_vlan.go (98%) rename {internal/cluster => fwprovider}/resource_options.go (99%) rename {internal => fwprovider}/structure/attribute.go (100%) rename {internal/test => fwprovider/tests}/datasource_version_test.go (84%) create mode 100644 fwprovider/tests/resource_linux_bridge_test.go create mode 100644 fwprovider/tests/resource_linux_vlan_test.go rename internal/test/cluster/cluster_options_test.go => fwprovider/tests/resource_options_test.go (94%) rename {internal/test => fwprovider/tests}/test_support.go (71%) rename {internal => fwprovider}/types/ip_addr.go (100%) rename {internal => fwprovider}/types/ip_addr_test.go (100%) rename {internal => fwprovider}/types/ip_addr_value.go (100%) rename {internal => fwprovider}/types/ip_cidr.go (100%) rename {internal => fwprovider}/types/ip_cidr_test.go (100%) rename {internal => fwprovider}/types/ip_cidr_value.go (100%) rename {internal => fwprovider}/validators/ha_resource_validator.go (100%) rename {internal => fwprovider}/validators/i18n.go (100%) rename {internal => fwprovider}/validators/parse_validator.go (100%) delete mode 100644 internal/internal.go delete mode 100644 internal/test/network/resource_linux_bridge_test.go delete mode 100644 internal/test/network/resource_linux_vlan_test.go diff --git a/Makefile b/Makefile index 5ba02824..8077e2e8 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/docs/resources/virtual_environment_container.md b/docs/resources/virtual_environment_container.md index 175077ce..b89330bdb 100644 --- a/docs/resources/virtual_environment_container.md +++ b/docs/resources/virtual_environment_container.md @@ -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 @@ -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 diff --git a/internal/cluster/datasource_hagroup.go b/fwprovider/datasource_hagroup.go similarity index 86% rename from internal/cluster/datasource_hagroup.go rename to fwprovider/datasource_hagroup.go index fb52cd8e..0de3b687 100644 --- a/internal/cluster/datasource_hagroup.go +++ b/fwprovider/datasource_hagroup.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "context" @@ -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, @@ -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{ @@ -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, @@ -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)...) diff --git a/internal/cluster/datasource_hagroups.go b/fwprovider/datasource_hagroups.go similarity index 81% rename from internal/cluster/datasource_hagroups.go rename to fwprovider/datasource_hagroups.go index 538c7a80..0f8792c9 100644 --- a/internal/cluster/datasource_hagroups.go +++ b/fwprovider/datasource_hagroups.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "context" @@ -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, @@ -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{ @@ -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, @@ -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 { diff --git a/internal/cluster/datasource_haresource.go b/fwprovider/datasource_haresource.go similarity index 85% rename from internal/cluster/datasource_haresource.go rename to fwprovider/datasource_haresource.go index 96635d53..b6d68848 100644 --- a/internal/cluster/datasource_haresource.go +++ b/fwprovider/datasource_haresource.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "context" @@ -14,8 +14,9 @@ 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" @@ -23,22 +24,22 @@ import ( // 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, @@ -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{ @@ -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, @@ -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)...) diff --git a/internal/cluster/datasource_haresources.go b/fwprovider/datasource_haresources.go similarity index 86% rename from internal/cluster/datasource_haresources.go rename to fwprovider/datasource_haresources.go index 66553fc7..d0386113 100644 --- a/internal/cluster/datasource_haresources.go +++ b/fwprovider/datasource_haresources.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "context" @@ -17,7 +17,8 @@ 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" @@ -25,22 +26,22 @@ import ( // 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. @@ -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, @@ -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{ @@ -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, @@ -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 ) diff --git a/internal/provider/datasource_version.go b/fwprovider/datasource_version.go similarity index 99% rename from internal/provider/datasource_version.go rename to fwprovider/datasource_version.go index 9cea6662..58912849 100644 --- a/internal/provider/datasource_version.go +++ b/fwprovider/datasource_version.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package provider +package fwprovider import ( "context" diff --git a/internal/cluster/hagroup.go b/fwprovider/hagroup_model.go similarity index 90% rename from internal/cluster/hagroup.go rename to fwprovider/hagroup_model.go index b25a4ad0..d6785f29 100644 --- a/internal/cluster/hagroup.go +++ b/fwprovider/hagroup_model.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "fmt" @@ -18,9 +18,9 @@ import ( hagroups "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/groups" ) -// hagroupModel is the model used to represent a High Availability group. -type hagroupModel struct { - ID types.String `tfsdk:"id"` // Identifier used by Terrraform +// haGroupModel is the model used to represent a High Availability group. +type haGroupModel struct { + ID types.String `tfsdk:"id"` // Identifier used by Terraform Group types.String `tfsdk:"group"` // HA group name Comment types.String `tfsdk:"comment"` // Comment, if present Nodes types.Map `tfsdk:"nodes"` // Map of member nodes associated with their priorities @@ -29,7 +29,7 @@ type hagroupModel struct { } // Import the contents of a HA group model from the API's response data. -func (m *hagroupModel) importFromAPI(group hagroups.HAGroupGetResponseData) diag.Diagnostics { +func (m *haGroupModel) importFromAPI(group hagroups.HAGroupGetResponseData) diag.Diagnostics { m.Comment = types.StringPointerValue(group.Comment) m.NoFailback = group.NoFailback.ToValue() m.Restricted = group.Restricted.ToValue() @@ -39,7 +39,7 @@ func (m *hagroupModel) importFromAPI(group hagroups.HAGroupGetResponseData) diag // Parse the list of member nodes. The list is received from the Proxmox API as a string. It must // be converted into a map value. Errors will be returned as Terraform diagnostics. -func (m *hagroupModel) parseHAGroupNodes(nodes string) diag.Diagnostics { +func (m *haGroupModel) parseHAGroupNodes(nodes string) diag.Diagnostics { var diags diag.Diagnostics nodesIn := strings.Split(nodes, ",") diff --git a/internal/cluster/haresource_model.go b/fwprovider/haresource_model.go similarity index 85% rename from internal/cluster/haresource_model.go rename to fwprovider/haresource_model.go index ee44d8b7..be98e267 100644 --- a/internal/cluster/haresource_model.go +++ b/fwprovider/haresource_model.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "fmt" @@ -15,8 +15,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -// haresourceModel maps the schema data for the High Availability resource data source. -type haresourceModel struct { +// haResourceModel maps the schema data for the High Availability resource data source. +type haResourceModel struct { // The Terraform resource identifier ID types.String `tfsdk:"id"` // The Proxmox HA resource identifier @@ -36,7 +36,7 @@ type haresourceModel struct { } // importFromAPI imports the contents of a HA resource model from the API's response data. -func (d *haresourceModel) importFromAPI(data *haresources.HAResourceGetResponseData) { +func (d *haResourceModel) importFromAPI(data *haresources.HAResourceGetResponseData) { d.ID = data.ID.ToValue() d.ResourceID = data.ID.ToValue() d.Type = data.Type.ToValue() @@ -48,7 +48,7 @@ func (d *haresourceModel) importFromAPI(data *haresources.HAResourceGetResponseD } // toRequestBase builds the common request data structure for HA resource creation or update API calls. -func (d haresourceModel) toRequestBase() haresources.HAResourceDataBase { +func (d *haResourceModel) toRequestBase() haresources.HAResourceDataBase { var state proxmoxtypes.HAResourceState if d.State.IsNull() { @@ -75,7 +75,7 @@ func (d haresourceModel) toRequestBase() haresources.HAResourceDataBase { } // toCreateRequest builds the request data structure for creating a new HA resource. -func (d haresourceModel) toCreateRequest(resID proxmoxtypes.HAResourceID) *haresources.HAResourceCreateRequestBody { +func (d *haResourceModel) toCreateRequest(resID proxmoxtypes.HAResourceID) *haresources.HAResourceCreateRequestBody { return &haresources.HAResourceCreateRequestBody{ ID: resID, Type: &resID.Type, @@ -84,8 +84,8 @@ func (d haresourceModel) toCreateRequest(resID proxmoxtypes.HAResourceID) *hares } // toUpdateRequest builds the request data structure for updating an existing HA resource. -func (d haresourceModel) toUpdateRequest(state *haresourceModel) *haresources.HAResourceUpdateRequestBody { - del := []string{} +func (d *haResourceModel) toUpdateRequest(state *haResourceModel) *haresources.HAResourceUpdateRequestBody { + var del []string if d.Comment.IsNull() && !state.Comment.IsNull() { del = append(del, "comment") @@ -103,10 +103,6 @@ func (d haresourceModel) toUpdateRequest(state *haresourceModel) *haresources.HA del = append(del, "max_restart") } - if len(del) == 0 { - del = nil - } - return &haresources.HAResourceUpdateRequestBody{ HAResourceDataBase: d.toRequestBase(), Delete: del, diff --git a/internal/provider/provider.go b/fwprovider/provider.go similarity index 96% rename from internal/provider/provider.go rename to fwprovider/provider.go index da9e69f3..6ad52a46 100644 --- a/internal/provider/provider.go +++ b/fwprovider/provider.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package provider +package fwprovider import ( "context" @@ -24,8 +24,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/bpg/terraform-provider-proxmox/internal/cluster" - "github.com/bpg/terraform-provider-proxmox/internal/network" "github.com/bpg/terraform-provider-proxmox/proxmox" "github.com/bpg/terraform-provider-proxmox/proxmox/api" "github.com/bpg/terraform-provider-proxmox/proxmox/nodes" @@ -365,21 +363,21 @@ func (p *proxmoxProvider) Configure( func (p *proxmoxProvider) Resources(_ context.Context) []func() resource.Resource { return []func() resource.Resource{ - cluster.NewHAGroupResource, - cluster.NewHAResourceResource, - cluster.NewClusterOptionsResource, - network.NewLinuxBridgeResource, - network.NewLinuxVLANResource, + NewHAGroupResource, + NewHAResourceResource, + NewClusterOptionsResource, + NewLinuxBridgeResource, + NewLinuxVLANResource, } } func (p *proxmoxProvider) DataSources(_ context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ NewVersionDataSource, - cluster.NewHAGroupsDataSource, - cluster.NewHAGroupDataSource, - cluster.NewHAResourcesDataSource, - cluster.NewHAResourceDataSource, + NewHAGroupsDataSource, + NewHAGroupDataSource, + NewHAResourcesDataSource, + NewHAResourceDataSource, } } diff --git a/internal/cluster/resource_hagroup.go b/fwprovider/resource_hagroup.go similarity index 97% rename from internal/cluster/resource_hagroup.go rename to fwprovider/resource_hagroup.go index 21464827..d300dc50 100644 --- a/internal/cluster/resource_hagroup.go +++ b/fwprovider/resource_hagroup.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "context" @@ -23,7 +23,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/tfsdk" "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" ) @@ -143,7 +144,7 @@ func (r *hagroupResource) Configure( // Create creates a new HA group on the Proxmox cluster. func (r *hagroupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data hagroupModel + var data haGroupModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -177,7 +178,7 @@ func (r *hagroupResource) Create(ctx context.Context, req resource.CreateRequest // Read reads a HA group definition from the Proxmox cluster. func (r *hagroupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - var data hagroupModel + var data haGroupModel resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -199,7 +200,7 @@ func (r *hagroupResource) Read(ctx context.Context, req resource.ReadRequest, re // Update updates a HA group definition on the Proxmox cluster. func (r *hagroupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var data, state hagroupModel + var data, state haGroupModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(req.State.Get(ctx, &state)...) @@ -232,7 +233,7 @@ func (r *hagroupResource) Update(ctx context.Context, req resource.UpdateRequest // Delete deletes a HA group definition. func (r *hagroupResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - var data hagroupModel + var data haGroupModel resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -269,7 +270,7 @@ func (r *hagroupResource) ImportState( resp *resource.ImportStateResponse, ) { reqID := req.ID - data := hagroupModel{ + data := haGroupModel{ ID: types.StringValue(reqID), Group: types.StringValue(reqID), } @@ -280,7 +281,7 @@ func (r *hagroupResource) ImportState( // state accordingly. It is assumed that the `state`'s identifier is set. func (r *hagroupResource) readBack( ctx context.Context, - data *hagroupModel, + data *haGroupModel, respDiags *diag.Diagnostics, respState *tfsdk.State, ) { @@ -302,7 +303,7 @@ func (r *hagroupResource) readBack( // read reads information about a HA group from the cluster. The group identifier must have been set in the // `data`. -func (r *hagroupResource) read(ctx context.Context, data *hagroupModel) (bool, diag.Diagnostics) { +func (r *hagroupResource) read(ctx context.Context, data *haGroupModel) (bool, diag.Diagnostics) { name := data.Group.ValueString() group, err := r.client.Get(ctx, name) diff --git a/internal/cluster/resource_haresource.go b/fwprovider/resource_haresource.go similarity index 88% rename from internal/cluster/resource_haresource.go rename to fwprovider/resource_haresource.go index 03affd3c..c64c9ea7 100644 --- a/internal/cluster/resource_haresource.go +++ b/fwprovider/resource_haresource.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "context" @@ -12,8 +12,8 @@ import ( "regexp" "strings" - "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" @@ -31,26 +31,28 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -// haresourceResource contains the resource's internal data. -type haresourceResource struct { +// haResourceResource contains the resource's internal data. +// NOTE: the naming is horrible, but this is the convention used by the framework. +// and the entity name in the API is "ha resource", so... +type haResourceResource struct { // The HA resources API client client haresources.Client } // Ensure the resource implements the expected interfaces. var ( - _ resource.Resource = &haresourceResource{} - _ resource.ResourceWithConfigure = &haresourceResource{} - _ resource.ResourceWithImportState = &haresourceResource{} + _ resource.Resource = &haResourceResource{} + _ resource.ResourceWithConfigure = &haResourceResource{} + _ resource.ResourceWithImportState = &haResourceResource{} ) // NewHAResourceResource returns a new resource for managing High Availability resources. func NewHAResourceResource() resource.Resource { - return &haresourceResource{} + return &haResourceResource{} } // Metadata defines the name of the resource. -func (r *haresourceResource) Metadata( +func (r *haResourceResource) Metadata( _ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse, @@ -59,7 +61,7 @@ func (r *haresourceResource) Metadata( } // Schema defines the schema for the resource. -func (r *haresourceResource) Schema( +func (r *haResourceResource) Schema( _ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse, @@ -134,7 +136,7 @@ func (r *haresourceResource) Schema( } // Configure adds the provider-configured client to the resource. -func (r *haresourceResource) Configure( +func (r *haResourceResource) Configure( _ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse, @@ -156,8 +158,8 @@ func (r *haresourceResource) Configure( } // Create creates a new HA resource. -func (r *haresourceResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var data haresourceModel +func (r *haResourceResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var data haResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -194,12 +196,12 @@ func (r *haresourceResource) Create(ctx context.Context, req resource.CreateRequ } // Update updates an existing HA resource. -func (r *haresourceResource) Update( +func (r *haResourceResource) Update( ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse, ) { - var data, state haresourceModel + var data, state haResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) resp.Diagnostics.Append(req.State.Get(ctx, &state)...) @@ -234,12 +236,12 @@ func (r *haresourceResource) Update( } // Delete deletes an existing HA resource. -func (r *haresourceResource) Delete( +func (r *haResourceResource) Delete( ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse, ) { - var data haresourceModel + var data haResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -279,12 +281,12 @@ func (r *haresourceResource) Delete( } // Read reads the HA resource. -func (r *haresourceResource) Read( +func (r *haResourceResource) Read( ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse, ) { - var data haresourceModel + var data haResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -305,13 +307,13 @@ func (r *haresourceResource) Read( } // ImportState imports a HA resource from the Proxmox cluster. -func (r *haresourceResource) ImportState( +func (r *haResourceResource) ImportState( ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse, ) { reqID := req.ID - data := haresourceModel{ + data := haResourceModel{ ID: types.StringValue(reqID), ResourceID: types.StringValue(reqID), } @@ -320,7 +322,7 @@ func (r *haresourceResource) ImportState( // read reads information about a HA resource from the cluster. The Terraform resource identifier must have been set // in the model before this function is called. -func (r *haresourceResource) read(ctx context.Context, data *haresourceModel) (bool, diag.Diagnostics) { +func (r *haResourceResource) read(ctx context.Context, data *haResourceModel) (bool, diag.Diagnostics) { var diags diag.Diagnostics resID, err := proxmoxtypes.ParseHAResourceID(data.ID.ValueString()) @@ -334,7 +336,7 @@ func (r *haresourceResource) read(ctx context.Context, data *haresourceModel) (b return false, diags } - resource, err := r.client.Get(ctx, resID) + res, err := r.client.Get(ctx, resID) if err != nil { if !strings.Contains(err.Error(), "no such resource") { diags.AddError("Could not read HA resource", err.Error()) @@ -343,16 +345,16 @@ func (r *haresourceResource) read(ctx context.Context, data *haresourceModel) (b return false, diags } - data.importFromAPI(resource) + data.importFromAPI(res) return true, nil } // readBack reads information about a created or modified HA resource from the cluster then updates the response // state accordingly. It is assumed that the `state`'s identifier is set. -func (r *haresourceResource) readBack( +func (r *haResourceResource) readBack( ctx context.Context, - data *haresourceModel, + data *haResourceModel, respDiags *diag.Diagnostics, respState *tfsdk.State, ) { diff --git a/internal/network/resource_linux_bridge.go b/fwprovider/resource_linux_bridge.go similarity index 98% rename from internal/network/resource_linux_bridge.go rename to fwprovider/resource_linux_bridge.go index 64d41098..53c74398 100644 --- a/internal/network/resource_linux_bridge.go +++ b/fwprovider/resource_linux_bridge.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package network +package fwprovider import ( "context" @@ -24,8 +24,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/bpg/terraform-provider-proxmox/internal/structure" - customtypes "github.com/bpg/terraform-provider-proxmox/internal/types" + "github.com/bpg/terraform-provider-proxmox/fwprovider/structure" + customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types" + "github.com/bpg/terraform-provider-proxmox/proxmox" "github.com/bpg/terraform-provider-proxmox/proxmox/nodes" proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types" diff --git a/internal/network/resource_linux_vlan.go b/fwprovider/resource_linux_vlan.go similarity index 98% rename from internal/network/resource_linux_vlan.go rename to fwprovider/resource_linux_vlan.go index 0c7bae4b..eea428b1 100644 --- a/internal/network/resource_linux_vlan.go +++ b/fwprovider/resource_linux_vlan.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package network +package fwprovider import ( "context" @@ -22,8 +22,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/bpg/terraform-provider-proxmox/internal/structure" - customtypes "github.com/bpg/terraform-provider-proxmox/internal/types" + "github.com/bpg/terraform-provider-proxmox/fwprovider/structure" + customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types" + "github.com/bpg/terraform-provider-proxmox/proxmox" "github.com/bpg/terraform-provider-proxmox/proxmox/nodes" proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types" @@ -208,6 +209,7 @@ func (r *linuxVLANResource) Schema( Description: "The VLAN tag. See also `name`.", Optional: true, Computed: true, + // 4,094 }, }, } diff --git a/internal/cluster/resource_options.go b/fwprovider/resource_options.go similarity index 99% rename from internal/cluster/resource_options.go rename to fwprovider/resource_options.go index 623766de..1b7a0966 100644 --- a/internal/cluster/resource_options.go +++ b/fwprovider/resource_options.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package fwprovider import ( "context" @@ -19,8 +19,9 @@ 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/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" "github.com/bpg/terraform-provider-proxmox/proxmox/cluster" ) @@ -645,7 +646,7 @@ func (r *clusterOptionsResource) Delete(ctx context.Context, req resource.Delete } } -// Imports a cluster options interface. +// ImportState a cluster options interface. func (r *clusterOptionsResource) ImportState( ctx context.Context, req resource.ImportStateRequest, diff --git a/internal/structure/attribute.go b/fwprovider/structure/attribute.go similarity index 100% rename from internal/structure/attribute.go rename to fwprovider/structure/attribute.go diff --git a/internal/test/datasource_version_test.go b/fwprovider/tests/datasource_version_test.go similarity index 84% rename from internal/test/datasource_version_test.go rename to fwprovider/tests/datasource_version_test.go index 5e7d6641..2a717cde 100644 --- a/internal/test/datasource_version_test.go +++ b/fwprovider/tests/datasource_version_test.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package test +package tests import ( "context" @@ -15,10 +15,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func Test_VersionDatasource(t *testing.T) { +func TestAccDatasourceVersion(t *testing.T) { t.Parallel() - accProviders := AccMuxProviders(context.Background(), t) + accProviders := testAccMuxProviders(context.Background(), t) datasourceName := "data.proxmox_virtual_environment_version.test" @@ -27,7 +27,7 @@ func Test_VersionDatasource(t *testing.T) { Steps: []resource.TestStep{ // Read testing { - Config: ProviderConfig + `data "proxmox_virtual_environment_version" "test" {}`, + Config: `data "proxmox_virtual_environment_version" "test" {}`, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(datasourceName, "release", "8.0"), resource.TestCheckResourceAttrSet(datasourceName, "repository_id"), diff --git a/fwprovider/tests/resource_linux_bridge_test.go b/fwprovider/tests/resource_linux_bridge_test.go new file mode 100644 index 00000000..0a7ea8e3 --- /dev/null +++ b/fwprovider/tests/resource_linux_bridge_test.go @@ -0,0 +1,110 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package tests + +import ( + "context" + "fmt" + "testing" + + "github.com/brianvoe/gofakeit/v6" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +const ( + accTestLinuxBridgeName = "proxmox_virtual_environment_network_linux_bridge.test" +) + +func TestAccResourceLinuxBridge(t *testing.T) { + t.Parallel() + + accProviders := testAccMuxProviders(context.Background(), t) + + iface := fmt.Sprintf("vmbr%d", gofakeit.Number(10, 9999)) + ipV4cidr1 := fmt.Sprintf("%s/24", gofakeit.IPv4Address()) + ipV4cidr2 := fmt.Sprintf("%s/24", gofakeit.IPv4Address()) + ipV6cidr := "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64" + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: accProviders, + Steps: []resource.TestStep{ + // Create and Read testing + { + Config: testAccResourceLinuxBridgeCreatedConfig(iface, ipV4cidr1), + Check: testAccResourceLinuxBridgeCreatedCheck(iface, ipV4cidr1), + }, + // Update testing + { + Config: testAccResourceLinuxBridgeUpdatedConfig(iface, ipV4cidr2, ipV6cidr), + Check: testAccResourceLinuxBridgeUpdatedCheck(iface, ipV4cidr2, ipV6cidr), + }, + // ImportState testing + { + ResourceName: accTestLinuxBridgeName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccResourceLinuxBridgeCreatedConfig(name string, ipV4cidr string) string { + return fmt.Sprintf(` + resource "proxmox_virtual_environment_network_linux_bridge" "test" { + node_name = "%s" + name = "%s" + address = "%s" + comment = "created by terraform" + vlan_aware = true + autostart = true + mtu = 1499 + } + `, accTestNodeName, name, ipV4cidr) +} + +func testAccResourceLinuxBridgeCreatedCheck(name string, ipV4cidr string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "name", name), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "address", ipV4cidr), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "comment", "created by terraform"), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "vlan_aware", "true"), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "autostart", "true"), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "mtu", "1499"), + resource.TestCheckResourceAttrSet(accTestLinuxBridgeName, "id"), + ) +} + +func testAccResourceLinuxBridgeUpdatedConfig(name string, ipV4cidr string, ipV6cidr string) string { + return fmt.Sprintf(` + resource "proxmox_virtual_environment_network_linux_bridge" "test" { + node_name = "%s" + name = "%s" + address = "%s" + address6 = "%s" + comment = "updated by terraform" + vlan_aware = false + autostart = false + mtu = null + } + `, accTestNodeName, name, ipV4cidr, ipV6cidr) +} + +func testAccResourceLinuxBridgeUpdatedCheck(name string, ipV4cidr string, ipV6cidr string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "name", name), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "address", ipV4cidr), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "address6", ipV6cidr), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "comment", "updated by terraform"), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "vlan_aware", "false"), + resource.TestCheckResourceAttr(accTestLinuxBridgeName, "autostart", "false"), + resource.TestCheckNoResourceAttr(accTestLinuxBridgeName, "mtu"), + resource.TestCheckResourceAttrSet(accTestLinuxBridgeName, "id"), + ), + ) +} diff --git a/fwprovider/tests/resource_linux_vlan_test.go b/fwprovider/tests/resource_linux_vlan_test.go new file mode 100644 index 00000000..49c66d57 --- /dev/null +++ b/fwprovider/tests/resource_linux_vlan_test.go @@ -0,0 +1,136 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package tests + +import ( + "context" + "fmt" + "strconv" + "testing" + + "github.com/brianvoe/gofakeit/v6" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +const ( + accTestLinuxVLANName = "proxmox_virtual_environment_network_linux_vlan.test" +) + +func TestAccResourceLinuxVLAN(t *testing.T) { + t.Parallel() + + accProviders := testAccMuxProviders(context.Background(), t) + + iface := "eno0" + vlan1 := gofakeit.Number(10, 4094) + customName := fmt.Sprintf("iface_%s", gofakeit.Word()) + vlan2 := gofakeit.Number(10, 4094) + ipV4cidr := fmt.Sprintf("%s/24", gofakeit.IPv4Address()) + + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: accProviders, + Steps: []resource.TestStep{ + // Create and Read testing + { + Config: testAccResourceLinuxVLANCreatedConfig(iface, vlan1), + Check: testAccResourceLinuxVLANCreatedCheck(iface, vlan1), + }, + // ImportState testing + { + ResourceName: accTestLinuxVLANName, + ImportState: true, + ImportStateVerify: true, + }, + // Create and Read with a custom name + { + Config: testAccResourceLinuxVLANCustomNameCreatedConfig(customName, iface, vlan2), + Check: testAccResourceLinuxVLANCustomNameCreatedCheck(customName, iface, vlan2), + // PVE API is unreliable. Sometimes it returns a wrong VLAN ID for this second interface. + SkipFunc: func() (bool, error) { + return true, nil + }, + }, + // Update testing + { + Config: testAccResourceLinuxVLANUpdatedConfig(iface, vlan1, ipV4cidr), + Check: testAccResourceLinuxVLANUpdatedCheck(iface, vlan1, ipV4cidr), + }, + }, + }) +} + +func testAccResourceLinuxVLANCreatedConfig(iface string, vlan int) string { + return fmt.Sprintf(` + resource "proxmox_virtual_environment_network_linux_vlan" "test" { + node_name = "%s" + name = "%s.%d" + comment = "created by terraform" + mtu = 1499 + } + `, accTestNodeName, iface, vlan) +} + +func testAccResourceLinuxVLANCreatedCheck(iface string, vlan int) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(accTestLinuxVLANName, "name", fmt.Sprintf("%s.%d", iface, vlan)), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "comment", "created by terraform"), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "vlan", strconv.Itoa(vlan)), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "interface", iface), + resource.TestCheckResourceAttrSet(accTestLinuxVLANName, "id"), + ) +} + +func testAccResourceLinuxVLANCustomNameCreatedConfig(name string, iface string, vlan int) string { + return fmt.Sprintf(` + resource "proxmox_virtual_environment_network_linux_vlan" "%s" { + node_name = "%s" + name = "%s" + interface = "%s" + vlan = %d + comment = "created by terraform" + mtu = 1499 + } + `, name, accTestNodeName, name, iface, vlan) +} + +func testAccResourceLinuxVLANCustomNameCreatedCheck(name string, iface string, vlan int) resource.TestCheckFunc { + resourceName := fmt.Sprintf("proxmox_virtual_environment_network_linux_vlan.%s", name) + + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "comment", "created by terraform"), + resource.TestCheckResourceAttr(resourceName, "vlan", strconv.Itoa(vlan)), + resource.TestCheckResourceAttr(resourceName, "interface", iface), + resource.TestCheckResourceAttrSet(resourceName, "id"), + ) +} + +func testAccResourceLinuxVLANUpdatedConfig(iface string, vlan int, ipV4cidr string) string { + return fmt.Sprintf(` + resource "proxmox_virtual_environment_network_linux_vlan" "test" { + node_name = "%s" + name = "%s.%d" + address = "%s" + address6 = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64" + comment = "updated by terraform" + mtu = null + } + `, accTestNodeName, iface, vlan, ipV4cidr) +} + +func testAccResourceLinuxVLANUpdatedCheck(iface string, vlan int, ipV4cidr string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(accTestLinuxVLANName, "name", fmt.Sprintf("%s.%d", iface, vlan)), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "vlan", strconv.Itoa(vlan)), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "interface", iface), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "address", ipV4cidr), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "address6", "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64"), + resource.TestCheckResourceAttr(accTestLinuxVLANName, "comment", "updated by terraform"), + resource.TestCheckNoResourceAttr(accTestLinuxVLANName, "mtu"), + resource.TestCheckResourceAttrSet(accTestLinuxVLANName, "id"), + ) +} diff --git a/internal/test/cluster/cluster_options_test.go b/fwprovider/tests/resource_options_test.go similarity index 94% rename from internal/test/cluster/cluster_options_test.go rename to fwprovider/tests/resource_options_test.go index a7d39f98..cd47faa7 100644 --- a/internal/test/cluster/cluster_options_test.go +++ b/fwprovider/tests/resource_options_test.go @@ -4,20 +4,19 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package cluster +package tests import ( "context" "testing" - "github.com/bpg/terraform-provider-proxmox/internal/test" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestClusterOptionsResource(t *testing.T) { t.Parallel() - accProviders := test.AccMuxProviders(context.Background(), t) + accProviders := testAccMuxProviders(context.Background(), t) resourceName := "proxmox_virtual_environment_cluster_options.test_options" @@ -26,7 +25,7 @@ func TestClusterOptionsResource(t *testing.T) { Steps: []resource.TestStep{ // Create and Read testing { - Config: test.ProviderConfig + ` + Config: ` resource "proxmox_virtual_environment_cluster_options" "test_options" { language = "en" keyboard = "pl" @@ -64,7 +63,7 @@ resource "proxmox_virtual_environment_cluster_options" "test_options" { }, // Update testing { - Config: test.ProviderConfig + ` + Config: ` resource "proxmox_virtual_environment_cluster_options" "test_options" { language = "en" keyboard = "pl" diff --git a/internal/test/test_support.go b/fwprovider/tests/test_support.go similarity index 71% rename from internal/test/test_support.go rename to fwprovider/tests/test_support.go index af87bbae..3ac18c51 100644 --- a/internal/test/test_support.go +++ b/fwprovider/tests/test_support.go @@ -4,7 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package test +package tests import ( "context" @@ -19,28 +19,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/require" - fwprovider "github.com/bpg/terraform-provider-proxmox/internal/provider" + "github.com/bpg/terraform-provider-proxmox/fwprovider" sdkV2provider "github.com/bpg/terraform-provider-proxmox/proxmoxtf/provider" ) const ( - // ProviderConfig is a shared configuration to combine with the actual - // test configuration so the Proxmox VE client is properly configured. - // It is also possible to use the PROXMOX_VE_ environment variables instead. - ProviderConfig = ` -provider "proxmox" { - username = "root@pam" - password = "password" - insecure = true - ssh { - agent = true - } -} -` + accTestNodeName = "pve" ) -// AccMuxProviders returns a map of mux servers for the acceptance tests. -func AccMuxProviders(ctx context.Context, t *testing.T) map[string]func() (tfprotov6.ProviderServer, error) { +// testAccMuxProviders returns a map of mux servers for the acceptance tests. +func testAccMuxProviders(ctx context.Context, t *testing.T) map[string]func() (tfprotov6.ProviderServer, error) { t.Helper() // Init sdkV2 provider diff --git a/internal/types/ip_addr.go b/fwprovider/types/ip_addr.go similarity index 100% rename from internal/types/ip_addr.go rename to fwprovider/types/ip_addr.go diff --git a/internal/types/ip_addr_test.go b/fwprovider/types/ip_addr_test.go similarity index 100% rename from internal/types/ip_addr_test.go rename to fwprovider/types/ip_addr_test.go diff --git a/internal/types/ip_addr_value.go b/fwprovider/types/ip_addr_value.go similarity index 100% rename from internal/types/ip_addr_value.go rename to fwprovider/types/ip_addr_value.go diff --git a/internal/types/ip_cidr.go b/fwprovider/types/ip_cidr.go similarity index 100% rename from internal/types/ip_cidr.go rename to fwprovider/types/ip_cidr.go diff --git a/internal/types/ip_cidr_test.go b/fwprovider/types/ip_cidr_test.go similarity index 100% rename from internal/types/ip_cidr_test.go rename to fwprovider/types/ip_cidr_test.go diff --git a/internal/types/ip_cidr_value.go b/fwprovider/types/ip_cidr_value.go similarity index 100% rename from internal/types/ip_cidr_value.go rename to fwprovider/types/ip_cidr_value.go diff --git a/internal/validators/ha_resource_validator.go b/fwprovider/validators/ha_resource_validator.go similarity index 100% rename from internal/validators/ha_resource_validator.go rename to fwprovider/validators/ha_resource_validator.go diff --git a/internal/validators/i18n.go b/fwprovider/validators/i18n.go similarity index 100% rename from internal/validators/i18n.go rename to fwprovider/validators/i18n.go diff --git a/internal/validators/parse_validator.go b/fwprovider/validators/parse_validator.go similarity index 100% rename from internal/validators/parse_validator.go rename to fwprovider/validators/parse_validator.go diff --git a/go.mod b/go.mod index b0be88a3..8fe993d7 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,8 @@ module github.com/bpg/terraform-provider-proxmox go 1.20 require ( + github.com/avast/retry-go/v4 v4.5.0 + github.com/brianvoe/gofakeit/v6 v6.23.2 github.com/google/go-cmp v0.5.9 github.com/google/go-querystring v1.1.0 github.com/google/uuid v1.3.1 diff --git a/go.sum b/go.sum index fbab8050..b5eb3e13 100644 --- a/go.sum +++ b/go.sum @@ -8,7 +8,10 @@ github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= -github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/avast/retry-go/v4 v4.5.0 h1:QoRAZZ90cj5oni2Lsgl2GW8mNTnUCnmpx/iKpwVisHg= +github.com/avast/retry-go/v4 v4.5.0/go.mod h1:7hLEXp0oku2Nir2xBAsg0PTphp9z71bN5Aq1fboC3+I= +github.com/brianvoe/gofakeit/v6 v6.23.2 h1:lVde18uhad5wII/f5RMVFLtdQNE0HaGFuBUXmYKk8i8= +github.com/brianvoe/gofakeit/v6 v6.23.2/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= diff --git a/internal/internal.go b/internal/internal.go deleted file mode 100644 index 85eb042d..00000000 --- a/internal/internal.go +++ /dev/null @@ -1,8 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -// Package internal contains implementation of the provider created with Terraform Plugin Framework. -package internal diff --git a/internal/test/network/resource_linux_bridge_test.go b/internal/test/network/resource_linux_bridge_test.go deleted file mode 100644 index 292bde44..00000000 --- a/internal/test/network/resource_linux_bridge_test.go +++ /dev/null @@ -1,105 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package network - -import ( - "context" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - - "github.com/bpg/terraform-provider-proxmox/internal/test" -) - -func TestLinuxBridgeResource(t *testing.T) { - t.Parallel() - - accProviders := test.AccMuxProviders(context.Background(), t) - - resourceName := "proxmox_virtual_environment_network_linux_bridge.test" - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, - Steps: []resource.TestStep{ - // Create and Read testing - { - Config: test.ProviderConfig + ` -resource "proxmox_virtual_environment_network_linux_bridge" "test" { - node_name = "pve" - name = "vmbr99" - address = "3.3.3.3/24" - comment = "created by terraform" - vlan_aware = false - autostart = false - mtu = 1499 -} -`, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", "vmbr99"), - resource.TestCheckResourceAttr(resourceName, "address", "3.3.3.3/24"), - resource.TestCheckResourceAttr(resourceName, "comment", "created by terraform"), - resource.TestCheckResourceAttr(resourceName, "vlan_aware", "false"), - resource.TestCheckResourceAttr(resourceName, "autostart", "false"), - resource.TestCheckResourceAttr(resourceName, "mtu", "1499"), - resource.TestCheckResourceAttrSet(resourceName, "id"), - ), - }, - // ImportState testing - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - // Update testing - { - Config: test.ProviderConfig + ` -resource "proxmox_virtual_environment_network_linux_bridge" "test" { - node_name = "pve" - name = "vmbr99" - address = "1.1.1.1/24" - address6 = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64" - comment = "updated by terraform" - vlan_aware = true - autostart = true - mtu = null -} -`, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", "vmbr99"), - resource.TestCheckResourceAttr(resourceName, "address", "1.1.1.1/24"), - resource.TestCheckResourceAttr(resourceName, "address6", "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64"), - resource.TestCheckResourceAttr(resourceName, "comment", "updated by terraform"), - resource.TestCheckResourceAttr(resourceName, "vlan_aware", "true"), - resource.TestCheckResourceAttr(resourceName, "autostart", "true"), - resource.TestCheckNoResourceAttr(resourceName, "mtu"), - resource.TestCheckResourceAttrSet(resourceName, "id"), - ), - }, - // Create with other default overrides - { - Config: test.ProviderConfig + ` -resource "proxmox_virtual_environment_network_linux_bridge" "test" { - node_name = "pve" - name = "vmbr98" - address = "3.3.3.4/24" - comment = "created by terraform 2" - vlan_aware = true - autostart = true -} -`, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", "vmbr98"), - resource.TestCheckResourceAttr(resourceName, "address", "3.3.3.4/24"), - resource.TestCheckResourceAttr(resourceName, "comment", "created by terraform 2"), - resource.TestCheckResourceAttr(resourceName, "vlan_aware", "true"), - resource.TestCheckResourceAttr(resourceName, "autostart", "true"), - resource.TestCheckResourceAttrSet(resourceName, "id"), - ), - }, - }, - }) -} diff --git a/internal/test/network/resource_linux_vlan_test.go b/internal/test/network/resource_linux_vlan_test.go deleted file mode 100644 index f5e61f7e..00000000 --- a/internal/test/network/resource_linux_vlan_test.go +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package network - -import ( - "context" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - - "github.com/bpg/terraform-provider-proxmox/internal/test" -) - -func TestLinuxVLANResource(t *testing.T) { - t.Parallel() - - accProviders := test.AccMuxProviders(context.Background(), t) - - resourceName := "proxmox_virtual_environment_network_linux_vlan.test" - - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: accProviders, - Steps: []resource.TestStep{ - // Create and Read testing - { - Config: test.ProviderConfig + ` -resource "proxmox_virtual_environment_network_linux_vlan" "test" { - node_name = "pve" - name = "eno0.33" - comment = "created by terraform" - mtu = 1499 -} -`, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", "eno0.33"), - resource.TestCheckResourceAttr(resourceName, "comment", "created by terraform"), - resource.TestCheckResourceAttr(resourceName, "vlan", "33"), - resource.TestCheckResourceAttr(resourceName, "interface", "eno0"), - resource.TestCheckResourceAttrSet(resourceName, "id"), - ), - }, - // ImportState testing - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - // Update testing - { - Config: test.ProviderConfig + ` -resource "proxmox_virtual_environment_network_linux_vlan" "test" { - node_name = "pve" - name = "eno0.33" - address = "1.1.1.1/24" - address6 = "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64" - comment = "updated by terraform" - mtu = null -} -`, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", "eno0.33"), - resource.TestCheckResourceAttr(resourceName, "address", "1.1.1.1/24"), - resource.TestCheckResourceAttr(resourceName, "address6", "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64"), - resource.TestCheckResourceAttr(resourceName, "comment", "updated by terraform"), - resource.TestCheckResourceAttr(resourceName, "vlan", "33"), - resource.TestCheckResourceAttr(resourceName, "interface", "eno0"), - resource.TestCheckNoResourceAttr(resourceName, "mtu"), - resource.TestCheckResourceAttrSet(resourceName, "id"), - ), - }, - }, - }) -} diff --git a/main.go b/main.go index a20224bc..26376259 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - newProvider "github.com/bpg/terraform-provider-proxmox/internal/provider" + "github.com/bpg/terraform-provider-proxmox/fwprovider" "github.com/bpg/terraform-provider-proxmox/proxmoxtf/provider" ) @@ -48,7 +48,7 @@ func main() { } providers := []func() tfprotov6.ProviderServer{ - providerserver.NewProtocol6(newProvider.New(version)()), + providerserver.NewProtocol6(fwprovider.New(version)()), func() tfprotov6.ProviderServer { return upgradedSdkServer }, diff --git a/proxmox/nodes/network.go b/proxmox/nodes/network.go index b055e17b..5d9f326c 100644 --- a/proxmox/nodes/network.go +++ b/proxmox/nodes/network.go @@ -12,6 +12,11 @@ import ( "net/http" "net/url" "sort" + "strings" + "sync" + "time" + + "github.com/avast/retry-go/v4" "github.com/bpg/terraform-provider-proxmox/proxmox/api" ) @@ -20,6 +25,12 @@ const ( networkReloadTimeoutSec = 5 ) +// reloadLock is used to prevent concurrent network reloads. +// global variable by design. +// +//nolint:gochecknoglobals +var reloadLock sync.Mutex + // ListNetworkInterfaces retrieves a list of network interfaces for a specific nodes. func (c *Client) ListNetworkInterfaces(ctx context.Context) ([]*NetworkInterfaceListResponseData, error) { resBody := &NetworkInterfaceListResponseBody{} @@ -55,22 +66,34 @@ func (c *Client) CreateNetworkInterface(ctx context.Context, d *NetworkInterface // ReloadNetworkConfiguration reloads the network configuration for a specific node. func (c *Client) ReloadNetworkConfiguration(ctx context.Context) error { + reloadLock.Lock() + defer reloadLock.Unlock() + resBody := &ReloadNetworkResponseBody{} - err := c.DoRequest(ctx, http.MethodPut, c.ExpandPath("network"), nil, resBody) + err := retry.Do( + func() error { + err := c.DoRequest(ctx, http.MethodPut, c.ExpandPath("network"), nil, resBody) + if err != nil { + return err //nolint:wrapcheck + } + + if resBody.Data == nil { + return api.ErrNoDataObjectInResponse + } + + return c.Tasks().WaitForTask(ctx, *resBody.Data, networkReloadTimeoutSec, 1) //nolint:wrapcheck + }, + retry.Delay(1*time.Second), + retry.Attempts(3), + retry.RetryIf(func(err error) bool { + return strings.Contains(err.Error(), "exit code 89") + }), + ) if err != nil { return fmt.Errorf("failed to reload network configuration for node \"%s\": %w", c.NodeName, err) } - if resBody.Data == nil { - return api.ErrNoDataObjectInResponse - } - - err = c.Tasks().WaitForTask(ctx, *resBody.Data, networkReloadTimeoutSec, 1) - if err == nil { - return nil - } - return nil } diff --git a/proxmox/nodes/vms/vms.go b/proxmox/nodes/vms/vms.go index eb0854e2..79aacb28 100644 --- a/proxmox/nodes/vms/vms.go +++ b/proxmox/nodes/vms/vms.go @@ -25,7 +25,7 @@ func (c *Client) CloneVM(ctx context.Context, retries int, d *CloneRequestBody, resBody := &MoveDiskResponseBody{} - // just a guard in case someone sets retries to 0 unknowingly + // just a guard in case someone sets retries to zero unknowingly if retries <= 0 { retries = 1 } diff --git a/proxmoxtf/resource/validator/vm.go b/proxmoxtf/resource/validator/vm.go index e2201e6d..19e260a7 100644 --- a/proxmoxtf/resource/validator/vm.go +++ b/proxmoxtf/resource/validator/vm.go @@ -18,8 +18,8 @@ import ( // VMID returns a schema validation function for a VM ID. func VMID() schema.SchemaValidateDiagFunc { return validation.ToDiagFunc(func(i interface{}, k string) ([]string, []error) { - min := 100 - max := 2147483647 + minID := 100 + maxID := 2147483647 var ws []string var es []error @@ -32,8 +32,8 @@ func VMID() schema.SchemaValidateDiagFunc { } if v != -1 { - if v < min || v > max { - es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) + if v < minID || v > maxID { + es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, minID, maxID, v)) return ws, es } } diff --git a/proxmoxtf/resource/validator/vm_test.go b/proxmoxtf/resource/validator/vm_test.go index e0b90064..0e709289 100644 --- a/proxmoxtf/resource/validator/vm_test.go +++ b/proxmoxtf/resource/validator/vm_test.go @@ -31,15 +31,14 @@ func Test_getCPUTypeValidator(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - require := require.New(t) f := CPUType() res := f(tt.value, nil) if tt.valid { - require.Empty(res, "validate: '%s'", tt.value) + require.Empty(t, res, "validate: '%s'", tt.value) } else { - require.NotEmpty(res, "validate: '%s'", tt.value) + require.NotEmpty(t, res, "validate: '%s'", tt.value) } }) } diff --git a/proxmoxtf/resource/vm.go b/proxmoxtf/resource/vm.go index 697c9293..c3d821df 100644 --- a/proxmoxtf/resource/vm.go +++ b/proxmoxtf/resource/vm.go @@ -3641,7 +3641,7 @@ func vmReadCustom( diags = append(diags, diag.FromErr(err)...) } - // Compare the IDE devices to the CDROM configurations stored in the state. + // Compare the IDE devices to the CD-ROM configurations stored in the state. currentInterface := dvResourceVirtualEnvironmentVMCDROMInterface currentCDROM := d.Get(mkResourceVirtualEnvironmentVMCDROM).([]interface{}) diff --git a/proxmoxtf/resource/vm_test.go b/proxmoxtf/resource/vm_test.go index 2bb5c96b..26b18dcb 100644 --- a/proxmoxtf/resource/vm_test.go +++ b/proxmoxtf/resource/vm_test.go @@ -460,18 +460,16 @@ func Test_parseImportIDWIthNodeName(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() - require := require.New(t) - nodeName, id, err := parseImportIDWithNodeName(tt.value) if !tt.valid { - require.Error(err) + require.Error(t, err) return } - require.Nil(err) - require.Equal(tt.expectedNodeName, nodeName) - require.Equal(tt.expectedID, id) + require.NoError(t, err) + require.Equal(t, tt.expectedNodeName, nodeName) + require.Equal(t, tt.expectedID, id) }) } } diff --git a/proxmoxtf/structure/schema.go b/proxmoxtf/structure/schema.go index b9f459a4..c0d8b837 100644 --- a/proxmoxtf/structure/schema.go +++ b/proxmoxtf/structure/schema.go @@ -15,8 +15,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// MergeSchema merges the map[string]*schema.Schema from src into dst. Safety -// against conflicts is enforced by panicking. +// MergeSchema merges the map[string]*schema.Schema from src into dst. +// Panicking enforces safety against conflicts. func MergeSchema(dst, src map[string]*schema.Schema) { for k, v := range src { if _, ok := dst[k]; ok {