Skip to content

Commit

Permalink
feat: tf - update block-storage (#1255)
Browse files Browse the repository at this point in the history
* feat: tf - update block-storage
  • Loading branch information
geffersonFerraz authored Nov 14, 2024
1 parent 6763542 commit e7f9104
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ mgc/spec_manipulator/cli_specs/specs.go.tmp
terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.d
**/__debug_bin**
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@ repos:
- id: tf-docs
name: generate terraform documentation
language: system
entry: bash -c 'if [ "$SKIP_TF_STEP" != "true" ]; then make -C ./mgc/terraform-provider-mgc/ generate-docs; else echo "Skipped"; fi'
# entry: make -C ./mgc/terraform-provider-mgc/ generate-docs
entry: make -C ./mgc/terraform-provider-mgc/ generate-docs
require_serial: true
pass_filenames: false
stages: [pre-commit]
- id: check-tf-examples
name: check terraform examples
language: system
entry: bash -c 'if [ "$SKIP_TF_STEP" != "true" ]; then make -C ./mgc/terraform-provider-mgc/ check-example-usage; else echo "Skipped"; fi'
# entry: make -C ./mgc/terraform-provider-mgc/ check-example-usage
entry: make -C ./mgc/terraform-provider-mgc/ check-example-usage
require_serial: true
pass_filenames: false
stages: [pre-commit]
- id: check-tf-docs
name: check terraform documentation subcategory
language: system
entry: bash -c 'if [ "$SKIP_TF_STEP" != "true" ]; then make -C ./mgc/terraform-provider-mgc/ check-empty-subcategory; else echo "Skipped"; fi'
# entry: make -C ./mgc/terraform-provider-mgc/ check-empty-subcategory
entry: make -C ./mgc/terraform-provider-mgc/ check-empty-subcategory
require_serial: true
pass_filenames: false
stages: [pre-commit]
Expand Down
4 changes: 2 additions & 2 deletions mgc/lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.23.0
toolchain go1.23.2

require (
magalu.cloud/core v0.29.2
magalu.cloud/sdk v0.29.2
magalu.cloud/core v0.30.0
magalu.cloud/sdk v0.30.0
)

require (
Expand Down
14 changes: 11 additions & 3 deletions mgc/lib/products/block_storage/snapshots/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ import (
)

type CreateParameters struct {
Description *string `json:"description"`
Name string `json:"name"`
Volume CreateParametersVolume `json:"volume"`
Description *string `json:"description"`
Name string `json:"name"`
SourceSnapshot *CreateParametersSourceSnapshot `json:"source_snapshot,omitempty"`
Type *string `json:"type,omitempty"`
Volume *CreateParametersVolume `json:"volume,omitempty"`
}

// any of: CreateParametersSourceSnapshot
type CreateParametersSourceSnapshot struct {
Id string `json:"id"`
Name *string `json:"name,omitempty"`
}

// any of: CreateParametersVolume
Expand Down
24 changes: 14 additions & 10 deletions mgc/lib/products/block_storage/snapshots/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ type GetConfigs struct {
}

type GetResult struct {
CreatedAt string `json:"created_at"`
Description *string `json:"description"`
Error *GetResultError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
Volume GetResultVolume `json:"volume"`
AvailabilityZones GetResultAvailabilityZones `json:"availability_zones"`
CreatedAt string `json:"created_at"`
Description *string `json:"description"`
Error *GetResultError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
Type string `json:"type"`
UpdatedAt string `json:"updated_at"`
Volume GetResultVolume `json:"volume"`
}

type GetResultAvailabilityZones []string

type GetResultError struct {
Message string `json:"message"`
Slug string `json:"slug"`
Expand Down
26 changes: 16 additions & 10 deletions mgc/lib/products/block_storage/snapshots/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type ListParameters struct {
Offset *int `json:"_offset,omitempty"`
Sort *string `json:"_sort,omitempty"`
Expand *ListParametersExpand `json:"expand,omitempty"`
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
}

type ListParametersExpand []string
Expand All @@ -46,18 +48,22 @@ type ListResult struct {
}

type ListResultSnapshotsItem struct {
CreatedAt string `json:"created_at"`
Description *string `json:"description"`
Error *ListResultSnapshotsItemError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
Volume ListResultSnapshotsItemVolume `json:"volume"`
AvailabilityZones ListResultSnapshotsItemAvailabilityZones `json:"availability_zones"`
CreatedAt string `json:"created_at"`
Description *string `json:"description"`
Error *ListResultSnapshotsItemError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
Type string `json:"type"`
UpdatedAt string `json:"updated_at"`
Volume ListResultSnapshotsItemVolume `json:"volume"`
}

type ListResultSnapshotsItemAvailabilityZones []string

type ListResultSnapshotsItemError struct {
Message string `json:"message"`
Slug string `json:"slug"`
Expand Down
26 changes: 21 additions & 5 deletions mgc/lib/products/block_storage/volume_types/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
mgcHelpers "magalu.cloud/lib/helpers"
)

type ListParameters struct {
AvailabilityZone *string `json:"availability-zone,omitempty"`
}

type ListConfigs struct {
Env *string `json:"env,omitempty"`
Region *string `json:"region,omitempty"`
Expand All @@ -38,21 +42,26 @@ type ListResult struct {
}

type ListResultTypesItem struct {
DiskType string `json:"disk_type"`
Id string `json:"id"`
Iops ListResultTypesItemIops `json:"iops"`
Name string `json:"name"`
Status string `json:"status"`
AvailabilityZones ListResultTypesItemAvailabilityZones `json:"availability_zones"`
DiskType string `json:"disk_type"`
Id string `json:"id"`
Iops ListResultTypesItemIops `json:"iops"`
Name string `json:"name"`
Status string `json:"status"`
}

type ListResultTypesItemAvailabilityZones []string

type ListResultTypesItemIops struct {
Read int `json:"read"`
Total int `json:"total"`
Write int `json:"write"`
}

type ListResultTypes []ListResultTypesItem

func (s *service) List(
parameters ListParameters,
configs ListConfigs,
) (
result ListResult,
Expand All @@ -64,6 +73,9 @@ func (s *service) List(
}

var p mgcCore.Parameters
if p, err = mgcHelpers.ConvertParameters[ListParameters](parameters); err != nil {
return
}

var c mgcCore.Configs
if c, err = mgcHelpers.ConvertConfigs[ListConfigs](configs); err != nil {
Expand All @@ -80,6 +92,7 @@ func (s *service) List(
// Context from caller is used to allow cancellation of long-running requests
func (s *service) ListContext(
ctx context.Context,
parameters ListParameters,
configs ListConfigs,
) (
result ListResult,
Expand All @@ -91,6 +104,9 @@ func (s *service) ListContext(
}

var p mgcCore.Parameters
if p, err = mgcHelpers.ConvertParameters[ListParameters](parameters); err != nil {
return
}

var c mgcCore.Configs
if c, err = mgcHelpers.ConvertConfigs[ListConfigs](configs); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions mgc/lib/products/block_storage/volume_types/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type service struct {
}

type Service interface {
ListContext(ctx context.Context, configs ListConfigs) (result ListResult, err error)
List(configs ListConfigs) (result ListResult, err error)
ListContext(ctx context.Context, parameters ListParameters, configs ListConfigs) (result ListResult, err error)
List(parameters ListParameters, configs ListConfigs) (result ListResult, err error)
}

func NewService(ctx context.Context, client *mgcClient.Client) Service {
Expand Down
16 changes: 5 additions & 11 deletions mgc/lib/products/block_storage/volumes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ import (
)

type CreateParameters struct {
Backup *CreateParametersBackup `json:"backup,omitempty"`
Name string `json:"name"`
Size int `json:"size"`
Snapshot *CreateParametersSnapshot `json:"snapshot,omitempty"`
Type CreateParametersType `json:"type"`
}

// any of: CreateParametersBackup
type CreateParametersBackup struct {
Id string `json:"id"`
Name *string `json:"name,omitempty"`
AvailabilityZone *string `json:"availability_zone,omitempty"`
Name string `json:"name"`
Size int `json:"size"`
Snapshot *CreateParametersSnapshot `json:"snapshot,omitempty"`
Type CreateParametersType `json:"type"`
}

// any of: CreateParametersSnapshot
Expand Down
24 changes: 14 additions & 10 deletions mgc/lib/products/block_storage/volumes/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ type GetConfigs struct {
}

type GetResult struct {
Attachment *GetResultAttachment `json:"attachment,omitempty"`
CreatedAt string `json:"created_at"`
Error *GetResultError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
Type GetResultType `json:"type"`
UpdatedAt string `json:"updated_at"`
Attachment *GetResultAttachment `json:"attachment,omitempty"`
AvailabilityZones GetResultAvailabilityZones `json:"availability_zones"`
CreatedAt string `json:"created_at"`
Error *GetResultError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
Type GetResultType `json:"type"`
UpdatedAt string `json:"updated_at"`
}

type GetResultAttachment struct {
Expand All @@ -71,6 +72,8 @@ type GetResultAttachmentInstance struct {
UpdatedAt string `json:"updated_at"`
}

type GetResultAvailabilityZones []string

type GetResultError struct {
Message string `json:"message"`
Slug string `json:"slug"`
Expand All @@ -87,6 +90,7 @@ type GetResultType struct {

type GetResultTypeIops struct {
Read int `json:"read"`
Total int `json:"total"`
Write int `json:"write"`
}

Expand Down
26 changes: 16 additions & 10 deletions mgc/lib/products/block_storage/volumes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type ListParameters struct {
Offset *int `json:"_offset,omitempty"`
Sort *string `json:"_sort,omitempty"`
Expand *ListParametersExpand `json:"expand,omitempty"`
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
}

type ListParametersExpand []string
Expand All @@ -45,16 +47,17 @@ type ListResult struct {
}

type ListResultVolumesItem struct {
Attachment *ListResultVolumesItemAttachment `json:"attachment,omitempty"`
CreatedAt string `json:"created_at"`
Error *ListResultVolumesItemError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
Type ListResultVolumesItemType `json:"type"`
UpdatedAt string `json:"updated_at"`
Attachment *ListResultVolumesItemAttachment `json:"attachment,omitempty"`
AvailabilityZones ListResultVolumesItemAvailabilityZones `json:"availability_zones"`
CreatedAt string `json:"created_at"`
Error *ListResultVolumesItemError `json:"error,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
Status string `json:"status"`
Type ListResultVolumesItemType `json:"type"`
UpdatedAt string `json:"updated_at"`
}

type ListResultVolumesItemAttachment struct {
Expand All @@ -77,9 +80,12 @@ type ListResultVolumesItemAttachmentInstance struct {

type ListResultVolumesItemAttachmentInstanceIops struct {
Read int `json:"read"`
Total int `json:"total"`
Write int `json:"write"`
}

type ListResultVolumesItemAvailabilityZones []string

type ListResultVolumesItemError struct {
Message string `json:"message"`
Slug string `json:"slug"`
Expand Down
1 change: 1 addition & 0 deletions mgc/lib/products/block_storage/volumes/retype.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type RetypeParametersNewType struct {

type RetypeParametersNewTypeIops struct {
Read int `json:"read"`
Total int `json:"total"`
Write int `json:"write"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ The block storage snapshots resource allows you to manage block storage snapshot
resource "mgc_block_storage_snapshots" "snapshot_example" {
description = "example of description"
name = "exemplo snapshot name"
snapshot_source_id = mgc_block_storage_snapshots.other_snapshot.id
type = "instant"
volume = {
id = mgc_block_storage_volumes.example_volume.id
}
}
resource "mgc_block_storage_snapshots" "snapshot_of_snap_example" {
snapshot_source_id = mgc_block_storage_snapshots.snapshot_example.id
type = "object"
description = "exampleDescription"
name = "exampleName"
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -29,14 +38,17 @@ resource "mgc_block_storage_snapshots" "snapshot_example" {

- `description` (String) The description of the volume snapshot.
- `name` (String) The name of the volume snapshot.
- `volume` (Attributes) (see [below for nested schema](#nestedatt--volume))

### Optional

- `name_is_prefix` (Boolean) Indicates whether the provided name is a prefix or the exact name of the volume snapshot.
- `snapshot_source_id` (String) The ID of the snapshot source.
- `type` (String) The type of the snapshot.
- `volume` (Attributes) (see [below for nested schema](#nestedatt--volume))

### Read-Only

- `availability_zones` (List of String) The availability zones of the snapshot.
- `created_at` (String) The timestamp when the block storage was created.
- `final_name` (String) The final name of the volume snapshot after applying any naming conventions or modifications.
- `id` (String) The unique identifier of the volume snapshot.
Expand Down
Loading

0 comments on commit e7f9104

Please sign in to comment.