From 285800c382650c153511ef2f737c4be8d330aed2 Mon Sep 17 00:00:00 2001 From: Arnout Hoebreckx Date: Sat, 6 May 2023 22:39:41 +0200 Subject: [PATCH] Update goreleaser --- .gitignore | 3 +- .goreleaser.yaml | 48 +++++++++++++++++++ client/virtualmachinemanager.go | 29 ++++++------ provider/resource_vmm_guest.go | 71 ++++++++++++++--------------- provider/resource_vmm_guest_test.go | 2 +- 5 files changed, 100 insertions(+), 53 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.gitignore b/.gitignore index 06cd65d..2ccbd5b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ examples/.terraform* examples/terraform.tfstate* examples/main* bin -.vscode \ No newline at end of file +.vscode +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..591ad53 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,48 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... +builds: + - env: + - CGO_ENABLED=0 + goarch: + - amd64 + - 386 + goos: + - linux + - windows + - darwin + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + +# The lines beneath this are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj diff --git a/client/virtualmachinemanager.go b/client/virtualmachinemanager.go index f36d61c..155f310 100644 --- a/client/virtualmachinemanager.go +++ b/client/virtualmachinemanager.go @@ -49,7 +49,6 @@ type GuestInfo struct { } type CreateGuestVnicRequest struct { - } type CreateGuestResponse struct { @@ -251,17 +250,17 @@ func (vdisk VDisk) String() string { func createValidRequestMap(input []interface{}, allowedKeys []string) []map[string]interface{} { var output []map[string]interface{} - for _, elem := range input { - if v, ok := elem.(map[string]interface{}); ok { - filtered := make(map[string]interface{}) - for _, k := range allowedKeys { - if val, found := v[k]; found && val != nil && val != "" { - filtered[k] = val - } - } - output = append(output, filtered) - } - } - - return output -} \ No newline at end of file + for _, elem := range input { + if v, ok := elem.(map[string]interface{}); ok { + filtered := make(map[string]interface{}) + for _, k := range allowedKeys { + if val, found := v[k]; found && val != nil && val != "" { + filtered[k] = val + } + } + output = append(output, filtered) + } + } + + return output +} diff --git a/provider/resource_vmm_guest.go b/provider/resource_vmm_guest.go index 1605e62..26be77a 100644 --- a/provider/resource_vmm_guest.go +++ b/provider/resource_vmm_guest.go @@ -2,11 +2,11 @@ package provider import ( "context" + "fmt" "github.com/arnouthoebreckx/terraform-provider-synology/client" "log" "strconv" "time" - "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -24,10 +24,10 @@ func guestItem() *schema.Resource { Required: true, Description: "The guest name", }, - "guest_id": { + "guest_id": { Type: schema.TypeString, Optional: true, - Computed: true, + Computed: true, Description: "The guest name", }, "description": { @@ -35,19 +35,19 @@ func guestItem() *schema.Resource { Optional: true, Description: "Optional. The description of the guest.", }, - "poweron": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Optional. Default VM is not powered on.", - }, + "poweron": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Optional. Default VM is not powered on.", + }, "autorun": { Type: schema.TypeInt, Optional: true, Default: 0, Description: "Optional. 0: off 1: last state 2: on", }, - "status": { + "status": { Type: schema.TypeString, Computed: true, Description: "The guest status. (running/shutdown/inaccessiblen/booting/shutting_down/moving/stor_migrating/creating/importing/preparing/ha_standby/unknown/crashed/undefined", @@ -96,13 +96,13 @@ func guestItem() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, + ForceNew: true, Description: "Optional. Connected network group id. At least network_id or network_name should be given. Note: network_id can be an empty string to represent not being connected.", }, "network_name": { Type: schema.TypeString, Optional: true, - ForceNew: true, + ForceNew: true, Description: "Optional. Connected network group name. At least network_id or network_name should be given.", }, "vnic_id": { @@ -122,34 +122,34 @@ func guestItem() *schema.Resource { "create_type": { Type: schema.TypeInt, Required: true, - ForceNew: true, + ForceNew: true, Description: "0: Create an empty vDisk, 1: Clone an existing image", }, "vdisk_size": { Type: schema.TypeInt, Optional: true, - ForceNew: true, + ForceNew: true, Description: "Optional. If create_type is 0, this field must be set. The created vDisk size in MB.", - ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { - if size, ok := val.(int); ok { - if size < 10240 { - errs = append(errs, fmt.Errorf("%q must be greater than 10240", key)) - } - } - return - }, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + if size, ok := val.(int); ok { + if size < 10240 { + errs = append(errs, fmt.Errorf("%q must be greater than 10240", key)) + } + } + return + }, }, "image_id": { Type: schema.TypeString, Computed: true, Optional: true, - ForceNew: true, + ForceNew: true, Description: "Optional. If create_type is 1, at least image_id or image_name should be given. The id of the image that is to be cloned. Note: Image type should be disk.", }, "image_name": { Type: schema.TypeString, Optional: true, - ForceNew: true, + ForceNew: true, Description: "Optional. If create_type is 1, at least image_id or image_name should be given. The name of the image that is to be cloned. Note: Image type should be disk.", }, "controller": { @@ -254,7 +254,6 @@ func resourceGuestCreateItem(ctx context.Context, d *schema.ResourceData, m inte return diags } - func resourceGuestReadItem(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics @@ -329,12 +328,12 @@ func resourceGuestDeleteItem(ctx context.Context, d *schema.ResourceData, m inte service := GuestService{synologyClient: client} name := d.Get("guest_name").(string) - // Incase of recreate turn off the VM - err := service.Power(name, false) - if err != nil { - return diag.FromErr(err) - } - time.Sleep(10 * time.Second) + // Incase of recreate turn off the VM + err := service.Power(name, false) + if err != nil { + return diag.FromErr(err) + } + time.Sleep(10 * time.Second) err = service.Delete(name) @@ -346,8 +345,8 @@ func resourceGuestDeleteItem(ctx context.Context, d *schema.ResourceData, m inte } func getShutdownNeeded(d *schema.ResourceData, shutdown_updates []string) bool { - if d.HasChanges(shutdown_updates...) { - return true - } - return false -} \ No newline at end of file + if d.HasChanges(shutdown_updates...) { + return true + } + return false +} diff --git a/provider/resource_vmm_guest_test.go b/provider/resource_vmm_guest_test.go index 455c1c1..50420ba 100644 --- a/provider/resource_vmm_guest_test.go +++ b/provider/resource_vmm_guest_test.go @@ -89,4 +89,4 @@ func testAccCheckSynologyVMMGuestExists(guestName string) resource.TestCheckFunc return nil } -} \ No newline at end of file +}