Skip to content

Commit

Permalink
Merge pull request #230 from alrayyes/refactor/functions
Browse files Browse the repository at this point in the history
refactor: remove pointless functions
  • Loading branch information
alrayyes authored Dec 20, 2024
2 parents ace2f1b + 6ba5852 commit 78b1403
Show file tree
Hide file tree
Showing 30 changed files with 2,116 additions and 3,720 deletions.
9 changes: 0 additions & 9 deletions docs/resources/public_cloud_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,3 @@ resource "leaseweb_public_cloud_image" "example" {
- `region` (String)
- `state` (String)
- `storage_types` (List of String) The supported storage types for the instance type

## Import

Import is supported using the following syntax:

```shell
# Public Cloud image can be imported by specifying the identifier.
terraform import leaseweb_public_cloud_image.example ace712e9-a166-47f1-9065-4af0f7e7fce1
```
2 changes: 0 additions & 2 deletions examples/resources/leaseweb_public_cloud_image/import.sh

This file was deleted.

20 changes: 10 additions & 10 deletions internal/provider/dedicatedserver/installation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ type partitionsResourceModel struct {
Size types.String `tfsdk:"size"`
}

func (p partitionsResourceModel) attributeTypes() map[string]attr.Type {
return map[string]attr.Type{
"filesystem": types.StringType,
"mountpoint": types.StringType,
"size": types.StringType,
}
}

func (i *installationResource) Schema(
_ context.Context,
_ resource.SchemaRequest,
Expand Down Expand Up @@ -345,6 +337,12 @@ func (i *installationResource) Create(
plan.Timezone = types.StringValue(payload.GetTimezone())
plan.PowerCycle = types.BoolValue(payload.GetPowerCycle())

partitionAttributeTypes := map[string]attr.Type{
"filesystem": types.StringType,
"mountpoint": types.StringType,
"size": types.StringType,
}

// Preparing and converting partitions into types.Object to store in the state
var partitionsObjects []attr.Value
for _, p := range payload.GetPartitions() {
Expand All @@ -356,7 +354,7 @@ func (i *installationResource) Create(

partitionObj, diags := types.ObjectValueFrom(
ctx,
partition.attributeTypes(),
partitionAttributeTypes,
partition,
)
if diags.HasError() {
Expand All @@ -370,7 +368,9 @@ func (i *installationResource) Create(
// Convert the slice of partition objects to a types.List and store it in the plan
partitionsList, diags := types.ListValueFrom(
ctx,
types.ObjectType{AttrTypes: partitionsResourceModel{}.attributeTypes()},
types.ObjectType{
AttrTypes: partitionAttributeTypes,
},
partitionsObjects,
)
if diags.HasError() {
Expand Down
56 changes: 28 additions & 28 deletions internal/provider/dedicatedserver/server_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ type serverDataSource struct {
type serverDataSourceModel struct {
Id types.String `tfsdk:"id"`
AssetId types.String `tfsdk:"asset_id"`
SerialNumber types.String `tfsdk:"serial_number"`
ContractId types.String `tfsdk:"contract_id"`
RackId types.String `tfsdk:"rack_id"`
RackCapacity types.String `tfsdk:"rack_capacity"`
RackType types.String `tfsdk:"rack_type"`
CpuQuantity types.Int32 `tfsdk:"cpu_quantity"`
CpuType types.String `tfsdk:"cpu_type"`
InternalGateway types.String `tfsdk:"internal_gateway"`
InternalIp types.String `tfsdk:"internal_ip"`
InternalMac types.String `tfsdk:"internal_mac"`
IsAutomationFeatureAvailable types.Bool `tfsdk:"is_automation_feature_available"`
IsIpmiRebootFeatureAvailable types.Bool `tfsdk:"is_ipmi_reboot_feature_available"`
IsPowerCycleFeatureAvailable types.Bool `tfsdk:"is_power_cycle_feature_available"`
Expand All @@ -35,19 +36,18 @@ type serverDataSourceModel struct {
LocationSite types.String `tfsdk:"location_site"`
LocationSuite types.String `tfsdk:"location_suite"`
LocationUnit types.String `tfsdk:"location_unit"`
PublicMac types.String `tfsdk:"public_mac"`
PublicIp types.String `tfsdk:"public_ip"`
PublicGateway types.String `tfsdk:"public_gateway"`
InternalMac types.String `tfsdk:"internal_mac"`
InternalIp types.String `tfsdk:"internal_ip"`
InternalGateway types.String `tfsdk:"internal_gateway"`
RemoteMac types.String `tfsdk:"remote_mac"`
RemoteIp types.String `tfsdk:"remote_ip"`
RemoteGateway types.String `tfsdk:"remote_gateway"`
PublicIp types.String `tfsdk:"public_ip"`
PublicMac types.String `tfsdk:"public_mac"`
RackCapacity types.String `tfsdk:"rack_capacity"`
RackId types.String `tfsdk:"rack_id"`
RackType types.String `tfsdk:"rack_type"`
RamSize types.Int32 `tfsdk:"ram_size"`
RamUnit types.String `tfsdk:"ram_unit"`
CpuQuantity types.Int32 `tfsdk:"cpu_quantity"`
CpuType types.String `tfsdk:"cpu_type"`
RemoteGateway types.String `tfsdk:"remote_gateway"`
RemoteIp types.String `tfsdk:"remote_ip"`
RemoteMac types.String `tfsdk:"remote_mac"`
SerialNumber types.String `tfsdk:"serial_number"`
}

func (s *serverDataSource) Read(
Expand Down Expand Up @@ -149,11 +149,13 @@ func (s *serverDataSource) Read(
serverDataSourceModel{
Id: types.StringValue(result.GetId()),
AssetId: types.StringValue(result.GetAssetId()),
SerialNumber: types.StringValue(result.GetSerialNumber()),
ContractId: types.StringPointerValue(contractId),
RackId: types.StringPointerValue(rackId),
RackCapacity: types.StringPointerValue(rackCapacity),
RackType: types.StringPointerValue(rackType),
CpuQuantity: types.Int32PointerValue(cpuQuantity),
CpuType: types.StringPointerValue(cpuType),
InternalGateway: types.StringPointerValue(internalGateway),
InternalIp: types.StringPointerValue(internalIp),
InternalMac: types.StringPointerValue(internalMac),
SerialNumber: types.StringValue(result.GetSerialNumber()),
IsAutomationFeatureAvailable: types.BoolPointerValue(automation),
IsIpmiRebootFeatureAvailable: types.BoolPointerValue(ipmiReboot),
IsPowerCycleFeatureAvailable: types.BoolPointerValue(powerCycle),
Expand All @@ -163,19 +165,17 @@ func (s *serverDataSource) Read(
LocationSite: types.StringPointerValue(locationSite),
LocationSuite: types.StringPointerValue(locationSuite),
LocationUnit: types.StringPointerValue(locationUnit),
PublicMac: types.StringPointerValue(publicMac),
PublicIp: types.StringPointerValue(publicIp),
PublicGateway: types.StringPointerValue(publicGateway),
InternalMac: types.StringPointerValue(internalMac),
InternalIp: types.StringPointerValue(internalIp),
InternalGateway: types.StringPointerValue(internalGateway),
RemoteMac: types.StringPointerValue(remoteMac),
RemoteIp: types.StringPointerValue(remoteIp),
RemoteGateway: types.StringPointerValue(remoteGateway),
PublicIp: types.StringPointerValue(publicIp),
PublicMac: types.StringPointerValue(publicMac),
RackCapacity: types.StringPointerValue(rackCapacity),
RackId: types.StringPointerValue(rackId),
RackType: types.StringPointerValue(rackType),
RamSize: types.Int32PointerValue(ramSize),
RamUnit: types.StringPointerValue(ramUnit),
CpuQuantity: types.Int32PointerValue(cpuQuantity),
CpuType: types.StringPointerValue(cpuType),
RemoteGateway: types.StringPointerValue(remoteGateway),
RemoteIp: types.StringPointerValue(remoteIp),
RemoteMac: types.StringPointerValue(remoteMac),
},
)...,
)
Expand Down
Loading

0 comments on commit 78b1403

Please sign in to comment.