|  | 
|  | 1 | +package storage | 
|  | 2 | + | 
|  | 3 | +import ( | 
|  | 4 | +	"context" | 
|  | 5 | + | 
|  | 6 | +	"github.com/hashicorp/terraform-plugin-framework/resource" | 
|  | 7 | +	"github.com/hashicorp/terraform-plugin-framework/resource/schema" | 
|  | 8 | +	"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" | 
|  | 9 | +	"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | 
|  | 10 | +	"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | 
|  | 11 | +) | 
|  | 12 | + | 
|  | 13 | +// Ensure the implementation satisfies the expected interfaces. | 
|  | 14 | +var _ resource.Resource = &smbStorageResource{} | 
|  | 15 | + | 
|  | 16 | +// NewCIFSStorageResource is a helper function to simplify the provider implementation. | 
|  | 17 | +func NewCIFSStorageResource() resource.Resource { | 
|  | 18 | +	return &smbStorageResource{ | 
|  | 19 | +		storageResource: &storageResource[ | 
|  | 20 | +			*CIFSStorageModel, | 
|  | 21 | +			CIFSStorageModel, | 
|  | 22 | +		]{ | 
|  | 23 | +			storageType:  "smb", | 
|  | 24 | +			resourceName: "proxmox_virtual_environment_storage_smb", | 
|  | 25 | +		}, | 
|  | 26 | +	} | 
|  | 27 | +} | 
|  | 28 | + | 
|  | 29 | +// smbStorageResource is the resource implementation. | 
|  | 30 | +type smbStorageResource struct { | 
|  | 31 | +	*storageResource[*CIFSStorageModel, CIFSStorageModel] | 
|  | 32 | +} | 
|  | 33 | + | 
|  | 34 | +// Metadata returns the resource type name. | 
|  | 35 | +func (r *smbStorageResource) Metadata(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) { | 
|  | 36 | +	resp.TypeName = r.resourceName | 
|  | 37 | +} | 
|  | 38 | + | 
|  | 39 | +// Schema defines the schema for the SMB storage resource. | 
|  | 40 | +func (r *smbStorageResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { | 
|  | 41 | +	attributes := map[string]schema.Attribute{ | 
|  | 42 | +		"server": schema.StringAttribute{ | 
|  | 43 | +			Description: "The IP address or DNS name of the SMB/CIFS server.", | 
|  | 44 | +			Required:    true, | 
|  | 45 | +			PlanModifiers: []planmodifier.String{ | 
|  | 46 | +				stringplanmodifier.RequiresReplace(), | 
|  | 47 | +			}, | 
|  | 48 | +		}, | 
|  | 49 | +		"username": schema.StringAttribute{ | 
|  | 50 | +			Description: "The username for authenticating with the SMB/CIFS server.", | 
|  | 51 | +			Required:    true, | 
|  | 52 | +		}, | 
|  | 53 | +		"password": schema.StringAttribute{ | 
|  | 54 | +			Description: "The password for authenticating with the SMB/CIFS server.", | 
|  | 55 | +			Required:    true, | 
|  | 56 | +			Sensitive:   true, | 
|  | 57 | +		}, | 
|  | 58 | +		"share": schema.StringAttribute{ | 
|  | 59 | +			Description: "The name of the SMB/CIFS share.", | 
|  | 60 | +			Required:    true, | 
|  | 61 | +			PlanModifiers: []planmodifier.String{ | 
|  | 62 | +				stringplanmodifier.RequiresReplace(), | 
|  | 63 | +			}, | 
|  | 64 | +		}, | 
|  | 65 | +		"domain": schema.StringAttribute{ | 
|  | 66 | +			Description: "The SMB/CIFS domain.", | 
|  | 67 | +			Optional:    true, | 
|  | 68 | +		}, | 
|  | 69 | +		"subdirectory": schema.StringAttribute{ | 
|  | 70 | +			Description: "A subdirectory to mount within the share.", | 
|  | 71 | +			Optional:    true, | 
|  | 72 | +		}, | 
|  | 73 | +		"preallocation": schema.StringAttribute{ | 
|  | 74 | +			Description: "The preallocation mode for raw and qcow2 images.", | 
|  | 75 | +			Optional:    true, | 
|  | 76 | +		}, | 
|  | 77 | +		"snapshot_as_volume_chain": schema.BoolAttribute{ | 
|  | 78 | +			Description: "Enable support for creating snapshots through volume backing-chains.", | 
|  | 79 | +			Optional:    true, | 
|  | 80 | +		}, | 
|  | 81 | +		"shared": schema.BoolAttribute{ | 
|  | 82 | +			Description: "Whether the storage is shared across all nodes.", | 
|  | 83 | +			Computed:    true, | 
|  | 84 | +			Default:     booldefault.StaticBool(true), | 
|  | 85 | +		}, | 
|  | 86 | +	} | 
|  | 87 | + | 
|  | 88 | +	factory := NewStorageSchemaFactory() | 
|  | 89 | +	factory.WithAttributes(attributes) | 
|  | 90 | +	factory.WithDescription("Manages an SMB/CIFS based storage server in Proxmox VE.") | 
|  | 91 | +	resp.Schema = *factory.Schema | 
|  | 92 | +} | 
0 commit comments