0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-04 21:14:05 +00:00

chore(code): align resource/datasource names in the fwprovider code (#1488)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2024-08-12 21:03:17 -04:00 committed by GitHub
parent 55bfe14ce1
commit 8f82d1a384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 154 additions and 126 deletions

View File

@ -25,18 +25,18 @@ import (
// Ensure the implementation satisfies the required interfaces. // Ensure the implementation satisfies the required interfaces.
var ( var (
_ datasource.DataSource = &dataSourcePCI{} _ datasource.DataSource = &pciDataSource{}
_ datasource.DataSourceWithConfigure = &dataSourcePCI{} _ datasource.DataSourceWithConfigure = &pciDataSource{}
) )
// dataSourcePCI is the data source implementation for a PCI hardware mapping. // pciDataSource is the data source implementation for a PCI hardware mapping.
type dataSourcePCI struct { type pciDataSource struct {
// client is the hardware mapping API client. // client is the hardware mapping API client.
client *mappings.Client client *mappings.Client
} }
// Configure adds the provider-configured client to the data source. // Configure adds the provider-configured client to the data source.
func (d *dataSourcePCI) Configure( func (d *pciDataSource) Configure(
_ context.Context, _ context.Context,
req datasource.ConfigureRequest, req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse, resp *datasource.ConfigureResponse,
@ -59,12 +59,12 @@ func (d *dataSourcePCI) Configure(
} }
// Metadata returns the data source type name. // Metadata returns the data source type name.
func (d *dataSourcePCI) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { func (d *pciDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_hardware_mapping_pci" resp.TypeName = req.ProviderTypeName + "_hardware_mapping_pci"
} }
// Read fetches the specified PCI hardware mapping from the Proxmox VE API. // Read fetches the specified PCI hardware mapping from the Proxmox VE API.
func (d *dataSourcePCI) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { func (d *pciDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var hm modelPCI var hm modelPCI
resp.Diagnostics.Append(req.Config.Get(ctx, &hm)...) resp.Diagnostics.Append(req.Config.Get(ctx, &hm)...)
@ -93,7 +93,7 @@ func (d *dataSourcePCI) Read(ctx context.Context, req datasource.ReadRequest, re
} }
// Schema defines the schema for the PCI hardware mapping. // Schema defines the schema for the PCI hardware mapping.
func (d *dataSourcePCI) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { func (d *pciDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
comment := dataSourceSchemaBaseAttrComment comment := dataSourceSchemaBaseAttrComment
comment.Optional = false comment.Optional = false
comment.Computed = true comment.Computed = true
@ -162,8 +162,8 @@ func (d *dataSourcePCI) Schema(_ context.Context, _ datasource.SchemaRequest, re
} }
} }
// NewDataSourcePCI returns a new data source for a PCI hardware mapping. // NewPCIDataSource returns a new data source for a PCI hardware mapping.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewDataSourcePCI() datasource.DataSource { func NewPCIDataSource() datasource.DataSource {
return &dataSourcePCI{} return &pciDataSource{}
} }

View File

@ -25,17 +25,17 @@ import (
// Ensure the implementation satisfies the required interfaces. // Ensure the implementation satisfies the required interfaces.
var ( var (
_ datasource.DataSource = &datasourceUSB{} _ datasource.DataSource = &usbDataSource{}
_ datasource.DataSourceWithConfigure = &datasourceUSB{} _ datasource.DataSourceWithConfigure = &usbDataSource{}
) )
// datasourceUSB is the data source implementation for a USB hardware mapping. // usbDataSource is the data source implementation for a USB hardware mapping.
type datasourceUSB struct { type usbDataSource struct {
client *mappings.Client client *mappings.Client
} }
// Configure adds the provider-configured client to the data source. // Configure adds the provider-configured client to the data source.
func (d *datasourceUSB) Configure( func (d *usbDataSource) Configure(
_ context.Context, _ context.Context,
req datasource.ConfigureRequest, req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse, resp *datasource.ConfigureResponse,
@ -58,12 +58,12 @@ func (d *datasourceUSB) Configure(
} }
// Metadata returns the data source type name. // Metadata returns the data source type name.
func (d *datasourceUSB) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { func (d *usbDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_hardware_mapping_usb" resp.TypeName = req.ProviderTypeName + "_hardware_mapping_usb"
} }
// Read fetches the specified USB hardware mapping from the Proxmox VE API. // Read fetches the specified USB hardware mapping from the Proxmox VE API.
func (d *datasourceUSB) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { func (d *usbDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var hm modelUSB var hm modelUSB
resp.Diagnostics.Append(req.Config.Get(ctx, &hm)...) resp.Diagnostics.Append(req.Config.Get(ctx, &hm)...)
@ -91,7 +91,7 @@ func (d *datasourceUSB) Read(ctx context.Context, req datasource.ReadRequest, re
} }
// Schema defines the schema for the USB hardware mapping. // Schema defines the schema for the USB hardware mapping.
func (d *datasourceUSB) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { func (d *usbDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
comment := dataSourceSchemaBaseAttrComment comment := dataSourceSchemaBaseAttrComment
comment.Optional = false comment.Optional = false
comment.Computed = true comment.Computed = true
@ -144,8 +144,8 @@ func (d *datasourceUSB) Schema(_ context.Context, _ datasource.SchemaRequest, re
} }
} }
// NewDataSourceUSB returns a new data source for a USB hardware mapping. // NewUSBDataSource returns a new data source for a USB hardware mapping.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewDataSourceUSB() datasource.DataSource { func NewUSBDataSource() datasource.DataSource {
return &datasourceUSB{} return &usbDataSource{}
} }

View File

@ -32,19 +32,19 @@ import (
// Ensure the resource implements the required interfaces. // Ensure the resource implements the required interfaces.
var ( var (
_ resource.Resource = &resourcePCI{} _ resource.Resource = &pciResource{}
_ resource.ResourceWithConfigure = &resourcePCI{} _ resource.ResourceWithConfigure = &pciResource{}
_ resource.ResourceWithImportState = &resourcePCI{} _ resource.ResourceWithImportState = &pciResource{}
) )
// resourcePCI contains the PCI hardware mapping resource's internal data. // pciResource contains the PCI hardware mapping resource's internal data.
type resourcePCI struct { type pciResource struct {
// client is the hardware mapping API client. // client is the hardware mapping API client.
client mappings.Client client mappings.Client
} }
// read reads information about a PCI hardware mapping from the Proxmox VE API. // read reads information about a PCI hardware mapping from the Proxmox VE API.
func (r *resourcePCI) read(ctx context.Context, hm *modelPCI) (bool, diag.Diagnostics) { func (r *pciResource) read(ctx context.Context, hm *modelPCI) (bool, diag.Diagnostics) {
var diags diag.Diagnostics var diags diag.Diagnostics
hmName := hm.Name.ValueString() hmName := hm.Name.ValueString()
@ -66,7 +66,7 @@ func (r *resourcePCI) read(ctx context.Context, hm *modelPCI) (bool, diag.Diagno
// readBack reads information about a created or modified PCI hardware mapping from the Proxmox VE API then updates the // readBack reads information about a created or modified PCI hardware mapping from the Proxmox VE API then updates the
// response state accordingly. // response state accordingly.
// The Terraform resource identifier must have been set in the state before this method is called! // The Terraform resource identifier must have been set in the state before this method is called!
func (r *resourcePCI) readBack(ctx context.Context, hm *modelPCI, respDiags *diag.Diagnostics, respState *tfsdk.State) { func (r *pciResource) readBack(ctx context.Context, hm *modelPCI, respDiags *diag.Diagnostics, respState *tfsdk.State) {
found, diags := r.read(ctx, hm) found, diags := r.read(ctx, hm)
respDiags.Append(diags...) respDiags.Append(diags...)
@ -84,7 +84,7 @@ func (r *resourcePCI) readBack(ctx context.Context, hm *modelPCI, respDiags *dia
} }
// Configure adds the provider-configured client to the resource. // Configure adds the provider-configured client to the resource.
func (r *resourcePCI) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { func (r *pciResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
if req.ProviderData == nil { if req.ProviderData == nil {
return return
} }
@ -101,7 +101,7 @@ func (r *resourcePCI) Configure(_ context.Context, req resource.ConfigureRequest
} }
// Create creates a new PCI hardware mapping. // Create creates a new PCI hardware mapping.
func (r *resourcePCI) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { func (r *pciResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var hm modelPCI var hm modelPCI
resp.Diagnostics.Append(req.Plan.Get(ctx, &hm)...) resp.Diagnostics.Append(req.Plan.Get(ctx, &hm)...)
@ -127,7 +127,7 @@ func (r *resourcePCI) Create(ctx context.Context, req resource.CreateRequest, re
} }
// Delete deletes an existing PCI hardware mapping. // Delete deletes an existing PCI hardware mapping.
func (r *resourcePCI) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { func (r *pciResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var hm modelPCI var hm modelPCI
resp.Diagnostics.Append(req.State.Get(ctx, &hm)...) resp.Diagnostics.Append(req.State.Get(ctx, &hm)...)
@ -154,7 +154,7 @@ func (r *resourcePCI) Delete(ctx context.Context, req resource.DeleteRequest, re
} }
// ImportState imports a PCI hardware mapping from the Proxmox VE API. // ImportState imports a PCI hardware mapping from the Proxmox VE API.
func (r *resourcePCI) ImportState( func (r *pciResource) ImportState(
ctx context.Context, ctx context.Context,
req resource.ImportStateRequest, req resource.ImportStateRequest,
resp *resource.ImportStateResponse, resp *resource.ImportStateResponse,
@ -169,12 +169,12 @@ func (r *resourcePCI) ImportState(
} }
// Metadata defines the name of the PCI hardware mapping. // Metadata defines the name of the PCI hardware mapping.
func (r *resourcePCI) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { func (r *pciResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_hardware_mapping_pci" resp.TypeName = req.ProviderTypeName + "_hardware_mapping_pci"
} }
// Read reads the PCI hardware mapping. // Read reads the PCI hardware mapping.
func (r *resourcePCI) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { func (r *pciResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var data modelPCI var data modelPCI
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
@ -196,7 +196,7 @@ func (r *resourcePCI) Read(ctx context.Context, req resource.ReadRequest, resp *
} }
// Schema defines the schema for the PCI hardware mapping. // Schema defines the schema for the PCI hardware mapping.
func (r *resourcePCI) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *pciResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
comment := resourceSchemaBaseAttrComment comment := resourceSchemaBaseAttrComment
comment.Description = "The comment of this PCI hardware mapping." comment.Description = "The comment of this PCI hardware mapping."
commentMap := comment commentMap := comment
@ -272,7 +272,7 @@ func (r *resourcePCI) Schema(_ context.Context, _ resource.SchemaRequest, resp *
} }
// Update updates an existing PCI hardware mapping. // Update updates an existing PCI hardware mapping.
func (r *resourcePCI) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { func (r *pciResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var hmCurrent, hmPlan modelPCI var hmCurrent, hmPlan modelPCI
resp.Diagnostics.Append(req.Plan.Get(ctx, &hmPlan)...) resp.Diagnostics.Append(req.Plan.Get(ctx, &hmPlan)...)
@ -301,8 +301,8 @@ func (r *resourcePCI) Update(ctx context.Context, req resource.UpdateRequest, re
r.readBack(ctx, &hmPlan, &resp.Diagnostics, &resp.State) r.readBack(ctx, &hmPlan, &resp.Diagnostics, &resp.State)
} }
// NewResourcePCI returns a new resource for managing a PCI hardware mapping. // NewPCIResource returns a new resource for managing a PCI hardware mapping.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewResourcePCI() resource.Resource { func NewPCIResource() resource.Resource {
return &resourcePCI{} return &pciResource{}
} }

View File

@ -31,19 +31,19 @@ import (
// Ensure the resource implements the required interfaces. // Ensure the resource implements the required interfaces.
var ( var (
_ resource.Resource = &resourceUSB{} _ resource.Resource = &usbResource{}
_ resource.ResourceWithConfigure = &resourceUSB{} _ resource.ResourceWithConfigure = &usbResource{}
_ resource.ResourceWithImportState = &resourceUSB{} _ resource.ResourceWithImportState = &usbResource{}
) )
// resourceUSB contains the USB hardware mapping resource's internal data. // usbResource contains the USB hardware mapping resource's internal data.
type resourceUSB struct { type usbResource struct {
// client is the hardware mapping API client. // client is the hardware mapping API client.
client mappings.Client client mappings.Client
} }
// read reads information about a USB hardware mapping from the Proxmox VE API. // read reads information about a USB hardware mapping from the Proxmox VE API.
func (r *resourceUSB) read(ctx context.Context, hm *modelUSB) (bool, diag.Diagnostics) { func (r *usbResource) read(ctx context.Context, hm *modelUSB) (bool, diag.Diagnostics) {
var diags diag.Diagnostics var diags diag.Diagnostics
hmName := hm.Name.ValueString() hmName := hm.Name.ValueString()
@ -65,7 +65,7 @@ func (r *resourceUSB) read(ctx context.Context, hm *modelUSB) (bool, diag.Diagno
// readBack reads information about a created or modified USB hardware mapping from the Proxmox VE API then updates the // readBack reads information about a created or modified USB hardware mapping from the Proxmox VE API then updates the
// response state accordingly. // response state accordingly.
// The Terraform resource identifier must have been set in the state before this method is called! // The Terraform resource identifier must have been set in the state before this method is called!
func (r *resourceUSB) readBack(ctx context.Context, hm *modelUSB, respDiags *diag.Diagnostics, respState *tfsdk.State) { func (r *usbResource) readBack(ctx context.Context, hm *modelUSB, respDiags *diag.Diagnostics, respState *tfsdk.State) {
found, diags := r.read(ctx, hm) found, diags := r.read(ctx, hm)
respDiags.Append(diags...) respDiags.Append(diags...)
@ -83,7 +83,7 @@ func (r *resourceUSB) readBack(ctx context.Context, hm *modelUSB, respDiags *dia
} }
// Configure adds the provider-configured client to the resource. // Configure adds the provider-configured client to the resource.
func (r *resourceUSB) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { func (r *usbResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
if req.ProviderData == nil { if req.ProviderData == nil {
return return
} }
@ -101,7 +101,7 @@ func (r *resourceUSB) Configure(_ context.Context, req resource.ConfigureRequest
} }
// Create creates a new USB hardware mapping. // Create creates a new USB hardware mapping.
func (r *resourceUSB) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { func (r *usbResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var hm modelUSB var hm modelUSB
resp.Diagnostics.Append(req.Plan.Get(ctx, &hm)...) resp.Diagnostics.Append(req.Plan.Get(ctx, &hm)...)
@ -129,7 +129,7 @@ func (r *resourceUSB) Create(ctx context.Context, req resource.CreateRequest, re
} }
// Delete deletes an existing USB hardware mapping. // Delete deletes an existing USB hardware mapping.
func (r *resourceUSB) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { func (r *usbResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var hm modelUSB var hm modelUSB
resp.Diagnostics.Append(req.State.Get(ctx, &hm)...) resp.Diagnostics.Append(req.State.Get(ctx, &hm)...)
@ -156,7 +156,7 @@ func (r *resourceUSB) Delete(ctx context.Context, req resource.DeleteRequest, re
} }
// ImportState imports a USB hardware mapping from the Proxmox VE API. // ImportState imports a USB hardware mapping from the Proxmox VE API.
func (r *resourceUSB) ImportState( func (r *usbResource) ImportState(
ctx context.Context, ctx context.Context,
req resource.ImportStateRequest, req resource.ImportStateRequest,
resp *resource.ImportStateResponse, resp *resource.ImportStateResponse,
@ -171,14 +171,14 @@ func (r *resourceUSB) ImportState(
} }
// Metadata defines the name of the USB hardware mapping. // Metadata defines the name of the USB hardware mapping.
func (r *resourceUSB) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { func (r *usbResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_hardware_mapping_usb" resp.TypeName = req.ProviderTypeName + "_hardware_mapping_usb"
} }
// Read reads the USB hardware mapping. // Read reads the USB hardware mapping.
// //
func (r *resourceUSB) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { func (r *usbResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var data modelUSB var data modelUSB
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
@ -200,7 +200,7 @@ func (r *resourceUSB) Read(ctx context.Context, req resource.ReadRequest, resp *
} }
// Schema defines the schema for the USB hardware mapping. // Schema defines the schema for the USB hardware mapping.
func (r *resourceUSB) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *usbResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
comment := resourceSchemaBaseAttrComment comment := resourceSchemaBaseAttrComment
comment.Description = "The comment of this USB hardware mapping." comment.Description = "The comment of this USB hardware mapping."
commentMap := comment commentMap := comment
@ -257,7 +257,7 @@ func (r *resourceUSB) Schema(_ context.Context, _ resource.SchemaRequest, resp *
} }
// Update updates an existing USB hardware mapping. // Update updates an existing USB hardware mapping.
func (r *resourceUSB) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { func (r *usbResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var hmCurrent, hmPlan modelUSB var hmCurrent, hmPlan modelUSB
resp.Diagnostics.Append(req.Plan.Get(ctx, &hmPlan)...) resp.Diagnostics.Append(req.Plan.Get(ctx, &hmPlan)...)
@ -283,8 +283,8 @@ func (r *resourceUSB) Update(ctx context.Context, req resource.UpdateRequest, re
r.readBack(ctx, &hmPlan, &resp.Diagnostics, &resp.State) r.readBack(ctx, &hmPlan, &resp.Diagnostics, &resp.State)
} }
// NewResourceUSB returns a new resource for managing a USB hardware mapping. // NewUSBResource returns a new resource for managing a USB hardware mapping.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewResourceUSB() resource.Resource { func NewUSBResource() resource.Resource {
return &resourceUSB{} return &usbResource{}
} }

View File

@ -23,18 +23,18 @@ import (
// Ensure the implementation satisfies the required interfaces. // Ensure the implementation satisfies the required interfaces.
var ( var (
_ datasource.DataSource = &dataSourceRepo{} _ datasource.DataSource = &repositoryDataSource{}
_ datasource.DataSourceWithConfigure = &dataSourceRepo{} _ datasource.DataSourceWithConfigure = &repositoryDataSource{}
) )
// dataSourceRepo is the data source implementation for an APT repository. // repositoryDataSource is the data source implementation for an APT repository.
type dataSourceRepo struct { type repositoryDataSource struct {
// client is the Proxmox VE API client. // client is the Proxmox VE API client.
client proxmox.Client client proxmox.Client
} }
// Configure adds the provider-configured client to the data source. // Configure adds the provider-configured client to the data source.
func (d *dataSourceRepo) Configure( func (d *repositoryDataSource) Configure(
_ context.Context, _ context.Context,
req datasource.ConfigureRequest, req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse, resp *datasource.ConfigureResponse,
@ -58,7 +58,7 @@ func (d *dataSourceRepo) Configure(
} }
// Metadata returns the data source type name. // Metadata returns the data source type name.
func (d *dataSourceRepo) Metadata( func (d *repositoryDataSource) Metadata(
_ context.Context, _ context.Context,
req datasource.MetadataRequest, req datasource.MetadataRequest,
resp *datasource.MetadataResponse, resp *datasource.MetadataResponse,
@ -67,7 +67,11 @@ func (d *dataSourceRepo) Metadata(
} }
// Read fetches the specified APT repository from the Proxmox VE API. // Read fetches the specified APT repository from the Proxmox VE API.
func (d *dataSourceRepo) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { func (d *repositoryDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var rp modelRepo var rp modelRepo
resp.Diagnostics.Append(req.Config.Get(ctx, &rp)...) resp.Diagnostics.Append(req.Config.Get(ctx, &rp)...)
@ -93,7 +97,7 @@ func (d *dataSourceRepo) Read(ctx context.Context, req datasource.ReadRequest, r
} }
// Schema defines the schema for the APT repository. // Schema defines the schema for the APT repository.
func (d *dataSourceRepo) Schema( func (d *repositoryDataSource) Schema(
_ context.Context, _ context.Context,
_ datasource.SchemaRequest, _ datasource.SchemaRequest,
resp *datasource.SchemaResponse, resp *datasource.SchemaResponse,
@ -159,8 +163,8 @@ func (d *dataSourceRepo) Schema(
} }
} }
// NewDataSourceRepo returns a new data source for an APT repository. // NewRepositoryDataSource returns a new data source for an APT repository.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewDataSourceRepo() datasource.DataSource { func NewRepositoryDataSource() datasource.DataSource {
return &dataSourceRepo{} return &repositoryDataSource{}
} }

View File

@ -22,18 +22,18 @@ import (
// Ensure the implementation satisfies the required interfaces. // Ensure the implementation satisfies the required interfaces.
var ( var (
_ datasource.DataSource = &dataSourceStandardRepo{} _ datasource.DataSource = &standardRepositoryDataSource{}
_ datasource.DataSourceWithConfigure = &dataSourceStandardRepo{} _ datasource.DataSourceWithConfigure = &standardRepositoryDataSource{}
) )
// dataSourceStandardRepo is the data source implementation for an APT standard repository. // standardRepositoryDataSource is the data source implementation for an APT standard repository.
type dataSourceStandardRepo struct { type standardRepositoryDataSource struct {
// client is the Proxmox VE API client. // client is the Proxmox VE API client.
client proxmox.Client client proxmox.Client
} }
// Configure adds the provider-configured client to the data source. // Configure adds the provider-configured client to the data source.
func (d *dataSourceStandardRepo) Configure( func (d *standardRepositoryDataSource) Configure(
_ context.Context, _ context.Context,
req datasource.ConfigureRequest, req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse, resp *datasource.ConfigureResponse,
@ -57,7 +57,7 @@ func (d *dataSourceStandardRepo) Configure(
} }
// Metadata returns the data source type name. // Metadata returns the data source type name.
func (d *dataSourceStandardRepo) Metadata( func (d *standardRepositoryDataSource) Metadata(
_ context.Context, _ context.Context,
req datasource.MetadataRequest, req datasource.MetadataRequest,
resp *datasource.MetadataResponse, resp *datasource.MetadataResponse,
@ -66,7 +66,11 @@ func (d *dataSourceStandardRepo) Metadata(
} }
// Read fetches the specified APT standard repository from the Proxmox VE API. // Read fetches the specified APT standard repository from the Proxmox VE API.
func (d *dataSourceStandardRepo) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { func (d *standardRepositoryDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var srp modelStandardRepo var srp modelStandardRepo
resp.Diagnostics.Append(req.Config.Get(ctx, &srp)...) resp.Diagnostics.Append(req.Config.Get(ctx, &srp)...)
@ -88,7 +92,7 @@ func (d *dataSourceStandardRepo) Read(ctx context.Context, req datasource.ReadRe
} }
// Schema defines the schema for the APT standard repository. // Schema defines the schema for the APT standard repository.
func (d *dataSourceStandardRepo) Schema( func (d *standardRepositoryDataSource) Schema(
_ context.Context, _ context.Context,
_ datasource.SchemaRequest, _ datasource.SchemaRequest,
resp *datasource.SchemaResponse, resp *datasource.SchemaResponse,
@ -135,8 +139,8 @@ func (d *dataSourceStandardRepo) Schema(
} }
} }
// NewDataSourceStandardRepo returns a new data source for an APT standard repository. // NewStandardRepositoryDataSource returns a new data source for an APT standard repository.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewDataSourceStandardRepo() datasource.DataSource { func NewStandardRepositoryDataSource() datasource.DataSource {
return &dataSourceStandardRepo{} return &standardRepositoryDataSource{}
} }

View File

@ -33,7 +33,7 @@ import (
) )
const ( const (
// ResourceRepoIDPrefix is the prefix for the resource ID of resourceRepo. // ResourceRepoIDPrefix is the prefix for the resource ID of repositoryResource.
ResourceRepoIDPrefix = "apt_repository" ResourceRepoIDPrefix = "apt_repository"
// ResourceRepoActivationStatus is the default activation status for newly created or imported APT repositories. // ResourceRepoActivationStatus is the default activation status for newly created or imported APT repositories.
@ -43,20 +43,20 @@ const (
// Ensure the resource implements the required interfaces. // Ensure the resource implements the required interfaces.
var ( var (
_ resource.Resource = &resourceRepo{} _ resource.Resource = &repositoryResource{}
_ resource.ResourceWithConfigure = &resourceRepo{} _ resource.ResourceWithConfigure = &repositoryResource{}
_ resource.ResourceWithImportState = &resourceRepo{} _ resource.ResourceWithImportState = &repositoryResource{}
) )
// resourceRepo contains the APT repository resource's internal data. // repositoryResource contains the APT repository resource's internal data.
type resourceRepo struct { type repositoryResource struct {
// client is the Proxmox VE API client. // client is the Proxmox VE API client.
client proxmox.Client client proxmox.Client
} }
// read reads information about an APT repository from the Proxmox VE API. // read reads information about an APT repository from the Proxmox VE API.
// Note that the name of the node must be set before this method is called! // Note that the name of the node must be set before this method is called!
func (r *resourceRepo) read(ctx context.Context, rp *modelRepo) (bool, diag.Diagnostics) { func (r *repositoryResource) read(ctx context.Context, rp *modelRepo) (bool, diag.Diagnostics) {
var diags diag.Diagnostics var diags diag.Diagnostics
data, err := r.client.Node(rp.Node.ValueString()).APT().Repositories().Get(ctx) data, err := r.client.Node(rp.Node.ValueString()).APT().Repositories().Get(ctx)
@ -78,7 +78,7 @@ func (r *resourceRepo) read(ctx context.Context, rp *modelRepo) (bool, diag.Diag
// readBack reads information about an APT repository from the Proxmox VE API and then updates the response state // readBack reads information about an APT repository from the Proxmox VE API and then updates the response state
// accordingly. // accordingly.
// Note that the Terraform resource identifier must be set in the state before this method is called! // Note that the Terraform resource identifier must be set in the state before this method is called!
func (r *resourceRepo) readBack(ctx context.Context, rp *modelRepo, diags *diag.Diagnostics, state *tfsdk.State) { func (r *repositoryResource) readBack(ctx context.Context, rp *modelRepo, diags *diag.Diagnostics, state *tfsdk.State) {
found, readDiags := r.read(ctx, rp) found, readDiags := r.read(ctx, rp)
diags.Append(readDiags...) diags.Append(readDiags...)
@ -96,7 +96,11 @@ func (r *resourceRepo) readBack(ctx context.Context, rp *modelRepo, diags *diag.
} }
// Configure adds the provider-configured client to the resource. // Configure adds the provider-configured client to the resource.
func (r *resourceRepo) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { func (r *repositoryResource) Configure(
_ context.Context,
req resource.ConfigureRequest,
resp *resource.ConfigureResponse,
) {
if req.ProviderData == nil { if req.ProviderData == nil {
return return
} }
@ -119,7 +123,11 @@ func (r *resourceRepo) Configure(_ context.Context, req resource.ConfigureReques
// to the repository lists. // to the repository lists.
// The name of this method might be a bit confusing for this resource, but this is due to the way how the Proxmox VE API // The name of this method might be a bit confusing for this resource, but this is due to the way how the Proxmox VE API
// works for APT repositories. // works for APT repositories.
func (r *resourceRepo) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { func (r *repositoryResource) Create(
ctx context.Context,
req resource.CreateRequest,
resp *resource.CreateResponse,
) {
var rp modelRepo var rp modelRepo
resp.Diagnostics.Append(req.Plan.Get(ctx, &rp)...) resp.Diagnostics.Append(req.Plan.Get(ctx, &rp)...)
@ -152,11 +160,11 @@ func (r *resourceRepo) Create(ctx context.Context, req resource.CreateRequest, r
// //
// [caveats]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#caveats // [caveats]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#caveats
// [recommendations]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#recommendations // [recommendations]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#recommendations
func (r *resourceRepo) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { func (r *repositoryResource) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) {
} }
// ImportState imports an APT repository from the Proxmox VE API. // ImportState imports an APT repository from the Proxmox VE API.
func (r *resourceRepo) ImportState( func (r *repositoryResource) ImportState(
ctx context.Context, ctx context.Context,
req resource.ImportStateRequest, req resource.ImportStateRequest,
resp *resource.ImportStateResponse, resp *resource.ImportStateResponse,
@ -206,7 +214,7 @@ func (r *resourceRepo) ImportState(
} }
// Metadata defines the name of the APT repository resource. // Metadata defines the name of the APT repository resource.
func (r *resourceRepo) Metadata( func (r *repositoryResource) Metadata(
_ context.Context, _ context.Context,
req resource.MetadataRequest, req resource.MetadataRequest,
resp *resource.MetadataResponse, resp *resource.MetadataResponse,
@ -215,7 +223,7 @@ func (r *resourceRepo) Metadata(
} }
// Read reads the APT repository. // Read reads the APT repository.
func (r *resourceRepo) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { func (r *repositoryResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var rp modelRepo var rp modelRepo
resp.Diagnostics.Append(req.State.Get(ctx, &rp)...) resp.Diagnostics.Append(req.State.Get(ctx, &rp)...)
@ -237,7 +245,7 @@ func (r *resourceRepo) Read(ctx context.Context, req resource.ReadRequest, resp
} }
// Schema defines the schema for the APT repository. // Schema defines the schema for the APT repository.
func (r *resourceRepo) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{ resp.Schema = schema.Schema{
Description: "Manages an APT repository of a Proxmox VE node.", Description: "Manages an APT repository of a Proxmox VE node.",
Attributes: map[string]schema.Attribute{ Attributes: map[string]schema.Attribute{
@ -312,7 +320,7 @@ func (r *resourceRepo) Schema(_ context.Context, _ resource.SchemaRequest, resp
} }
// Update updates an existing APT repository. // Update updates an existing APT repository.
func (r *resourceRepo) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { func (r *repositoryResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var rpPlan modelRepo var rpPlan modelRepo
resp.Diagnostics.Append(req.Plan.Get(ctx, &rpPlan)...) resp.Diagnostics.Append(req.Plan.Get(ctx, &rpPlan)...)
@ -345,8 +353,8 @@ func (r *resourceRepo) Update(ctx context.Context, req resource.UpdateRequest, r
r.readBack(ctx, &rpPlan, &resp.Diagnostics, &resp.State) r.readBack(ctx, &rpPlan, &resp.Diagnostics, &resp.State)
} }
// NewResourceRepo returns a new resource for managing an APT repository. // NewRepositoryResource returns a new resource for managing an APT repository.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewResourceRepo() resource.Resource { func NewRepositoryResource() resource.Resource {
return &resourceRepo{} return &repositoryResource{}
} }

View File

@ -29,26 +29,26 @@ import (
) )
const ( const (
// ResourceStandardRepoIDPrefix is the prefix for the resource ID of resourceStandardRepo. // ResourceStandardRepoIDPrefix is the prefix for the resource ID of standardRepositoryResource.
ResourceStandardRepoIDPrefix = "apt_standard_repository" ResourceStandardRepoIDPrefix = "apt_standard_repository"
) )
// Ensure the resource implements the required interfaces. // Ensure the resource implements the required interfaces.
var ( var (
_ resource.Resource = &resourceStandardRepo{} _ resource.Resource = &standardRepositoryResource{}
_ resource.ResourceWithConfigure = &resourceStandardRepo{} _ resource.ResourceWithConfigure = &standardRepositoryResource{}
_ resource.ResourceWithImportState = &resourceStandardRepo{} _ resource.ResourceWithImportState = &standardRepositoryResource{}
) )
// resourceStandardRepo contains the APT standard repository resource's internal data. // standardRepositoryResource contains the APT standard repository resource's internal data.
type resourceStandardRepo struct { type standardRepositoryResource struct {
// client is the Proxmox VE API client. // client is the Proxmox VE API client.
client proxmox.Client client proxmox.Client
} }
// read reads information about an APT standard repository from the Proxmox VE API. // read reads information about an APT standard repository from the Proxmox VE API.
// Note that the name of the node must be set before this method is called! // Note that the name of the node must be set before this method is called!
func (r *resourceStandardRepo) read(ctx context.Context, srp *modelStandardRepo) (bool, diag.Diagnostics) { func (r *standardRepositoryResource) read(ctx context.Context, srp *modelStandardRepo) (bool, diag.Diagnostics) {
var diags diag.Diagnostics var diags diag.Diagnostics
data, err := r.client.Node(srp.Node.ValueString()).APT().Repositories().Get(ctx) data, err := r.client.Node(srp.Node.ValueString()).APT().Repositories().Get(ctx)
@ -74,7 +74,7 @@ func (r *resourceStandardRepo) read(ctx context.Context, srp *modelStandardRepo)
// readBack reads information about an APT standard repository from the Proxmox VE API and then updates the response // readBack reads information about an APT standard repository from the Proxmox VE API and then updates the response
// state accordingly. // state accordingly.
func (r *resourceStandardRepo) readBack( func (r *standardRepositoryResource) readBack(
ctx context.Context, ctx context.Context,
srp *modelStandardRepo, srp *modelStandardRepo,
diags *diag.Diagnostics, diags *diag.Diagnostics,
@ -97,7 +97,7 @@ func (r *resourceStandardRepo) readBack(
} }
// Configure adds the provider-configured client to the resource. // Configure adds the provider-configured client to the resource.
func (r *resourceStandardRepo) Configure( func (r *standardRepositoryResource) Configure(
_ context.Context, _ context.Context,
req resource.ConfigureRequest, req resource.ConfigureRequest,
resp *resource.ConfigureResponse, resp *resource.ConfigureResponse,
@ -123,7 +123,11 @@ func (r *resourceStandardRepo) Configure(
// Create adds an APT standard repository to the repository source lists. // Create adds an APT standard repository to the repository source lists.
// The name of this method might be a bit confusing for this resource, but this is due to the way how the Proxmox VE API // The name of this method might be a bit confusing for this resource, but this is due to the way how the Proxmox VE API
// works for APT standard repositories. // works for APT standard repositories.
func (r *resourceStandardRepo) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { func (r *standardRepositoryResource) Create(
ctx context.Context,
req resource.CreateRequest,
resp *resource.CreateResponse,
) {
var srp modelStandardRepo var srp modelStandardRepo
resp.Diagnostics.Append(req.Plan.Get(ctx, &srp)...) resp.Diagnostics.Append(req.Plan.Get(ctx, &srp)...)
@ -153,11 +157,11 @@ func (r *resourceStandardRepo) Create(ctx context.Context, req resource.CreateRe
// //
// [caveats]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#caveats // [caveats]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#caveats
// [recommendations]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#recommendations // [recommendations]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#recommendations
func (r *resourceStandardRepo) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) { func (r *standardRepositoryResource) Delete(_ context.Context, _ resource.DeleteRequest, _ *resource.DeleteResponse) {
} }
// ImportState imports an APT standard repository from the Proxmox VE API. // ImportState imports an APT standard repository from the Proxmox VE API.
func (r *resourceStandardRepo) ImportState( func (r *standardRepositoryResource) ImportState(
ctx context.Context, ctx context.Context,
req resource.ImportStateRequest, req resource.ImportStateRequest,
resp *resource.ImportStateResponse, resp *resource.ImportStateResponse,
@ -184,7 +188,7 @@ func (r *resourceStandardRepo) ImportState(
} }
// Metadata defines the name of the APT standard repository resource. // Metadata defines the name of the APT standard repository resource.
func (r *resourceStandardRepo) Metadata( func (r *standardRepositoryResource) Metadata(
_ context.Context, _ context.Context,
req resource.MetadataRequest, req resource.MetadataRequest,
resp *resource.MetadataResponse, resp *resource.MetadataResponse,
@ -193,7 +197,11 @@ func (r *resourceStandardRepo) Metadata(
} }
// Read reads the APT standard repository. // Read reads the APT standard repository.
func (r *resourceStandardRepo) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { func (r *standardRepositoryResource) Read(
ctx context.Context,
req resource.ReadRequest,
resp *resource.ReadResponse,
) {
var srp modelStandardRepo var srp modelStandardRepo
resp.Diagnostics.Append(req.State.Get(ctx, &srp)...) resp.Diagnostics.Append(req.State.Get(ctx, &srp)...)
@ -215,7 +223,11 @@ func (r *resourceStandardRepo) Read(ctx context.Context, req resource.ReadReques
} }
// Schema defines the schema for the APT standard repository. // Schema defines the schema for the APT standard repository.
func (r *resourceStandardRepo) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *standardRepositoryResource) Schema(
_ context.Context,
_ resource.SchemaRequest,
resp *resource.SchemaResponse,
) {
resp.Schema = schema.Schema{ resp.Schema = schema.Schema{
Description: "Manages an APT standard repository of a Proxmox VE node.", Description: "Manages an APT standard repository of a Proxmox VE node.",
Attributes: map[string]schema.Attribute{ Attributes: map[string]schema.Attribute{
@ -276,11 +288,11 @@ func (r *resourceStandardRepo) Schema(_ context.Context, _ resource.SchemaReques
// //
// [caveats]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#caveats // [caveats]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#caveats
// [recommendations]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#recommendations // [recommendations]: https://developer.hashicorp.com/terraform/plugin/framework/resources/delete#recommendations
func (r *resourceStandardRepo) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) { func (r *standardRepositoryResource) Update(_ context.Context, _ resource.UpdateRequest, _ *resource.UpdateResponse) {
} }
// NewResourceStandardRepo returns a new resource for managing an APT standard repository. // NewStandardRepositoryResource returns a new resource for managing an APT standard repository.
// This is a helper function to simplify the provider implementation. // This is a helper function to simplify the provider implementation.
func NewResourceStandardRepo() resource.Resource { func NewStandardRepositoryResource() resource.Resource {
return &resourceStandardRepo{} return &standardRepositoryResource{}
} }

View File

@ -446,14 +446,14 @@ func (p *proxmoxProvider) Resources(_ context.Context) []func() resource.Resourc
NewClusterOptionsResource, NewClusterOptionsResource,
NewDownloadFileResource, NewDownloadFileResource,
acme.NewACMEAccountResource, acme.NewACMEAccountResource,
apt.NewResourceRepo, apt.NewRepositoryResource,
apt.NewResourceStandardRepo, apt.NewStandardRepositoryResource,
access.NewACLResource, access.NewACLResource,
access.NewUserTokenResource, access.NewUserTokenResource,
ha.NewHAGroupResource, ha.NewHAGroupResource,
ha.NewHAResourceResource, ha.NewHAResourceResource,
hardwaremapping.NewResourcePCI, hardwaremapping.NewPCIResource,
hardwaremapping.NewResourceUSB, hardwaremapping.NewUSBResource,
network.NewLinuxBridgeResource, network.NewLinuxBridgeResource,
network.NewLinuxVLANResource, network.NewLinuxVLANResource,
vm.NewResource, vm.NewResource,
@ -465,15 +465,15 @@ func (p *proxmoxProvider) DataSources(_ context.Context) []func() datasource.Dat
NewVersionDataSource, NewVersionDataSource,
acme.NewACMEAccountsDataSource, acme.NewACMEAccountsDataSource,
acme.NewACMEAccountDataSource, acme.NewACMEAccountDataSource,
apt.NewDataSourceRepo, apt.NewRepositoryDataSource,
apt.NewDataSourceStandardRepo, apt.NewStandardRepositoryDataSource,
ha.NewHAGroupDataSource, ha.NewHAGroupDataSource,
ha.NewHAGroupsDataSource, ha.NewHAGroupsDataSource,
ha.NewHAResourceDataSource, ha.NewHAResourceDataSource,
ha.NewHAResourcesDataSource, ha.NewHAResourcesDataSource,
hardwaremapping.NewDataSource, hardwaremapping.NewDataSource,
hardwaremapping.NewDataSourcePCI, hardwaremapping.NewPCIDataSource,
hardwaremapping.NewDataSourceUSB, hardwaremapping.NewUSBDataSource,
vm.NewDataSource, vm.NewDataSource,
} }
} }