Skip to content

Commit

Permalink
Merge pull request #50 from alrayyes/docs/update-docs
Browse files Browse the repository at this point in the history
Docs/update docs
  • Loading branch information
alrayyes authored Aug 27, 2024
2 parents 0a42c4e + f4e50e2 commit 9d31c7f
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 77 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ A Terraform provider to manage Leaseweb resources.
## Requirements

- [Terraform](https://developer.hashicorp.com/terraform/downloads) >= 1.7
- [Go](https://golang.org/doc/install) >= 1.21
- [Node](https://nodejs.org) >= 20.13
- [pnPM](https://pnpm.io/) >= 9.1
- [Go](https://golang.org/doc/install) >= 1.22
- [Node](https://nodejs.org) >= 20.17
- [pnPM](https://pnpm.io/) >= 9.7

All requirements are also satisfied by the included [docker-compose.yml](docker-compose.yml).

Expand Down Expand Up @@ -73,5 +73,5 @@ curl -i http://localhost:8080/publicCloud/v1/instances --header 'x-lsw-auth: tra
Files are automatically linted via git hooks on commit and on push. To enable the git hooks run

```bash
pnpm husky
pnpm i
```
32 changes: 26 additions & 6 deletions docs/data-sources/public_cloud_instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,23 @@ Read-Only:

Read-Only:

- `billing_frequency` (Number) The billing frequency (in months)
- `billing_frequency` (Number) The billing frequency (in months). Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `created_at` (String) Date when the contract was created
- `ends_at` (String)
- `renewals_at` (String) Date when the contract will be automatically renewed
- `state` (String)
- `term` (Number) Contract term (in months). Used only when type is MONTHLY
- `type` (String) Select HOURLY for billing based on hourly usage, else MONTHLY for billing per month usage
- `term` (Number) Contract term (in months). Used only when type is *MONTHLY*. Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `type` (String) Select *HOURLY* for billing based on hourly usage, else *MONTHLY* for billing per month usage


<a id="nestedatt--instances--auto_scaling_group--load_balancer--ips"></a>
Expand Down Expand Up @@ -347,13 +357,23 @@ Read-Only:

Read-Only:

- `billing_frequency` (Number) The billing frequency (in months)
- `billing_frequency` (Number) The billing frequency (in months). Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `created_at` (String) Date when the contract was created
- `ends_at` (String)
- `renewals_at` (String) Date when the contract will be automatically renewed
- `state` (String)
- `term` (Number) Contract term (in months). Used only when type is MONTHLY
- `type` (String) Select HOURLY for billing based on hourly usage, else MONTHLY for billing per month usage
- `term` (Number) Contract term (in months). Used only when type is *MONTHLY*. Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `type` (String) Select *HOURLY* for billing based on hourly usage, else *MONTHLY* for billing per month usage


<a id="nestedatt--instances--image"></a>
Expand Down
46 changes: 33 additions & 13 deletions docs/resources/public_cloud_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ resource "leaseweb_public_cloud_instance" "example" {
- `contract` (Attributes) (see [below for nested schema](#nestedatt--contract))
- `image` (Attributes) (see [below for nested schema](#nestedatt--image))
- `region` (Attributes) (see [below for nested schema](#nestedatt--region))
- `root_disk_storage_type` (String) The root disk's storage type.**WARNING!** Changing this value once running will cause this instance to be destroyed and a new one to be created.
- `root_disk_storage_type` (String) The root disk's storage type. Can be *LOCAL* or *CENTRAL*. **WARNING!** Changing this value once running will cause this instance to be destroyed and a new one to be created.
- `type` (Attributes) (see [below for nested schema](#nestedatt--type))

### Optional

- `market_app_id` (String) Market App ID that must be installed into the instance.**WARNING!** Changing this value once running will cause this instance to be destroyed and a new one to be created.
- `reference` (String) The identifying name set to the instance
- `root_disk_size` (Number) The root disk's size in GB. Must be at least 5 GB for Linux and FreeBSD instances and 50 GB for Windows instances
- `root_disk_size` (Number) The root disk's size in GB. Must be at least 5 GB for Linux and FreeBSD instances and 50 GB for Windows instances. The maximum size is 1000 GB

### Read-Only

Expand All @@ -71,9 +71,19 @@ resource "leaseweb_public_cloud_instance" "example" {

Required:

- `billing_frequency` (Number) The billing frequency (in months)
- `term` (Number) Contract term (in months). Used only when type is MONTHLY
- `type` (String) Select HOURLY for billing based on hourly usage, else MONTHLY for billing per month usage
- `billing_frequency` (Number) The billing frequency (in months). Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `term` (Number) Contract term (in months). Used only when type is *MONTHLY*. Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `type` (String) Select *HOURLY* for billing based on hourly usage, else *MONTHLY* for billing per month usage

Read-Only:

Expand All @@ -88,7 +98,7 @@ Read-Only:

Required:

- `id` (String) Image ID.**WARNING!** Changing this value once running will cause this instance to be destroyed and a new one to be created.
- `id` (String) Can be either an Operating System or a UUID in case of a Custom Image ID.**WARNING!** Changing this value once running will cause this instance to be destroyed and a new one to be created.

Read-Only:

Expand All @@ -113,7 +123,7 @@ Read-Only:
Read-Only:

- `location` (String) The city where the region is located
- `name` (String)
- `name` (String) Our current regions can be found in the [developer documentation](https://developer.leaseweb.com/api-docs/publiccloud_v1.html#tag/Instances/operation/launchInstance)


<a id="nestedatt--image--storage_size"></a>
Expand All @@ -131,7 +141,7 @@ Read-Only:

Required:

- `name` (String) **WARNING!** Changing this value once running will cause this instance to be destroyed and a new one to be created.
- `name` (String) Our current regions can be found in the [developer documentation](https://developer.leaseweb.com/api-docs/publiccloud_v1.html#tag/Instances/operation/launchInstance)**WARNING!** Changing this value once running will cause this instance to be destroyed and a new one to be created.

Read-Only:

Expand Down Expand Up @@ -290,13 +300,23 @@ Read-Only:

Read-Only:

- `billing_frequency` (Number) The billing frequency (in months)
- `billing_frequency` (Number) The billing frequency (in months). Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `created_at` (String) Date when the contract was created
- `ends_at` (String)
- `renewals_at` (String) Date when the contract will be automatically renewed
- `state` (String)
- `term` (Number) Contract term (in months). Used only when type is MONTHLY
- `type` (String) Select HOURLY for billing based on hourly usage, else MONTHLY for billing per month usage
- `term` (Number) Contract term (in months). Used only when type is *MONTHLY*. Valid options are
- *0*
- *1*
- *3*
- *6*
- *12*
- `type` (String) Select *HOURLY* for billing based on hourly usage, else *MONTHLY* for billing per month usage


<a id="nestedatt--auto_scaling_group--load_balancer--ips"></a>
Expand Down Expand Up @@ -372,7 +392,7 @@ Read-Only:
Read-Only:

- `location` (String) The city where the region is located
- `name` (String)
- `name` (String) Our current regions can be found in the [developer documentation](https://developer.leaseweb.com/api-docs/publiccloud_v1.html#tag/Instances/operation/launchInstance)


<a id="nestedatt--auto_scaling_group--load_balancer--resources"></a>
Expand Down Expand Up @@ -534,7 +554,7 @@ Read-Only:
Read-Only:

- `location` (String) The city where the region is located
- `name` (String)
- `name` (String) Our current regions can be found in the [developer documentation](https://developer.leaseweb.com/api-docs/publiccloud_v1.html#tag/Instances/operation/launchInstance)



Expand Down
35 changes: 0 additions & 35 deletions internal/core/shared/enum/region.go

This file was deleted.

12 changes: 4 additions & 8 deletions internal/facades/public_cloud/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,13 @@ func (p PublicCloudFacade) GetRootDiskStorageTypes() []string {
}

// GetBillingFrequencies returns a list of valid billing frequencies.
func (p PublicCloudFacade) GetBillingFrequencies() []int64 {
return shared.AdaptIntArrayToInt64Array(
enum.ContractBillingFrequencyThree.Values(),
)
func (p PublicCloudFacade) GetBillingFrequencies() shared.IntMarkdownList {
return shared.NewIntMarkdownList(enum.ContractBillingFrequencyThree.Values())
}

// GetContractTerms returns a list of valid contract terms.
func (p PublicCloudFacade) GetContractTerms() []int64 {
return shared.AdaptIntArrayToInt64Array(
enum.ContractTermThree.Values(),
)
func (p PublicCloudFacade) GetContractTerms() shared.IntMarkdownList {
return shared.NewIntMarkdownList(enum.ContractTermThree.Values())
}

// GetContractTypes returns a list of valid contract types.
Expand Down
5 changes: 3 additions & 2 deletions internal/facades/public_cloud/facade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
serviceErrors "github.com/leaseweb/terraform-provider-leaseweb/internal/core/services/errors"
"github.com/leaseweb/terraform-provider-leaseweb/internal/core/shared/enum"
"github.com/leaseweb/terraform-provider-leaseweb/internal/core/shared/value_object"
"github.com/leaseweb/terraform-provider-leaseweb/internal/facades/shared"
dataSourceModel "github.com/leaseweb/terraform-provider-leaseweb/internal/provider/data_sources/public_cloud/model"
"github.com/leaseweb/terraform-provider-leaseweb/internal/provider/resources/public_cloud/model"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -744,15 +745,15 @@ func TestPublicCloudFacade_GetRootDiskStorageTypes(t *testing.T) {

func TestPublicCloudFacade_GetBillingFrequencies(t *testing.T) {
facade := PublicCloudFacade{}
want := []int64{0, 1, 3, 6, 12}
want := shared.NewIntMarkdownList([]int{0, 1, 3, 6, 12})
got := facade.GetBillingFrequencies()

assert.Equal(t, want, got)
}

func TestPublicCloudFacade_GetContractTerms(t *testing.T) {
facade := PublicCloudFacade{}
want := []int64{0, 1, 3, 6, 12}
want := shared.NewIntMarkdownList([]int{0, 1, 3, 6, 12})
got := facade.GetContractTerms()

assert.Equal(t, want, got)
Expand Down
35 changes: 35 additions & 0 deletions internal/facades/shared/int_markdown_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package shared

import (
"strconv"
)

type IntMarkdownList []int

func (i IntMarkdownList) Markdown() string {
markdown := "\n"
for _, i := range i {
markdown += " - *" + strconv.Itoa(i) + "*\n"
}

return markdown
}

func (i IntMarkdownList) ToInt64() []int64 {
var returnValues []int64

for _, i := range i {
returnValues = append(returnValues, int64(i))
}

return returnValues
}

func NewIntMarkdownList(values []int) IntMarkdownList {
i := IntMarkdownList{}
for _, value := range values {
i = append(i, value)
}

return i
}
29 changes: 29 additions & 0 deletions internal/facades/shared/int_markdown_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package shared

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestIntMarkdownList_Markdown(t *testing.T) {
t.Run("returns valid markdown", func(t *testing.T) {
got := IntMarkdownList{1, 2, 3}.Markdown()
want := "\n - *1*\n - *2*\n - *3*\n"
assert.Equal(t, want, got)
})
}

func TestNewIntMarkdownList(t *testing.T) {
got := NewIntMarkdownList([]int{1, 2, 3})
want := IntMarkdownList{1, 2, 3}

assert.Equal(t, want, got)
}

func TestIntMarkdownList_ToInt64(t *testing.T) {
got := IntMarkdownList{1, 2, 3}.ToInt64()
want := []int64{1, 2, 3}

assert.Equal(t, want, got)
}
6 changes: 3 additions & 3 deletions internal/provider/resources/public_cloud/instance/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (i *instanceResource) Schema(
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Required: true,
Description: "Image ID." + warningError,
Description: "Can be either an Operating System or a UUID in case of a Custom Image ID." + warningError,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Expand Down Expand Up @@ -137,7 +137,7 @@ func (i *instanceResource) Schema(
"root_disk_size": schema.Int64Attribute{
Computed: true,
Optional: true,
Description: "The root disk's size in GB. Must be at least 5 GB for Linux and FreeBSD instances and 50 GB for Windows instances",
Description: "The root disk's size in GB. Must be at least 5 GB for Linux and FreeBSD instances and 50 GB for Windows instances. The maximum size is 1000 GB",
Validators: []validator.Int64{
int64validator.Between(
facade.GetMinimumRootDiskSize(),
Expand All @@ -147,7 +147,7 @@ func (i *instanceResource) Schema(
},
"root_disk_storage_type": schema.StringAttribute{
Required: true,
Description: "The root disk's storage type." + warningError,
Description: "The root disk's storage type. Can be *LOCAL* or *CENTRAL*. " + warningError,
Validators: []validator.String{
stringvalidator.OneOf(facade.GetRootDiskStorageTypes()...),
},
Expand Down
Loading

0 comments on commit 9d31c7f

Please sign in to comment.