From d776a86303bc8d8f64b97a91b54433047bd3cfd4 Mon Sep 17 00:00:00 2001 From: Petr Krutov Date: Mon, 27 Jun 2022 11:11:17 +0300 Subject: [PATCH 1/3] Dev --- CHANGELOG.md | 2 ++ decort/controller.go | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06aeaff..88fa8aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - changing boot\_disk\_size in kvmvm - downsizing CPU and RAM in kvmvm - pfw recreation if public\_port\_end unspecified +- uninformative error message when retrying on 500 +- hardcoded 3 minute timeout ### New datasources - disk\_list diff --git a/decort/controller.go b/decort/controller.go index 25e27ea..19a5ac1 100644 --- a/decort/controller.go +++ b/decort/controller.go @@ -27,7 +27,6 @@ package decort import ( "bytes" "crypto/tls" - "errors" "fmt" "io/ioutil" "net/http" @@ -140,12 +139,9 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) { transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} //nolint:gosec ret_config.cc_client = &http.Client{ Transport: transCfg, - Timeout: Timeout180s, } } else { - ret_config.cc_client = &http.Client{ - Timeout: Timeout180s, // time.Second * 30, - } + ret_config.cc_client = &http.Client{} } switch ret_config.auth_mode_code { @@ -379,13 +375,15 @@ func (config *ControllerCfg) decortAPICall(method string, api_name string, url_v req.Header.Set("Authorization", fmt.Sprintf("bearer %s", config.jwt)) } + var resp *http.Response + var body []byte for i := 0; i < 5; i++ { - resp, err := config.cc_client.Do(req) + resp, err = config.cc_client.Do(req) if err != nil { return "", err } - body, err := ioutil.ReadAll(resp.Body) + body, err = ioutil.ReadAll(resp.Body) if err != nil { return "", err } @@ -405,5 +403,6 @@ func (config *ControllerCfg) decortAPICall(method string, api_name string, url_v } } - return "", errors.New("number of retries exceeded") + return "", fmt.Errorf("decortAPICall: unexpected status code %d when calling API %q with request Body %q. Respone:\n%s", + resp.StatusCode, req.URL, params_str, body) } From 3613bbea28c9739ec5cdbeb1a4ddeb0678e12823 Mon Sep 17 00:00:00 2001 From: stSolo Date: Wed, 29 Jun 2022 11:34:14 +0300 Subject: [PATCH 2/3] Migrate to sdkv2 and project structure refactoring --- .gitignore | 1 + Makefile | 4 +- main.go => cmd/decort/main.go | 16 +- decort/data_source_account_deleted_list.go | 58 - decort/data_source_bservice_deleted_list.go | 58 - decort/models_api.go | 1486 ----------------- decort/provider.go | 196 --- go.mod | 2 +- go.sum | 87 + internal/constants/api.go | 26 + {decort => internal/constants}/constants.go | 27 +- internal/constants/timeouts.go | 28 + {decort => internal/controller}/controller.go | 22 +- internal/flattens/meta.go | 41 + internal/location/api.go | 22 + .../location/location.go | 124 +- internal/location/models.go | 30 + internal/provider/data_sources_map.go | 87 + internal/provider/provider.go | 134 ++ internal/provider/resource_map.go | 58 + internal/service/cloudapi/account/api.go | 55 + .../cloudapi/account}/data_source_account.go | 54 +- .../data_source_account_audits_list.go | 35 +- .../data_source_account_computes_list.go | 35 +- .../data_source_account_consumed_units.go | 35 +- ...a_source_account_consumed_units_by_type.go | 35 +- .../data_source_account_deleted_list.go | 69 + .../data_source_account_disks_list.go | 36 +- .../data_source_account_flipgroups_list.go | 35 +- .../account}/data_source_account_list.go | 51 +- .../data_source_account_reserved_units.go | 35 +- .../account}/data_source_account_rg_list.go | 35 +- .../data_source_account_templates_list.go | 35 +- .../account}/data_source_account_vins_list.go | 35 +- internal/service/cloudapi/account/models.go | 260 +++ .../cloudapi/account}/resource_account.go | 123 +- .../cloudapi/account}/utility_account.go | 24 +- .../account}/utility_account_audits_list.go | 24 +- .../account}/utility_account_computes_list.go | 24 +- .../utility_account_consumed_units.go | 24 +- .../utility_account_consumed_units_by_type.go | 24 +- .../account}/utility_account_deleted_list.go | 24 +- .../account}/utility_account_disks_list.go | 24 +- .../account}/utility_account_flip_groups.go | 24 +- .../cloudapi/account}/utility_account_list.go | 24 +- .../utility_account_reserved_units.go | 24 +- .../account}/utility_account_rg_list.go | 24 +- .../utility_account_templates_list.go | 24 +- .../account}/utility_account_vins_list.go | 24 +- internal/service/cloudapi/bservice/api.go | 59 + .../bservice}/data_source_bservice.go | 35 +- .../data_source_bservice_deleted_list.go | 69 + .../bservice}/data_source_bservice_group.go | 35 +- .../bservice}/data_source_bservice_list.go | 35 +- .../data_source_bservice_snapshot_list.go | 35 +- internal/service/cloudapi/bservice/models.go | 144 ++ .../cloudapi/bservice}/resource_bservice.go | 112 +- .../bservice}/resource_bservice_group.go | 122 +- .../utility_bservicce_deleted_list.go | 24 +- .../cloudapi/bservice}/utility_bservice.go | 24 +- .../bservice}/utility_bservice_group.go | 24 +- .../bservice}/utility_bservice_list.go | 24 +- .../utility_bservice_snapshot_list.go | 24 +- internal/service/cloudapi/disks/api.go | 39 + .../cloudapi/disks}/data_source_disk.go | 88 +- .../cloudapi/disks}/data_source_disk_list.go | 36 +- internal/service/cloudapi/disks/models.go | 95 ++ .../service/cloudapi/disks}/resource_disk.go | 101 +- .../service/cloudapi/disks}/utility_disk.go | 28 +- .../cloudapi/disks}/utility_disk_list.go | 24 +- internal/service/cloudapi/extnet/api.go | 37 + .../cloudapi/extnet}/data_source_extnet.go | 38 +- .../data_source_extnet_computes_list.go | 35 +- .../extnet}/data_source_extnet_default.go | 36 +- .../extnet}/data_source_extnet_list.go | 35 +- internal/service/cloudapi/extnet/models.go | 111 ++ .../cloudapi/extnet}/utility_extnet.go | 24 +- .../extnet}/utility_extnet_computes_list.go | 24 +- .../extnet}/utility_extnet_default.go | 24 +- .../cloudapi/extnet}/utility_extnet_list.go | 24 +- internal/service/cloudapi/k8s/api.go | 49 + internal/service/cloudapi/k8s/models.go | 131 ++ .../service/cloudapi/k8s}/node_subresource.go | 19 +- .../service/cloudapi/k8s}/resource_k8s.go | 113 +- .../service/cloudapi/k8s}/resource_k8s_wg.go | 81 +- .../service/cloudapi/k8s}/utility_k8s.go | 24 +- .../service/cloudapi/k8s}/utility_k8s_wg.go | 24 +- internal/service/cloudapi/kvmvm/api.go | 46 + .../cloudapi/kvmvm}/data_source_compute.go | 41 +- internal/service/cloudapi/kvmvm/models.go | 190 +++ .../cloudapi/kvmvm}/network_subresource.go | 32 +- .../cloudapi/kvmvm}/osusers_subresource.go | 23 +- .../cloudapi/kvmvm}/resource_compute.go | 147 +- .../cloudapi/kvmvm}/utility_compute.go | 51 +- internal/service/cloudapi/pfw/api.go | 36 + internal/service/cloudapi/pfw/models.go | 45 + .../service/cloudapi/pfw}/resource_pfw.go | 71 +- .../service/cloudapi/pfw}/utility_pfw.go | 24 +- internal/service/cloudapi/rg/api.go | 39 + .../service/cloudapi/rg}/data_source_rg.go | 83 +- .../cloudapi/rg}/data_source_rg_list.go | 35 +- internal/service/cloudapi/rg/models.go | 149 ++ .../service/cloudapi/rg}/quota_subresource.go | 27 +- .../service/cloudapi/rg}/resource_rg.go | 103 +- .../service/cloudapi/rg}/utility_rg.go | 31 +- .../service/cloudapi/rg}/utility_rg_list.go | 24 +- internal/service/cloudapi/snapshot/api.go | 37 + .../snapshot}/data_source_snapshot_list.go | 35 +- internal/service/cloudapi/snapshot/models.go | 41 + .../cloudapi/snapshot}/resource_snapshot.go | 100 +- .../cloudapi/snapshot}/utility_snapshot.go | 19 +- .../snapshot}/utility_snapshot_list.go | 26 +- internal/service/cloudapi/vgpu/api.go | 34 + .../cloudapi/vgpu}/data_source_vgpu.go | 29 +- internal/service/cloudapi/vgpu/models.go | 44 + .../service/cloudapi/vgpu}/utility_vgpu.go | 24 +- internal/service/cloudapi/vins/api.go | 44 + .../cloudapi/vins}/data_source_vins.go | 42 +- .../cloudapi/vins}/data_source_vins_list.go | 35 +- internal/service/cloudapi/vins/models.go | 94 ++ .../service/cloudapi/vins}/resource_vins.go | 97 +- .../service/cloudapi/vins}/utility_vins.go | 30 +- .../cloudapi/vins}/utility_vins_list.go | 24 +- internal/service/cloudbroker/grid/api.go | 35 + .../cloudbroker/grid}/data_source_grid.go | 34 +- .../grid}/data_source_grid_list.go | 35 +- internal/service/cloudbroker/grid/models.go | 43 + .../service/cloudbroker/grid}/utility_grid.go | 24 +- .../cloudbroker/grid}/utility_grid_list.go | 24 +- internal/service/cloudbroker/image/api.go | 52 + .../cloudbroker/image}/data_source_image.go | 37 +- .../image}/data_source_image_list.go | 35 +- .../image}/data_source_image_list_stacks.go | 35 +- internal/service/cloudbroker/image/models.go | 101 ++ .../image}/resource_cdrom_image.go | 120 +- .../image}/resource_delete_images.go | 53 +- .../cloudbroker/image}/resource_image.go | 241 +-- .../image}/resource_virtual_image.go | 111 +- .../cloudbroker/image}/utility_image.go | 24 +- .../cloudbroker/image}/utility_image_list.go | 24 +- .../image}/utility_image_list_stacks.go | 24 +- internal/service/cloudbroker/pcidevice/api.go | 38 + .../pcidevice}/data_source_pcidevice.go | 37 +- .../pcidevice}/data_source_pcidevice_list.go | 38 +- .../service/cloudbroker/pcidevice/models.go | 49 + .../pcidevice}/resource_pcidevice.go | 99 +- .../pcidevice}/utility_pcidevice.go | 19 +- .../pcidevice}/utility_pcidevice_list.go | 24 +- internal/service/cloudbroker/sep/api.go | 59 + .../cloudbroker/sep}/data_source_sep.go | 37 +- .../sep}/data_source_sep_config.go | 34 +- .../sep}/data_source_sep_consumption.go | 35 +- .../sep}/data_source_sep_disk_list.go | 35 +- .../cloudbroker/sep}/data_source_sep_list.go | 37 +- .../cloudbroker/sep}/data_source_sep_pool.go | 34 +- internal/service/cloudbroker/sep/models.go | 77 + .../service/cloudbroker/sep}/resource_sep.go | 197 ++- .../cloudbroker/sep}/resource_sep_config.go | 88 +- .../service/cloudbroker/sep}/utility_sep.go | 24 +- .../cloudbroker/sep}/utility_sep_config.go | 24 +- .../sep}/utility_sep_consumption.go | 24 +- .../cloudbroker/sep}/utility_sep_disk_list.go | 24 +- .../cloudbroker/sep}/utility_sep_list.go | 24 +- .../cloudbroker/sep}/utility_sep_pool.go | 24 +- 164 files changed, 5946 insertions(+), 3927 deletions(-) rename main.go => cmd/decort/main.go (73%) delete mode 100644 decort/data_source_account_deleted_list.go delete mode 100644 decort/data_source_bservice_deleted_list.go delete mode 100644 decort/models_api.go delete mode 100644 decort/provider.go create mode 100644 internal/constants/api.go rename {decort => internal/constants}/constants.go (65%) create mode 100644 internal/constants/timeouts.go rename {decort => internal/controller}/controller.go (95%) create mode 100644 internal/flattens/meta.go create mode 100644 internal/location/api.go rename decort/utility_location.go => internal/location/location.go (64%) create mode 100644 internal/location/models.go create mode 100644 internal/provider/data_sources_map.go create mode 100644 internal/provider/provider.go create mode 100644 internal/provider/resource_map.go create mode 100644 internal/service/cloudapi/account/api.go rename {decort => internal/service/cloudapi/account}/data_source_account.go (86%) rename {decort => internal/service/cloudapi/account}/data_source_account_audits_list.go (66%) rename {decort => internal/service/cloudapi/account}/data_source_account_computes_list.go (77%) rename {decort => internal/service/cloudapi/account}/data_source_account_consumed_units.go (62%) rename {decort => internal/service/cloudapi/account}/data_source_account_consumed_units_by_type.go (56%) create mode 100644 internal/service/cloudapi/account/data_source_account_deleted_list.go rename {decort => internal/service/cloudapi/account}/data_source_account_disks_list.go (67%) rename {decort => internal/service/cloudapi/account}/data_source_account_flipgroups_list.go (77%) rename {decort => internal/service/cloudapi/account}/data_source_account_list.go (79%) rename {decort => internal/service/cloudapi/account}/data_source_account_reserved_units.go (62%) rename {decort => internal/service/cloudapi/account}/data_source_account_rg_list.go (83%) rename {decort => internal/service/cloudapi/account}/data_source_account_templates_list.go (70%) rename {decort => internal/service/cloudapi/account}/data_source_account_vins_list.go (75%) create mode 100644 internal/service/cloudapi/account/models.go rename {decort => internal/service/cloudapi/account}/resource_account.go (81%) rename {decort => internal/service/cloudapi/account}/utility_account.go (63%) rename {decort => internal/service/cloudapi/account}/utility_account_audits_list.go (60%) rename {decort => internal/service/cloudapi/account}/utility_account_computes_list.go (60%) rename {decort => internal/service/cloudapi/account}/utility_account_consumed_units.go (60%) rename {decort => internal/service/cloudapi/account}/utility_account_consumed_units_by_type.go (59%) rename {decort => internal/service/cloudapi/account}/utility_account_deleted_list.go (61%) rename {decort => internal/service/cloudapi/account}/utility_account_disks_list.go (59%) rename {decort => internal/service/cloudapi/account}/utility_account_flip_groups.go (60%) rename {decort => internal/service/cloudapi/account}/utility_account_list.go (70%) rename {decort => internal/service/cloudapi/account}/utility_account_reserved_units.go (59%) rename {decort => internal/service/cloudapi/account}/utility_account_rg_list.go (59%) rename {decort => internal/service/cloudapi/account}/utility_account_templates_list.go (60%) rename {decort => internal/service/cloudapi/account}/utility_account_vins_list.go (59%) create mode 100644 internal/service/cloudapi/bservice/api.go rename {decort => internal/service/cloudapi/bservice}/data_source_bservice.go (82%) create mode 100644 internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go rename {decort => internal/service/cloudapi/bservice}/data_source_bservice_group.go (81%) rename {decort => internal/service/cloudapi/bservice}/data_source_bservice_list.go (79%) rename {decort => internal/service/cloudapi/bservice}/data_source_bservice_snapshot_list.go (61%) create mode 100644 internal/service/cloudapi/bservice/models.go rename {decort => internal/service/cloudapi/bservice}/resource_bservice.go (77%) rename {decort => internal/service/cloudapi/bservice}/resource_bservice_group.go (78%) rename {decort => internal/service/cloudapi/bservice}/utility_bservicce_deleted_list.go (65%) rename {decort => internal/service/cloudapi/bservice}/utility_bservice.go (61%) rename {decort => internal/service/cloudapi/bservice}/utility_bservice_group.go (62%) rename {decort => internal/service/cloudapi/bservice}/utility_bservice_list.go (64%) rename {decort => internal/service/cloudapi/bservice}/utility_bservice_snapshot_list.go (61%) create mode 100644 internal/service/cloudapi/disks/api.go rename {decort => internal/service/cloudapi/disks}/data_source_disk.go (69%) rename {decort => internal/service/cloudapi/disks}/data_source_disk_list.go (86%) create mode 100644 internal/service/cloudapi/disks/models.go rename {decort => internal/service/cloudapi/disks}/resource_disk.go (76%) rename {decort => internal/service/cloudapi/disks}/utility_disk.go (82%) rename {decort => internal/service/cloudapi/disks}/utility_disk_list.go (65%) create mode 100644 internal/service/cloudapi/extnet/api.go rename {decort => internal/service/cloudapi/extnet}/data_source_extnet.go (81%) rename {decort => internal/service/cloudapi/extnet}/data_source_extnet_computes_list.go (73%) rename {decort => internal/service/cloudapi/extnet}/data_source_extnet_default.go (53%) rename {decort => internal/service/cloudapi/extnet}/data_source_extnet_list.go (65%) create mode 100644 internal/service/cloudapi/extnet/models.go rename {decort => internal/service/cloudapi/extnet}/utility_extnet.go (58%) rename {decort => internal/service/cloudapi/extnet}/utility_extnet_computes_list.go (59%) rename {decort => internal/service/cloudapi/extnet}/utility_extnet_default.go (53%) rename {decort => internal/service/cloudapi/extnet}/utility_extnet_list.go (63%) create mode 100644 internal/service/cloudapi/k8s/api.go create mode 100644 internal/service/cloudapi/k8s/models.go rename {decort => internal/service/cloudapi/k8s}/node_subresource.go (77%) rename {decort => internal/service/cloudapi/k8s}/resource_k8s.go (73%) rename {decort => internal/service/cloudapi/k8s}/resource_k8s_wg.go (68%) rename {decort => internal/service/cloudapi/k8s}/utility_k8s.go (58%) rename {decort => internal/service/cloudapi/k8s}/utility_k8s_wg.go (63%) create mode 100644 internal/service/cloudapi/kvmvm/api.go rename {decort => internal/service/cloudapi/kvmvm}/data_source_compute.go (89%) create mode 100644 internal/service/cloudapi/kvmvm/models.go rename {decort => internal/service/cloudapi/kvmvm}/network_subresource.go (83%) rename {decort => internal/service/cloudapi/kvmvm}/osusers_subresource.go (73%) rename {decort => internal/service/cloudapi/kvmvm}/resource_compute.go (80%) rename {decort => internal/service/cloudapi/kvmvm}/utility_compute.go (86%) create mode 100644 internal/service/cloudapi/pfw/api.go create mode 100644 internal/service/cloudapi/pfw/models.go rename {decort => internal/service/cloudapi/pfw}/resource_pfw.go (68%) rename {decort => internal/service/cloudapi/pfw}/utility_pfw.go (63%) create mode 100644 internal/service/cloudapi/rg/api.go rename {decort => internal/service/cloudapi/rg}/data_source_rg.go (68%) rename {decort => internal/service/cloudapi/rg}/data_source_rg_list.go (84%) create mode 100644 internal/service/cloudapi/rg/models.go rename {decort => internal/service/cloudapi/rg}/quota_subresource.go (84%) rename {decort => internal/service/cloudapi/rg}/resource_rg.go (79%) rename {decort => internal/service/cloudapi/rg}/utility_rg.go (80%) rename {decort => internal/service/cloudapi/rg}/utility_rg_list.go (63%) create mode 100644 internal/service/cloudapi/snapshot/api.go rename {decort => internal/service/cloudapi/snapshot}/data_source_snapshot_list.go (68%) create mode 100644 internal/service/cloudapi/snapshot/models.go rename {decort => internal/service/cloudapi/snapshot}/resource_snapshot.go (56%) rename {decort => internal/service/cloudapi/snapshot}/utility_snapshot.go (63%) rename {decort => internal/service/cloudapi/snapshot}/utility_snapshot_list.go (58%) create mode 100644 internal/service/cloudapi/vgpu/api.go rename {decort => internal/service/cloudapi/vgpu}/data_source_vgpu.go (69%) create mode 100644 internal/service/cloudapi/vgpu/models.go rename {decort => internal/service/cloudapi/vgpu}/utility_vgpu.go (65%) create mode 100644 internal/service/cloudapi/vins/api.go rename {decort => internal/service/cloudapi/vins}/data_source_vins.go (78%) rename {decort => internal/service/cloudapi/vins}/data_source_vins_list.go (75%) create mode 100644 internal/service/cloudapi/vins/models.go rename {decort => internal/service/cloudapi/vins}/resource_vins.go (78%) rename {decort => internal/service/cloudapi/vins}/utility_vins.go (82%) rename {decort => internal/service/cloudapi/vins}/utility_vins_list.go (63%) create mode 100644 internal/service/cloudbroker/grid/api.go rename {decort => internal/service/cloudbroker/grid}/data_source_grid.go (61%) rename {decort => internal/service/cloudbroker/grid}/data_source_grid_list.go (68%) create mode 100644 internal/service/cloudbroker/grid/models.go rename {decort => internal/service/cloudbroker/grid}/utility_grid.go (60%) rename {decort => internal/service/cloudbroker/grid}/utility_grid_list.go (61%) create mode 100644 internal/service/cloudbroker/image/api.go rename {decort => internal/service/cloudbroker/image}/data_source_image.go (86%) rename {decort => internal/service/cloudbroker/image}/data_source_image_list.go (74%) rename {decort => internal/service/cloudbroker/image}/data_source_image_list_stacks.go (75%) create mode 100644 internal/service/cloudbroker/image/models.go rename {decort => internal/service/cloudbroker/image}/resource_cdrom_image.go (73%) rename {decort => internal/service/cloudbroker/image}/resource_delete_images.go (56%) rename {decort => internal/service/cloudbroker/image}/resource_image.go (72%) rename {decort => internal/service/cloudbroker/image}/resource_virtual_image.go (70%) rename {decort => internal/service/cloudbroker/image}/utility_image.go (61%) rename {decort => internal/service/cloudbroker/image}/utility_image_list.go (64%) rename {decort => internal/service/cloudbroker/image}/utility_image_list_stacks.go (59%) create mode 100644 internal/service/cloudbroker/pcidevice/api.go rename {decort => internal/service/cloudbroker/pcidevice}/data_source_pcidevice.go (65%) rename {decort => internal/service/cloudbroker/pcidevice}/data_source_pcidevice_list.go (69%) create mode 100644 internal/service/cloudbroker/pcidevice/models.go rename {decort => internal/service/cloudbroker/pcidevice}/resource_pcidevice.go (61%) rename {decort => internal/service/cloudbroker/pcidevice}/utility_pcidevice.go (64%) rename {decort => internal/service/cloudbroker/pcidevice}/utility_pcidevice_list.go (55%) create mode 100644 internal/service/cloudbroker/sep/api.go rename {decort => internal/service/cloudbroker/sep}/data_source_sep.go (68%) rename {decort => internal/service/cloudbroker/sep}/data_source_sep_config.go (56%) rename {decort => internal/service/cloudbroker/sep}/data_source_sep_consumption.go (78%) rename {decort => internal/service/cloudbroker/sep}/data_source_sep_disk_list.go (58%) rename {decort => internal/service/cloudbroker/sep}/data_source_sep_list.go (72%) rename {decort => internal/service/cloudbroker/sep}/data_source_sep_pool.go (57%) create mode 100644 internal/service/cloudbroker/sep/models.go rename {decort => internal/service/cloudbroker/sep}/resource_sep.go (69%) rename {decort => internal/service/cloudbroker/sep}/resource_sep_config.go (57%) rename {decort => internal/service/cloudbroker/sep}/utility_sep.go (59%) rename {decort => internal/service/cloudbroker/sep}/utility_sep_config.go (59%) rename {decort => internal/service/cloudbroker/sep}/utility_sep_consumption.go (57%) rename {decort => internal/service/cloudbroker/sep}/utility_sep_disk_list.go (60%) rename {decort => internal/service/cloudbroker/sep}/utility_sep_list.go (61%) rename {decort => internal/service/cloudbroker/sep}/utility_sep_pool.go (59%) diff --git a/.gitignore b/.gitignore index 66a0b7a..6e92c2a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ decort/vendor/ examples/ url_scrapping/ terraform-provider-decort* +.vscode/ \ No newline at end of file diff --git a/Makefile b/Makefile index 7dfe1d4..abc8d7e 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ NAMESPACE=decort NAME=terraform-provider-decort #BINARY=terraform-provider-${NAME} BINARY=${NAME}.exe +MAINPATH = ./cmd/decort/ VERSION=0.2 #OS_ARCH=darwin_amd64 OS_ARCH=windows_amd64 @@ -11,8 +12,7 @@ OS_ARCH=windows_amd64 default: install build: - go build -o ${BINARY} - + go build -o ${BINARY} ${MAINPATH} release: GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64 GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386 diff --git a/main.go b/cmd/decort/main.go similarity index 73% rename from main.go rename to cmd/decort/main.go index f5106cc..aeb5fa4 100644 --- a/main.go +++ b/cmd/decort/main.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -32,10 +34,10 @@ package main import ( log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/plugin" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" - "github.com/rudecs/terraform-provider-decort/decort" + "github.com/rudecs/terraform-provider-decort/internal/provider" ) //go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs @@ -45,8 +47,8 @@ func main() { log.Debug("Debug logging enabled") plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: func() terraform.ResourceProvider { - return decort.Provider() + ProviderFunc: func() *schema.Provider { + return provider.Provider() }, }) } diff --git a/decort/data_source_account_deleted_list.go b/decort/data_source_account_deleted_list.go deleted file mode 100644 index d2a57c5..0000000 --- a/decort/data_source_account_deleted_list.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. - -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. -*/ - -package decort - -import ( - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceAccountDeletedListRead(d *schema.ResourceData, m interface{}) error { - accountDeletedList, err := utilityAccountDeletedListCheckPresence(d, m) - if err != nil { - return err - } - - id := uuid.New() - d.SetId(id.String()) - d.Set("items", flattenAccountList(accountDeletedList)) - - return nil -} - -func dataSourceAccountDeletedList() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceAccountDeletedListRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceAccountListSchemaMake(), - } -} diff --git a/decort/data_source_bservice_deleted_list.go b/decort/data_source_bservice_deleted_list.go deleted file mode 100644 index 3f4dce8..0000000 --- a/decort/data_source_bservice_deleted_list.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. - -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. -*/ - -package decort - -import ( - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceBasicServiceDeletedListRead(d *schema.ResourceData, m interface{}) error { - basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(d, m) - if err != nil { - return err - } - - id := uuid.New() - d.SetId(id.String()) - d.Set("items", flattenBasicServiceList(basicServiceDeletedList)) - - return nil -} - -func dataSourceBasicServiceDeletedList() *schema.Resource { - return &schema.Resource{ - SchemaVersion: 1, - - Read: dataSourceBasicServiceDeletedListRead, - - Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, - }, - - Schema: dataSourceBasicServiceListSchemaMake(), - } -} diff --git a/decort/models_api.go b/decort/models_api.go deleted file mode 100644 index 89e8676..0000000 --- a/decort/models_api.go +++ /dev/null @@ -1,1486 +0,0 @@ -/* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. - -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. -*/ - -package decort - -import ( - "encoding/json" - "fmt" - "strconv" - "time" -) - -// -// timeouts for API calls from CRUD functions of Terraform plugin -var Timeout30s = time.Second * 30 -var Timeout60s = time.Second * 60 -var Timeout180s = time.Second * 180 -var Timeout20m = time.Minute * 20 - -// -// structures related to /cloudapi/rg/list API -// -type UserAclRecord struct { - IsExplicit bool `json:"explicit"` - Rights string `json:"right"` - Status string `json:"status"` - Type string `json:"type"` - UgroupID string `json:"userGroupId"` - // CanBeDeleted bool `json:"canBeDeleted"` -} - -type AccountAclRecord struct { - IsExplicit bool `json:"explicit"` - Guid string `json:"guid"` - Rights string `json:"right"` - Status string `json:"status"` - Type string `json:"type"` - UgroupID string `json:"userGroupId"` - CanBeDeleted bool `json:"canBeDeleted"` -} - -type ResourceLimits struct { - CUC float64 `json:"CU_C"` - CUD float64 `json:"CU_D"` - CUI float64 `json:"CU_I"` - CUM float64 `json:"CU_M"` - CUNP float64 `json:"CU_NP"` - GpuUnits float64 `json:"gpu_units"` -} - -type ResgroupRecord struct { - ACLs []AccountAclRecord `json:"acl"` - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - DefaultNetID int `json:"def_net_id"` - DefaultNetType string `json:"def_net_type"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - Decsription string `json:"desc"` - GridID int `json:"gid"` - GUID int `json:"guid"` - ID uint `json:"id"` - LockStatus string `json:"lockStatus"` - Milestones int `json:"milestones"` - Name string `json:"name"` - RegisterComputes bool `json:"registerComputes"` - ResourceLimits ResourceLimits `json:"resourceLimits"` - Secret string `json:"secret"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` - Vins []int `json:"vins"` - Computes []int `json:"vms"` -} - -const ResgroupListAPI = "/restmachine/cloudapi/rg/list" - -type ResgroupListResp []ResgroupRecord - -// -// structures related to /cloudapi/rg/create API call -// -const ResgroupCreateAPI = "/restmachine/cloudapi/rg/create" - -// -// structures related to /cloudapi/rg/update API call -// -const ResgroupUpdateAPI = "/restmachine/cloudapi/rg/update" - -type ResgroupUpdateParam struct { - RgId int `json:"rgId"` - Name string `json:"name"` - Desc string `json:"decs"` - Ram int `json:"maxMemoryCapacity"` - Disk int `json:"maxVDiskCapacity"` - Cpu int `json:"maxCPUCapacity"` - NetTraffic int `json:"maxNetworkPeerTransfer"` - Reason string `json:"reason"` -} - -// -// structures related to /cloudapi/rg/get API call -// -type QuotaRecord struct { // this is how quota is reported by /api/.../rg/get - Cpu int `json:"CU_C"` // CPU count in pcs - Ram float64 `json:"CU_M"` // RAM volume in MB, it is STILL reported as FLOAT - Disk int `json:"CU_D"` // Disk capacity in GB - ExtIPs int `json:"CU_I"` // Ext IPs count - ExtTraffic int `json:"CU_NP"` // Ext network traffic - GpuUnits int `json:"gpu_units"` // GPU count -} - -type ResourceRecord struct { // this is how actual usage is reported by /api/.../rg/get - Cpu int `json:"cpu"` - Disk int `json:"disksize"` - ExtIPs int `json:"extips"` - ExtTraffic int `json:"exttraffic"` - Gpu int `json:"gpu"` - Ram int `json:"ram"` -} - -type UsageRecord struct { - Current ResourceRecord `json:"Current"` - Reserved ResourceRecord `json:"Reserved"` -} - -const ResgroupGetAPI = "/restmachine/cloudapi/rg/get" - -type ResgroupGetResp struct { - ACLs []UserAclRecord `json:"ACLs"` - Usage UsageRecord `json:"Resources"` - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - GridID int `json:"gid"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - DefaultNetID int `json:"def_net_id"` - DefaultNetType string `json:"def_net_type"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - Desc string `json:"desc"` - ID uint `json:"id"` - LockStatus string `json:"lockStatus"` - Name string `json:"name"` - Quota QuotaRecord `json:"resourceLimits"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime uint64 `json:"updatedTime"` - Vins []int `json:"vins"` - Computes []int `json:"vms"` - - Ignored map[string]interface{} `json:"-"` -} - -// -// structures related to /cloudapi/rg/delete API -// -const ResgroupDeleteAPI = "/restmachine/cloudapi/rg/delete" - -// -// structures related to /cloudapi/rg/listComputes API -// -type ComputeBriefRecord struct { // this is a brief compute specifiaction as returned by API rg/listComputes - // we do not even include here all fields as returned by this API, but only the most important that - // are really necessary to identify and distinguish computes - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - Name string `json:"name"` - ID uint `json:"id"` - RgID int `json:"rgId"` - RgName string `json:"rgName"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` -} - -const RgListComputesAPI = "/restmachine/cloudapi/rg/listComputes" - -type RgListComputesResp []ComputeBriefRecord - -// -// structures related to /cloudapi/kvmXXX/create APIs -// -const KvmX86CreateAPI = "/restmachine/cloudapi/kvmx86/create" -const KvmPPCCreateAPI = "/restmachine/cloudapi/kvmppc/create" - -type KvmVmCreateParam struct { // this is unified structure for both x86 and PPC based KVM VMs creation - RgID uint `json:"rgId"` - Name string `json:"name"` - Cpu int `json:"cpu"` - Ram int `json:"ram"` - ImageID int `json:"imageId"` - BootDisk int `json:"bootDisk"` - NetType string `json:"netType"` - NetId int `json:"netId"` - IPAddr string `json:"ipAddr"` - UserData string `json:"userdata"` - Desc string `json:"desc"` - Start bool `json:"start"` -} - -// structures related to cloudapi/compute/start API -const ComputeStartAPI = "/restmachine/cloudapi/compute/start" -const ComputeStopAPI = "/restmachine/cloudapi/compute/stop" - -// structures related to cloudapi/compute/delete API -const ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete" - -// -// structures related to /cloudapi/compute/list API -// - -type InterfaceQosRecord struct { - ERate int `json:"eRate"` - Guid string `json:"guid"` - InBurst int `json:"inBurst"` - InRate int `json:"inRate"` -} - -type InterfaceRecord struct { - ConnID int `json:"connId"` // This is VLAN ID or VxLAN ID, depending on ConnType - ConnType string `json:"connType"` // Either "VLAN" or "VXLAN" tag - DefaultGW string `json:"defGw"` - Guid string `json:"guid"` - IPAddress string `json:"ipAddress"` // without trailing network mask, i.e. "192.168.1.3" - MAC string `json:"mac"` - Name string `json:"name"` - NetID int `json:"netId"` // This is either ExtNet ID or ViNS ID, depending on NetType - NetMask int `json:"netMask"` - NetType string `json:"netType"` // Either "EXTNET" or "VINS" tag - PciSlot int `json:"pciSlot"` - Target string `json:"target"` - Type string `json:"type"` - VNFs []int `json:"vnfs"` - QOS InterfaceQosRecord `json:"qos"` -} - -type SnapSetRecord struct { - Disks []int `json:"disks"` - Guid string `json:"guid"` - Label string `json:"label"` - TimeStamp uint64 `json:"timestamp"` -} - -type ComputeRecord struct { - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - ACLs []UserAclRecord `json:"acl"` - Arch string `json:"arch"` - BootDiskSize int `json:"bootdiskSize"` - CloneReference int `json:"cloneReference"` - Clones []int `json:"clones"` - Cpus int `json:"cpus"` - CreatedBy string `json:"createdBy"` - CreatedTime uint64 `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime uint64 `json:"deletedTime"` - Desc string `json:"desc"` - Disks []int `json:"disks"` - GridID int `json:"gid"` - ID uint `json:"id"` - ImageID int `json:"imageId"` - Interfaces []InterfaceRecord `json:"interfaces"` - LockStatus string `json:"lockStatus"` - ManagerID int `json:"managerId"` - Name string `json:"name"` - Ram int `json:"ram"` - RgID int `json:"rgId"` - RgName string `json:"rgName"` - SnapSets []SnapSetRecord `json:"snapSets"` - Status string `json:"status"` - // Tags []string `json:"tags"` // Tags were reworked since DECORT 3.7.1 - TechStatus string `json:"techStatus"` - TotalDiskSize int `json:"totalDiskSize"` - UpdatedBy string `json:"updatedBy"` - UpdateTime uint64 `json:"updateTime"` - UserManaged bool `json:"userManaged"` - Vgpus []int `json:"vgpus"` - VinsConnected int `json:"vinsConnected"` - VirtualImageID int `json:"virtualImageId"` -} - -const ComputeListAPI = "/restmachine/cloudapi/compute/list" - -type ComputeListResp []ComputeRecord - -const ComputeResizeAPI = "/restmachine/cloudapi/compute/resize" - -// -// structures related to /cloudapi/compute/get -// -type SnapshotRecord struct { - Guid string `json:"guid"` - Label string `json:"label"` - ResId string `json:"resId"` - SnapSetGuid string `json:"snapSetGuid"` - SnapSetTime uint64 `json:"snapSetTime"` - TimeStamp uint64 `json:"timestamp"` -} - -type SnapshotRecordList []SnapshotRecord - -type DiskRecord struct { - Acl map[string]interface{} `json:"acl"` - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - BootPartition int `json:"bootPartition"` - CreatedTime uint64 `json:"creationTime"` - ComputeID int `json:"computeId"` - ComputeName string `json:"computeName"` - DeletedTime uint64 `json:"deletionTime"` - DeviceName string `json:"devicename"` - Desc string `json:"desc"` - DestructionTime uint64 `json:"destructionTime"` - DiskPath string `json:"diskPath"` - GridID int `json:"gid"` - GUID int `json:"guid"` - ID uint `json:"id"` - ImageID int `json:"imageId"` - Images []int `json:"images"` - IOTune map[string]interface{} `json:"iotune"` - IQN string `json:"iqn"` - Login string `json:"login"` - Name string `json:"name"` - MachineId int `json:"machineId"` - MachineName string `json:"machineName"` - Milestones uint64 `json:"milestones"` - Order int `json:"order"` - Params string `json:"params"` - Passwd string `json:"passwd"` - ParentId int `json:"parentId"` - PciSlot int `json:"pciSlot"` - Pool string `json:"pool"` - PurgeTime uint64 `json:"purgeTime"` - PurgeAttempts uint64 `json:"purgeAttempts"` - RealityDeviceNumber int `json:"realityDeviceNumber"` - ReferenceId string `json:"referenceId"` - ResID string `json:"resId"` - ResName string `json:"resName"` - Role string `json:"role"` - SepType string `json:"sepType"` - SepID int `json:"sepId"` // NOTE: absent from compute/get output - SizeMax int `json:"sizeMax"` - SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space - Snapshots []SnapshotRecord `json:"snapshots"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - UpdateBy uint64 `json:"updateBy"` - VMID int `json:"vmid"` -} - -type OsUserRecord struct { - Guid string `json:"guid"` - Login string `json:"login"` - Password string `json:"password"` - PubKey string `json:"pubkey"` -} - -const ComputeGetAPI = "/restmachine/cloudapi/compute/get" - -type ComputeGetResp struct { - // ACLs `json:"ACL"` - it is a dictionary, special parsing required - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - Arch string `json:"arch"` - BootDiskSize int `json:"bootdiskSize"` - CloneReference int `json:"cloneReference"` - Clones []int `json:"clones"` - Cpu int `json:"cpus"` - Desc string `json:"desc"` - Disks []DiskRecord `json:"disks"` - Driver string `json:"driver"` - GridID int `json:"gid"` - ID uint `json:"id"` - ImageID int `json:"imageId"` - ImageName string `json:"imageName"` - Interfaces []InterfaceRecord `json:"interfaces"` - LockStatus string `json:"lockStatus"` - ManagerID int `json:"managerId"` - ManagerType string `json:"manageType"` - Name string `json:"name"` - NatableVinsID int `json:"natableVinsId"` - NatableVinsIP string `json:"natableVinsIp"` - NatableVinsName string `json:"natableVinsName"` - NatableVinsNet string `json:"natableVinsNetwork"` - NatableVinsNetName string `json:"natableVinsNetworkName"` - OsUsers []OsUserRecord `json:"osUsers"` - Ram int `json:"ram"` - RgID int `json:"rgId"` - RgName string `json:"rgName"` - SnapSets []SnapSetRecord `json:"snapSets"` - Status string `json:"status"` - // Tags []string `json:"tags"` // Tags were reworked since DECORT 3.7.1 - TechStatus string `json:"techStatus"` - TotalDiskSize int `json:"totalDiskSize"` - UpdatedBy string `json:"updatedBy"` - UpdateTime uint64 `json:"updateTime"` - UserManaged bool `json:"userManaged"` - Vgpus []int `json:"vgpus"` - VinsConnected int `json:"vinsConnected"` - VirtualImageID int `json:"virtualImageId"` -} - -// -// structures related to /restmachine/cloudapi/image/list API -// -type ImageRecord struct { - AccountID uint `json:"accountId"` - Arch string `json:"architecture"` - BootType string `json:"bootType"` - IsBootable bool `json:"bootable"` - IsCdrom bool `json:"cdrom"` - Desc string `json:"desc"` - IsHotResize bool `json:"hotResize"` - ID uint `json:"id"` - Name string `json:"name"` - Pool string `json:"pool"` - SepID int `json:"sepId"` - Size int `json:"size"` - Status string `json:"status"` - Type string `json:"type"` - Username string `json:"username"` - IsVirtual bool `json:"virtual"` -} - -const ImagesListAPI = "/restmachine/cloudapi/image/list" - -type ImagesListResp []ImageRecord - -// -// structures related to /cloudapi/extnet/list API -// -type ExtNetRecord struct { - Name string `json:"name"` - ID uint `json:"id"` - IPCIDR string `json:"ipcidr"` -} - -const ExtNetListAPI = "/restmachine/cloudapi/extnet/list" - -type ExtNetListResp []ExtNetRecord - -// -// structures related to /cloudapi/account/list API -// -type AccountRecord struct { - // ACLs []UserAclRecord `json:"acl"` - // CreatedTime uint64 `json:"creationTime"` - // DeletedTime uint64 `json:"deletionTime"` - ID int `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - // UpdatedTime uint64 `json:"updateTime"` -} - -const AccountsGetAPI = "/restmachine/cloudapi/account/get" // returns AccountRecord superset - -const AccountsListAPI = "/restmachine/cloudapi/account/list" // returns list of abdridged info about accounts -type AccountsListResp []AccountRecord - -// -// structures related to /cloudapi/portforwarding/list API -// -type PfwRecord struct { - ID int `json:"id"` - LocalIP string `json:"localIp"` - LocalPort int `json:"localPort"` - Protocol string `json:"protocol"` - PublicPortEnd int `json:"publicPortEnd"` - PublicPortStart int `json:"publicPortStart"` - ComputeID int `json:"vmId"` -} - -const ComputePfwListAPI = "/restmachine/cloudapi/compute/pfwList" - -type ComputePfwListResp []PfwRecord - -const ComputePfwAddAPI = "/restmachine/cloudapi/compute/pfwAdd" - -const ComputePfwDelAPI = "/restmachine/cloudapi/compute/pfwDel" - -// -// structures related to /cloudapi/compute/net Attach/Detach API -// -type ComputeNetMgmtRecord struct { // used to "cache" network specs when preparing to manage compute networks - ID int - Type string - IPAddress string - MAC string -} - -const ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach" - -const ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach" - -// -// structures related to /cloudapi/compute/disk Attach/Detach API -// -const ComputeDiskAttachAPI = "/restmachine/cloudapi/compute/diskAttach" - -const ComputeDiskDetachAPI = "/restmachine/cloudapi/compute/diskDetach" - -// -// structures related to /cloudapi/disks/create -// -const DisksCreateAPI = "/restmachine/cloudapi/disks/create" - -// -// structures related to /cloudapi/disks/get -// -const DisksGetAPI = "/restmachine/cloudapi/disks/get" // Returns single DiskRecord on success - -const DisksListAPI = "/restmachine/cloudapi/disks/list" // Returns list of DiskRecord on success - -type DisksListResp []DiskRecord - -// -// structures related to /cloudapi/disks/resize -// -const DisksResizeAPI = "/restmachine/cloudapi/disks/resize2" - -// -// structures related to /cloudapi/disks/resize -// -const DisksRenameAPI = "/restmachine/cloudapi/disks/rename" - -// -// structures related to /cloudapi/disks/delete -// -const DisksDeleteAPI = "/restmachine/cloudapi/disks/delete" - -// -// ViNS structures -// - -// this is the structure of the element in the list returned by vins/search API -type VinsSearchRecord struct { - ID int `json:"id"` - Name string `json:"name"` - IPCidr string `json:"network"` - VxLanID int `json:"vxlanId"` - ExternalIP string `json:"externalIP"` - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - RgID int `json:"rgId"` - RgName string `json:"rgName"` -} - -const VinsSearchAPI = "/restmachine/cloudapi/vins/search" - -type VinsSearchResp []VinsSearchRecord - -type VnfRecord struct { - ID int `json:"id"` - AccountID int `json:"accountId"` - Type string `json:"type"` // "DHCP", "NAT", "GW" etc - Config map[string]interface{} `json:"config"` // NOTE: VNF specs vary by VNF type -} - -type VnfGwConfigRecord struct { // describes GW VNF config structure inside ViNS, as returned by API vins/get - ExtNetID int `json:"ext_net_id"` - ExtNetIP string `json:"ext_net_ip"` - ExtNetMask int `json:"ext_net_mask"` - DefaultGW string `json:"default_gw"` -} -type VinsRecord struct { // represents part of the response from API vins/get - ID int `json:"id"` - Name string `json:"name"` - IPCidr string `json:"network"` - VxLanID int `json:"vxlanId"` - ExternalIP string `json:"externalIP"` - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - RgID int `json:"rgid"` - RgName string `json:"rgName"` - VNFs map[string]VnfRecord `json:"vnfs"` - Desc string `json:"desc"` -} - -const VinsGetAPI = "/restmachine/cloudapi/vins/get" - -const VinsCreateInAccountAPI = "/restmachine/cloudapi/vins/createInAccount" -const VinsCreateInRgAPI = "/restmachine/cloudapi/vins/createInRG" - -const VinsExtNetConnectAPI = "/restmachine/cloudapi/vins/extNetConnect" -const VinsExtNetDisconnectAPI = "/restmachine/cloudapi/vins/extNetDisconnect" - -const VinsDeleteAPI = "/restmachine/cloudapi/vins/delete" - -// -// K8s structures -// - -//K8sNodeRecord represents a worker/master group -type K8sNodeRecord struct { - ID int `json:"id"` - Name string `json:"name"` - Disk int `json:"disk"` - Cpu int `json:"cpu"` - Num int `json:"num"` - Ram int `json:"ram"` - DetailedInfo []struct { - ID int `json:"id"` - Name string `json:"name"` - } `json:"detailedInfo"` -} - -//K8sRecord represents k8s instance -type K8sRecord struct { - AccountID int `json:"accountId"` - AccountName string `json:"accountName"` - CI int `json:"ciId"` - ID int `json:"id"` - Groups struct { - Masters K8sNodeRecord `json:"masters"` - Workers []K8sNodeRecord `json:"workers"` - } `json:"k8sGroups"` - LbID int `json:"lbId"` - Name string `json:"name"` - RgID int `json:"rgId"` - RgName string `json:"rgName"` -} - -//LbRecord represents load balancer instance -type LbRecord struct { - ID int `json:"id"` - Name string `json:"name"` - RgID int `json:"rgId"` - VinsID int `json:"vinsId"` - ExtNetID int `json:"extnetId"` - PrimaryNode struct { - BackendIP string `json:"backendIp"` - ComputeID int `json:"computeId"` - FrontendIP string `json:"frontendIp"` - NetworkID int `json:"networkId"` - } `json:"primaryNode"` -} - -const K8sCreateAPI = "/restmachine/cloudapi/k8s/create" -const K8sGetAPI = "/restmachine/cloudapi/k8s/get" -const K8sUpdateAPI = "/restmachine/cloudapi/k8s/update" -const K8sDeleteAPI = "/restmachine/cloudapi/k8s/delete" - -const K8sWgCreateAPI = "/restmachine/cloudapi/k8s/workersGroupAdd" -const K8sWgDeleteAPI = "/restmachine/cloudapi/k8s/workersGroupDelete" - -const K8sWorkerAddAPI = "/restmachine/cloudapi/k8s/workerAdd" -const K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup" - -const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig" - -const LbGetAPI = "/restmachine/cloudapi/lb/get" - -//Blasphemous workaround for parsing Result value -type TaskResult int - -func (r *TaskResult) UnmarshalJSON(b []byte) error { - if b[0] == '"' { - b := b[1 : len(b)-1] - if len(b) == 0 { - *r = 0 - return nil - } - n, err := strconv.Atoi(string(b)) - if err != nil { - return err - } - *r = TaskResult(n) - } else if b[0] == '[' { - res := []interface{}{} - if err := json.Unmarshal(b, &res); err != nil { - return err - } - if n, ok := res[0].(float64); ok { - *r = TaskResult(n) - } else { - return fmt.Errorf("could not unmarshal %v into int", res[0]) - } - } - - return nil -} - -//AsyncTask represents a long task completion status -type AsyncTask struct { - AuditID string `json:"auditId"` - Completed bool `json:"completed"` - Error string `json:"error"` - Log []string `json:"log"` - Result TaskResult `json:"result"` - Stage string `json:"stage"` - Status string `json:"status"` - UpdateTime uint64 `json:"updateTime"` - UpdatedTime uint64 `json:"updatedTime"` -} - -const AsyncTaskGetAPI = "/restmachine/cloudapi/tasks/get" - -// -// Grid ID structures -// -type LocationRecord struct { - GridID int `json:"gid"` - Id int `json:"id"` - LocationCode string `json:"locationCode"` - Name string `json:"name"` - Flag string `json:"flag"` -} - -const LocationsListAPI = "/restmachine/cloudapi/locations/list" // Returns list of GridRecord on success -type LocationsListResp []LocationRecord - -// -// Auxiliary structures -// -type SshKeyConfig struct { - User string - SshKey string - UserShell string -} - -//////////////////// -// IMAGE API // -//////////////////// -const imageCreateAPI = "/restmachine/cloudbroker/image/createImage" -const imageSyncCreateAPI = "/restmachine/cloudbroker/image/syncCreateImage" -const imageCreateVirtualAPI = "/restmachine/cloudbroker/image/createVirtual" -const imageCreateCDROMAPI = "/restmachine/cloudbroker/image/createCDROMImage" -const imageListStacksApi = "/restmachine/cloudbroker/image/listStacks" -const imageGetAPI = "/restmachine/cloudbroker/image/get" -const imageListGetAPI = "/restmachine/cloudbroker/image/list" -const imageEditAPI = "/restmachine/cloudbroker/image/edit" -const imageDeleteAPI = "/restmachine/cloudbroker/image/delete" -const imageDeleteCDROMAPI = "/restmachine/cloudbroker/image/deleteCDROMImage" -const imageEnableAPI = "/restmachine/cloudbroker/image/enable" -const imageDisableAPI = "/restmachine/cloudbroker/image/disable" -const imageEditNameAPI = "/restmachine/cloudbroker/image/rename" -const imageLinkAPI = "/restmachine/cloudbroker/image/link" -const imageShareAPI = "/restmachine/cloudbroker/image/share" -const imageComputeciSetAPI = "/restmachine/cloudbroker/image/computeciSet" -const imageComputeciUnsetAPI = "/restmachine/cloudbroker/image/computeciUnset" -const imageUpdateNodesAPI = "/restmachine/cloudbroker/image/updateNodes" -const imageDeleteImagesAPI = "/restmachine/cloudbroker/image/deleteImages" - -type History struct { - Guid string `json:"guid"` - Id int `json:"id"` - Timestamp int64 `json:"timestamp"` -} - -type Image struct { - ImageId int `json:"id"` - Name string `json:"name"` - Url string `json:"url"` - Gid int `json:"gid"` - Guid int `json:"guid"` - Boottype string `json:"bootType"` - Imagetype string `json:"type"` - Drivers []string `json:"drivers"` - Hotresize bool `json:"hotResize"` - Bootable bool `json:"bootable"` - Username string `json:"username"` - Password string `json:"password"` - AccountId int `json:"accountId"` - UsernameDL string `json:"usernameDL"` - PasswordDL string `json:"passwordDL"` - SepId int `json:"sepId"` - PoolName string `json:"pool"` - Architecture string `json:"architecture"` - UNCPath string `json:"UNCPath"` - LinkTo int `json:"linkTo"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - Size int `json:"size"` - Version string `json:"version"` - Enabled bool `json:"enabled"` - ComputeciId int `json:"computeciId"` - Milestones int `json:"milestones"` - ProviderName string `json:"provider_name"` - PurgeAttempts int `json:"purgeAttempts"` - ReferenceId string `json:"referenceId"` - ResId string `json:"resId"` - ResName string `json:"resName"` - Rescuecd bool `json:"rescuecd"` - Meta []interface{} `json:"_meta"` - History []History `json:"history"` - LastModified int64 `json:"lastModified"` - Desc string `json:"desc"` - SharedWith []int `json:"sharedWith"` -} - -type ImageList []Image - -type ImageStack struct { - ApiURL string `json:"apiUrl"` - ApiKey string `json:"apikey"` - AppId string `json:"appId"` - Desc string `json:"desc"` - Drivers []string `json:"drivers"` - Error int `json:"error"` - Guid int `json:"guid"` - Id int `json:"id"` - Images []int `json:"images"` - Login string `json:"login"` - Name string `json:"name"` - Passwd string `json:"passwd"` - ReferenceId string `json:"referenceId"` - Status string `json:"status"` - Type string `json:"type"` -} - -type ImageListStacks []ImageStack - -///////////////// -// GRID API // -///////////////// -const GridListGetAPI = "/restmachine/cloudbroker/grid/list" -const GridGetAPI = "/restmachine/cloudbroker/grid/get" - -type Grid struct { - Flag string `json:"flag"` - Gid int `json:"gid"` - Guid int `json:"guid"` - Id int `json:"id"` - LocationCode string `json:"locationCode"` - Name string `json:"name"` -} - -type GridList []Grid - -///////////////////// -/// SNAPSHOT API /// -///////////////////// - -const snapshotCreateAPI = "/restmachine/cloudapi/compute/snapshotCreate" -const snapshotDeleteAPI = "/restmachine/cloudapi/compute/snapshotDelete" -const snapshotRollbackAPI = "/restmachine/cloudapi/compute/snapshotRollback" -const snapshotListAPI = "/restmachine/cloudapi/compute/snapshotList" - -type Snapshot struct { - Disks []int `json:"disks"` - Guid string `json:"guid"` - Label string `json:"label"` - Timestamp uint64 `json:"timestamp"` -} - -type SnapshotList []Snapshot - -//////////////// -/// VGPU API /// -//////////////// - -const vgpuListAPI = "/restmachine/cloudbroker/vgpu/list" - -type VGPU struct { - AccountID int `json:"accountId"` - ID int `json:"id"` - Mode string `json:"mode"` - PgpuID int `json:"pgpuid"` - ProfileID int `json:"profileId"` - RAM int `json:"ram"` - Status string `json:"status"` - Type string `json:"type"` - VmID int `json:"vmid"` -} - -///////////////////////////// -// PCIDEVICE // -///////////////////////////// - -const pcideviceListAPI = "/restmachine/cloudbroker/pcidevice/list" -const pcideviceDisableAPI = "/restmachine/cloudbroker/pcidevice/disable" -const pcideviceEnableAPI = "/restmachine/cloudbroker/pcidevice/enable" -const pcideviceCreateAPI = "/restmachine/cloudbroker/pcidevice/create" -const pcideviceDeleteAPI = "/restmachine/cloudbroker/pcidevice/delete" - -type Pcidevice struct { - CKey string `json:"_ckey"` - Meta []interface{} `json:"_meta"` - Computeid int `json:"computeId"` - Description string `json:"description"` - Guid int `json:"guid"` - HwPath string `json:"hwPath"` - ID int `json:"id"` - Name string `json:"name"` - RgID int `json:"rgId"` - StackID int `json:"stackId"` - Status string `json:"status"` - SystemName string `json:"systemName"` -} - -type PcideviceList []Pcidevice - -/////////////////// -///// SEP API ///// -/////////////////// -const sepAddConsumerNodesAPI = "/restmachine/cloudbroker/sep/addConsumerNodes" -const sepDelConsumerNodesAPI = "/restmachine/cloudbroker/sep/delConsumerNodes" -const sepAddProviderNodesAPI = "/restmachine/cloudbroker/sep/addProviderNodes" - -const sepConfigFieldEditAPI = "/restmachine/cloudbroker/sep/configFieldEdit" -const sepConfigInsertAPI = "/restmachine/cloudbroker/sep/configInsert" -const sepConfigValidateAPI = "/restmachine/cloudbroker/sep/configValidate" - -const sepConsumptionAPI = "/restmachine/cloudbroker/sep/consumption" - -const sepDecommissionAPI = "/restmachine/cloudbroker/sep/decommission" - -const sepEnableAPI = "/restmachine/cloudbroker/sep/enable" -const sepDisableAPI = "/restmachine/cloudbroker/sep/disable" - -const sepDiskListAPI = "/restmachine/cloudbroker/sep/diskList" - -const sepGetAPI = "/restmachine/cloudbroker/sep/get" -const sepGetConfigAPI = "/restmachine/cloudbroker/sep/getConfig" -const sepGetPoolAPI = "/restmachine/cloudbroker/sep/getPool" - -const sepCreateAPI = "/restmachine/cloudbroker/sep/create" -const sepDeleteAPI = "/restmachine/cloudbroker/sep/delete" -const sepListAPI = "/restmachine/cloudbroker/sep/list" - -const sepUpdateCapacityLimitAPI = "/restmachine/cloudbroker/sep/updateCapacityLimit" - -///Sep Models -type SepConsumptionInd struct { - DiskCount int `json:"disk_count"` - DiskUsage int `json:"disk_usage"` - SnapshotCount int `json:"snapshot_count"` - SnapshotUsage int `json:"snapshot_usage"` - Usage int `json:"usage"` - UsageLimit int `json:"usage_limit"` -} - -type SepConsumptionTotal struct { - CapacityLimit int `json:"capacity_limit"` - SepConsumptionInd -} - -type SepConsumption struct { - Total SepConsumptionTotal `json:"total"` - Type string `json:"type"` - ByPool map[string]SepConsumptionInd `json:"byPool"` -} - -type SepDiskList []int - -type Sep struct { - Ckey string `json:"_ckey"` - Meta []interface{} `json:"_meta"` - ConsumedBy []int `json:"consumedBy"` - Desc string `json:"desc"` - Gid int `json:"gid"` - Guid int `json:"guid"` - Id int `json:"id"` - Milestones int `json:"milestones"` - Name string `json:"name"` - ObjStatus string `json:"objStatus"` - ProvidedBy []int `json:"providedBy"` - TechStatus string `json:"techStatus"` - Type string `json:"type"` - Config SepConfig `json:"config"` -} - -type SepConfig map[string]interface{} - -type SepList []Sep -type SepPool map[string]interface{} - -/////////////////////// -///// ACCOUNTS //// -/////////////////////// - -const accountAddUserAPI = "/restmachine/cloudapi/account/addUser" -const accountAuditsAPI = "/restmachine/cloudapi/account/audits" -const accountCreateAPI = "/restmachine/cloudapi/account/create" -const accountDeleteAPI = "/restmachine/cloudapi/account/delete" -const accountDeleteUserAPI = "/restmachine/cloudapi/account/deleteUser" -const accountDisableAPI = "/restmachine/cloudapi/account/disable" -const accountEnableAPI = "/restmachine/cloudapi/account/enable" -const accountGetAPI = "/restmachine/cloudapi/account/get" -const accountGetConsumedUnitsAPI = "/restmachine/cloudapi/account/getConsumedAccountUnits" -const accountGetConsumedUnitsByTypeAPI = "/restmachine/cloudapi/account/getConsumedCloudUnitsByType" -const accountGetReservedUnitsAPI = "/restmachine/cloudapi/account/getReservedAccountUnits" -const accountListAPI = "/restmachine/cloudapi/account/list" -const accountListComputesAPI = "/restmachine/cloudapi/account/listComputes" -const accountListDeletedAPI = "/restmachine/cloudapi/account/listDeleted" -const accountListDisksAPI = "/restmachine/cloudapi/account/listDisks" -const accountListFlipGroupsAPI = "/restmachine/cloudapi/account/listFlipGroups" -const accountListRGAPI = "/restmachine/cloudapi/account/listRG" -const accountListTemplatesAPI = "/restmachine/cloudapi/account/listTemplates" -const accountListVinsAPI = "/restmachine/cloudapi/account/listVins" -const accountRestoreAPI = "/restmachine/cloudapi/account/restore" -const accountUpdateAPI = "/restmachine/cloudapi/account/update" -const accountUpdateUserAPI = "/restmachine/cloudapi/account/updateUser" - -////Structs - -type Account struct { - DCLocation string `json:"DCLocation"` - CKey string `jspn:"_ckey"` - Meta []interface{} `json:"_meta"` - Acl []AccountAclRecord `json:"acl"` - Company string `json:"company"` - CompanyUrl string `json:"companyurl"` - CreatedBy string `jspn:"createdBy"` - CreatedTime int `json:"createdTime"` - DeactiovationTime float64 `json:"deactivationTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - DisplayName string `json:"displayname"` - GUID int `json:"guid"` - ID int `json:"id"` - Name string `json:"name"` - ResourceLimits ResourceLimits `json:"resourceLimits"` - SendAccessEmails bool `json:"sendAccessEmails"` - ServiceAccount bool `json:"serviceAccount"` - Status string `json:"status"` - UpdatedTime int `json:"updatedTime"` - Version int `json:"version"` - Vins []int `json:"vins"` -} - -type AccountList []Account - -type AccountCloudApi struct { - Acl []AccountAclRecord `json:"acl"` - CreatedTime int `json:"createdTime"` - DeletedTime int `json:"deletedTime"` - ID int `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - UpdatedTime int `json:"updatedTime"` -} - -type AccountCloudApiList []AccountCloudApi - -type Resource struct { - CPU int `json:"cpu"` - Disksize int `json:"disksize"` - Extips int `json:"extips"` - Exttraffic int `json:"exttraffic"` - GPU int `json:"gpu"` - RAM int `json:"ram"` -} - -type Resources struct { - Current Resource `json:"Current"` - Reserved Resource `json:"Reserved"` -} - -type Computes struct { - Started int `json:"started"` - Stopped int `json:"stopped"` -} - -type Machines struct { - Running int `json:"running"` - Halted int `json:"halted"` -} - -type AccountWithResources struct { - Account - Resources Resources `json:"Resources"` - Computes Computes `json:"computes"` - Machines Machines `json:"machines"` - Vinses int `json:"vinses"` -} - -type AccountCompute struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - CPUs int `json:"cpus"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - ComputeId int `json:"id"` - ComputeName string `json:"name"` - RAM int `json:"ram"` - Registered bool `json:"registered"` - RgId int `json:"rgId"` - RgName string `json:"rgName"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - TotalDisksSize int `json:"totalDisksSize"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - UserManaged bool `json:"userManaged"` - VinsConnected int `json:"vinsConnected"` -} - -type AccountComputesList []AccountCompute - -type AccountDisk struct { - ID int `json:"id"` - Name string `json:"name"` - Pool string `json:"pool"` - SepId int `json:"sepId"` - SizeMax int `json:"sizeMax"` - Type string `json:"type"` -} - -type AccountDisksList []AccountDisk - -type AccountVin struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - Computes int `json:"computes"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - ExternalIP string `json:"externalIP"` - ID int `json:"id"` - Name string `json:"name"` - Network string `json:"network"` - PriVnfDevId int `json:"priVnfDevId"` - RgId int `json:"rgId"` - RgName string `json:"rgName"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` -} - -type AccountVinsList []AccountVin - -type AccountAudit struct { - Call string `json:"call"` - ResponseTime float64 `json:"responsetime"` - StatusCode int `json:"statuscode"` - Timestamp float64 `json:"timestamp"` - User string `json:"user"` -} - -type AccountAuditsList []AccountAudit - -type AccountRGComputes struct { - Started int `json:"Started"` - Stopped int `json:"Stopped"` -} - -type AccountRGResources struct { - Consumed Resource `json:"Consumed"` - Limits Resource `json:"Limits"` - Reserved Resource `json:"Reserved"` -} - -type AccountRG struct { - Computes AccountRGComputes `json:"Computes"` - Resources AccountRGResources `json:"Resources"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - RGID int `json:"id"` - Milestones int `json:"milestones"` - RGName string `json:"name"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - Vinses int `json:"vinses"` -} - -type AccountRGList []AccountRG - -type AccountTemplate struct { - UNCPath string `json:"UNCPath"` - AccountId int `json:"accountId"` - Desc string `json:"desc"` - ID int `json:"id"` - Name string `json:"name"` - Public bool `json:"public"` - Size int `json:"size"` - Status string `json:"status"` - Type string `json:"type"` - Username string `json:"username"` -} - -type AccountTemplatesList []AccountTemplate - -type AccountFlipGroup struct { - AccountId int `json:"accountId"` - ClientType string `json:"clientType"` - ConnType string `json:"connType"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DefaultGW string `json:"defaultGW"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - Desc string `json:"desc"` - GID int `json:"gid"` - GUID int `json:"guid"` - ID int `json:"id"` - IP string `json:"ip"` - Milestones int `json:"milestones"` - Name string `json:"name"` - NetID int `json:"netId"` - NetType string `json:"netType"` - NetMask int `json:"netmask"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` -} - -type AccountFlipGroupsList []AccountFlipGroup - -//////////////////// -//// BSERVICE //// -//////////////////// - -const bserviceCreateAPI = "/restmachine/cloudapi/bservice/create" -const bserviceDeleteAPI = "/restmachine/cloudapi/bservice/delete" -const bserviceDisableAPI = "/restmachine/cloudapi/bservice/disable" -const bserviceEnableAPI = "/restmachine/cloudapi/bservice/enable" -const bserviceGetAPI = "/restmachine/cloudapi/bservice/get" -const bserviceGroupAddAPI = "/restmachine/cloudapi/bservice/groupAdd" -const bserviceGroupComputeRemoveAPI = "/restmachine/cloudapi/bservice/groupComputeRemove" -const bserviceGroupGetAPI = "/restmachine/cloudapi/bservice/groupGet" -const bserviceGroupParentAddAPI = "/restmachine/cloudapi/bservice/groupParentAdd" -const bserviceGroupParentRemoveAPI = "/restmachine/cloudapi/bservice/groupParentRemove" -const bserviceGroupRemoveAPI = "/restmachine/cloudapi/bservice/groupRemove" -const bserviceGroupResizeAPI = "/restmachine/cloudapi/bservice/groupResize" -const bserviceGroupStartAPI = "/restmachine/cloudapi/bservice/groupStart" -const bserviceGroupStopAPI = "/restmachine/cloudapi/bservice/groupStop" -const bserviceGroupUpdateAPI = "/restmachine/cloudapi/bservice/groupUpdate" -const bserviceGroupUpdateExtnetAPI = "/restmachine/cloudapi/bservice/groupUpdateExtnet" -const bserviceGroupUpdateVinsAPI = "/restmachine/cloudapi/bservice/groupUpdateVins" -const bserviceListAPI = "/restmachine/cloudapi/bservice/list" -const bserviceListDeletedAPI = "/restmachine/cloudapi/bservice/listDeleted" -const bserviceRestoreAPI = "/restmachine/cloudapi/bservice/restore" -const bserviceSnapshotCreateAPI = "/restmachine/cloudapi/bservice/snapshotCreate" -const bserviceSnapshotDeleteAPI = "/restmachine/cloudapi/bservice/snapshotDelete" -const bserviceSnapshotListAPI = "/restmachine/cloudapi/bservice/snapshotList" -const bserviceSnapshotRollbackAPI = "/restmachine/cloudapi/bservice/snapshotRollback" -const bserviceStartAPI = "/restmachine/cloudapi/bservice/start" -const bserviceStopAPI = "/restmachine/cloudapi/bservice/stop" - -///Structs - -type BasicServiceCompute struct { - CompGroupId int `json:"compgroupId"` - CompGroupName string `json:"compgroupName"` - CompGroupRole string `json:"compgroupRole"` - ID int `json:"id"` - Name string `json:"name"` -} - -type BasicServiceComputes []BasicServiceCompute - -type BasicServiceSnapshot struct { - GUID string `json:"guid"` - Label string `json:"label"` - Timestamp int `json:"timestamp"` - Valid bool `json:"valid"` -} - -type BasicServiceSnapshots []BasicServiceSnapshot - -type BasicService struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - BaseDomain string `json:"baseDomain"` - - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - GID int `json:"gid"` - Groups []int `json:"groups"` - GUID int `json:"guid"` - ID int `json:"id"` - Name string `json:"name"` - ParentSrvId int `json:"parentSrvId"` - ParentSrvType string `json:"parentSrvType"` - RGID int `json:"rgId"` - RGName string `json:"rgName"` - SSHUser string `json:"sshUser"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - UserManaged bool `json:"userManaged"` -} - -type BasicServiceList []BasicService - -type BasicServiceExtend struct { - BasicService - Computes BasicServiceComputes `json:"computes"` - CPUTotal int `json:"cpuTotal"` - DiskTotal int `json:"diskTotal"` - GroupsName []string `json:"groupsName"` - Milestones int `json:"milestones"` - RamTotal int `json:"ramTotal"` - Snapshots BasicServiceSnapshots `json:"snapshots"` - SSHKey string `json:"sshKey"` -} - -type BasicServiceGroupOSUser struct { - Login string `json:"login"` - Password string `json:"password"` -} - -type BasicServiceGroupOSUsers []BasicServiceGroupOSUser - -type BasicServicceGroupCompute struct { - ID int `json:"id"` - IPAdresses []string `json:"ipAddresses"` - Name string `json:"name"` - OSUsers BasicServiceGroupOSUsers `json:"osUsers"` -} - -type BasicServiceGroupComputes []BasicServicceGroupCompute - -type BasicServiceGroup struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - Computes BasicServiceGroupComputes `json:"computes"` - Consistency bool `json:"consistency"` - CPU int `json:"cpu"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - Disk int `json:"disk"` - Driver string `json:"driver"` - Extnets []int `json:"extnets"` - GID int `json:"gid"` - GUID int `json:"guid"` - ID int `json:"id"` - ImageId int `json:"imageId"` - Milestones int `json:"milestones"` - Name string `json:"name"` - Parents []int `json:"parents"` - RAM int `json:"ram"` - RGID int `json:"rgId"` - RGName string `json:"rgName"` - Role string `json:"role"` - SepId int `json:"sepId"` - SeqNo int `json:"seqNo"` - ServiceId int `json:"serviceId"` - Status string `json:"status"` - TechStatus string `json:"techStatus"` - TimeoutStart int `json:"timeoutStart"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - Vinses []int `json:"vinses"` -} - -/////////////////// -///// EXTNET ///// -/////////////////// - -const extnetListAPI = "/restmachine/cloudapi/extnet/list" -const extnetListComputesAPI = "/restmachine/cloudapi/extnet/listComputes" -const extnetGetDefaultAPI = "/restmachine/cloudapi/extnet/getDefault" -const extnetGetAPI = "/restmachine/cloudapi/extnet/get" - -type Extnet struct { - ID int `json:"id"` - IPCidr string `json:"ipcidr"` - Name string `json:"name"` -} -type ExtnetExtend struct { - Extnet - IPAddr string `json:"ipaddr"` -} - -type ExtnetList []Extnet -type ExtnetExtendList []ExtnetExtend - -type ExtnetComputes struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - Extnets ExtnetExtendList `json:"extnets"` - ID int `json:"id"` - Name string `json:"name"` - RGID int `json:"rgId"` - RGName string `json:"rgName"` -} - -type ExtnetComputesList []ExtnetComputes - -type ExtnetQos struct { - ERate int `json:"eRate"` - GUID string `json:"guid"` - InBurst int `json:"inBurst"` - InRate int `json:"inRate"` -} - -type ExtnetReservation struct { - ClientType string `json:"clientType"` - Desc string `json:"desc"` - DomainName string `json:"domainname"` - HostName string `json:"hostname"` - IP string `json:"ip"` - MAC string `json:"mac"` - Type string `json:"type"` - VMID int `json:"vmId"` -} - -type ExtnetReservations []ExtnetReservation - -type ExtnetVNFS struct { - DHCP int `json:"dhcp"` -} - -type ExtnetDetailed struct { - CKey string `json:"_ckey"` - Meta []interface{} `json:"_meta"` - CheckIPs []string `json:"checkIPs"` - CheckIps []string `json:"checkIps"` - Default bool `json:"default"` - DefaultQos ExtnetQos `json:"defaultQos"` - Desc string `json:"desc"` - Dns []string `json:"dns"` - Excluded []string `json:"excluded"` - FreeIps int `json:"free_ips"` - Gateway string `json:"gateway"` - GID int `json:"gid"` - GUID int `json:"guid"` - ID int `json:"id"` - IPCidr string `json:"ipcidr"` - Milestones int `json:"milestones"` - Name string `json:"name"` - Network string `json:"network"` - NetworkId int `json:"networkId"` - PreReservationsNum int `json:"preReservationsNum"` - Prefix int `json:"prefix"` - PriVnfDevId int `json:"priVnfDevId"` - Reservations ExtnetReservations `json:"reservations"` - SharedWith []int `json:"sharedWith"` - Status string `json:"status"` - VlanID int `json:"vlanId"` - VNFS ExtnetVNFS `json:"vnfs"` -} - -////////////// -//// VINS //// -////////////// - -const vinsListAPI = "/restmachine/cloudapi/vins/list" - -type Vins struct { - AccountId int `json:"accountId"` - AccountName string `json:"accountName"` - CreatedBy string `json:"createdBy"` - CreatedTime int `json:"createdTime"` - DeletedBy string `json:"deletedBy"` - DeletedTime int `json:"deletedTime"` - ExternalIP string `json:"externalIP"` - ID int `json:"id"` - Name string `json:"name"` - Network string `json:"network"` - RGID int `json:"rgId"` - RGName string `json:"rgName"` - Status string `json:"status"` - UpdatedBy string `json:"updatedBy"` - UpdatedTime int `json:"updatedTime"` - VXLanID int `json:"vxlanId"` -} - -type VinsList []Vins diff --git a/decort/provider.go b/decort/provider.go deleted file mode 100644 index 1f47cbc..0000000 --- a/decort/provider.go +++ /dev/null @@ -1,196 +0,0 @@ -/* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package decort - -import ( - "fmt" - "strings" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - // "github.com/hashicorp/terraform-plugin-sdk/terraform" -) - -func Provider() *schema.Provider { - return &schema.Provider{ - Schema: map[string]*schema.Schema{ - "authenticator": { - Type: schema.TypeString, - Required: true, - StateFunc: stateFuncToLower, - ValidateFunc: validation.StringInSlice([]string{"oauth2", "legacy", "jwt"}, true), // ignore case while validating - Description: "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'oauth2', 'legacy' or 'jwt'.", - }, - - "oauth2_url": { - Type: schema.TypeString, - Optional: true, - StateFunc: stateFuncToLower, - DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil), - Description: "OAuth2 application URL in 'oauth2' authentication mode.", - }, - - "controller_url": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: stateFuncToLower, - Description: "URL of DECORT Cloud controller to use. API calls will be directed to this URL.", - }, - - "user": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("DECORT_USER", nil), - Description: "User name for DECORT cloud API operations in 'legacy' authentication mode.", - }, - - "password": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("DECORT_PASSWORD", nil), - Description: "User password for DECORT cloud API operations in 'legacy' authentication mode.", - }, - - "app_id": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_ID", nil), - Description: "Application ID to access DECORT cloud API in 'oauth2' authentication mode.", - }, - - "app_secret": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_SECRET", nil), - Description: "Application secret to access DECORT cloud API in 'oauth2' authentication mode.", - }, - - "jwt": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("DECORT_JWT", nil), - Description: "JWT to access DECORT cloud API in 'jwt' authentication mode.", - }, - - "allow_unverified_ssl": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "If true, DECORT API will not verify SSL certificates. Use this with caution and in trusted environments only!", - }, - }, - - ResourcesMap: map[string]*schema.Resource{ - "decort_resgroup": resourceResgroup(), - "decort_kvmvm": resourceCompute(), - "decort_disk": resourceDisk(), - "decort_vins": resourceVins(), - "decort_pfw": resourcePfw(), - "decort_k8s": resourceK8s(), - "decort_k8s_wg": resourceK8sWg(), - "decort_image": resourceImage(), - "decort_virtual_image": resourceVirtualImage(), - "decort_cdrom_image": resourceCDROMImage(), - "decort_delete_images": resourceDeleteImages(), - "decort_snapshot": resourceSnapshot(), - "decort_pcidevice": resourcePcidevice(), - "decort_sep": resourceSep(), - "decort_sep_config": resourceSepConfig(), - "decort_account": resourceAccount(), - "decort_bservice": resourceBasicService(), - "decort_bservice_group": resourceBasicServiceGroup(), - }, - - DataSourcesMap: map[string]*schema.Resource{ - "decort_account": dataSourceAccount(), - "decort_resgroup": dataSourceResgroup(), - "decort_kvmvm": dataSourceCompute(), - "decort_image": dataSourceImage(), - "decort_disk": dataSourceDisk(), - "decort_vins": dataSourceVins(), - "decort_grid": dataSourceGrid(), - "decort_grid_list": dataSourceGridList(), - "decort_image_list": dataSourceImageList(), - "decort_image_list_stacks": dataSourceImageListStacks(), - "decort_snapshot_list": dataSourceSnapshotList(), - "decort_vgpu": dataSourceVGPU(), - "decort_pcidevice": dataSourcePcidevice(), - "decort_pcidevice_list": dataSourcePcideviceList(), - "decort_sep_list": dataSourceSepList(), - "decort_sep": dataSourceSep(), - "decort_sep_consumption": dataSourceSepConsumption(), - "decort_sep_disk_list": dataSourceSepDiskList(), - "decort_sep_config": dataSourceSepConfig(), - "decort_sep_pool": dataSourceSepPool(), - "decort_disk_list": dataSourceDiskList(), - "decort_rg_list": dataSourceRgList(), - "decort_account_list": dataSourceAccountList(), - "decort_account_computes_list": dataSourceAccountComputesList(), - "decort_account_disks_list": dataSourceAccountDisksList(), - "decort_account_vins_list": dataSourceAccountVinsList(), - "decort_account_audits_list": dataSourceAccountAuditsList(), - "decort_account_rg_list": dataSourceAccountRGList(), - "decort_account_consumed_units": dataSourceAccountConsumedUnits(), - "decort_account_consumed_units_by_type": dataSourceAccountConsumedUnitsByType(), - "decort_account_reserved_units": dataSourceAccountReservedUnits(), - "decort_account_templates_list": dataSourceAccountTemplatessList(), - "decort_account_deleted_list": dataSourceAccountDeletedList(), - "decort_account_flipgroups_list": dataSourceAccountFlipGroupsList(), - "decort_bservice_list": dataSourceBasicServiceList(), - "decort_bservice": dataSourceBasicService(), - "decort_bservice_snapshot_list": dataSourceBasicServiceSnapshotList(), - "decort_bservice_group": dataSourceBasicServiceGroup(), - "decort_bservice_deleted_list": dataSourceBasicServiceDeletedList(), - "decort_extnet_list": dataSourceExtnetList(), - "decort_extnet_computes_list": dataSourceExtnetComputesList(), - "decort_extnet": dataSourceExtnet(), - "decort_extnet_default": dataSourceExtnetDefault(), - "decort_vins_list": dataSourceVinsList(), - // "decort_pfw": dataSourcePfw(), - }, - - ConfigureFunc: providerConfigure, - } -} - -func stateFuncToLower(argval interface{}) string { - return strings.ToLower(argval.(string)) -} - -func stateFuncToUpper(argval interface{}) string { - return strings.ToUpper(argval.(string)) -} - -func providerConfigure(d *schema.ResourceData) (interface{}, error) { - decsController, err := ControllerConfigure(d) - if err != nil { - return nil, err - } - - // initialize global default Grid ID - it will be needed to create some resource types, e.g. disks - gridId, err := decsController.utilityLocationGetDefaultGridID() - if err != nil { - return nil, err - } - if gridId == 0 { - return nil, fmt.Errorf("providerConfigure: invalid default Grid ID = 0") - } - - return decsController, nil -} diff --git a/go.mod b/go.mod index 6221e3f..8663324 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,6 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/google/uuid v1.3.0 github.com/hashicorp/terraform-plugin-docs v0.5.1 - github.com/hashicorp/terraform-plugin-sdk v1.16.0 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0 // indirect github.com/sirupsen/logrus v1.7.0 ) diff --git a/go.sum b/go.sum index b3d57c6..66dcc19 100644 --- a/go.sum +++ b/go.sum @@ -55,13 +55,17 @@ github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/g github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apparentlymart/go-cidr v1.0.1 h1:NmIwLZ/KdsjIUlhf+/Np40atNXm/+lZ5txfTJ/SpF+U= github.com/apparentlymart/go-cidr v1.0.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= +github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU= +github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFUye+ZcSR6opIgz9Co7WcDx6ZcY+RjfFHoA0I= github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= +github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= @@ -77,12 +81,18 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -94,11 +104,14 @@ github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3 github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= @@ -145,6 +158,10 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -154,8 +171,12 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0 h1:pMen7vLs8nvgEYhywH3KDWJIJTeEr2ULsVWHWYHQyBs= @@ -175,6 +196,7 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU= @@ -183,6 +205,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY= github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY= github.com/hashicorp/go-getter v1.5.3 h1:NF5+zOlQegim+w/EUhSLh6QhXHmZMEeHLQzllkQ3ROU= @@ -190,27 +214,43 @@ github.com/hashicorp/go-getter v1.5.3/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXj github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= +github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-plugin v1.3.0 h1:4d/wJojzvHV1I4i/rrjVaeuyxWrLzDE1mDCyDy8fXS8= github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0= +github.com/hashicorp/go-plugin v1.4.4 h1:NVdrSdFRt3SkZtNckJ6tog7gbpRrcbOjQi/rgF7JYWQ= +github.com/hashicorp/go-plugin v1.4.4/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s= github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo= github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw= github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.5.0 h1:O293SZ2Eg+AAYijkVK3jR786Am1bhDEh2GHT0tIVE5E= +github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hc-install v0.3.1/go.mod h1:3LCdWcCDS1gaHC9mhHCGbkYfoY6vdsKohGjugbZdZak= +github.com/hashicorp/hc-install v0.3.2/go.mod h1:xMG6Tr8Fw1WFjlxH0A9v61cW15pFwgEGqEz0V4jisHs= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90= github.com/hashicorp/hcl/v2 v2.3.0 h1:iRly8YaMwTBAKhn1Ybk7VSdzbnopghktCD031P8ggUE= github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8= +github.com/hashicorp/hcl/v2 v2.12.0 h1:PsYxySWpMD4KPaoJLnsHwtK5Qptvj/4Q6s0t4sUxZf4= +github.com/hashicorp/hcl/v2 v2.12.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 h1:+RyjwU+Gnd/aTJBPZVDNm903eXVjjqhbaR4Ypx3xYyY= @@ -218,16 +258,28 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 github.com/hashicorp/terraform-exec v0.10.0/go.mod h1:tOT8j1J8rP05bZBGWXfMyU3HkLi1LWyqL3Bzsc3CJjo= github.com/hashicorp/terraform-exec v0.15.0 h1:cqjh4d8HYNQrDoEmlSGelHmg2DYDh5yayckvJ5bV18E= github.com/hashicorp/terraform-exec v0.15.0/go.mod h1:H4IG8ZxanU+NW0ZpDRNsvh9f0ul7C0nHP+rUR/CHs7I= +github.com/hashicorp/terraform-exec v0.16.1/go.mod h1:aj0lVshy8l+MHhFNoijNHtqTJQI3Xlowv5EOsEaGO7M= github.com/hashicorp/terraform-json v0.5.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY= github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk= +github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= github.com/hashicorp/terraform-plugin-docs v0.5.1 h1:WwrUcamix9x0TqfTw/WGHMRqoTe1QPZKaeWJPuFb4lQ= github.com/hashicorp/terraform-plugin-docs v0.5.1/go.mod h1:SQwEgy0/B0UPQ07rNEG1Wpt6E3jvRcCwkVHPNybGgc0= +github.com/hashicorp/terraform-plugin-go v0.9.1 h1:vXdHaQ6aqL+OF076nMSBV+JKPdmXlzG5mzVDD04WyPs= +github.com/hashicorp/terraform-plugin-go v0.9.1/go.mod h1:ItjVSlQs70otlzcCwlPcU8FRXLdO973oYFRZwAOxy8M= +github.com/hashicorp/terraform-plugin-log v0.4.0 h1:F3eVnm8r2EfQCe2k9blPIiF/r2TT01SHijXnS7bujvc= +github.com/hashicorp/terraform-plugin-log v0.4.0/go.mod h1:9KclxdunFownr4pIm1jdmwKRmE4d6HVG2c9XDq47rpg= github.com/hashicorp/terraform-plugin-sdk v1.16.0 h1:NrkXMRjHErUPPTHQkZ6JIn6bByiJzGnlJzH1rVdNEuE= github.com/hashicorp/terraform-plugin-sdk v1.16.0/go.mod h1:5sVxrwW6/xzFhZyql+Q9zXCUEJaGWcBIxBbZFLpVXOI= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0 h1:Qr5fWNg1SPSfCRMtou67Y6Kcy9UnMYRNlIJTKRuUvXU= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0/go.mod h1:b+LFg8WpYgFgvEBP/6Htk5H9/pJp1V1E8NJAekfH2Ws= github.com/hashicorp/terraform-plugin-test/v2 v2.1.2/go.mod h1:jerO5mrd+jVNALy8aiq+VZOg/CR8T2T1QR3jd6JKGOI= +github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 h1:1FGtlkJw87UsTMg5s8jrekrHmUPUJaMcu6ELiVhQrNw= +github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= +github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0= +github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= @@ -272,11 +324,14 @@ github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -294,16 +349,21 @@ github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go. github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.0.4 h1:ZU1VNC02qyufSZsjjs7+khruk2fKvbQ3TwRV/IBCeFA= github.com/mitchellh/go-testing-interface v1.0.4/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= +github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -316,6 +376,7 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI= github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= @@ -336,6 +397,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -346,6 +408,8 @@ github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oW github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU= github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= +github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvCazn8G65U= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY= @@ -360,6 +424,7 @@ github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= +github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.9.1/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0= github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= @@ -372,6 +437,7 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -384,6 +450,7 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -444,6 +511,9 @@ golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210326060303-6b1517762897 h1:KrsHThm5nFk34YtATK1LsThyGhGbGe1olrte/HInHvs= golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= @@ -477,6 +547,7 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -492,10 +563,13 @@ golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -554,6 +628,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -601,6 +676,7 @@ google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= @@ -619,6 +695,11 @@ google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKa google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE= google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -630,6 +711,11 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -641,6 +727,7 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/constants/api.go b/internal/constants/api.go new file mode 100644 index 0000000..74f24e8 --- /dev/null +++ b/internal/constants/api.go @@ -0,0 +1,26 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package constants + +//CloudApi - a part of url for cloudapi +const CloudApi = "/restmachine/cloudapi" + +//CloudBroker - a part of url for cloudbroker +const CloudBroker = "/restmachine/cloudbroker" diff --git a/decort/constants.go b/internal/constants/constants.go similarity index 65% rename from decort/constants.go rename to internal/constants/constants.go index e4ddc67..436d647 100644 --- a/decort/constants.go +++ b/internal/constants/constants.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,29 +17,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. - -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. -*/ - -package decort +package constants // LimitMaxVinsPerResgroup set maximum number of VINs instances per Resource Group -const LimitMaxVinsPerResgroup=4 +const LimitMaxVinsPerResgroup = 4 // MaxSshKeysPerCompute sets maximum number of user:ssh_key pairs to authorize when creating new compute -const MaxSshKeysPerCompute=12 +const MaxSshKeysPerCompute = 12 // MaxExtraDisksPerCompute sets maximum number of extra disks that can be added when creating new compute -const MaxExtraDisksPerCompute=12 +const MaxExtraDisksPerCompute = 12 // MaxNetworksPerCompute sets maximum number of vNICs per compute -const MaxNetworksPerCompute=8 +const MaxNetworksPerCompute = 8 // MaxCpusPerCompute sets maximum number of vCPUs per compute -const MaxCpusPerCompute=128 +const MaxCpusPerCompute = 128 // MinRamPerCompute sets minimum amount of RAM per compute in MB -const MinRamPerCompute=128 \ No newline at end of file +const MinRamPerCompute = 128 diff --git a/internal/constants/timeouts.go b/internal/constants/timeouts.go new file mode 100644 index 0000000..71cc7d1 --- /dev/null +++ b/internal/constants/timeouts.go @@ -0,0 +1,28 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package constants + +import "time" + +// timeouts for API calls from CRUD functions of Terraform plugin +var Timeout30s = time.Second * 30 +var Timeout60s = time.Second * 60 +var Timeout180s = time.Second * 180 +var Timeout20m = time.Minute * 20 diff --git a/decort/controller.go b/internal/controller/controller.go similarity index 95% rename from decort/controller.go rename to internal/controller/controller.go index 19a5ac1..d36389e 100644 --- a/decort/controller.go +++ b/internal/controller/controller.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,14 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. - -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. -*/ - -package decort +package controller import ( "bytes" @@ -41,8 +36,7 @@ import ( "github.com/dgrijalva/jwt-go" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // enumerated constants that define authentication modes @@ -191,7 +185,7 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) { return ret_config, nil } -func (config *ControllerCfg) getDecortUsername() string { +func (config *ControllerCfg) GetDecortUsername() string { return config.decort_username } @@ -331,7 +325,7 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) { return true, nil } -func (config *ControllerCfg) decortAPICall(method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam +func (config *ControllerCfg) DecortAPICall(method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam // This is a convenience wrapper around standard HTTP request methods that is aware of the // authorization mode for which the provider was initialized and compiles request accordingly. diff --git a/internal/flattens/meta.go b/internal/flattens/meta.go new file mode 100644 index 0000000..85c30c3 --- /dev/null +++ b/internal/flattens/meta.go @@ -0,0 +1,41 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package flattens + +import "strconv" + +func FlattenMeta(m []interface{}) []string { + output := []string{} + for _, item := range m { + switch d := item.(type) { + case string: + output = append(output, d) + case int: + output = append(output, strconv.Itoa(d)) + case int64: + output = append(output, strconv.FormatInt(d, 10)) + case float64: + output = append(output, strconv.FormatInt(int64(d), 10)) + default: + output = append(output, "") + } + } + return output +} diff --git a/internal/location/api.go b/internal/location/api.go new file mode 100644 index 0000000..169b89b --- /dev/null +++ b/internal/location/api.go @@ -0,0 +1,22 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package location + +const LocationsListAPI = "/restmachine/cloudapi/locations/list" // Returns list of GridRecord on success diff --git a/decort/utility_location.go b/internal/location/location.go similarity index 64% rename from decort/utility_location.go rename to internal/location/location.go index c1fd12f..a5333a9 100644 --- a/decort/utility_location.go +++ b/internal/location/location.go @@ -1,65 +1,59 @@ -/* -Copyright (c) 2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -/* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. - -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. -*/ - -package decort - -import ( - "encoding/json" - "fmt" - "net/url" - - log "github.com/sirupsen/logrus" - - // "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" -) - -var DefaultGridID int - -func (controller *ControllerCfg) utilityLocationGetDefaultGridID() (int, error) { - urlValues := &url.Values{} - - log.Debug("utilityLocationGetDefaultGridID: retrieving locations list") - apiResp, err := controller.decortAPICall("POST", LocationsListAPI, urlValues) - if err != nil { - return 0, err - } - - locList := LocationsListResp{} - err = json.Unmarshal([]byte(apiResp), &locList) - if err != nil { - return 0, err - } - - if len(locList) == 0 { - DefaultGridID = 0 - return 0, fmt.Errorf("utilityLocationGetDefaultGridID: retrieved 0 length locations list") - } - - DefaultGridID = locList[0].GridID - log.Debugf("utilityLocationGetDefaultGridID: default location GridID %d, name %s", DefaultGridID, locList[0].Name) - - return DefaultGridID, nil -} - +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package location + +import ( + "encoding/json" + "fmt" + "net/url" + + "github.com/rudecs/terraform-provider-decort/internal/controller" + log "github.com/sirupsen/logrus" +) + +var DefaultGridID int + +func UtilityLocationGetDefaultGridID(m interface{}) (int, error) { + c := m.(*controller.ControllerCfg) + + urlValues := &url.Values{} + + log.Debug("utilityLocationGetDefaultGridID: retrieving locations list") + apiResp, err := c.DecortAPICall("POST", LocationsListAPI, urlValues) + if err != nil { + return 0, err + } + + locList := LocationsListResp{} + err = json.Unmarshal([]byte(apiResp), &locList) + if err != nil { + return 0, err + } + + if len(locList) == 0 { + DefaultGridID = 0 + return 0, fmt.Errorf("utilityLocationGetDefaultGridID: retrieved 0 length locations list") + } + + DefaultGridID = locList[0].GridID + log.Debugf("utilityLocationGetDefaultGridID: default location GridID %d, name %s", DefaultGridID, locList[0].Name) + + return DefaultGridID, nil +} diff --git a/internal/location/models.go b/internal/location/models.go new file mode 100644 index 0000000..b42c9f8 --- /dev/null +++ b/internal/location/models.go @@ -0,0 +1,30 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package location + +type LocationRecord struct { + GridID int `json:"gid"` + Id int `json:"id"` + LocationCode string `json:"locationCode"` + Name string `json:"name"` + Flag string `json:"flag"` +} + +type LocationsListResp []LocationRecord diff --git a/internal/provider/data_sources_map.go b/internal/provider/data_sources_map.go new file mode 100644 index 0000000..70d715a --- /dev/null +++ b/internal/provider/data_sources_map.go @@ -0,0 +1,87 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package provider + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/account" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/bservice" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/disks" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/extnet" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/rg" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/snapshot" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/vgpu" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/vins" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/grid" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/image" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/pcidevice" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/sep" +) + +func NewDataSourcesMap() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "decort_account": account.DataSourceAccount(), + "decort_resgroup": rg.DataSourceResgroup(), + // "decort_kvmvm": dataSourceCompute(), + "decort_image": image.DataSourceImage(), + "decort_disk": disks.DataSourceDisk(), + "decort_vins": vins.DataSourceVins(), + "decort_grid": grid.DataSourceGrid(), + "decort_grid_list": grid.DataSourceGridList(), + "decort_image_list": image.DataSourceImageList(), + "decort_image_list_stacks": image.DataSourceImageListStacks(), + "decort_snapshot_list": snapshot.DataSourceSnapshotList(), + "decort_vgpu": vgpu.DataSourceVGPU(), + "decort_pcidevice": pcidevice.DataSourcePcidevice(), + "decort_pcidevice_list": pcidevice.DataSourcePcideviceList(), + "decort_sep_list": sep.DataSourceSepList(), + "decort_sep": sep.DataSourceSep(), + "decort_sep_consumption": sep.DataSourceSepConsumption(), + "decort_sep_disk_list": sep.DataSourceSepDiskList(), + "decort_sep_config": sep.DataSourceSepConfig(), + "decort_sep_pool": sep.DataSourceSepPool(), + "decort_disk_list": disks.DataSourceDiskList(), + "decort_rg_list": rg.DataSourceRgList(), + "decort_account_list": account.DataSourceAccountList(), + "decort_account_computes_list": account.DataSourceAccountComputesList(), + "decort_account_disks_list": account.DataSourceAccountDisksList(), + "decort_account_vins_list": account.DataSourceAccountVinsList(), + "decort_account_audits_list": account.DataSourceAccountAuditsList(), + "decort_account_rg_list": account.DataSourceAccountRGList(), + "decort_account_consumed_units": account.DataSourceAccountConsumedUnits(), + "decort_account_consumed_units_by_type": account.DataSourceAccountConsumedUnitsByType(), + "decort_account_reserved_units": account.DataSourceAccountReservedUnits(), + "decort_account_templates_list": account.DataSourceAccountTemplatessList(), + "decort_account_deleted_list": account.DataSourceAccountDeletedList(), + "decort_account_flipgroups_list": account.DataSourceAccountFlipGroupsList(), + "decort_bservice_list": bservice.DataSourceBasicServiceList(), + "decort_bservice": bservice.DataSourceBasicService(), + "decort_bservice_snapshot_list": bservice.DataSourceBasicServiceSnapshotList(), + "decort_bservice_group": bservice.DataSourceBasicServiceGroup(), + "decort_bservice_deleted_list": bservice.DataSourceBasicServiceDeletedList(), + "decort_extnet_list": extnet.DataSourceExtnetList(), + "decort_extnet_computes_list": extnet.DataSourceExtnetComputesList(), + "decort_extnet": extnet.DataSourceExtnet(), + "decort_extnet_default": extnet.DataSourceExtnetDefault(), + "decort_vins_list": vins.DataSourceVinsList(), + // "decort_pfw": dataSourcePfw(), + } + +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go new file mode 100644 index 0000000..ec3d24d --- /dev/null +++ b/internal/provider/provider.go @@ -0,0 +1,134 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package provider + +import ( + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/location" +) + +func Provider() *schema.Provider { + return &schema.Provider{ + Schema: map[string]*schema.Schema{ + "authenticator": { + Type: schema.TypeString, + Required: true, + StateFunc: StateFuncToLower, + ValidateFunc: validation.StringInSlice([]string{"oauth2", "legacy", "jwt"}, true), // ignore case while validating + Description: "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'oauth2', 'legacy' or 'jwt'.", + }, + + "oauth2_url": { + Type: schema.TypeString, + Optional: true, + StateFunc: StateFuncToLower, + DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil), + Description: "OAuth2 application URL in 'oauth2' authentication mode.", + }, + + "controller_url": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + StateFunc: StateFuncToLower, + Description: "URL of DECORT Cloud controller to use. API calls will be directed to this URL.", + }, + + "user": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("DECORT_USER", nil), + Description: "User name for DECORT cloud API operations in 'legacy' authentication mode.", + }, + + "password": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("DECORT_PASSWORD", nil), + Description: "User password for DECORT cloud API operations in 'legacy' authentication mode.", + }, + + "app_id": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_ID", nil), + Description: "Application ID to access DECORT cloud API in 'oauth2' authentication mode.", + }, + + "app_secret": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_SECRET", nil), + Description: "Application secret to access DECORT cloud API in 'oauth2' authentication mode.", + }, + + "jwt": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("DECORT_JWT", nil), + Description: "JWT to access DECORT cloud API in 'jwt' authentication mode.", + }, + + "allow_unverified_ssl": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "If true, DECORT API will not verify SSL certificates. Use this with caution and in trusted environments only!", + }, + }, + + ResourcesMap: NewRersourcesMap(), + + DataSourcesMap: NewDataSourcesMap(), + + ConfigureFunc: providerConfigure, + } +} + +func StateFuncToLower(argval interface{}) string { + return strings.ToLower(argval.(string)) +} + +func StateFuncToUpper(argval interface{}) string { + return strings.ToUpper(argval.(string)) +} + +func providerConfigure(d *schema.ResourceData) (interface{}, error) { + decsController, err := controller.ControllerConfigure(d) + if err != nil { + return nil, err + } + + gridId, err := location.UtilityLocationGetDefaultGridID(decsController) + if err != nil { + return nil, err + } + if gridId == 0 { + return nil, fmt.Errorf("providerConfigure: invalid default Grid ID = 0") + } + + return decsController, nil +} diff --git a/internal/provider/resource_map.go b/internal/provider/resource_map.go new file mode 100644 index 0000000..1c03347 --- /dev/null +++ b/internal/provider/resource_map.go @@ -0,0 +1,58 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package provider + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/account" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/bservice" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/disks" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/k8s" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/pfw" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/rg" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/snapshot" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudapi/vins" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/image" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/pcidevice" + "github.com/rudecs/terraform-provider-decort/internal/service/cloudbroker/sep" +) + +func NewRersourcesMap() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "decort_resgroup": rg.ResourceResgroup(), + // "decort_kvmvm": resourceCompute(), + "decort_disk": disks.ResourceDisk(), + "decort_vins": vins.ResourceVins(), + "decort_pfw": pfw.ResourcePfw(), + "decort_k8s": k8s.ResourceK8s(), + "decort_k8s_wg": k8s.ResourceK8sWg(), + "decort_image": image.ResourceImage(), + "decort_virtual_image": image.ResourceVirtualImage(), + "decort_cdrom_image": image.ResourceCDROMImage(), + "decort_delete_images": image.ResourceDeleteImages(), + "decort_snapshot": snapshot.ResourceSnapshot(), + "decort_pcidevice": pcidevice.ResourcePcidevice(), + "decort_sep": sep.ResourceSep(), + "decort_sep_config": sep.ResourceSepConfig(), + "decort_account": account.ResourceAccount(), + "decort_bservice": bservice.ResourceBasicService(), + "decort_bservice_group": bservice.ResourceBasicServiceGroup(), + } +} diff --git a/internal/service/cloudapi/account/api.go b/internal/service/cloudapi/account/api.go new file mode 100644 index 0000000..b69c616 --- /dev/null +++ b/internal/service/cloudapi/account/api.go @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package account + +const accountAddUserAPI = "/restmachine/cloudapi/account/addUser" +const accountAuditsAPI = "/restmachine/cloudapi/account/audits" +const accountCreateAPI = "/restmachine/cloudapi/account/create" +const accountDeleteAPI = "/restmachine/cloudapi/account/delete" +const accountDeleteUserAPI = "/restmachine/cloudapi/account/deleteUser" +const accountDisableAPI = "/restmachine/cloudapi/account/disable" +const accountEnableAPI = "/restmachine/cloudapi/account/enable" +const accountGetAPI = "/restmachine/cloudapi/account/get" +const accountGetConsumedUnitsAPI = "/restmachine/cloudapi/account/getConsumedAccountUnits" +const accountGetConsumedUnitsByTypeAPI = "/restmachine/cloudapi/account/getConsumedCloudUnitsByType" +const accountGetReservedUnitsAPI = "/restmachine/cloudapi/account/getReservedAccountUnits" +const accountListAPI = "/restmachine/cloudapi/account/list" +const accountListComputesAPI = "/restmachine/cloudapi/account/listComputes" +const accountListDeletedAPI = "/restmachine/cloudapi/account/listDeleted" +const accountListDisksAPI = "/restmachine/cloudapi/account/listDisks" +const accountListFlipGroupsAPI = "/restmachine/cloudapi/account/listFlipGroups" +const accountListRGAPI = "/restmachine/cloudapi/account/listRG" +const accountListTemplatesAPI = "/restmachine/cloudapi/account/listTemplates" +const accountListVinsAPI = "/restmachine/cloudapi/account/listVins" +const accountRestoreAPI = "/restmachine/cloudapi/account/restore" +const accountUpdateAPI = "/restmachine/cloudapi/account/update" +const accountUpdateUserAPI = "/restmachine/cloudapi/account/updateUser" diff --git a/decort/data_source_account.go b/internal/service/cloudapi/account/data_source_account.go similarity index 86% rename from decort/data_source_account.go rename to internal/service/cloudapi/account/data_source_account.go index 39ef95c..85f4003 100644 --- a/decort/data_source_account.go +++ b/internal/service/cloudapi/account/data_source_account.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/flattens" ) -func dataSourceAccountRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { acc, err := utilityAccountCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -40,7 +52,7 @@ func dataSourceAccountRead(d *schema.ResourceData, m interface{}) error { d.Set("dc_location", acc.DCLocation) d.Set("resources", flattenAccResources(acc.Resources)) d.Set("ckey", acc.CKey) - d.Set("meta", flattenMeta(acc.Meta)) + d.Set("meta", flattens.FlattenMeta(acc.Meta)) d.Set("acl", flattenAccAcl(acc.Acl)) d.Set("company", acc.Company) d.Set("companyurl", acc.CompanyUrl) @@ -103,6 +115,22 @@ func flattenAccAcl(acls []AccountAclRecord) []map[string]interface{} { return res } +func flattenRgResourceLimits(rl ResourceLimits) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + temp := map[string]interface{}{ + "cu_c": rl.CUC, + "cu_d": rl.CUD, + "cu_i": rl.CUI, + "cu_m": rl.CUM, + "cu_np": rl.CUNP, + "gpu_units": rl.GpuUnits, + } + res = append(res, temp) + + return res + +} + func flattenAccResources(r Resources) []map[string]interface{} { res := make([]map[string]interface{}, 0) temp := map[string]interface{}{ @@ -401,15 +429,15 @@ func dataSourceAccountSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccount() *schema.Resource { +func DataSourceAccount() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountRead, + ReadContext: dataSourceAccountRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountSchemaMake(), diff --git a/decort/data_source_account_audits_list.go b/internal/service/cloudapi/account/data_source_account_audits_list.go similarity index 66% rename from decort/data_source_account_audits_list.go rename to internal/service/cloudapi/account/data_source_account_audits_list.go index c31e947..6351c70 100644 --- a/decort/data_source_account_audits_list.go +++ b/internal/service/cloudapi/account/data_source_account_audits_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountAuditsList(aal AccountAuditsList) []map[string]interface{} { @@ -45,10 +56,10 @@ func flattenAccountAuditsList(aal AccountAuditsList) []map[string]interface{} { } -func dataSourceAccountAuditsListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountAuditsList, err := utilityAccountAuditsListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -98,15 +109,15 @@ func dataSourceAccountAuditsListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountAuditsList() *schema.Resource { +func DataSourceAccountAuditsList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountAuditsListRead, + ReadContext: dataSourceAccountAuditsListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountAuditsListSchemaMake(), diff --git a/decort/data_source_account_computes_list.go b/internal/service/cloudapi/account/data_source_account_computes_list.go similarity index 77% rename from decort/data_source_account_computes_list.go rename to internal/service/cloudapi/account/data_source_account_computes_list.go index 8a7ba77..9828c2a 100644 --- a/decort/data_source_account_computes_list.go +++ b/internal/service/cloudapi/account/data_source_account_computes_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountComputesList(acl AccountComputesList) []map[string]interface{} { @@ -60,10 +71,10 @@ func flattenAccountComputesList(acl AccountComputesList) []map[string]interface{ } -func dataSourceAccountComputesListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountComputesList, err := utilityAccountComputesListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -173,15 +184,15 @@ func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountComputesList() *schema.Resource { +func DataSourceAccountComputesList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountComputesListRead, + ReadContext: dataSourceAccountComputesListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountComputesListSchemaMake(), diff --git a/decort/data_source_account_consumed_units.go b/internal/service/cloudapi/account/data_source_account_consumed_units.go similarity index 62% rename from decort/data_source_account_consumed_units.go rename to internal/service/cloudapi/account/data_source_account_consumed_units.go index 6723e17..52b9f19 100644 --- a/decort/data_source_account_consumed_units.go +++ b/internal/service/cloudapi/account/data_source_account_consumed_units.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceAccountConsumedUnitsRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -82,15 +93,15 @@ func dataSourceAccountConsumedUnitsSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountConsumedUnits() *schema.Resource { +func DataSourceAccountConsumedUnits() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountConsumedUnitsRead, + ReadContext: dataSourceAccountConsumedUnitsRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountConsumedUnitsSchemaMake(), diff --git a/decort/data_source_account_consumed_units_by_type.go b/internal/service/cloudapi/account/data_source_account_consumed_units_by_type.go similarity index 56% rename from decort/data_source_account_consumed_units_by_type.go rename to internal/service/cloudapi/account/data_source_account_consumed_units_by_type.go index 4b9ccd6..877608e 100644 --- a/decort/data_source_account_consumed_units_by_type.go +++ b/internal/service/cloudapi/account/data_source_account_consumed_units_by_type.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceAccountConsumedUnitsByTypeRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountConsumedUnitsByTypeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { result, err := utilityAccountConsumedUnitsByTypeCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -62,15 +73,15 @@ func dataSourceAccountConsumedUnitsByTypeSchemaMake() map[string]*schema.Schema return res } -func dataSourceAccountConsumedUnitsByType() *schema.Resource { +func DataSourceAccountConsumedUnitsByType() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountConsumedUnitsByTypeRead, + ReadContext: dataSourceAccountConsumedUnitsByTypeRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountConsumedUnitsByTypeSchemaMake(), diff --git a/internal/service/cloudapi/account/data_source_account_deleted_list.go b/internal/service/cloudapi/account/data_source_account_deleted_list.go new file mode 100644 index 0000000..0dc1d3f --- /dev/null +++ b/internal/service/cloudapi/account/data_source_account_deleted_list.go @@ -0,0 +1,69 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package account + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" +) + +func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountDeletedList, err := utilityAccountDeletedListCheckPresence(d, m) + if err != nil { + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenAccountList(accountDeletedList)) + + return nil +} + +func DataSourceAccountDeletedList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceAccountDeletedListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceAccountListSchemaMake(), + } +} diff --git a/decort/data_source_account_disks_list.go b/internal/service/cloudapi/account/data_source_account_disks_list.go similarity index 67% rename from decort/data_source_account_disks_list.go rename to internal/service/cloudapi/account/data_source_account_disks_list.go index def9676..9871eed 100644 --- a/decort/data_source_account_disks_list.go +++ b/internal/service/cloudapi/account/data_source_account_disks_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,25 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. -*/ +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. -package decort +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} { @@ -46,10 +56,10 @@ func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} { } -func dataSourceAccountDisksListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountDisksList, err := utilityAccountDisksListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -103,15 +113,15 @@ func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountDisksList() *schema.Resource { +func DataSourceAccountDisksList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountDisksListRead, + ReadContext: dataSourceAccountDisksListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountDisksListSchemaMake(), diff --git a/decort/data_source_account_flipgroups_list.go b/internal/service/cloudapi/account/data_source_account_flipgroups_list.go similarity index 77% rename from decort/data_source_account_flipgroups_list.go rename to internal/service/cloudapi/account/data_source_account_flipgroups_list.go index dd83716..09bc65b 100644 --- a/decort/data_source_account_flipgroups_list.go +++ b/internal/service/cloudapi/account/data_source_account_flipgroups_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountFlipGroupsList(afgl AccountFlipGroupsList) []map[string]interface{} { @@ -61,10 +72,10 @@ func flattenAccountFlipGroupsList(afgl AccountFlipGroupsList) []map[string]inter } -func dataSourceAccountFlipGroupsListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -178,15 +189,15 @@ func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountFlipGroupsList() *schema.Resource { +func DataSourceAccountFlipGroupsList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountFlipGroupsListRead, + ReadContext: dataSourceAccountFlipGroupsListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountFlipGroupsListSchemaMake(), diff --git a/decort/data_source_account_list.go b/internal/service/cloudapi/account/data_source_account_list.go similarity index 79% rename from decort/data_source_account_list.go rename to internal/service/cloudapi/account/data_source_account_list.go index b587bda..df625d0 100644 --- a/decort/data_source_account_list.go +++ b/internal/service/cloudapi/account/data_source_account_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountList(al AccountCloudApiList) []map[string]interface{} { @@ -46,6 +57,22 @@ func flattenAccountList(al AccountCloudApiList) []map[string]interface{} { return res } +func flattenRgAcl(rgAcls []AccountAclRecord) []map[string]interface{} { + res := make([]map[string]interface{}, 0) + for _, rgAcl := range rgAcls { + temp := map[string]interface{}{ + "explicit": rgAcl.IsExplicit, + "guid": rgAcl.Guid, + "right": rgAcl.Rights, + "status": rgAcl.Status, + "type": rgAcl.Type, + "user_group_id": rgAcl.UgroupID, + } + res = append(res, temp) + } + return res +} + /*uncomment for cloudbroker func flattenAccountList(al AccountList) []map[string]interface{} { res := make([]map[string]interface{}, 0) @@ -91,10 +118,10 @@ func flattenAccountList(al AccountList) []map[string]interface{} { } */ -func dataSourceAccountListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountList, err := utilityAccountListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -290,15 +317,15 @@ func dataSourceAccountListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountList() *schema.Resource { +func DataSourceAccountList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountListRead, + ReadContext: dataSourceAccountListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountListSchemaMake(), diff --git a/decort/data_source_account_reserved_units.go b/internal/service/cloudapi/account/data_source_account_reserved_units.go similarity index 62% rename from decort/data_source_account_reserved_units.go rename to internal/service/cloudapi/account/data_source_account_reserved_units.go index b4d48c9..d708129 100644 --- a/decort/data_source_account_reserved_units.go +++ b/internal/service/cloudapi/account/data_source_account_reserved_units.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceAccountReservedUnitsRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -82,15 +93,15 @@ func dataSourceAccountReservedUnitsSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountReservedUnits() *schema.Resource { +func DataSourceAccountReservedUnits() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountReservedUnitsRead, + ReadContext: dataSourceAccountReservedUnitsRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountReservedUnitsSchemaMake(), diff --git a/decort/data_source_account_rg_list.go b/internal/service/cloudapi/account/data_source_account_rg_list.go similarity index 83% rename from decort/data_source_account_rg_list.go rename to internal/service/cloudapi/account/data_source_account_rg_list.go index 40e2284..29f885f 100644 --- a/decort/data_source_account_rg_list.go +++ b/internal/service/cloudapi/account/data_source_account_rg_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountRGList(argl AccountRGList) []map[string]interface{} { @@ -74,10 +85,10 @@ func flattenAccRGResources(argr AccountRGResources) []map[string]interface{} { return res } -func dataSourceAccountRGListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountRGList, err := utilityAccountRGListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -278,15 +289,15 @@ func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountRGList() *schema.Resource { +func DataSourceAccountRGList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountRGListRead, + ReadContext: dataSourceAccountRGListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountRGListSchemaMake(), diff --git a/decort/data_source_account_templates_list.go b/internal/service/cloudapi/account/data_source_account_templates_list.go similarity index 70% rename from decort/data_source_account_templates_list.go rename to internal/service/cloudapi/account/data_source_account_templates_list.go index 4071088..113d9a7 100644 --- a/decort/data_source_account_templates_list.go +++ b/internal/service/cloudapi/account/data_source_account_templates_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountTemplatesList(atl AccountTemplatesList) []map[string]interface{} { @@ -50,10 +61,10 @@ func flattenAccountTemplatesList(atl AccountTemplatesList) []map[string]interfac } -func dataSourceAccountTemplatesListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -123,15 +134,15 @@ func dataSourceAccountTemplatesListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountTemplatessList() *schema.Resource { +func DataSourceAccountTemplatessList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountTemplatesListRead, + ReadContext: dataSourceAccountTemplatesListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountTemplatesListSchemaMake(), diff --git a/decort/data_source_account_vins_list.go b/internal/service/cloudapi/account/data_source_account_vins_list.go similarity index 75% rename from decort/data_source_account_vins_list.go rename to internal/service/cloudapi/account/data_source_account_vins_list.go index e9d50e7..6542018 100644 --- a/decort/data_source_account_vins_list.go +++ b/internal/service/cloudapi/account/data_source_account_vins_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} { @@ -57,10 +68,10 @@ func flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} { } -func dataSourceAccountVinsListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { accountVinsList, err := utilityAccountVinsListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -158,15 +169,15 @@ func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceAccountVinsList() *schema.Resource { +func DataSourceAccountVinsList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceAccountVinsListRead, + ReadContext: dataSourceAccountVinsListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceAccountVinsListSchemaMake(), diff --git a/internal/service/cloudapi/account/models.go b/internal/service/cloudapi/account/models.go new file mode 100644 index 0000000..e7fca15 --- /dev/null +++ b/internal/service/cloudapi/account/models.go @@ -0,0 +1,260 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package account + +type AccountAclRecord struct { + IsExplicit bool `json:"explicit"` + Guid string `json:"guid"` + Rights string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UgroupID string `json:"userGroupId"` + CanBeDeleted bool `json:"canBeDeleted"` +} + +type ResourceLimits struct { + CUC float64 `json:"CU_C"` + CUD float64 `json:"CU_D"` + CUI float64 `json:"CU_I"` + CUM float64 `json:"CU_M"` + CUNP float64 `json:"CU_NP"` + GpuUnits float64 `json:"gpu_units"` +} + +type Account struct { + DCLocation string `json:"DCLocation"` + CKey string `jspn:"_ckey"` + Meta []interface{} `json:"_meta"` + Acl []AccountAclRecord `json:"acl"` + Company string `json:"company"` + CompanyUrl string `json:"companyurl"` + CreatedBy string `jspn:"createdBy"` + CreatedTime int `json:"createdTime"` + DeactiovationTime float64 `json:"deactivationTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + DisplayName string `json:"displayname"` + GUID int `json:"guid"` + ID int `json:"id"` + Name string `json:"name"` + ResourceLimits ResourceLimits `json:"resourceLimits"` + SendAccessEmails bool `json:"sendAccessEmails"` + ServiceAccount bool `json:"serviceAccount"` + Status string `json:"status"` + UpdatedTime int `json:"updatedTime"` + Version int `json:"version"` + Vins []int `json:"vins"` +} + +type AccountList []Account + +type AccountCloudApi struct { + Acl []AccountAclRecord `json:"acl"` + CreatedTime int `json:"createdTime"` + DeletedTime int `json:"deletedTime"` + ID int `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + UpdatedTime int `json:"updatedTime"` +} + +type AccountCloudApiList []AccountCloudApi + +type Resource struct { + CPU int `json:"cpu"` + Disksize int `json:"disksize"` + Extips int `json:"extips"` + Exttraffic int `json:"exttraffic"` + GPU int `json:"gpu"` + RAM int `json:"ram"` +} + +type Resources struct { + Current Resource `json:"Current"` + Reserved Resource `json:"Reserved"` +} + +type Computes struct { + Started int `json:"started"` + Stopped int `json:"stopped"` +} + +type Machines struct { + Running int `json:"running"` + Halted int `json:"halted"` +} + +type AccountWithResources struct { + Account + Resources Resources `json:"Resources"` + Computes Computes `json:"computes"` + Machines Machines `json:"machines"` + Vinses int `json:"vinses"` +} + +type AccountCompute struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + CPUs int `json:"cpus"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + ComputeId int `json:"id"` + ComputeName string `json:"name"` + RAM int `json:"ram"` + Registered bool `json:"registered"` + RgId int `json:"rgId"` + RgName string `json:"rgName"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + TotalDisksSize int `json:"totalDisksSize"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` + UserManaged bool `json:"userManaged"` + VinsConnected int `json:"vinsConnected"` +} + +type AccountComputesList []AccountCompute + +type AccountDisk struct { + ID int `json:"id"` + Name string `json:"name"` + Pool string `json:"pool"` + SepId int `json:"sepId"` + SizeMax int `json:"sizeMax"` + Type string `json:"type"` +} + +type AccountDisksList []AccountDisk + +type AccountVin struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + Computes int `json:"computes"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + ExternalIP string `json:"externalIP"` + ID int `json:"id"` + Name string `json:"name"` + Network string `json:"network"` + PriVnfDevId int `json:"priVnfDevId"` + RgId int `json:"rgId"` + RgName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` +} + +type AccountVinsList []AccountVin + +type AccountAudit struct { + Call string `json:"call"` + ResponseTime float64 `json:"responsetime"` + StatusCode int `json:"statuscode"` + Timestamp float64 `json:"timestamp"` + User string `json:"user"` +} + +type AccountAuditsList []AccountAudit + +type AccountRGComputes struct { + Started int `json:"Started"` + Stopped int `json:"Stopped"` +} + +type AccountRGResources struct { + Consumed Resource `json:"Consumed"` + Limits Resource `json:"Limits"` + Reserved Resource `json:"Reserved"` +} + +type AccountRG struct { + Computes AccountRGComputes `json:"Computes"` + Resources AccountRGResources `json:"Resources"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + RGID int `json:"id"` + Milestones int `json:"milestones"` + RGName string `json:"name"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` + Vinses int `json:"vinses"` +} + +type AccountRGList []AccountRG + +type AccountTemplate struct { + UNCPath string `json:"UNCPath"` + AccountId int `json:"accountId"` + Desc string `json:"desc"` + ID int `json:"id"` + Name string `json:"name"` + Public bool `json:"public"` + Size int `json:"size"` + Status string `json:"status"` + Type string `json:"type"` + Username string `json:"username"` +} + +type AccountTemplatesList []AccountTemplate + +type AccountFlipGroup struct { + AccountId int `json:"accountId"` + ClientType string `json:"clientType"` + ConnType string `json:"connType"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DefaultGW string `json:"defaultGW"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + Desc string `json:"desc"` + GID int `json:"gid"` + GUID int `json:"guid"` + ID int `json:"id"` + IP string `json:"ip"` + Milestones int `json:"milestones"` + Name string `json:"name"` + NetID int `json:"netId"` + NetType string `json:"netType"` + NetMask int `json:"netmask"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` +} + +type AccountFlipGroupsList []AccountFlipGroup diff --git a/decort/resource_account.go b/internal/service/cloudapi/account/resource_account.go similarity index 81% rename from decort/resource_account.go rename to internal/service/cloudapi/account/resource_account.go index 66fc97c..14a1222 100644 --- a/decort/resource_account.go +++ b/internal/service/cloudapi/account/resource_account.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,45 +18,54 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( - "errors" + "context" "net/url" "strconv" "strings" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/flattens" log "github.com/sirupsen/logrus" ) -func resourceAccountCreate(d *schema.ResourceData, m interface{}) error { +func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceAccountCreate") if accountId, ok := d.GetOk("account_id"); ok { if exists, err := resourceAccountExists(d, m); exists { if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(accountId.(int))) - err = resourceAccountRead(d, m) - if err != nil { - return err + diagnostics := resourceAccountRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } - return errors.New("provided account id does not exist") + return diag.Errorf("provided account id does not exist") } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("account_name").(string)) @@ -122,18 +133,18 @@ func resourceAccountCreate(d *schema.ResourceData, m interface{}) error { } } - accountId, err := controller.decortAPICall("POST", accountCreateAPI, urlValues) + accountId, err := c.DecortAPICall("POST", accountCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(accountId) d.Set("account_id", accountId) - err = resourceAccountRead(d, m) - if err != nil { - return err + diagnostics := resourceAccountRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } d.SetId(id.String()) @@ -141,19 +152,19 @@ func resourceAccountCreate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceAccountRead(d *schema.ResourceData, m interface{}) error { +func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceAccountRead") acc, err := utilityAccountCheckPresence(d, m) if acc == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("dc_location", acc.DCLocation) d.Set("resources", flattenAccResources(acc.Resources)) d.Set("ckey", acc.CKey) - d.Set("meta", flattenMeta(acc.Meta)) + d.Set("meta", flattens.FlattenMeta(acc.Meta)) d.Set("acl", flattenAccAcl(acc.Acl)) d.Set("company", acc.Company) d.Set("companyurl", acc.CompanyUrl) @@ -180,25 +191,25 @@ func resourceAccountRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceAccountDelete(d *schema.ResourceData, m interface{}) error { +func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceAccountDelete") account, err := utilityAccountCheckPresence(d, m) if account == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool))) - _, err = controller.decortAPICall("POST", accountDeleteAPI, urlValues) + _, err = c.DecortAPICall("POST", accountDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -219,9 +230,9 @@ func resourceAccountExists(d *schema.ResourceData, m interface{}) (bool, error) return true, nil } -func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { +func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceAccountEdit") - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if d.HasChange("enable") { @@ -232,9 +243,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { } urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.decortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall("POST", api, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -243,9 +254,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { if d.HasChange("account_name") { urlValues.Add("name", d.Get("account_name").(string)) urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.decortAPICall("POST", accountUpdateAPI, urlValues) + _, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -307,9 +318,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { } urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.decortAPICall("POST", accountUpdateAPI, urlValues) + _, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -318,9 +329,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { if d.HasChange("send_access_emails") { urlValues.Add("sendAccessEmails", strconv.FormatBool(d.Get("send_access_emails").(bool))) urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.decortAPICall("POST", accountUpdateAPI, urlValues) + _, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -330,9 +341,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { restore := d.Get("restore").(bool) if restore { urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.decortAPICall("POST", accountRestoreAPI, urlValues) + _, err := c.DecortAPICall("POST", accountRestoreAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -368,9 +379,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("userId", userConv["user_id"].(string)) urlValues.Add("recursivedelete", strconv.FormatBool(userConv["recursive_delete"].(bool))) - _, err := c.decortAPICall("POST", accountDeleteUserAPI, urlValues) + _, err := c.DecortAPICall("POST", accountDeleteUserAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -383,9 +394,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("userId", userConv["user_id"].(string)) urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string))) - _, err := c.decortAPICall("POST", accountAddUserAPI, urlValues) + _, err := c.DecortAPICall("POST", accountAddUserAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -398,9 +409,9 @@ func resourceAccountEdit(d *schema.ResourceData, m interface{}) error { urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("userId", userConv["user_id"].(string)) urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string))) - _, err := c.decortAPICall("POST", accountUpdateUserAPI, urlValues) + _, err := c.DecortAPICall("POST", accountUpdateUserAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -767,26 +778,26 @@ func resourceAccountSchemaMake() map[string]*schema.Schema { } } -func resourceAccount() *schema.Resource { +func ResourceAccount() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceAccountCreate, - Read: resourceAccountRead, - Update: resourceAccountEdit, - Delete: resourceAccountDelete, - Exists: resourceAccountExists, + CreateContext: resourceAccountCreate, + ReadContext: resourceAccountRead, + UpdateContext: resourceAccountEdit, + DeleteContext: resourceAccountDelete, + Exists: resourceAccountExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceAccountSchemaMake(), diff --git a/decort/utility_account.go b/internal/service/cloudapi/account/utility_account.go similarity index 63% rename from decort/utility_account.go rename to internal/service/cloudapi/account/utility_account.go index 136a939..5d89df6 100644 --- a/decort/utility_account.go +++ b/internal/service/cloudapi/account/utility_account.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (*AccountWithResources, error) { account := &AccountWithResources{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if (strconv.Itoa(d.Get("account_id").(int))) != "0" { @@ -46,7 +54,7 @@ func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (*Accoun } log.Debugf("utilityAccountCheckPresence: load account") - accountRaw, err := controller.decortAPICall("POST", accountGetAPI, urlValues) + accountRaw, err := c.DecortAPICall("POST", accountGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_audits_list.go b/internal/service/cloudapi/account/utility_account_audits_list.go similarity index 60% rename from decort/utility_account_audits_list.go rename to internal/service/cloudapi/account/utility_account_audits_list.go index 283c513..dc61dc8 100644 --- a/decort/utility_account_audits_list.go +++ b/internal/service/cloudapi/account/utility_account_audits_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountAuditsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountAuditsList, error) { accountAuditsList := AccountAuditsList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountAuditsListCheckPresence: load account list") - accountAuditsListRaw, err := controller.decortAPICall("POST", accountAuditsAPI, urlValues) + accountAuditsListRaw, err := c.DecortAPICall("POST", accountAuditsAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_computes_list.go b/internal/service/cloudapi/account/utility_account_computes_list.go similarity index 60% rename from decort/utility_account_computes_list.go rename to internal/service/cloudapi/account/utility_account_computes_list.go index 6c92590..957af49 100644 --- a/decort/utility_account_computes_list.go +++ b/internal/service/cloudapi/account/utility_account_computes_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountComputesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountComputesList, error) { accountComputesList := AccountComputesList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountComputesListCheckPresence: load account list") - accountComputesListRaw, err := controller.decortAPICall("POST", accountListComputesAPI, urlValues) + accountComputesListRaw, err := c.DecortAPICall("POST", accountListComputesAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_consumed_units.go b/internal/service/cloudapi/account/utility_account_consumed_units.go similarity index 60% rename from decort/utility_account_consumed_units.go rename to internal/service/cloudapi/account/utility_account_consumed_units.go index b5cdd1e..295a4fe 100644 --- a/decort/utility_account_consumed_units.go +++ b/internal/service/cloudapi/account/utility_account_consumed_units.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountConsumedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { accountConsumedUnits := &ResourceLimits{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountConsumedUnitsCheckPresence: load account list") - accountConsumedUnitsRaw, err := controller.decortAPICall("POST", accountGetConsumedUnitsAPI, urlValues) + accountConsumedUnitsRaw, err := c.DecortAPICall("POST", accountGetConsumedUnitsAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_consumed_units_by_type.go b/internal/service/cloudapi/account/utility_account_consumed_units_by_type.go similarity index 59% rename from decort/utility_account_consumed_units_by_type.go rename to internal/service/cloudapi/account/utility_account_consumed_units_by_type.go index d0d65f2..f102c01 100644 --- a/decort/utility_account_consumed_units_by_type.go +++ b/internal/service/cloudapi/account/utility_account_consumed_units_by_type.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "net/url" "strconv" "strings" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountConsumedUnitsByTypeCheckPresence(d *schema.ResourceData, m interface{}) (float64, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("cutype", strings.ToUpper(d.Get("cu_type").(string))) log.Debugf("utilityAccountConsumedUnitsByTypeCheckPresence") - resultRaw, err := controller.decortAPICall("POST", accountGetConsumedUnitsByTypeAPI, urlValues) + resultRaw, err := c.DecortAPICall("POST", accountGetConsumedUnitsByTypeAPI, urlValues) if err != nil { return 0, err } diff --git a/decort/utility_account_deleted_list.go b/internal/service/cloudapi/account/utility_account_deleted_list.go similarity index 61% rename from decort/utility_account_deleted_list.go rename to internal/service/cloudapi/account/utility_account_deleted_list.go index 7c82750..2395001 100644 --- a/decort/utility_account_deleted_list.go +++ b/internal/service/cloudapi/account/utility_account_deleted_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { accountDeletedList := AccountCloudApiList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if page, ok := d.GetOk("page"); ok { @@ -47,7 +55,7 @@ func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{ } log.Debugf("utilityAccountDeletedListCheckPresence: load") - accountDeletedListRaw, err := controller.decortAPICall("POST", accountListDeletedAPI, urlValues) + accountDeletedListRaw, err := c.DecortAPICall("POST", accountListDeletedAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_disks_list.go b/internal/service/cloudapi/account/utility_account_disks_list.go similarity index 59% rename from decort/utility_account_disks_list.go rename to internal/service/cloudapi/account/utility_account_disks_list.go index 941a2bc..4c0dbd3 100644 --- a/decort/utility_account_disks_list.go +++ b/internal/service/cloudapi/account/utility_account_disks_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountDisksListCheckPresence(d *schema.ResourceData, m interface{}) (AccountDisksList, error) { accountDisksList := AccountDisksList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountDisksListCheckPresence: load account list") - accountDisksListRaw, err := controller.decortAPICall("POST", accountListDisksAPI, urlValues) + accountDisksListRaw, err := c.DecortAPICall("POST", accountListDisksAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_flip_groups.go b/internal/service/cloudapi/account/utility_account_flip_groups.go similarity index 60% rename from decort/utility_account_flip_groups.go rename to internal/service/cloudapi/account/utility_account_flip_groups.go index df2c36b..d2862b5 100644 --- a/decort/utility_account_flip_groups.go +++ b/internal/service/cloudapi/account/utility_account_flip_groups.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountFlipGroupsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountFlipGroupsList, error) { accountFlipGroupsList := AccountFlipGroupsList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountFlipGroupsListCheckPresence") - accountFlipGroupsListRaw, err := controller.decortAPICall("POST", accountListFlipGroupsAPI, urlValues) + accountFlipGroupsListRaw, err := c.DecortAPICall("POST", accountListFlipGroupsAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_list.go b/internal/service/cloudapi/account/utility_account_list.go similarity index 70% rename from decort/utility_account_list.go rename to internal/service/cloudapi/account/utility_account_list.go index 0dd3514..3d814ff 100644 --- a/decort/utility_account_list.go +++ b/internal/service/cloudapi/account/utility_account_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { accountList := AccountCloudApiList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if page, ok := d.GetOk("page"); ok { @@ -47,7 +55,7 @@ func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (Acc } log.Debugf("utilityAccountListCheckPresence: load account list") - accountListRaw, err := controller.decortAPICall("POST", accountListAPI, urlValues) + accountListRaw, err := c.DecortAPICall("POST", accountListAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_reserved_units.go b/internal/service/cloudapi/account/utility_account_reserved_units.go similarity index 59% rename from decort/utility_account_reserved_units.go rename to internal/service/cloudapi/account/utility_account_reserved_units.go index 31bd4b9..599964c 100644 --- a/decort/utility_account_reserved_units.go +++ b/internal/service/cloudapi/account/utility_account_reserved_units.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountReservedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { accountReservedUnits := &ResourceLimits{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountReservedUnitsCheckPresence: load units") - accountReservedUnitsRaw, err := controller.decortAPICall("POST", accountGetReservedUnitsAPI, urlValues) + accountReservedUnitsRaw, err := c.DecortAPICall("POST", accountGetReservedUnitsAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_rg_list.go b/internal/service/cloudapi/account/utility_account_rg_list.go similarity index 59% rename from decort/utility_account_rg_list.go rename to internal/service/cloudapi/account/utility_account_rg_list.go index 0145b3a..266ba1c 100644 --- a/decort/utility_account_rg_list.go +++ b/internal/service/cloudapi/account/utility_account_rg_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountRGListCheckPresence(d *schema.ResourceData, m interface{}) (AccountRGList, error) { accountRGList := AccountRGList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountRGListCheckPresence: load account list") - accountRGListRaw, err := controller.decortAPICall("POST", accountListRGAPI, urlValues) + accountRGListRaw, err := c.DecortAPICall("POST", accountListRGAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_templates_list.go b/internal/service/cloudapi/account/utility_account_templates_list.go similarity index 60% rename from decort/utility_account_templates_list.go rename to internal/service/cloudapi/account/utility_account_templates_list.go index 2dd3a2e..76f9930 100644 --- a/decort/utility_account_templates_list.go +++ b/internal/service/cloudapi/account/utility_account_templates_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountTemplatesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountTemplatesList, error) { accountTemplatesList := AccountTemplatesList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountTemplatesListCheckPresence: load") - accountTemplatesListRaw, err := controller.decortAPICall("POST", accountListTemplatesAPI, urlValues) + accountTemplatesListRaw, err := c.DecortAPICall("POST", accountListTemplatesAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_account_vins_list.go b/internal/service/cloudapi/account/utility_account_vins_list.go similarity index 59% rename from decort/utility_account_vins_list.go rename to internal/service/cloudapi/account/utility_account_vins_list.go index 31291ff..72fc5d6 100644 --- a/decort/utility_account_vins_list.go +++ b/internal/service/cloudapi/account/utility_account_vins_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package account import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityAccountVinsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountVinsList, error) { accountVinsList := AccountVinsList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountVinsListCheckPresence: load account list") - accountVinsListRaw, err := controller.decortAPICall("POST", accountListVinsAPI, urlValues) + accountVinsListRaw, err := c.DecortAPICall("POST", accountListVinsAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/bservice/api.go b/internal/service/cloudapi/bservice/api.go new file mode 100644 index 0000000..8878915 --- /dev/null +++ b/internal/service/cloudapi/bservice/api.go @@ -0,0 +1,59 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package bservice + +const bserviceCreateAPI = "/restmachine/cloudapi/bservice/create" +const bserviceDeleteAPI = "/restmachine/cloudapi/bservice/delete" +const bserviceDisableAPI = "/restmachine/cloudapi/bservice/disable" +const bserviceEnableAPI = "/restmachine/cloudapi/bservice/enable" +const bserviceGetAPI = "/restmachine/cloudapi/bservice/get" +const bserviceGroupAddAPI = "/restmachine/cloudapi/bservice/groupAdd" +const bserviceGroupComputeRemoveAPI = "/restmachine/cloudapi/bservice/groupComputeRemove" +const bserviceGroupGetAPI = "/restmachine/cloudapi/bservice/groupGet" +const bserviceGroupParentAddAPI = "/restmachine/cloudapi/bservice/groupParentAdd" +const bserviceGroupParentRemoveAPI = "/restmachine/cloudapi/bservice/groupParentRemove" +const bserviceGroupRemoveAPI = "/restmachine/cloudapi/bservice/groupRemove" +const bserviceGroupResizeAPI = "/restmachine/cloudapi/bservice/groupResize" +const bserviceGroupStartAPI = "/restmachine/cloudapi/bservice/groupStart" +const bserviceGroupStopAPI = "/restmachine/cloudapi/bservice/groupStop" +const bserviceGroupUpdateAPI = "/restmachine/cloudapi/bservice/groupUpdate" +const bserviceGroupUpdateExtnetAPI = "/restmachine/cloudapi/bservice/groupUpdateExtnet" +const bserviceGroupUpdateVinsAPI = "/restmachine/cloudapi/bservice/groupUpdateVins" +const bserviceListAPI = "/restmachine/cloudapi/bservice/list" +const bserviceListDeletedAPI = "/restmachine/cloudapi/bservice/listDeleted" +const bserviceRestoreAPI = "/restmachine/cloudapi/bservice/restore" +const bserviceSnapshotCreateAPI = "/restmachine/cloudapi/bservice/snapshotCreate" +const bserviceSnapshotDeleteAPI = "/restmachine/cloudapi/bservice/snapshotDelete" +const bserviceSnapshotListAPI = "/restmachine/cloudapi/bservice/snapshotList" +const bserviceSnapshotRollbackAPI = "/restmachine/cloudapi/bservice/snapshotRollback" +const bserviceStartAPI = "/restmachine/cloudapi/bservice/start" +const bserviceStopAPI = "/restmachine/cloudapi/bservice/stop" diff --git a/decort/data_source_bservice.go b/internal/service/cloudapi/bservice/data_source_bservice.go similarity index 82% rename from decort/data_source_bservice.go rename to internal/service/cloudapi/bservice/data_source_bservice.go index a013981..ef1fc17 100644 --- a/decort/data_source_bservice.go +++ b/internal/service/cloudapi/bservice/data_source_bservice.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceBasicServiceRead(d *schema.ResourceData, m interface{}) error { +func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { bs, err := utilityBasicServiceCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -277,15 +288,15 @@ func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema { return res } -func dataSourceBasicService() *schema.Resource { +func DataSourceBasicService() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceBasicServiceRead, + ReadContext: dataSourceBasicServiceRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceBasicServiceSchemaMake(), diff --git a/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go b/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go new file mode 100644 index 0000000..4341c43 --- /dev/null +++ b/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go @@ -0,0 +1,69 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package bservice + +import ( + "context" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" +) + +func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(d, m) + if err != nil { + return diag.FromErr(err) + } + + id := uuid.New() + d.SetId(id.String()) + d.Set("items", flattenBasicServiceList(basicServiceDeletedList)) + + return nil +} + +func DataSourceBasicServiceDeletedList() *schema.Resource { + return &schema.Resource{ + SchemaVersion: 1, + + ReadContext: dataSourceBasicServiceDeletedListRead, + + Timeouts: &schema.ResourceTimeout{ + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, + }, + + Schema: dataSourceBasicServiceListSchemaMake(), + } +} diff --git a/decort/data_source_bservice_group.go b/internal/service/cloudapi/bservice/data_source_bservice_group.go similarity index 81% rename from decort/data_source_bservice_group.go rename to internal/service/cloudapi/bservice/data_source_bservice_group.go index b8c3d92..f333d1c 100644 --- a/decort/data_source_bservice_group.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_group.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceBasicServiceGroupRead(d *schema.ResourceData, m interface{}) error { +func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { bsg, err := utilityBasicServiceGroupCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -275,15 +286,15 @@ func dataSourceBasicServiceGroupSchemaMake() map[string]*schema.Schema { return res } -func dataSourceBasicServiceGroup() *schema.Resource { +func DataSourceBasicServiceGroup() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceBasicServiceGroupRead, + ReadContext: dataSourceBasicServiceGroupRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceBasicServiceGroupSchemaMake(), diff --git a/decort/data_source_bservice_list.go b/internal/service/cloudapi/bservice/data_source_bservice_list.go similarity index 79% rename from decort/data_source_bservice_list.go rename to internal/service/cloudapi/bservice/data_source_bservice_list.go index 21ead41..d3b2e43 100644 --- a/decort/data_source_bservice_list.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenBasicServiceList(bsl BasicServiceList) []map[string]interface{} { @@ -61,10 +72,10 @@ func flattenBasicServiceList(bsl BasicServiceList) []map[string]interface{} { return res } -func dataSourceBasicServiceListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { basicServiceList, err := utilityBasicServiceListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -199,15 +210,15 @@ func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceBasicServiceList() *schema.Resource { +func DataSourceBasicServiceList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceBasicServiceListRead, + ReadContext: dataSourceBasicServiceListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceBasicServiceListSchemaMake(), diff --git a/decort/data_source_bservice_snapshot_list.go b/internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go similarity index 61% rename from decort/data_source_bservice_snapshot_list.go rename to internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go index 306ce99..93fe820 100644 --- a/decort/data_source_bservice_snapshot_list.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceBasicServiceSnapshotListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -77,15 +88,15 @@ func dataSourceBasicServiceSnapshotListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceBasicServiceSnapshotList() *schema.Resource { +func DataSourceBasicServiceSnapshotList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceBasicServiceSnapshotListRead, + ReadContext: dataSourceBasicServiceSnapshotListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceBasicServiceSnapshotListSchemaMake(), diff --git a/internal/service/cloudapi/bservice/models.go b/internal/service/cloudapi/bservice/models.go new file mode 100644 index 0000000..75c5bbf --- /dev/null +++ b/internal/service/cloudapi/bservice/models.go @@ -0,0 +1,144 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package bservice + +///Structs + +type BasicServiceCompute struct { + CompGroupId int `json:"compgroupId"` + CompGroupName string `json:"compgroupName"` + CompGroupRole string `json:"compgroupRole"` + ID int `json:"id"` + Name string `json:"name"` +} + +type BasicServiceComputes []BasicServiceCompute + +type BasicServiceSnapshot struct { + GUID string `json:"guid"` + Label string `json:"label"` + Timestamp int `json:"timestamp"` + Valid bool `json:"valid"` +} + +type BasicServiceSnapshots []BasicServiceSnapshot + +type BasicService struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + BaseDomain string `json:"baseDomain"` + + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + GID int `json:"gid"` + Groups []int `json:"groups"` + GUID int `json:"guid"` + ID int `json:"id"` + Name string `json:"name"` + ParentSrvId int `json:"parentSrvId"` + ParentSrvType string `json:"parentSrvType"` + RGID int `json:"rgId"` + RGName string `json:"rgName"` + SSHUser string `json:"sshUser"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` + UserManaged bool `json:"userManaged"` +} + +type BasicServiceList []BasicService + +type BasicServiceExtend struct { + BasicService + Computes BasicServiceComputes `json:"computes"` + CPUTotal int `json:"cpuTotal"` + DiskTotal int `json:"diskTotal"` + GroupsName []string `json:"groupsName"` + Milestones int `json:"milestones"` + RamTotal int `json:"ramTotal"` + Snapshots BasicServiceSnapshots `json:"snapshots"` + SSHKey string `json:"sshKey"` +} + +type BasicServiceGroupOSUser struct { + Login string `json:"login"` + Password string `json:"password"` +} + +type BasicServiceGroupOSUsers []BasicServiceGroupOSUser + +type BasicServicceGroupCompute struct { + ID int `json:"id"` + IPAdresses []string `json:"ipAddresses"` + Name string `json:"name"` + OSUsers BasicServiceGroupOSUsers `json:"osUsers"` +} + +type BasicServiceGroupComputes []BasicServicceGroupCompute + +type BasicServiceGroup struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + Computes BasicServiceGroupComputes `json:"computes"` + Consistency bool `json:"consistency"` + CPU int `json:"cpu"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + Disk int `json:"disk"` + Driver string `json:"driver"` + Extnets []int `json:"extnets"` + GID int `json:"gid"` + GUID int `json:"guid"` + ID int `json:"id"` + ImageId int `json:"imageId"` + Milestones int `json:"milestones"` + Name string `json:"name"` + Parents []int `json:"parents"` + RAM int `json:"ram"` + RGID int `json:"rgId"` + RGName string `json:"rgName"` + Role string `json:"role"` + SepId int `json:"sepId"` + SeqNo int `json:"seqNo"` + ServiceId int `json:"serviceId"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + TimeoutStart int `json:"timeoutStart"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` + Vinses []int `json:"vinses"` +} diff --git a/decort/resource_bservice.go b/internal/service/cloudapi/bservice/resource_bservice.go similarity index 77% rename from decort/resource_bservice.go rename to internal/service/cloudapi/bservice/resource_bservice.go index 9f0df09..7456728 100644 --- a/decort/resource_bservice.go +++ b/internal/service/cloudapi/bservice/resource_bservice.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,46 +18,54 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( - "errors" + "context" "net/url" "strconv" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceBasicServiceCreate(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceCreate") if serviceId, ok := d.GetOk("service_id"); ok { if exists, err := resourceBasicServiceExists(d, m); exists { if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(strconv.Itoa(serviceId.(int))) d.Set("service_id", strconv.Itoa(serviceId.(int))) - err = resourceBasicServiceRead(d, m) - if err != nil { - return err + diagnostics := resourceBasicServiceRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } d.SetId(id.String()) return nil } - return errors.New("provided service id does not exist") + return diag.Errorf("provided service id does not exist") } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("service_name").(string)) @@ -68,18 +78,18 @@ func resourceBasicServiceCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("sshUser", sshUser.(string)) } - serviceId, err := controller.decortAPICall("POST", bserviceCreateAPI, urlValues) + serviceId, err := c.DecortAPICall("POST", bserviceCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(serviceId) d.Set("service_id", serviceId) - err = resourceBasicServiceRead(d, m) - if err != nil { - return err + diagnostics := resourceBasicServiceRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } d.SetId(id.String()) @@ -87,13 +97,13 @@ func resourceBasicServiceCreate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceBasicServiceRead(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceRead") bs, err := utilityBasicServiceCheckPresence(d, m) if bs == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("account_id", bs.AccountId) @@ -130,25 +140,25 @@ func resourceBasicServiceRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceBasicServiceDelete(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceDelete") bs, err := utilityBasicServiceCheckPresence(d, m) if bs == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool))) - _, err = controller.decortAPICall("POST", bserviceDeleteAPI, urlValues) + _, err = c.DecortAPICall("POST", bserviceDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -169,9 +179,9 @@ func resourceBasicServiceExists(d *schema.ResourceData, m interface{}) (bool, er return true, nil } -func resourceBasicServiceEdit(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceEdit") - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if d.HasChange("enable") { @@ -182,9 +192,9 @@ func resourceBasicServiceEdit(d *schema.ResourceData, m interface{}) error { } urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) - _, err := c.decortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall("POST", api, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -194,9 +204,9 @@ func resourceBasicServiceEdit(d *schema.ResourceData, m interface{}) error { restore := d.Get("restore").(bool) if restore { urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) - _, err := c.decortAPICall("POST", bserviceRestoreAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceRestoreAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -211,9 +221,9 @@ func resourceBasicServiceEdit(d *schema.ResourceData, m interface{}) error { } urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) - _, err := c.decortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall("POST", api, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -247,9 +257,9 @@ func resourceBasicServiceEdit(d *schema.ResourceData, m interface{}) error { snapshotConv := snapshot.(map[string]interface{}) urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("label", snapshotConv["label"].(string)) - _, err := c.decortAPICall("POST", bserviceSnapshotDeleteAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceSnapshotDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -261,9 +271,9 @@ func resourceBasicServiceEdit(d *schema.ResourceData, m interface{}) error { snapshotConv := snapshot.(map[string]interface{}) urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("label", snapshotConv["label"].(string)) - _, err := c.decortAPICall("POST", bserviceSnapshotCreateAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceSnapshotCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -275,9 +285,9 @@ func resourceBasicServiceEdit(d *schema.ResourceData, m interface{}) error { snapshotConv := snapshot.(map[string]interface{}) urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("label", snapshotConv["label"].(string)) - _, err := c.decortAPICall("POST", bserviceSnapshotRollbackAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceSnapshotRollbackAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -527,26 +537,26 @@ func resourceBasicServiceSchemaMake() map[string]*schema.Schema { } } -func resourceBasicService() *schema.Resource { +func ResourceBasicService() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceBasicServiceCreate, - Read: resourceBasicServiceRead, - Update: resourceBasicServiceEdit, - Delete: resourceBasicServiceDelete, - Exists: resourceBasicServiceExists, + CreateContext: resourceBasicServiceCreate, + ReadContext: resourceBasicServiceRead, + UpdateContext: resourceBasicServiceEdit, + DeleteContext: resourceBasicServiceDelete, + Exists: resourceBasicServiceExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceBasicServiceSchemaMake(), diff --git a/decort/resource_bservice_group.go b/internal/service/cloudapi/bservice/resource_bservice_group.go similarity index 78% rename from decort/resource_bservice_group.go rename to internal/service/cloudapi/bservice/resource_bservice_group.go index 6bbff5a..aa2d5a3 100644 --- a/decort/resource_bservice_group.go +++ b/internal/service/cloudapi/bservice/resource_bservice_group.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,50 +18,58 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( - "errors" + "context" "net/url" "strconv" "strings" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceBasicServiceGroupCreate(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceGroupCreate") if compgroupId, ok := d.GetOk("compgroup_id"); ok { if _, ok := d.GetOk("service_id"); ok { if exists, err := resourceBasicServiceGroupExists(d, m); exists { if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(strconv.Itoa(compgroupId.(int))) d.Set("compgroup_id", strconv.Itoa(compgroupId.(int))) - err = resourceBasicServiceGroupRead(d, m) - if err != nil { - return err + diagnostics := resourceBasicServiceGroupRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } d.SetId(id.String()) return nil } - return errors.New("provided compgroup id does not exist") + return diag.Errorf("provided compgroup id does not exist") } } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) @@ -109,18 +119,18 @@ func resourceBasicServiceGroupCreate(d *schema.ResourceData, m interface{}) erro urlValues.Add("extnets", temp) } - compgroupId, err := controller.decortAPICall("POST", bserviceGroupAddAPI, urlValues) + compgroupId, err := c.DecortAPICall("POST", bserviceGroupAddAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(compgroupId) d.Set("compgroup_id", compgroupId) - err = resourceBasicServiceGroupRead(d, m) - if err != nil { - return err + diagnostics := resourceBasicServiceGroupRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } d.SetId(id.String()) @@ -128,13 +138,13 @@ func resourceBasicServiceGroupCreate(d *schema.ResourceData, m interface{}) erro return nil } -func resourceBasicServiceGroupRead(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceGroupRead") bsg, err := utilityBasicServiceGroupCheckPresence(d, m) if bsg == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("account_id", bsg.AccountId) @@ -172,25 +182,25 @@ func resourceBasicServiceGroupRead(d *schema.ResourceData, m interface{}) error return nil } -func resourceBasicServiceGroupDelete(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceGroupDelete") bsg, err := utilityBasicServiceGroupCheckPresence(d, m) if bsg == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) - _, err = controller.decortAPICall("POST", bserviceGroupRemoveAPI, urlValues) + _, err = c.DecortAPICall("POST", bserviceGroupRemoveAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -211,9 +221,9 @@ func resourceBasicServiceGroupExists(d *schema.ResourceData, m interface{}) (boo return true, nil } -func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error { +func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceGroupEdit") - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -222,9 +232,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("count", strconv.Itoa(d.Get("comp_count").(int))) urlValues.Add("mode", strings.ToUpper(d.Get("mode").(string))) - _, err := c.decortAPICall("POST", bserviceGroupResizeAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceGroupResizeAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -241,9 +251,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) - _, err := c.decortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall("POST", api, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -260,9 +270,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) - _, err := c.decortAPICall("POST", bserviceGroupUpdateAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceGroupUpdateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -286,9 +296,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("extnets", temp) - _, err := c.decortAPICall("POST", bserviceGroupUpdateExtnetAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceGroupUpdateExtnetAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -312,9 +322,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("vinses", temp) - _, err := c.decortAPICall("POST", bserviceGroupUpdateVinsAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceGroupUpdateVinsAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -346,9 +356,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("parentId", strconv.Itoa(parentConv)) - _, err := c.decortAPICall("POST", bserviceGroupParentRemoveAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceGroupParentRemoveAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -361,9 +371,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("parentId", strconv.Itoa(parentConv)) - _, err := c.decortAPICall("POST", bserviceGroupParentAddAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceGroupParentAddAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -379,9 +389,9 @@ func resourceBasicServiceGroupEdit(d *schema.ResourceData, m interface{}) error urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("computeId", strconv.Itoa(rc.(int))) - _, err := c.decortAPICall("POST", bserviceGroupComputeRemoveAPI, urlValues) + _, err := c.DecortAPICall("POST", bserviceGroupComputeRemoveAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -634,26 +644,26 @@ func resourceBasicServiceGroupSchemaMake() map[string]*schema.Schema { } } -func resourceBasicServiceGroup() *schema.Resource { +func ResourceBasicServiceGroup() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceBasicServiceGroupCreate, - Read: resourceBasicServiceGroupRead, - Update: resourceBasicServiceGroupEdit, - Delete: resourceBasicServiceGroupDelete, - Exists: resourceBasicServiceGroupExists, + CreateContext: resourceBasicServiceGroupCreate, + ReadContext: resourceBasicServiceGroupRead, + UpdateContext: resourceBasicServiceGroupEdit, + DeleteContext: resourceBasicServiceGroupDelete, + Exists: resourceBasicServiceGroupExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceBasicServiceGroupSchemaMake(), diff --git a/decort/utility_bservicce_deleted_list.go b/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go similarity index 65% rename from decort/utility_bservicce_deleted_list.go rename to internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go index d52ebee..29d1b7f 100644 --- a/decort/utility_bservicce_deleted_list.go +++ b/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) { basicServiceDeletedList := BasicServiceList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if accountId, ok := d.GetOk("account_id"); ok { @@ -53,7 +61,7 @@ func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m inter } log.Debugf("utilityBasicServiceDeletedListCheckPresence") - basicServiceDeletedListRaw, err := controller.decortAPICall("POST", bserviceListDeletedAPI, urlValues) + basicServiceDeletedListRaw, err := c.DecortAPICall("POST", bserviceListDeletedAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_bservice.go b/internal/service/cloudapi/bservice/utility_bservice.go similarity index 61% rename from decort/utility_bservice.go rename to internal/service/cloudapi/bservice/utility_bservice.go index 65c41d8..57ff329 100644 --- a/decort/utility_bservice.go +++ b/internal/service/cloudapi/bservice/utility_bservice.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceExtend, error) { bservice := &BasicServiceExtend{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if (strconv.Itoa(d.Get("service_id").(int))) != "0" { @@ -46,7 +54,7 @@ func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*B } log.Debugf("utilityBasicServiceCheckPresence") - bserviceRaw, err := controller.decortAPICall("POST", bserviceGetAPI, urlValues) + bserviceRaw, err := c.DecortAPICall("POST", bserviceGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_bservice_group.go b/internal/service/cloudapi/bservice/utility_bservice_group.go similarity index 62% rename from decort/utility_bservice_group.go rename to internal/service/cloudapi/bservice/utility_bservice_group.go index 6f75dc0..b91d2a7 100644 --- a/decort/utility_bservice_group.go +++ b/internal/service/cloudapi/bservice/utility_bservice_group.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceGroup, error) { bserviceGroup := &BasicServiceGroup{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) @@ -47,7 +55,7 @@ func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{} } log.Debugf("utilityBasicServiceGroupCheckPresence") - bserviceGroupRaw, err := controller.decortAPICall("POST", bserviceGroupGetAPI, urlValues) + bserviceGroupRaw, err := c.DecortAPICall("POST", bserviceGroupGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_bservice_list.go b/internal/service/cloudapi/bservice/utility_bservice_list.go similarity index 64% rename from decort/utility_bservice_list.go rename to internal/service/cloudapi/bservice/utility_bservice_list.go index efbe623..73ec82d 100644 --- a/decort/utility_bservice_list.go +++ b/internal/service/cloudapi/bservice/utility_bservice_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) { basicServiceList := BasicServiceList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if accountId, ok := d.GetOk("account_id"); ok { @@ -53,7 +61,7 @@ func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{}) } log.Debugf("utilityBasicServiceListCheckPresence") - basicServiceListRaw, err := controller.decortAPICall("POST", bserviceListAPI, urlValues) + basicServiceListRaw, err := c.DecortAPICall("POST", bserviceListAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_bservice_snapshot_list.go b/internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go similarity index 61% rename from decort/utility_bservice_snapshot_list.go rename to internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go index 1f310f3..3bacdbe 100644 --- a/decort/utility_bservice_snapshot_list.go +++ b/internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package bservice import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceSnapshots, error) { basicServiceSnapshotList := BasicServiceSnapshots{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if serviceId, ok := d.GetOk("service_id"); ok { @@ -44,7 +52,7 @@ func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m inte } log.Debugf("utilityBasicServiceSnapshotListCheckPresence") - basicServiceSnapshotListRaw, err := controller.decortAPICall("POST", bserviceSnapshotListAPI, urlValues) + basicServiceSnapshotListRaw, err := c.DecortAPICall("POST", bserviceSnapshotListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/disks/api.go b/internal/service/cloudapi/disks/api.go new file mode 100644 index 0000000..678cd69 --- /dev/null +++ b/internal/service/cloudapi/disks/api.go @@ -0,0 +1,39 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package disks + +const DisksCreateAPI = "/restmachine/cloudapi/disks/create" +const DisksGetAPI = "/restmachine/cloudapi/disks/get" // Returns single DiskRecord on success +const DisksListAPI = "/restmachine/cloudapi/disks/list" // Returns list of DiskRecord on success +const DisksResizeAPI = "/restmachine/cloudapi/disks/resize2" +const DisksRenameAPI = "/restmachine/cloudapi/disks/rename" +const DisksDeleteAPI = "/restmachine/cloudapi/disks/delete" diff --git a/decort/data_source_disk.go b/internal/service/cloudapi/disks/data_source_disk.go similarity index 69% rename from decort/data_source_disk.go rename to internal/service/cloudapi/disks/data_source_disk.go index 8236f4a..acaeb0a 100644 --- a/decort/data_source_disk.go +++ b/internal/service/cloudapi/disks/data_source_disk.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,31 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package disks import ( + "context" "encoding/json" "fmt" + // "net/url" + "github.com/rudecs/terraform-provider-decort/internal/constants" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func flattenDisk(d *schema.ResourceData, disk_facts string) error { @@ -44,7 +54,7 @@ func flattenDisk(d *schema.ResourceData, disk_facts string) error { log.Debugf("flattenDisk: ready to unmarshal string %s", disk_facts) model := DiskRecord{} - + err := json.Unmarshal([]byte(disk_facts), &model) if err != nil { return err @@ -71,16 +81,16 @@ func flattenDisk(d *schema.ResourceData, disk_facts string) error { return nil } -func dataSourceDiskRead(d *schema.ResourceData, m interface{}) error { +func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { disk_facts, err := utilityDiskCheckPresence(d, m) if disk_facts == "" { // if empty string is returned from utilityDiskCheckPresence then there is no // such Disk and err tells so - just return it to the calling party d.SetId("") // ensure ID is empty - return err + return diag.FromErr(err) } - return flattenDisk(d, disk_facts) + return diag.FromErr(flattenDisk(d, disk_facts)) } func dataSourceDiskSchemaMake() map[string]*schema.Schema { @@ -103,7 +113,7 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema { Description: "ID of the account this disk belongs to. If disk ID is specified, then account ID is ignored.", }, - // The rest of the data source Disk schema are all computed + // The rest of the data source Disk schema are all computed "sep_id": { Type: schema.TypeInt, Computed: true, @@ -153,47 +163,47 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema { }, /* - "snapshots": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource { - Schema: snapshotSubresourceSchemaMake(), + "snapshots": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource { + Schema: snapshotSubresourceSchemaMake(), + }, + Description: "List of user-created snapshots for this disk." }, - Description: "List of user-created snapshots for this disk." - }, - "status": { - Type: schema.TypeString, - Computed: true, - Description: "Current model status of this disk.", - }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Current model status of this disk.", + }, - "tech_status": { - Type: schema.TypeString, - Computed: true, - Description: "Current technical status of this disk.", - }, + "tech_status": { + Type: schema.TypeString, + Computed: true, + Description: "Current technical status of this disk.", + }, - "compute_id": { - Type: schema.TypeInt, - Computed: true, - Description: "ID of the compute instance where this disk is attached to, or 0 for unattached disk.", - }, + "compute_id": { + Type: schema.TypeInt, + Computed: true, + Description: "ID of the compute instance where this disk is attached to, or 0 for unattached disk.", + }, */ } return rets } -func dataSourceDisk() *schema.Resource { +func DataSourceDisk() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceDiskRead, + ReadContext: dataSourceDiskRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceDiskSchemaMake(), diff --git a/decort/data_source_disk_list.go b/internal/service/cloudapi/disks/data_source_disk_list.go similarity index 86% rename from decort/data_source_disk_list.go rename to internal/service/cloudapi/disks/data_source_disk_list.go index fa118aa..86914ef 100644 --- a/decort/data_source_disk_list.go +++ b/internal/service/cloudapi/disks/data_source_disk_list.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,19 +18,27 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package disks import ( + "context" "encoding/json" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenDiskList(dl DisksListResp) []map[string]interface{} { @@ -109,10 +119,10 @@ func flattendDiskSnapshotList(sl SnapshotRecordList) []interface{} { } -func dataSourceDiskListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { diskList, err := utilityDiskListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -375,15 +385,15 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceDiskList() *schema.Resource { +func DataSourceDiskList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceDiskListRead, + ReadContext: dataSourceDiskListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceDiskListSchemaMake(), diff --git a/internal/service/cloudapi/disks/models.go b/internal/service/cloudapi/disks/models.go new file mode 100644 index 0000000..8b997ea --- /dev/null +++ b/internal/service/cloudapi/disks/models.go @@ -0,0 +1,95 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package disks + +type DiskRecord struct { + Acl map[string]interface{} `json:"acl"` + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + BootPartition int `json:"bootPartition"` + CreatedTime uint64 `json:"creationTime"` + ComputeID int `json:"computeId"` + ComputeName string `json:"computeName"` + DeletedTime uint64 `json:"deletionTime"` + DeviceName string `json:"devicename"` + Desc string `json:"desc"` + DestructionTime uint64 `json:"destructionTime"` + DiskPath string `json:"diskPath"` + GridID int `json:"gid"` + GUID int `json:"guid"` + ID uint `json:"id"` + ImageID int `json:"imageId"` + Images []int `json:"images"` + IOTune map[string]interface{} `json:"iotune"` + IQN string `json:"iqn"` + Login string `json:"login"` + Name string `json:"name"` + MachineId int `json:"machineId"` + MachineName string `json:"machineName"` + Milestones uint64 `json:"milestones"` + Order int `json:"order"` + Params string `json:"params"` + Passwd string `json:"passwd"` + ParentId int `json:"parentId"` + PciSlot int `json:"pciSlot"` + Pool string `json:"pool"` + PurgeTime uint64 `json:"purgeTime"` + PurgeAttempts uint64 `json:"purgeAttempts"` + RealityDeviceNumber int `json:"realityDeviceNumber"` + ReferenceId string `json:"referenceId"` + ResID string `json:"resId"` + ResName string `json:"resName"` + Role string `json:"role"` + SepType string `json:"sepType"` + SepID int `json:"sepId"` // NOTE: absent from compute/get output + SizeMax int `json:"sizeMax"` + SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space + Snapshots []SnapshotRecord `json:"snapshots"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + UpdateBy uint64 `json:"updateBy"` + VMID int `json:"vmid"` +} + +type SnapshotRecord struct { + Guid string `json:"guid"` + Label string `json:"label"` + ResId string `json:"resId"` + SnapSetGuid string `json:"snapSetGuid"` + SnapSetTime uint64 `json:"snapSetTime"` + TimeStamp uint64 `json:"timestamp"` +} + +type SnapshotRecordList []SnapshotRecord + +type DisksListResp []DiskRecord diff --git a/decort/resource_disk.go b/internal/service/cloudapi/disks/resource_disk.go similarity index 76% rename from decort/resource_disk.go rename to internal/service/cloudapi/disks/resource_disk.go index efee695..b29f199 100644 --- a/decort/resource_disk.go +++ b/internal/service/cloudapi/disks/resource_disk.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,34 +18,44 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package disks import ( // "encoding/json" + "context" "fmt" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/location" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func resourceDiskCreate(d *schema.ResourceData, m interface{}) error { +func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceDiskCreate: called for Disk name %q, Account ID %d", d.Get("name").(string), d.Get("account_id").(int)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} // accountId, gid, name, description, size, type, sep_id, pool urlValues.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int))) - urlValues.Add("gid", fmt.Sprintf("%d", DefaultGridID)) // we use default Grid ID, which was obtained along with DECORT Controller init + urlValues.Add("gid", fmt.Sprintf("%d", location.DefaultGridID)) // we use default Grid ID, which was obtained along with DECORT Controller init urlValues.Add("name", d.Get("name").(string)) urlValues.Add("size", fmt.Sprintf("%d", d.Get("size").(int))) urlValues.Add("type", "D") // NOTE: only disks of Data type are managed via plugin @@ -61,9 +73,9 @@ func resourceDiskCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("description", argVal.(string)) } - apiResp, err := controller.decortAPICall("POST", DisksCreateAPI, urlValues) + apiResp, err := c.DecortAPICall("POST", DisksCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(apiResp) // update ID of the resource to tell Terraform that the disk resource exists @@ -75,22 +87,22 @@ func resourceDiskCreate(d *schema.ResourceData, m interface{}) error { // between Disk resource and Disk data source schemas // Disk resource read function will also update resource ID on success, so that Terraform // will know the resource exists (however, we already did it a few lines before) - return dataSourceDiskRead(d, m) + return dataSourceDiskRead(ctx, d, m) } -func resourceDiskRead(d *schema.ResourceData, m interface{}) error { +func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { diskFacts, err := utilityDiskCheckPresence(d, m) if diskFacts == "" { // if empty string is returned from utilityDiskCheckPresence then there is no // such Disk and err tells so - just return it to the calling party d.SetId("") // ensure ID is empty - return err + return diag.FromErr(err) } - return flattenDisk(d, diskFacts) + return diag.FromErr(flattenDisk(d, diskFacts)) } -func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error { +func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // Update will only change the following attributes of the disk: // - Size; to keep data safe, shrinking disk is not allowed. // - Name @@ -100,9 +112,7 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error { log.Debugf("resourceDiskUpdate: called for Disk ID / name %s / %s, Account ID %d", d.Id(), d.Get("name").(string), d.Get("account_id").(int)) - d.Partial(true) - - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) oldSize, newSize := d.GetChange("size") if oldSize.(int) < newSize.(int) { @@ -111,13 +121,13 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error { sizeParams := &url.Values{} sizeParams.Add("diskId", d.Id()) sizeParams.Add("size", fmt.Sprintf("%d", newSize.(int))) - _, err := controller.decortAPICall("POST", DisksResizeAPI, sizeParams) + _, err := c.DecortAPICall("POST", DisksResizeAPI, sizeParams) if err != nil { - return err + return diag.FromErr(err) } - d.SetPartial("size") + d.Set("size", newSize) } else if oldSize.(int) > newSize.(int) { - return fmt.Errorf("resourceDiskUpdate: Disk ID %s - reducing disk size is not allowed", d.Id()) + return diag.FromErr(fmt.Errorf("resourceDiskUpdate: Disk ID %s - reducing disk size is not allowed", d.Id())) } oldName, newName := d.GetChange("name") @@ -127,11 +137,10 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error { renameParams := &url.Values{} renameParams.Add("diskId", d.Id()) renameParams.Add("name", newName.(string)) - _, err := controller.decortAPICall("POST", DisksRenameAPI, renameParams) + _, err := c.DecortAPICall("POST", DisksRenameAPI, renameParams) if err != nil { - return err + return diag.FromErr(err) } - d.SetPartial("name") } /* @@ -143,14 +152,12 @@ func resourceDiskUpdate(d *schema.ResourceData, m interface{}) error { } */ - d.Partial(false) - // we may reuse dataSourceDiskRead here as we maintain similarity // between Compute resource and Compute data source schemas - return dataSourceDiskRead(d, m) + return dataSourceDiskRead(ctx, d, m) } -func resourceDiskDelete(d *schema.ResourceData, m interface{}) error { +func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // NOTE: this function tries to detach and destroy target Disk "permanently", so // there is no way to restore it. // If, however, the disk is attached to a compute, the method will @@ -161,7 +168,7 @@ func resourceDiskDelete(d *schema.ResourceData, m interface{}) error { diskFacts, err := utilityDiskCheckPresence(d, m) if diskFacts == "" { if err != nil { - return err + return diag.FromErr(err) } // the specified Disk does not exist - in this case according to Terraform best practice // we exit from Destroy method without error @@ -179,10 +186,10 @@ func resourceDiskDelete(d *schema.ResourceData, m interface{}) error { params.Add("detach", "0") params.Add("permanently", "1") - controller := m.(*ControllerCfg) - _, err = controller.decortAPICall("POST", DisksDeleteAPI, params) + c := m.(*controller.ControllerCfg) + _, err = c.DecortAPICall("POST", DisksDeleteAPI, params) if err != nil { - return err + return diag.FromErr(err) } return nil @@ -305,26 +312,26 @@ func resourceDiskSchemaMake() map[string]*schema.Schema { return rets } -func resourceDisk() *schema.Resource { +func ResourceDisk() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceDiskCreate, - Read: resourceDiskRead, - Update: resourceDiskUpdate, - Delete: resourceDiskDelete, - Exists: resourceDiskExists, + CreateContext: resourceDiskCreate, + ReadContext: resourceDiskRead, + UpdateContext: resourceDiskUpdate, + DeleteContext: resourceDiskDelete, + Exists: resourceDiskExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout180s, - Read: &Timeout30s, - Update: &Timeout180s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout180s, + Read: &constants.Timeout30s, + Update: &constants.Timeout180s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceDiskSchemaMake(), diff --git a/decort/utility_disk.go b/internal/service/cloudapi/disks/utility_disk.go similarity index 82% rename from decort/utility_disk.go rename to internal/service/cloudapi/disks/utility_disk.go index c9a8605..a76edf0 100644 --- a/decort/utility_disk.go +++ b/internal/service/cloudapi/disks/utility_disk.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package disks import ( "encoding/json" @@ -30,9 +37,10 @@ import ( "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, error) { @@ -52,7 +60,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er // method for resource's Exists method. // - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} // make it possible to use "read" & "check presence" functions with disk ID set so @@ -73,7 +81,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er // disk ID is specified, try to get disk instance straight by this ID log.Debugf("utilityDiskCheckPresence: locating disk by its ID %d", theId) urlValues.Add("diskId", fmt.Sprintf("%d", theId)) - diskFacts, err := controller.decortAPICall("POST", DisksGetAPI, urlValues) + diskFacts, err := c.DecortAPICall("POST", DisksGetAPI, urlValues) if err != nil { return "", err } @@ -92,7 +100,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er // obtain Account ID by account name - it should not be zero on success urlValues.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int))) - diskFacts, err := controller.decortAPICall("POST", DisksListAPI, urlValues) + diskFacts, err := c.DecortAPICall("POST", DisksListAPI, urlValues) if err != nil { return "", err } diff --git a/decort/utility_disk_list.go b/internal/service/cloudapi/disks/utility_disk_list.go similarity index 65% rename from decort/utility_disk_list.go rename to internal/service/cloudapi/disks/utility_disk_list.go index 447f92c..9100172 100644 --- a/decort/utility_disk_list.go +++ b/internal/service/cloudapi/disks/utility_disk_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package disks import ( "encoding/json" @@ -30,14 +37,15 @@ import ( "strconv" "strings" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksListResp, error) { diskList := DisksListResp{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if page, ok := d.GetOk("page"); ok { @@ -54,7 +62,7 @@ func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksL } log.Debugf("utilityDiskListCheckPresence: load grid list") - diskListRaw, err := controller.decortAPICall("POST", DisksListAPI, urlValues) + diskListRaw, err := c.DecortAPICall("POST", DisksListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/extnet/api.go b/internal/service/cloudapi/extnet/api.go new file mode 100644 index 0000000..d0421b6 --- /dev/null +++ b/internal/service/cloudapi/extnet/api.go @@ -0,0 +1,37 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package extnet + +const extnetListAPI = "/restmachine/cloudapi/extnet/list" +const extnetListComputesAPI = "/restmachine/cloudapi/extnet/listComputes" +const extnetGetDefaultAPI = "/restmachine/cloudapi/extnet/getDefault" +const extnetGetAPI = "/restmachine/cloudapi/extnet/get" diff --git a/decort/data_source_extnet.go b/internal/service/cloudapi/extnet/data_source_extnet.go similarity index 81% rename from decort/data_source_extnet.go rename to internal/service/cloudapi/extnet/data_source_extnet.go index e28445f..ec16727 100644 --- a/decort/data_source_extnet.go +++ b/internal/service/cloudapi/extnet/data_source_extnet.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,29 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/flattens" ) -func dataSourceExtnetRead(d *schema.ResourceData, m interface{}) error { +func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { e, err := utilityExtnetCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) d.Set("ckey", e.CKey) - d.Set("meta", flattenMeta(e.Meta)) + d.Set("meta", flattens.FlattenMeta(e.Meta)) d.Set("check__ips", e.CheckIPs) d.Set("check_ips", e.CheckIps) d.Set("default", e.Default) @@ -305,15 +317,15 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema { return res } -func dataSourceExtnet() *schema.Resource { +func DataSourceExtnet() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceExtnetRead, + ReadContext: dataSourceExtnetRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceExtnetSchemaMake(), diff --git a/decort/data_source_extnet_computes_list.go b/internal/service/cloudapi/extnet/data_source_extnet_computes_list.go similarity index 73% rename from decort/data_source_extnet_computes_list.go rename to internal/service/cloudapi/extnet/data_source_extnet_computes_list.go index c963a61..521f2a7 100644 --- a/decort/data_source_extnet_computes_list.go +++ b/internal/service/cloudapi/extnet/data_source_extnet_computes_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenExtnetsComputes(ecs ExtnetExtendList) []map[string]interface{} { @@ -60,10 +71,10 @@ func flattenExtnetComputesList(ecl ExtnetComputesList) []map[string]interface{} return res } -func dataSourceExtnetComputesListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceExtnetComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { extnetComputesList, err := utilityExtnetComputesListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -140,15 +151,15 @@ func dataSourceExtnetComputesListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceExtnetComputesList() *schema.Resource { +func DataSourceExtnetComputesList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceExtnetComputesListRead, + ReadContext: dataSourceExtnetComputesListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceExtnetComputesListSchemaMake(), diff --git a/decort/data_source_extnet_default.go b/internal/service/cloudapi/extnet/data_source_extnet_default.go similarity index 53% rename from decort/data_source_extnet_default.go rename to internal/service/cloudapi/extnet/data_source_extnet_default.go index de5585f..bf14365 100644 --- a/decort/data_source_extnet_default.go +++ b/internal/service/cloudapi/extnet/data_source_extnet_default.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,32 +18,40 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( + "context" "strconv" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceExtnetDefaultRead(d *schema.ResourceData, m interface{}) error { +func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { extnetId, err := utilityExtnetDefaultCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) extnetIdInt, err := strconv.ParseInt(extnetId, 10, 32) if err != nil { - return err + return diag.FromErr(err) } d.Set("net_id", extnetIdInt) @@ -58,15 +68,15 @@ func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema { return res } -func dataSourceExtnetDefault() *schema.Resource { +func DataSourceExtnetDefault() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceExtnetDefaultRead, + ReadContext: dataSourceExtnetDefaultRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceExtnetDefaultSchemaMake(), diff --git a/decort/data_source_extnet_list.go b/internal/service/cloudapi/extnet/data_source_extnet_list.go similarity index 65% rename from decort/data_source_extnet_list.go rename to internal/service/cloudapi/extnet/data_source_extnet_list.go index 4789f33..4d88625 100644 --- a/decort/data_source_extnet_list.go +++ b/internal/service/cloudapi/extnet/data_source_extnet_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenExtnetList(el ExtnetList) []map[string]interface{} { @@ -42,10 +53,10 @@ func flattenExtnetList(el ExtnetList) []map[string]interface{} { return res } -func dataSourceExtnetListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { extnetList, err := utilityExtnetListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -96,15 +107,15 @@ func dataSourceExtnetListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceExtnetList() *schema.Resource { +func DataSourceExtnetList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceExtnetListRead, + ReadContext: dataSourceExtnetListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceExtnetListSchemaMake(), diff --git a/internal/service/cloudapi/extnet/models.go b/internal/service/cloudapi/extnet/models.go new file mode 100644 index 0000000..207e06b --- /dev/null +++ b/internal/service/cloudapi/extnet/models.go @@ -0,0 +1,111 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package extnet + +type Extnet struct { + ID int `json:"id"` + IPCidr string `json:"ipcidr"` + Name string `json:"name"` +} +type ExtnetExtend struct { + Extnet + IPAddr string `json:"ipaddr"` +} + +type ExtnetList []Extnet +type ExtnetExtendList []ExtnetExtend + +type ExtnetComputes struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + Extnets ExtnetExtendList `json:"extnets"` + ID int `json:"id"` + Name string `json:"name"` + RGID int `json:"rgId"` + RGName string `json:"rgName"` +} + +type ExtnetComputesList []ExtnetComputes + +type ExtnetQos struct { + ERate int `json:"eRate"` + GUID string `json:"guid"` + InBurst int `json:"inBurst"` + InRate int `json:"inRate"` +} + +type ExtnetReservation struct { + ClientType string `json:"clientType"` + Desc string `json:"desc"` + DomainName string `json:"domainname"` + HostName string `json:"hostname"` + IP string `json:"ip"` + MAC string `json:"mac"` + Type string `json:"type"` + VMID int `json:"vmId"` +} + +type ExtnetReservations []ExtnetReservation + +type ExtnetVNFS struct { + DHCP int `json:"dhcp"` +} + +type ExtnetDetailed struct { + CKey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + CheckIPs []string `json:"checkIPs"` + CheckIps []string `json:"checkIps"` + Default bool `json:"default"` + DefaultQos ExtnetQos `json:"defaultQos"` + Desc string `json:"desc"` + Dns []string `json:"dns"` + Excluded []string `json:"excluded"` + FreeIps int `json:"free_ips"` + Gateway string `json:"gateway"` + GID int `json:"gid"` + GUID int `json:"guid"` + ID int `json:"id"` + IPCidr string `json:"ipcidr"` + Milestones int `json:"milestones"` + Name string `json:"name"` + Network string `json:"network"` + NetworkId int `json:"networkId"` + PreReservationsNum int `json:"preReservationsNum"` + Prefix int `json:"prefix"` + PriVnfDevId int `json:"priVnfDevId"` + Reservations ExtnetReservations `json:"reservations"` + SharedWith []int `json:"sharedWith"` + Status string `json:"status"` + VlanID int `json:"vlanId"` + VNFS ExtnetVNFS `json:"vnfs"` +} diff --git a/decort/utility_extnet.go b/internal/service/cloudapi/extnet/utility_extnet.go similarity index 58% rename from decort/utility_extnet.go rename to internal/service/cloudapi/extnet/utility_extnet.go index f7cb0b4..037dcf9 100644 --- a/decort/utility_extnet.go +++ b/internal/service/cloudapi/extnet/utility_extnet.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityExtnetCheckPresence(d *schema.ResourceData, m interface{}) (*ExtnetDetailed, error) { extnet := &ExtnetDetailed{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("net_id", strconv.Itoa(d.Get("net_id").(int))) log.Debugf("utilityExtnetCheckPresence") - extnetRaw, err := controller.decortAPICall("POST", extnetGetAPI, urlValues) + extnetRaw, err := c.DecortAPICall("POST", extnetGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_extnet_computes_list.go b/internal/service/cloudapi/extnet/utility_extnet_computes_list.go similarity index 59% rename from decort/utility_extnet_computes_list.go rename to internal/service/cloudapi/extnet/utility_extnet_computes_list.go index 2f5c629..69f0c5e 100644 --- a/decort/utility_extnet_computes_list.go +++ b/internal/service/cloudapi/extnet/utility_extnet_computes_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityExtnetComputesListCheckPresence(d *schema.ResourceData, m interface{}) (ExtnetComputesList, error) { extnetComputesList := ExtnetComputesList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityExtnetComputesListCheckPresence") - extnetComputesListRaw, err := controller.decortAPICall("POST", extnetListComputesAPI, urlValues) + extnetComputesListRaw, err := c.DecortAPICall("POST", extnetListComputesAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_extnet_default.go b/internal/service/cloudapi/extnet/utility_extnet_default.go similarity index 53% rename from decort/utility_extnet_default.go rename to internal/service/cloudapi/extnet/utility_extnet_default.go index a76b93c..cdf6686 100644 --- a/decort/utility_extnet_default.go +++ b/internal/service/cloudapi/extnet/utility_extnet_default.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,28 +18,34 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( "net/url" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityExtnetDefaultCheckPresence(_ *schema.ResourceData, m interface{}) (string, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} log.Debugf("utilityExtnetDefaultCheckPresence") - res, err := controller.decortAPICall("POST", extnetGetDefaultAPI, urlValues) + res, err := c.DecortAPICall("POST", extnetGetDefaultAPI, urlValues) if err != nil { return "", err } diff --git a/decort/utility_extnet_list.go b/internal/service/cloudapi/extnet/utility_extnet_list.go similarity index 63% rename from decort/utility_extnet_list.go rename to internal/service/cloudapi/extnet/utility_extnet_list.go index a0abe60..56411bf 100644 --- a/decort/utility_extnet_list.go +++ b/internal/service/cloudapi/extnet/utility_extnet_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package extnet import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityExtnetListCheckPresence(d *schema.ResourceData, m interface{}) (ExtnetList, error) { extnetList := ExtnetList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if accountId, ok := d.GetOk("account_id"); ok { @@ -50,7 +58,7 @@ func utilityExtnetListCheckPresence(d *schema.ResourceData, m interface{}) (Extn } log.Debugf("utilityExtnetListCheckPresence") - extnetListRaw, err := controller.decortAPICall("POST", extnetListAPI, urlValues) + extnetListRaw, err := c.DecortAPICall("POST", extnetListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/k8s/api.go b/internal/service/cloudapi/k8s/api.go new file mode 100644 index 0000000..ab5bf88 --- /dev/null +++ b/internal/service/cloudapi/k8s/api.go @@ -0,0 +1,49 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package k8s + +const K8sCreateAPI = "/restmachine/cloudapi/k8s/create" +const K8sGetAPI = "/restmachine/cloudapi/k8s/get" +const K8sUpdateAPI = "/restmachine/cloudapi/k8s/update" +const K8sDeleteAPI = "/restmachine/cloudapi/k8s/delete" + +const K8sWgCreateAPI = "/restmachine/cloudapi/k8s/workersGroupAdd" +const K8sWgDeleteAPI = "/restmachine/cloudapi/k8s/workersGroupDelete" + +const K8sWorkerAddAPI = "/restmachine/cloudapi/k8s/workerAdd" +const K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup" + +const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig" + +const LbGetAPI = "/restmachine/cloudapi/lb/get" + +const AsyncTaskGetAPI = "/restmachine/cloudapi/tasks/get" diff --git a/internal/service/cloudapi/k8s/models.go b/internal/service/cloudapi/k8s/models.go new file mode 100644 index 0000000..7634dd0 --- /dev/null +++ b/internal/service/cloudapi/k8s/models.go @@ -0,0 +1,131 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package k8s + +import ( + "encoding/json" + "fmt" + "strconv" +) + +type K8sNodeRecord struct { + ID int `json:"id"` + Name string `json:"name"` + Disk int `json:"disk"` + Cpu int `json:"cpu"` + Num int `json:"num"` + Ram int `json:"ram"` + DetailedInfo []struct { + ID int `json:"id"` + Name string `json:"name"` + } `json:"detailedInfo"` +} + +//K8sRecord represents k8s instance +type K8sRecord struct { + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + CI int `json:"ciId"` + ID int `json:"id"` + Groups struct { + Masters K8sNodeRecord `json:"masters"` + Workers []K8sNodeRecord `json:"workers"` + } `json:"k8sGroups"` + LbID int `json:"lbId"` + Name string `json:"name"` + RgID int `json:"rgId"` + RgName string `json:"rgName"` +} + +//LbRecord represents load balancer instance +type LbRecord struct { + ID int `json:"id"` + Name string `json:"name"` + RgID int `json:"rgId"` + VinsID int `json:"vinsId"` + ExtNetID int `json:"extnetId"` + PrimaryNode struct { + BackendIP string `json:"backendIp"` + ComputeID int `json:"computeId"` + FrontendIP string `json:"frontendIp"` + NetworkID int `json:"networkId"` + } `json:"primaryNode"` +} + +//Blasphemous workaround for parsing Result value +type TaskResult int + +func (r *TaskResult) UnmarshalJSON(b []byte) error { + if b[0] == '"' { + b := b[1 : len(b)-1] + if len(b) == 0 { + *r = 0 + return nil + } + n, err := strconv.Atoi(string(b)) + if err != nil { + return err + } + *r = TaskResult(n) + } else if b[0] == '[' { + res := []interface{}{} + if err := json.Unmarshal(b, &res); err != nil { + return err + } + if n, ok := res[0].(float64); ok { + *r = TaskResult(n) + } else { + return fmt.Errorf("could not unmarshal %v into int", res[0]) + } + } + + return nil +} + +//AsyncTask represents a long task completion status +type AsyncTask struct { + AuditID string `json:"auditId"` + Completed bool `json:"completed"` + Error string `json:"error"` + Log []string `json:"log"` + Result TaskResult `json:"result"` + Stage string `json:"stage"` + Status string `json:"status"` + UpdateTime uint64 `json:"updateTime"` + UpdatedTime uint64 `json:"updatedTime"` +} + +type SshKeyConfig struct { + User string + SshKey string + UserShell string +} diff --git a/decort/node_subresource.go b/internal/service/cloudapi/k8s/node_subresource.go similarity index 77% rename from decort/node_subresource.go rename to internal/service/cloudapi/k8s/node_subresource.go index 96040c5..78fc9ce 100644 --- a/decort/node_subresource.go +++ b/internal/service/cloudapi/k8s/node_subresource.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,15 +18,20 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package k8s -import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" func nodeMasterDefault() K8sNodeRecord { return K8sNodeRecord{ diff --git a/decort/resource_k8s.go b/internal/service/cloudapi/k8s/resource_k8s.go similarity index 73% rename from decort/resource_k8s.go rename to internal/service/cloudapi/k8s/resource_k8s.go index e0f3cb0..59d240c 100644 --- a/decort/resource_k8s.go +++ b/internal/service/cloudapi/k8s/resource_k8s.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,15 +18,21 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package k8s import ( + "context" "encoding/json" "fmt" "net/url" @@ -32,14 +40,17 @@ import ( "strings" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceK8sCreate(d *schema.ResourceData, m interface{}) error { +func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sCreate: called with name %s, rg %d", d.Get("name").(string), d.Get("rg_id").(int)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("name").(string)) urlValues.Add("rgId", strconv.Itoa(d.Get("rg_id").(int))) @@ -83,29 +94,29 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error { //urlValues.Add("desc", desc.(string)) //} - resp, err := controller.decortAPICall("POST", K8sCreateAPI, urlValues) + resp, err := c.DecortAPICall("POST", K8sCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} urlValues.Add("auditId", strings.Trim(resp, `"`)) for { - resp, err := controller.decortAPICall("POST", AsyncTaskGetAPI, urlValues) + resp, err := c.DecortAPICall("POST", AsyncTaskGetAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } task := AsyncTask{} if err := json.Unmarshal([]byte(resp), &task); err != nil { - return err + return diag.FromErr(err) } log.Debugf("resourceK8sCreate: instance creating - %s", task.Stage) if task.Completed { if task.Error != "" { - return fmt.Errorf("cannot create k8s instance: %v", task.Error) + return diag.FromErr(fmt.Errorf("cannot create k8s instance: %v", task.Error)) } d.SetId(strconv.Itoa(int(task.Result))) @@ -117,7 +128,7 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error { k8s, err := utilityK8sCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.Set("default_wg_id", k8s.Groups.Workers[0].ID) @@ -125,21 +136,21 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error { urlValues = &url.Values{} urlValues.Add("lbId", strconv.Itoa(k8s.LbID)) - resp, err = controller.decortAPICall("POST", LbGetAPI, urlValues) + resp, err = c.DecortAPICall("POST", LbGetAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } var lb LbRecord if err := json.Unmarshal([]byte(resp), &lb); err != nil { - return err + return diag.FromErr(err) } d.Set("extnet_id", lb.ExtNetID) d.Set("lb_ip", lb.PrimaryNode.FrontendIP) urlValues = &url.Values{} urlValues.Add("k8sId", d.Id()) - kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues) + kubeconfig, err := c.DecortAPICall("POST", K8sGetConfigAPI, urlValues) if err != nil { log.Warnf("could not get kubeconfig: %v", err) } @@ -148,13 +159,13 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceK8sRead(d *schema.ResourceData, m interface{}) error { +func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) k8s, err := utilityK8sCheckPresence(d, m) if k8s == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("name", k8s.Name) @@ -165,25 +176,25 @@ func resourceK8sRead(d *schema.ResourceData, m interface{}) error { d.Set("workers", nodeToResource(k8s.Groups.Workers[0])) d.Set("default_wg_id", k8s.Groups.Workers[0].ID) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("lbId", strconv.Itoa(k8s.LbID)) - resp, err := controller.decortAPICall("POST", LbGetAPI, urlValues) + resp, err := c.DecortAPICall("POST", LbGetAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } var lb LbRecord if err := json.Unmarshal([]byte(resp), &lb); err != nil { - return err + return diag.FromErr(err) } d.Set("extnet_id", lb.ExtNetID) d.Set("lb_ip", lb.PrimaryNode.FrontendIP) urlValues = &url.Values{} urlValues.Add("k8sId", d.Id()) - kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues) + kubeconfig, err := c.DecortAPICall("POST", K8sGetConfigAPI, urlValues) if err != nil { log.Warnf("could not get kubeconfig: %v", err) } @@ -192,26 +203,26 @@ func resourceK8sRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceK8sUpdate(d *schema.ResourceData, m interface{}) error { +func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sUpdate: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) if d.HasChange("name") { urlValues := &url.Values{} urlValues.Add("k8sId", d.Id()) urlValues.Add("name", d.Get("name").(string)) - _, err := controller.decortAPICall("POST", K8sUpdateAPI, urlValues) + _, err := c.DecortAPICall("POST", K8sUpdateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } if d.HasChange("workers") { k8s, err := utilityK8sCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } wg := k8s.Groups.Workers[0] @@ -223,14 +234,14 @@ func resourceK8sUpdate(d *schema.ResourceData, m interface{}) error { if newWorkers.Num > wg.Num { urlValues.Add("num", strconv.Itoa(newWorkers.Num-wg.Num)) - if _, err := controller.decortAPICall("POST", K8sWorkerAddAPI, urlValues); err != nil { - return err + if _, err := c.DecortAPICall("POST", K8sWorkerAddAPI, urlValues); err != nil { + return diag.FromErr(err) } } else { for i := wg.Num - 1; i >= newWorkers.Num; i-- { urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID)) - if _, err := controller.decortAPICall("POST", K8sWorkerDeleteAPI, urlValues); err != nil { - return err + if _, err := c.DecortAPICall("POST", K8sWorkerDeleteAPI, urlValues); err != nil { + return diag.FromErr(err) } } } @@ -239,25 +250,25 @@ func resourceK8sUpdate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceK8sDelete(d *schema.ResourceData, m interface{}) error { +func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) k8s, err := utilityK8sCheckPresence(d, m) if k8s == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("k8sId", d.Id()) urlValues.Add("permanently", "true") - _, err = controller.decortAPICall("POST", K8sDeleteAPI, urlValues) + _, err = c.DecortAPICall("POST", K8sDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } return nil @@ -366,26 +377,26 @@ func resourceK8sSchemaMake() map[string]*schema.Schema { } } -func resourceK8s() *schema.Resource { +func ResourceK8s() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceK8sCreate, - Read: resourceK8sRead, - Update: resourceK8sUpdate, - Delete: resourceK8sDelete, - Exists: resourceK8sExists, + CreateContext: resourceK8sCreate, + ReadContext: resourceK8sRead, + UpdateContext: resourceK8sUpdate, + DeleteContext: resourceK8sDelete, + Exists: resourceK8sExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout20m, - Read: &Timeout30s, - Update: &Timeout20m, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout20m, + Read: &constants.Timeout30s, + Update: &constants.Timeout20m, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceK8sSchemaMake(), diff --git a/decort/resource_k8s_wg.go b/internal/service/cloudapi/k8s/resource_k8s_wg.go similarity index 68% rename from decort/resource_k8s_wg.go rename to internal/service/cloudapi/k8s/resource_k8s_wg.go index d9f4054..420130d 100644 --- a/decort/resource_k8s_wg.go +++ b/internal/service/cloudapi/k8s/resource_k8s_wg.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,26 +18,35 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package k8s import ( + "context" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceK8sWgCreate(d *schema.ResourceData, m interface{}) error { +func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sWgCreate: called with k8s id %d", d.Get("k8s_id").(int)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int))) urlValues.Add("name", d.Get("name").(string)) @@ -44,9 +55,9 @@ func resourceK8sWgCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("workerRam", strconv.Itoa(d.Get("ram").(int))) urlValues.Add("workerDisk", strconv.Itoa(d.Get("disk").(int))) - resp, err := controller.decortAPICall("POST", K8sWgCreateAPI, urlValues) + resp, err := c.DecortAPICall("POST", K8sWgCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(resp) @@ -83,13 +94,13 @@ func resourceK8sWgCreate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceK8sWgRead(d *schema.ResourceData, m interface{}) error { +func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int)) wg, err := utilityK8sWgCheckPresence(d, m) if wg == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("name", wg.Name) @@ -101,14 +112,14 @@ func resourceK8sWgRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceK8sWgUpdate(d *schema.ResourceData, m interface{}) error { +func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sWgUpdate: called with k8s id %d", d.Get("k8s_id").(int)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) wg, err := utilityK8sWgCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } urlValues := &url.Values{} @@ -117,16 +128,16 @@ func resourceK8sWgUpdate(d *schema.ResourceData, m interface{}) error { if newNum := d.Get("num").(int); newNum > wg.Num { urlValues.Add("num", strconv.Itoa(newNum-wg.Num)) - _, err := controller.decortAPICall("POST", K8sWorkerAddAPI, urlValues) + _, err := c.DecortAPICall("POST", K8sWorkerAddAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } else { for i := wg.Num - 1; i >= newNum; i-- { urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID)) - _, err := controller.decortAPICall("POST", K8sWorkerDeleteAPI, urlValues) + _, err := c.DecortAPICall("POST", K8sWorkerDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } } @@ -134,25 +145,25 @@ func resourceK8sWgUpdate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceK8sWgDelete(d *schema.ResourceData, m interface{}) error { +func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sWgDelete: called with k8s id %d", d.Get("k8s_id").(int)) wg, err := utilityK8sWgCheckPresence(d, m) if wg == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int))) urlValues.Add("workersGroupId", strconv.Itoa(wg.ID)) - _, err = controller.decortAPICall("POST", K8sWgDeleteAPI, urlValues) + _, err = c.DecortAPICall("POST", K8sWgDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } return nil @@ -221,26 +232,26 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema { } } -func resourceK8sWg() *schema.Resource { +func ResourceK8sWg() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceK8sWgCreate, - Read: resourceK8sWgRead, - Update: resourceK8sWgUpdate, - Delete: resourceK8sWgDelete, - Exists: resourceK8sWgExists, + CreateContext: resourceK8sWgCreate, + ReadContext: resourceK8sWgRead, + UpdateContext: resourceK8sWgUpdate, + DeleteContext: resourceK8sWgDelete, + Exists: resourceK8sWgExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout20m, - Read: &Timeout30s, - Update: &Timeout20m, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout20m, + Read: &constants.Timeout30s, + Update: &constants.Timeout20m, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceK8sWgSchemaMake(), diff --git a/decort/utility_k8s.go b/internal/service/cloudapi/k8s/utility_k8s.go similarity index 58% rename from decort/utility_k8s.go rename to internal/service/cloudapi/k8s/utility_k8s.go index 2a3fcdb..b9a5db7 100644 --- a/decort/utility_k8s.go +++ b/internal/service/cloudapi/k8s/utility_k8s.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package k8s import ( "encoding/json" "net/url" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilityK8sCheckPresence(d *schema.ResourceData, m interface{}) (*K8sRecord, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("k8sId", d.Id()) - resp, err := controller.decortAPICall("POST", K8sGetAPI, urlValues) + resp, err := c.DecortAPICall("POST", K8sGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_k8s_wg.go b/internal/service/cloudapi/k8s/utility_k8s_wg.go similarity index 63% rename from decort/utility_k8s_wg.go rename to internal/service/cloudapi/k8s/utility_k8s_wg.go index f4ed797..e95f6c6 100644 --- a/decort/utility_k8s_wg.go +++ b/internal/service/cloudapi/k8s/utility_k8s_wg.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,28 +18,34 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package k8s import ( "encoding/json" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilityK8sWgCheckPresence(d *schema.ResourceData, m interface{}) (*K8sNodeRecord, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int))) - resp, err := controller.decortAPICall("POST", K8sGetAPI, urlValues) + resp, err := c.DecortAPICall("POST", K8sGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/kvmvm/api.go b/internal/service/cloudapi/kvmvm/api.go new file mode 100644 index 0000000..97678d9 --- /dev/null +++ b/internal/service/cloudapi/kvmvm/api.go @@ -0,0 +1,46 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package kvmvm + +const KvmX86CreateAPI = "/restmachine/cloudapi/kvmx86/create" +const KvmPPCCreateAPI = "/restmachine/cloudapi/kvmppc/create" +const ComputeGetAPI = "/restmachine/cloudapi/compute/get" +const RgListComputesAPI = "/restmachine/cloudapi/rg/listComputes" +const ComputeNetAttachAPI = "/restmachine/cloudapi/compute/netAttach" +const ComputeNetDetachAPI = "/restmachine/cloudapi/compute/netDetach" +const ComputeDiskAttachAPI = "/restmachine/cloudapi/compute/diskAttach" +const ComputeDiskDetachAPI = "/restmachine/cloudapi/compute/diskDetach" +const ComputeStartAPI = "/restmachine/cloudapi/compute/start" +const ComputeStopAPI = "/restmachine/cloudapi/compute/stop" +const ComputeResizeAPI = "/restmachine/cloudapi/compute/resize" +const DisksResizeAPI = "/restmachine/cloudapi/disks/resize2" +const ComputeDeleteAPI = "/restmachine/cloudapi/compute/delete" diff --git a/decort/data_source_compute.go b/internal/service/cloudapi/kvmvm/data_source_compute.go similarity index 89% rename from decort/data_source_compute.go rename to internal/service/cloudapi/kvmvm/data_source_compute.go index e1b4169..6e66b98 100644 --- a/decort/data_source_compute.go +++ b/internal/service/cloudapi/kvmvm/data_source_compute.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,24 +18,31 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package kvmvm import ( + "context" "encoding/json" "fmt" // "net/url" + "github.com/rudecs/terraform-provider-decort/internal/constants" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Parse list of all disks from API compute/get into a list of "extra disks" attached to this compute @@ -186,27 +195,27 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error { return nil } -func dataSourceComputeRead(d *schema.ResourceData, m interface{}) error { +func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { compFacts, err := utilityComputeCheckPresence(d, m) if compFacts == "" { // if empty string is returned from utilityComputeCheckPresence then there is no // such Compute and err tells so - just return it to the calling party d.SetId("") // ensure ID is empty - return err + return diag.FromErr(err) } - return flattenCompute(d, compFacts) + return diag.FromErr(flattenCompute(d, compFacts)) } func dataSourceCompute() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceComputeRead, + ReadContext: dataSourceComputeRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: map[string]*schema.Schema{ @@ -293,7 +302,7 @@ func dataSourceCompute() *schema.Resource { "extra_disks": { Type: schema.TypeSet, Computed: true, - MaxItems: MaxExtraDisksPerCompute, + MaxItems: constants.MaxExtraDisksPerCompute, Elem: &schema.Schema{ Type: schema.TypeInt, }, @@ -314,7 +323,7 @@ func dataSourceCompute() *schema.Resource { "network": { Type: schema.TypeSet, Optional: true, - MaxItems: MaxNetworksPerCompute, + MaxItems: constants.MaxNetworksPerCompute, Elem: &schema.Resource{ Schema: networkSubresourceSchemaMake(), }, diff --git a/internal/service/cloudapi/kvmvm/models.go b/internal/service/cloudapi/kvmvm/models.go new file mode 100644 index 0000000..220fafd --- /dev/null +++ b/internal/service/cloudapi/kvmvm/models.go @@ -0,0 +1,190 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package kvmvm + +type DiskRecord struct { + Acl map[string]interface{} `json:"acl"` + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + BootPartition int `json:"bootPartition"` + CreatedTime uint64 `json:"creationTime"` + ComputeID int `json:"computeId"` + ComputeName string `json:"computeName"` + DeletedTime uint64 `json:"deletionTime"` + DeviceName string `json:"devicename"` + Desc string `json:"desc"` + DestructionTime uint64 `json:"destructionTime"` + DiskPath string `json:"diskPath"` + GridID int `json:"gid"` + GUID int `json:"guid"` + ID uint `json:"id"` + ImageID int `json:"imageId"` + Images []int `json:"images"` + IOTune map[string]interface{} `json:"iotune"` + IQN string `json:"iqn"` + Login string `json:"login"` + Name string `json:"name"` + MachineId int `json:"machineId"` + MachineName string `json:"machineName"` + Milestones uint64 `json:"milestones"` + Order int `json:"order"` + Params string `json:"params"` + Passwd string `json:"passwd"` + ParentId int `json:"parentId"` + PciSlot int `json:"pciSlot"` + Pool string `json:"pool"` + PurgeTime uint64 `json:"purgeTime"` + PurgeAttempts uint64 `json:"purgeAttempts"` + RealityDeviceNumber int `json:"realityDeviceNumber"` + ReferenceId string `json:"referenceId"` + ResID string `json:"resId"` + ResName string `json:"resName"` + Role string `json:"role"` + SepType string `json:"sepType"` + SepID int `json:"sepId"` // NOTE: absent from compute/get output + SizeMax int `json:"sizeMax"` + SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space + Snapshots []SnapshotRecord `json:"snapshots"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + UpdateBy uint64 `json:"updateBy"` + VMID int `json:"vmid"` +} + +type InterfaceRecord struct { + ConnID int `json:"connId"` // This is VLAN ID or VxLAN ID, depending on ConnType + ConnType string `json:"connType"` // Either "VLAN" or "VXLAN" tag + DefaultGW string `json:"defGw"` + Guid string `json:"guid"` + IPAddress string `json:"ipAddress"` // without trailing network mask, i.e. "192.168.1.3" + MAC string `json:"mac"` + Name string `json:"name"` + NetID int `json:"netId"` // This is either ExtNet ID or ViNS ID, depending on NetType + NetMask int `json:"netMask"` + NetType string `json:"netType"` // Either "EXTNET" or "VINS" tag + PciSlot int `json:"pciSlot"` + Target string `json:"target"` + Type string `json:"type"` + VNFs []int `json:"vnfs"` + QOS InterfaceQosRecord `json:"qos"` +} + +type InterfaceQosRecord struct { + ERate int `json:"eRate"` + Guid string `json:"guid"` + InBurst int `json:"inBurst"` + InRate int `json:"inRate"` +} + +type SnapshotRecord struct { + Guid string `json:"guid"` + Label string `json:"label"` + ResId string `json:"resId"` + SnapSetGuid string `json:"snapSetGuid"` + SnapSetTime uint64 `json:"snapSetTime"` + TimeStamp uint64 `json:"timestamp"` +} + +type SnapshotRecordList []SnapshotRecord + +type ComputeGetResp struct { + // ACLs `json:"ACL"` - it is a dictionary, special parsing required + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + Arch string `json:"arch"` + BootDiskSize int `json:"bootdiskSize"` + CloneReference int `json:"cloneReference"` + Clones []int `json:"clones"` + Cpu int `json:"cpus"` + Desc string `json:"desc"` + Disks []DiskRecord `json:"disks"` + Driver string `json:"driver"` + GridID int `json:"gid"` + ID uint `json:"id"` + ImageID int `json:"imageId"` + ImageName string `json:"imageName"` + Interfaces []InterfaceRecord `json:"interfaces"` + LockStatus string `json:"lockStatus"` + ManagerID int `json:"managerId"` + ManagerType string `json:"manageType"` + Name string `json:"name"` + NatableVinsID int `json:"natableVinsId"` + NatableVinsIP string `json:"natableVinsIp"` + NatableVinsName string `json:"natableVinsName"` + NatableVinsNet string `json:"natableVinsNetwork"` + NatableVinsNetName string `json:"natableVinsNetworkName"` + OsUsers []OsUserRecord `json:"osUsers"` + Ram int `json:"ram"` + RgID int `json:"rgId"` + RgName string `json:"rgName"` + SnapSets []SnapSetRecord `json:"snapSets"` + Status string `json:"status"` + // Tags []string `json:"tags"` // Tags were reworked since DECORT 3.7.1 + TechStatus string `json:"techStatus"` + TotalDiskSize int `json:"totalDiskSize"` + UpdatedBy string `json:"updatedBy"` + UpdateTime uint64 `json:"updateTime"` + UserManaged bool `json:"userManaged"` + Vgpus []int `json:"vgpus"` + VinsConnected int `json:"vinsConnected"` + VirtualImageID int `json:"virtualImageId"` +} + +type OsUserRecord struct { + Guid string `json:"guid"` + Login string `json:"login"` + Password string `json:"password"` + PubKey string `json:"pubkey"` +} + +type SnapSetRecord struct { + Disks []int `json:"disks"` + Guid string `json:"guid"` + Label string `json:"label"` + TimeStamp uint64 `json:"timestamp"` +} + +type ComputeBriefRecord struct { // this is a brief compute specifiaction as returned by API rg/listComputes + // we do not even include here all fields as returned by this API, but only the most important that + // are really necessary to identify and distinguish computes + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + Name string `json:"name"` + ID uint `json:"id"` + RgID int `json:"rgId"` + RgName string `json:"rgName"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` +} + +type RgListComputesResp []ComputeBriefRecord diff --git a/decort/network_subresource.go b/internal/service/cloudapi/kvmvm/network_subresource.go similarity index 83% rename from decort/network_subresource.go rename to internal/service/cloudapi/kvmvm/network_subresource.go index 183fe5a..4a0663f 100644 --- a/decort/network_subresource.go +++ b/internal/service/cloudapi/kvmvm/network_subresource.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,23 +17,31 @@ See the License for the specific language governing permissions and limitations under the License. */ -package decort +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -import ( +Source code: https://github.com/rudecs/terraform-provider-decort - // "encoding/json" - // "fmt" +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package kvmvm + +import ( "bytes" "hash/fnv" + "github.com/rudecs/terraform-provider-decort/internal/provider" log "github.com/sirupsen/logrus" - // "net/url" "sort" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - // "github.com/hashicorp/terraform-plugin-sdk/v2/internal/helper/hashcode" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) // This is subresource of compute resource used when creating/managing compute network connections @@ -115,7 +125,7 @@ func networkSubresourceSchemaMake() map[string]*schema.Schema { "net_type": { Type: schema.TypeString, Required: true, - StateFunc: stateFuncToUpper, + StateFunc: provider.StateFuncToUpper, ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, false), // observe case while validating Description: "Type of the network for this connection, either EXTNET or VINS.", }, diff --git a/decort/osusers_subresource.go b/internal/service/cloudapi/kvmvm/osusers_subresource.go similarity index 73% rename from decort/osusers_subresource.go rename to internal/service/cloudapi/kvmvm/osusers_subresource.go index f146f85..2e6787f 100644 --- a/decort/osusers_subresource.go +++ b/internal/service/cloudapi/kvmvm/osusers_subresource.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,13 +17,24 @@ See the License for the specific language governing permissions and limitations under the License. */ -package decort +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package kvmvm import ( log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func parseOsUsers(logins []OsUserRecord) []interface{} { diff --git a/decort/resource_compute.go b/internal/service/cloudapi/kvmvm/resource_compute.go similarity index 80% rename from decort/resource_compute.go rename to internal/service/cloudapi/kvmvm/resource_compute.go index ea43785..575c2a8 100644 --- a/decort/resource_compute.go +++ b/internal/service/cloudapi/kvmvm/resource_compute.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,24 +18,34 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package kvmvm import ( + "context" "encoding/json" "fmt" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/provider" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func cloudInitDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool { @@ -49,7 +61,7 @@ func cloudInitDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) b return true // suppress difference } -func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { +func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // we assume all mandatory parameters it takes to create a comptue instance are properly // specified - we rely on schema "Required" attributes to let Terraform validate them for us @@ -57,9 +69,7 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { // create basic Compute (i.e. without extra disks and network connections - those will be attached // by subsequent individual API calls). - // creating Compute is a multi-step workflow, which may fail at some step, so we use "partial" feature of Terraform - d.Partial(true) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("rgId", fmt.Sprintf("%d", d.Get("rg_id").(int))) urlValues.Add("name", d.Get("name").(string)) @@ -102,25 +112,14 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { } } - apiResp, err := controller.decortAPICall("POST", computeCreateAPI, urlValues) + apiResp, err := c.DecortAPICall("POST", computeCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } // Compute create API returns ID of the new Compute instance on success d.SetId(apiResp) // update ID of the resource to tell Terraform that the resource exists, albeit partially compId, _ := strconv.Atoi(apiResp) - d.SetPartial("name") - d.SetPartial("description") - d.SetPartial("cpu") - d.SetPartial("ram") - d.SetPartial("image_id") - d.SetPartial("boot_disk_size") - /* - if sshKeysSet { - d.SetPartial("ssh_keys") - } - */ log.Debugf("resourceComputeCreate: new simple Compute ID %d, name %s created", compId, d.Get("name").(string)) @@ -130,7 +129,7 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { if argSet && argVal.(*schema.Set).Len() > 0 { // urlValues.Add("desc", argVal.(string)) log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len()) - err = controller.utilityComputeExtraDisksConfigure(d, false) // do_delta=false, as we are working on a new compute + err = utilityComputeExtraDisksConfigure(d, m, false) // do_delta=false, as we are working on a new compute if err != nil { log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", compId, err) extraDisksOk = false @@ -145,7 +144,7 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { argVal, argSet = d.GetOk("network") if argSet && argVal.(*schema.Set).Len() > 0 { log.Debugf("resourceComputeCreate: calling utilityComputeNetworksConfigure to attach %d network(s)", argVal.(*schema.Set).Len()) - err = controller.utilityComputeNetworksConfigure(d, false) // do_delta=false, as we are working on a new compute + err = utilityComputeNetworksConfigure(d, m, false) // do_delta=false, as we are working on a new compute if err != nil { log.Errorf("resourceComputeCreate: error when attaching networks to a new Compute ID %d: %s", compId, err) netsOk = false @@ -167,8 +166,8 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { reqValues := &url.Values{} reqValues.Add("computeId", fmt.Sprintf("%d", compId)) log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", compId) - if _, err := controller.decortAPICall("POST", ComputeStartAPI, reqValues); err != nil { - return err + if _, err := c.DecortAPICall("POST", ComputeStartAPI, reqValues); err != nil { + return diag.FromErr(err) } } @@ -178,24 +177,24 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { // between Compute resource and Compute data source schemas // Compute read function will also update resource ID on success, so that Terraform // will know the resource exists - return dataSourceComputeRead(d, m) + return dataSourceComputeRead(ctx, d, m) } -func resourceComputeRead(d *schema.ResourceData, m interface{}) error { +func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceComputeRead: called for Compute name %s, RG ID %d", d.Get("name").(string), d.Get("rg_id").(int)) compFacts, err := utilityComputeCheckPresence(d, m) if compFacts == "" { if err != nil { - return err + return diag.FromErr(err) } // Compute with such name and RG ID was not found return nil } if err = flattenCompute(d, compFacts); err != nil { - return err + return diag.FromErr(err) } log.Debugf("resourceComputeRead: after flattenCompute: Compute ID %s, name %q, RG ID %d", @@ -204,11 +203,11 @@ func resourceComputeRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error { +func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceComputeUpdate: called for Compute ID %s / name %s, RGID %d", d.Id(), d.Get("name").(string), d.Get("rg_id").(int)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) /* 1. Resize CPU/RAM @@ -246,10 +245,11 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error { oldCpu.(int), newCpu.(int), oldRam.(int), newRam.(int)) params.Add("force", "true") - _, err := controller.decortAPICall("POST", ComputeResizeAPI, params) + _, err := c.DecortAPICall("POST", ComputeResizeAPI, params) if err != nil { - return err + return diag.FromErr(err) } + d.SetPartial("cpu") d.SetPartial("ram") } @@ -262,9 +262,9 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error { bdsParams.Add("size", fmt.Sprintf("%d", newSize.(int))) log.Debugf("resourceComputeUpdate: compute ID %s, boot disk ID %d resize %d -> %d", d.Id(), d.Get("boot_disk_id").(int), oldSize.(int), newSize.(int)) - _, err := controller.decortAPICall("POST", DisksResizeAPI, bdsParams) + _, err := c.DecortAPICall("POST", DisksResizeAPI, bdsParams) if err != nil { - return err + return diag.FromErr(err) } d.SetPartial("boot_disk_size") } else if oldSize.(int) > newSize.(int) { @@ -272,44 +272,37 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error { } // 3. Calculate and apply changes to data disks - err := controller.utilityComputeExtraDisksConfigure(d, true) // pass do_delta = true to apply changes, if any + err := utilityComputeExtraDisksConfigure(d, m, true) // pass do_delta = true to apply changes, if any if err != nil { - return err - } else { - d.SetPartial("extra_disks") + return diag.FromErr(err) } // 4. Calculate and apply changes to network connections - err = controller.utilityComputeNetworksConfigure(d, true) // pass do_delta = true to apply changes, if any + err = utilityComputeNetworksConfigure(d, m, true) // pass do_delta = true to apply changes, if any if err != nil { - return err - } else { - d.SetPartial("network") + return diag.FromErr(err) } if d.HasChange("started") { params := &url.Values{} params.Add("computeId", d.Id()) if d.Get("started").(bool) { - if _, err := controller.decortAPICall("POST", ComputeStartAPI, params); err != nil { - return err + if _, err := c.DecortAPICall("POST", ComputeStartAPI, params); err != nil { + return diag.FromErr(err) } } else { - if _, err := controller.decortAPICall("POST", ComputeStopAPI, params); err != nil { - return err + if _, err := c.DecortAPICall("POST", ComputeStopAPI, params); err != nil { + return diag.FromErr(err) } } - d.SetPartial("started") } - d.Partial(false) - // we may reuse dataSourceComputeRead here as we maintain similarity // between Compute resource and Compute data source schemas - return dataSourceComputeRead(d, m) + return dataSourceComputeRead(ctx, d, m) } -func resourceComputeDelete(d *schema.ResourceData, m interface{}) error { +func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // NOTE: this function destroys target Compute instance "permanently", so // there is no way to restore it. // If compute being destroyed has some extra disks attached, they are @@ -320,14 +313,14 @@ func resourceComputeDelete(d *schema.ResourceData, m interface{}) error { compFacts, err := utilityComputeCheckPresence(d, m) if compFacts == "" { if err != nil { - return err + return diag.FromErr(err) } // the target Compute does not exist - in this case according to Terraform best practice // we exit from Destroy method without error return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) model := ComputeGetResp{} log.Debugf("resourceComputeDelete: ready to unmarshal string %s", compFacts) @@ -347,7 +340,7 @@ func resourceComputeDelete(d *schema.ResourceData, m interface{}) error { detachParams.Add("computeId", d.Id()) detachParams.Add("diskId", fmt.Sprintf("%d", diskFacts.ID)) - _, err = controller.decortAPICall("POST", ComputeDiskDetachAPI, detachParams) + _, err = c.DecortAPICall("POST", ComputeDiskDetachAPI, detachParams) if err != nil { // We do not fail compute deletion on data disk detach errors log.Errorf("resourceComputeDelete: error when detaching Disk ID %d: %s", diskFacts.ID, err) @@ -360,9 +353,9 @@ func resourceComputeDelete(d *schema.ResourceData, m interface{}) error { params.Add("permanently", "1") // TODO: this is for the upcoming API update - params.Add("detachdisks", "1") - _, err = controller.decortAPICall("POST", ComputeDeleteAPI, params) + _, err = c.DecortAPICall("POST", ComputeDeleteAPI, params) if err != nil { - return err + return diag.FromErr(err) } return nil @@ -383,26 +376,26 @@ func resourceComputeExists(d *schema.ResourceData, m interface{}) (bool, error) return true, nil } -func resourceCompute() *schema.Resource { +func ResourceCompute() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceComputeCreate, - Read: resourceComputeRead, - Update: resourceComputeUpdate, - Delete: resourceComputeDelete, - Exists: resourceComputeExists, + CreateContext: resourceComputeCreate, + ReadContext: resourceComputeRead, + UpdateContext: resourceComputeUpdate, + DeleteContext: resourceComputeDelete, + Exists: resourceComputeExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout180s, - Read: &Timeout30s, - Update: &Timeout180s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout180s, + Read: &constants.Timeout30s, + Update: &constants.Timeout180s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: map[string]*schema.Schema{ @@ -423,7 +416,7 @@ func resourceCompute() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - StateFunc: stateFuncToUpper, + StateFunc: provider.StateFuncToUpper, ValidateFunc: validation.StringInSlice([]string{"KVM_X86", "KVM_PPC"}, false), // observe case while validating Description: "Hardware architecture of this compute instance.", }, @@ -431,14 +424,14 @@ func resourceCompute() *schema.Resource { "cpu": { Type: schema.TypeInt, Required: true, - ValidateFunc: validation.IntBetween(1, MaxCpusPerCompute), + ValidateFunc: validation.IntBetween(1, constants.MaxCpusPerCompute), Description: "Number of CPUs to allocate to this compute instance.", }, "ram": { Type: schema.TypeInt, Required: true, - ValidateFunc: validation.IntAtLeast(MinRamPerCompute), + ValidateFunc: validation.IntAtLeast(constants.MinRamPerCompute), Description: "Amount of RAM in MB to allocate to this compute instance.", }, @@ -459,7 +452,7 @@ func resourceCompute() *schema.Resource { "extra_disks": { Type: schema.TypeSet, Optional: true, - MaxItems: MaxExtraDisksPerCompute, + MaxItems: constants.MaxExtraDisksPerCompute, Elem: &schema.Schema{ Type: schema.TypeInt, }, @@ -469,7 +462,7 @@ func resourceCompute() *schema.Resource { "network": { Type: schema.TypeSet, Optional: true, - MaxItems: MaxNetworksPerCompute, + MaxItems: constants.MaxNetworksPerCompute, Elem: &schema.Resource{ Schema: networkSubresourceSchemaMake(), }, diff --git a/decort/utility_compute.go b/internal/service/cloudapi/kvmvm/utility_compute.go similarity index 86% rename from decort/utility_compute.go rename to internal/service/cloudapi/kvmvm/utility_compute.go index d8b559d..894e81d 100644 --- a/decort/utility_compute.go +++ b/internal/service/cloudapi/kvmvm/utility_compute.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package kvmvm import ( "encoding/json" @@ -30,13 +37,13 @@ import ( "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceData, do_delta bool) error { +func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do_delta bool) error { // d is filled with data according to computeResource schema, so extra disks config is retrieved via "extra_disks" key // If do_delta is true, this function will identify changes between new and existing specs for extra disks and try to // update compute configuration accordingly @@ -45,6 +52,8 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD // Note that this function will not abort on API errors, but will continue to configure (attach / detach) other individual // disks via atomic API calls. However, it will not retry failed manipulation on the same disk. + c := m.(*controller.ControllerCfg) + log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta) // NB: as of rc-1.25 "extra_disks" are TypeSet with the elem of TypeInt @@ -62,7 +71,7 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD urlValues := &url.Values{} urlValues.Add("computeId", d.Id()) urlValues.Add("diskId", fmt.Sprintf("%d", disk.(int))) - _, err := ctrl.decortAPICall("POST", ComputeDiskAttachAPI, urlValues) + _, err := c.DecortAPICall("POST", ComputeDiskAttachAPI, urlValues) if err != nil { // failed to attach extra disk - partial resource update apiErrCount++ @@ -85,7 +94,7 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD urlValues := &url.Values{} urlValues.Add("computeId", d.Id()) urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int))) - _, err := ctrl.decortAPICall("POST", ComputeDiskDetachAPI, urlValues) + _, err := c.DecortAPICall("POST", ComputeDiskDetachAPI, urlValues) if err != nil { // failed to detach disk - there will be partial resource update log.Errorf("utilityComputeExtraDisksConfigure: failed to detach disk ID %d from Compute ID %s: %s", diskId.(int), d.Id(), err) @@ -100,7 +109,7 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD urlValues := &url.Values{} urlValues.Add("computeId", d.Id()) urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int))) - _, err := ctrl.decortAPICall("POST", ComputeDiskAttachAPI, urlValues) + _, err := c.DecortAPICall("POST", ComputeDiskAttachAPI, urlValues) if err != nil { // failed to attach disk - there will be partial resource update log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err) @@ -118,13 +127,15 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD return nil } -func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceData, do_delta bool) error { +func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_delta bool) error { // "d" is filled with data according to computeResource schema, so extra networks config is retrieved via "network" key // If do_delta is true, this function will identify changes between new and existing specs for network and try to // update compute configuration accordingly // Otherwise it will apply whatever is found in the new set of "network" right away. // Primary use of do_delta=false is when calling this function from compute Create handler. + c := m.(*controller.ControllerCfg) + old_set, new_set := d.GetChange("network") apiErrCount := 0 @@ -145,7 +156,7 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat if ipSet { urlValues.Add("ipAddr", ipaddr.(string)) } - _, err := ctrl.decortAPICall("POST", ComputeNetAttachAPI, urlValues) + _, err := c.DecortAPICall("POST", ComputeNetAttachAPI, urlValues) if err != nil { // failed to attach network - partial resource update apiErrCount++ @@ -169,7 +180,7 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat urlValues.Add("computeId", d.Id()) urlValues.Add("ipAddr", net_data["ip_address"].(string)) urlValues.Add("mac", net_data["mac"].(string)) - _, err := ctrl.decortAPICall("POST", ComputeNetDetachAPI, urlValues) + _, err := c.DecortAPICall("POST", ComputeNetDetachAPI, urlValues) if err != nil { // failed to detach this network - there will be partial resource update log.Errorf("utilityComputeNetworksConfigure: failed to detach net ID %d of type %s from Compute ID %s: %s", @@ -190,7 +201,7 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat if net_data["ip_address"].(string) != "" { urlValues.Add("ipAddr", net_data["ip_address"].(string)) } - _, err := ctrl.decortAPICall("POST", ComputeNetAttachAPI, urlValues) + _, err := c.DecortAPICall("POST", ComputeNetAttachAPI, urlValues) if err != nil { // failed to attach this network - there will be partial resource update log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s", @@ -223,7 +234,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, // method for resource's Exists method. // - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} // make it possible to use "read" & "check presence" functions with compute ID set so @@ -244,7 +255,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, // compute ID is specified, try to get compute instance straight by this ID log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", theId) urlValues.Add("computeId", fmt.Sprintf("%d", theId)) - computeFacts, err := controller.decortAPICall("POST", ComputeGetAPI, urlValues) + computeFacts, err := c.DecortAPICall("POST", ComputeGetAPI, urlValues) if err != nil { return "", err } @@ -264,7 +275,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, } urlValues.Add("rgId", fmt.Sprintf("%d", rgId)) - apiResp, err := controller.decortAPICall("POST", RgListComputesAPI, urlValues) + apiResp, err := c.DecortAPICall("POST", RgListComputesAPI, urlValues) if err != nil { return "", err } @@ -286,7 +297,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, // we found the Compute we need - now get detailed information via compute/get API cgetValues := &url.Values{} cgetValues.Add("computeId", fmt.Sprintf("%d", item.ID)) - apiResp, err = controller.decortAPICall("POST", ComputeGetAPI, cgetValues) + apiResp, err = c.DecortAPICall("POST", ComputeGetAPI, cgetValues) if err != nil { return "", err } diff --git a/internal/service/cloudapi/pfw/api.go b/internal/service/cloudapi/pfw/api.go new file mode 100644 index 0000000..8a13c4f --- /dev/null +++ b/internal/service/cloudapi/pfw/api.go @@ -0,0 +1,36 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package pfw + +const ComputePfwListAPI = "/restmachine/cloudapi/compute/pfwList" +const ComputePfwAddAPI = "/restmachine/cloudapi/compute/pfwAdd" +const ComputePfwDelAPI = "/restmachine/cloudapi/compute/pfwDel" diff --git a/internal/service/cloudapi/pfw/models.go b/internal/service/cloudapi/pfw/models.go new file mode 100644 index 0000000..e74524b --- /dev/null +++ b/internal/service/cloudapi/pfw/models.go @@ -0,0 +1,45 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package pfw +type PfwRecord struct { + ID int `json:"id"` + LocalIP string `json:"localIp"` + LocalPort int `json:"localPort"` + Protocol string `json:"protocol"` + PublicPortEnd int `json:"publicPortEnd"` + PublicPortStart int `json:"publicPortStart"` + ComputeID int `json:"vmId"` +} + +type ComputePfwListResp []PfwRecord + + diff --git a/decort/resource_pfw.go b/internal/service/cloudapi/pfw/resource_pfw.go similarity index 68% rename from decort/resource_pfw.go rename to internal/service/cloudapi/pfw/resource_pfw.go index 314bc1a..381bcb2 100644 --- a/decort/resource_pfw.go +++ b/internal/service/cloudapi/pfw/resource_pfw.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,28 +18,37 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package pfw import ( + "context" "fmt" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourcePfwCreate(d *schema.ResourceData, m interface{}) error { +func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourcePfwCreate: called for compute %d", d.Get("compute_id").(int)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) urlValues.Add("publicPortStart", strconv.Itoa(d.Get("public_port_start").(int))) @@ -48,16 +59,16 @@ func resourcePfwCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("publicPortEnd", strconv.Itoa(portEnd.(int))) } - pfwId, err := controller.decortAPICall("POST", ComputePfwAddAPI, urlValues) + pfwId, err := c.DecortAPICall("POST", ComputePfwAddAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(fmt.Sprintf("%d-%s", d.Get("compute_id").(int), pfwId)) pfw, err := utilityPfwCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.Set("local_ip", pfw.LocalIP) @@ -68,13 +79,13 @@ func resourcePfwCreate(d *schema.ResourceData, m interface{}) error { return nil } -func resourcePfwRead(d *schema.ResourceData, m interface{}) error { +func resourcePfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourcePfwRead: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id()) pfw, err := utilityPfwCheckPresence(d, m) if pfw == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("compute_id", pfw.ComputeID) @@ -87,25 +98,25 @@ func resourcePfwRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourcePfwDelete(d *schema.ResourceData, m interface{}) error { +func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourcePfwDelete: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id()) pfw, err := utilityPfwCheckPresence(d, m) if pfw == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) urlValues.Add("ruleId", strconv.Itoa(pfw.ID)) - _, err = controller.decortAPICall("POST", ComputePfwDelAPI, urlValues) + _, err = c.DecortAPICall("POST", ComputePfwDelAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } return nil @@ -175,25 +186,25 @@ func resourcePfwSchemaMake() map[string]*schema.Schema { } } -func resourcePfw() *schema.Resource { +func ResourcePfw() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourcePfwCreate, - Read: resourcePfwRead, - Delete: resourcePfwDelete, - Exists: resourcePfwExists, + CreateContext: resourcePfwCreate, + ReadContext: resourcePfwRead, + DeleteContext: resourcePfwDelete, + Exists: resourcePfwExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourcePfwSchemaMake(), diff --git a/decort/utility_pfw.go b/internal/service/cloudapi/pfw/utility_pfw.go similarity index 63% rename from decort/utility_pfw.go rename to internal/service/cloudapi/pfw/utility_pfw.go index ea125fb..af7937f 100644 --- a/decort/utility_pfw.go +++ b/internal/service/cloudapi/pfw/utility_pfw.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package pfw import ( "encoding/json" @@ -30,15 +37,16 @@ import ( "strconv" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilityPfwCheckPresence(d *schema.ResourceData, m interface{}) (*PfwRecord, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) - resp, err := controller.decortAPICall("POST", ComputePfwListAPI, urlValues) + resp, err := c.DecortAPICall("POST", ComputePfwListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/rg/api.go b/internal/service/cloudapi/rg/api.go new file mode 100644 index 0000000..c9067f6 --- /dev/null +++ b/internal/service/cloudapi/rg/api.go @@ -0,0 +1,39 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package rg + +const ResgroupCreateAPI = "/restmachine/cloudapi/rg/create" +const ResgroupUpdateAPI = "/restmachine/cloudapi/rg/update" +const ResgroupListAPI = "/restmachine/cloudapi/rg/list" +const ResgroupGetAPI = "/restmachine/cloudapi/rg/get" +const ResgroupDeleteAPI = "/restmachine/cloudapi/rg/delete" +const RgListComputesAPI = "/restmachine/cloudapi/rg/listComputes" diff --git a/decort/data_source_rg.go b/internal/service/cloudapi/rg/data_source_rg.go similarity index 68% rename from decort/data_source_rg.go rename to internal/service/cloudapi/rg/data_source_rg.go index c1ae000..33f7f0e 100644 --- a/decort/data_source_rg.go +++ b/internal/service/cloudapi/rg/data_source_rg.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,24 +18,31 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package rg import ( + "context" "encoding/json" "fmt" + "github.com/rudecs/terraform-provider-decort/internal/constants" log "github.com/sirupsen/logrus" // "net/url" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func flattenResgroup(d *schema.ResourceData, rg_facts string) error { @@ -61,8 +70,8 @@ func flattenResgroup(d *schema.ResourceData, rg_facts string) error { d.Set("def_net_type", details.DefaultNetType) d.Set("def_net_id", details.DefaultNetID) /* - d.Set("vins", details.Vins) - d.Set("computes", details.Computes) + d.Set("vins", details.Vins) + d.Set("computes", details.Computes) */ log.Debugf("flattenResgroup: calling flattenQuota()") @@ -73,27 +82,27 @@ func flattenResgroup(d *schema.ResourceData, rg_facts string) error { return nil } -func dataSourceResgroupRead(d *schema.ResourceData, m interface{}) error { +func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { rg_facts, err := utilityResgroupCheckPresence(d, m) if rg_facts == "" { // if empty string is returned from utilityResgroupCheckPresence then there is no // such resource group and err tells so - just return it to the calling party d.SetId("") // ensure ID is empty in this case - return err + return diag.FromErr(err) } - return flattenResgroup(d, rg_facts) + return diag.FromErr(flattenResgroup(d, rg_facts)) } -func dataSourceResgroup() *schema.Resource { +func DataSourceResgroup() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceResgroupRead, + ReadContext: dataSourceResgroupRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: map[string]*schema.Schema{ @@ -158,30 +167,30 @@ func dataSourceResgroup() *schema.Resource { }, /* - "status": { - Type: schema.TypeString, - Computed: true, - Description: "Current status of this resource group.", - }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Current status of this resource group.", + }, - "vins": { - Type: schema.TypeList, // this is a list of ints - Computed: true, - MaxItems: LimitMaxVinsPerResgroup, - Elem: &schema.Schema{ - Type: schema.TypeInt, + "vins": { + Type: schema.TypeList, // this is a list of ints + Computed: true, + MaxItems: LimitMaxVinsPerResgroup, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "List of VINs deployed in this resource group.", }, - Description: "List of VINs deployed in this resource group.", - }, - "computes": { - Type: schema.TypeList, //t his is a list of ints - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeInt, + "computes": { + Type: schema.TypeList, //t his is a list of ints + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + Description: "List of computes deployed in this resource group.", }, - Description: "List of computes deployed in this resource group.", - }, */ }, } diff --git a/decort/data_source_rg_list.go b/internal/service/cloudapi/rg/data_source_rg_list.go similarity index 84% rename from decort/data_source_rg_list.go rename to internal/service/cloudapi/rg/data_source_rg_list.go index 73afce5..cfd71ba 100644 --- a/decort/data_source_rg_list.go +++ b/internal/service/cloudapi/rg/data_source_rg_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package rg import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenRgList(rgl ResgroupListResp) []map[string]interface{} { @@ -96,10 +107,10 @@ func flattenRgResourceLimits(rl ResourceLimits) []map[string]interface{} { } -func dataSourceRgListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { rgList, err := utilityRgListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -298,15 +309,15 @@ func dataSourceRgListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceRgList() *schema.Resource { +func DataSourceRgList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceRgListRead, + ReadContext: dataSourceRgListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceRgListSchemaMake(), diff --git a/internal/service/cloudapi/rg/models.go b/internal/service/cloudapi/rg/models.go new file mode 100644 index 0000000..f1f6e05 --- /dev/null +++ b/internal/service/cloudapi/rg/models.go @@ -0,0 +1,149 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package rg + +type ResourceLimits struct { + CUC float64 `json:"CU_C"` + CUD float64 `json:"CU_D"` + CUI float64 `json:"CU_I"` + CUM float64 `json:"CU_M"` + CUNP float64 `json:"CU_NP"` + GpuUnits float64 `json:"gpu_units"` +} + +type ResgroupRecord struct { + ACLs []AccountAclRecord `json:"acl"` + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DefaultNetID int `json:"def_net_id"` + DefaultNetType string `json:"def_net_type"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + Decsription string `json:"desc"` + GridID int `json:"gid"` + GUID int `json:"guid"` + ID uint `json:"id"` + LockStatus string `json:"lockStatus"` + Milestones int `json:"milestones"` + Name string `json:"name"` + RegisterComputes bool `json:"registerComputes"` + ResourceLimits ResourceLimits `json:"resourceLimits"` + Secret string `json:"secret"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + Vins []int `json:"vins"` + Computes []int `json:"vms"` +} + +type ResgroupListResp []ResgroupRecord + +type ResgroupUpdateParam struct { + RgId int `json:"rgId"` + Name string `json:"name"` + Desc string `json:"decs"` + Ram int `json:"maxMemoryCapacity"` + Disk int `json:"maxVDiskCapacity"` + Cpu int `json:"maxCPUCapacity"` + NetTraffic int `json:"maxNetworkPeerTransfer"` + Reason string `json:"reason"` +} + +type AccountAclRecord struct { + IsExplicit bool `json:"explicit"` + Guid string `json:"guid"` + Rights string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UgroupID string `json:"userGroupId"` + CanBeDeleted bool `json:"canBeDeleted"` +} + +type ResgroupGetResp struct { + ACLs []UserAclRecord `json:"ACLs"` + Usage UsageRecord `json:"Resources"` + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + GridID int `json:"gid"` + CreatedBy string `json:"createdBy"` + CreatedTime uint64 `json:"createdTime"` + DefaultNetID int `json:"def_net_id"` + DefaultNetType string `json:"def_net_type"` + DeletedBy string `json:"deletedBy"` + DeletedTime uint64 `json:"deletedTime"` + Desc string `json:"desc"` + ID uint `json:"id"` + LockStatus string `json:"lockStatus"` + Name string `json:"name"` + Quota QuotaRecord `json:"resourceLimits"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime uint64 `json:"updatedTime"` + Vins []int `json:"vins"` + Computes []int `json:"vms"` + + Ignored map[string]interface{} `json:"-"` +} + +type UserAclRecord struct { + IsExplicit bool `json:"explicit"` + Rights string `json:"right"` + Status string `json:"status"` + Type string `json:"type"` + UgroupID string `json:"userGroupId"` + // CanBeDeleted bool `json:"canBeDeleted"` +} + +type QuotaRecord struct { // this is how quota is reported by /api/.../rg/get + Cpu int `json:"CU_C"` // CPU count in pcs + Ram float64 `json:"CU_M"` // RAM volume in MB, it is STILL reported as FLOAT + Disk int `json:"CU_D"` // Disk capacity in GB + ExtIPs int `json:"CU_I"` // Ext IPs count + ExtTraffic int `json:"CU_NP"` // Ext network traffic + GpuUnits int `json:"gpu_units"` // GPU count +} + +type ResourceRecord struct { // this is how actual usage is reported by /api/.../rg/get + Cpu int `json:"cpu"` + Disk int `json:"disksize"` + ExtIPs int `json:"extips"` + ExtTraffic int `json:"exttraffic"` + Gpu int `json:"gpu"` + Ram int `json:"ram"` +} + +type UsageRecord struct { + Current ResourceRecord `json:"Current"` + Reserved ResourceRecord `json:"Reserved"` +} diff --git a/decort/quota_subresource.go b/internal/service/cloudapi/rg/quota_subresource.go similarity index 84% rename from decort/quota_subresource.go rename to internal/service/cloudapi/rg/quota_subresource.go index f6e2fc1..6da4300 100644 --- a/decort/quota_subresource.go +++ b/internal/service/cloudapi/rg/quota_subresource.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,17 +17,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -package decort +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -import ( +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. - // "encoding/json" - // "fmt" - // "log" - // "net/url" +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package rg - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func makeQuotaRecord(arg_list []interface{}) QuotaRecord { diff --git a/decort/resource_rg.go b/internal/service/cloudapi/rg/resource_rg.go similarity index 79% rename from decort/resource_rg.go rename to internal/service/cloudapi/rg/resource_rg.go index cf5a9bc..815c427 100644 --- a/decort/resource_rg.go +++ b/internal/service/cloudapi/rg/resource_rg.go @@ -1,5 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions. All Rights Reserved. +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -7,7 +10,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -15,26 +18,36 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package rg import ( + "context" "encoding/json" "fmt" "net/url" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/location" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { +func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // First validate that we have all parameters required to create the new Resource Group // Valid account ID is required to create new resource group @@ -42,7 +55,7 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { rg_name, arg_set := d.GetOk("name") if !arg_set { - return fmt.Errorf("Cannot create new RG: missing name.") + return diag.FromErr(fmt.Errorf("Cannot create new RG: missing name.")) } /* Current version of provider works with default grid id (same is true for disk resources) @@ -70,16 +83,16 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { set_quota = true } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) log.Debugf("resourceResgroupCreate: called by user %q for RG name %s, account ID %d", - controller.getDecortUsername(), + c.GetDecortUsername(), rg_name.(string), d.Get("account_id").(int)) url_values := &url.Values{} url_values.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int))) url_values.Add("name", rg_name.(string)) - url_values.Add("gid", fmt.Sprintf("%d", DefaultGridID)) // use default Grid ID, similar to disk resource mgmt convention - url_values.Add("owner", controller.getDecortUsername()) + url_values.Add("gid", fmt.Sprintf("%d", location.DefaultGridID)) // use default Grid ID, similar to disk resource mgmt convention + url_values.Add("owner", c.GetDecortUsername()) // pass quota values as set if set_quota { @@ -112,9 +125,9 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { url_values.Add("extIp", ext_ip.(string)) } - api_resp, err := controller.decortAPICall("POST", ResgroupCreateAPI, url_values) + api_resp, err := c.DecortAPICall("POST", ResgroupCreateAPI, url_values) if err != nil { - return err + return diag.FromErr(err) } d.SetId(api_resp) // rg/create API returns ID of the newly creted resource group on success @@ -122,22 +135,22 @@ func resourceResgroupCreate(d *schema.ResourceData, m interface{}) error { if !set_quota { resp, err := utilityResgroupCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } rg := ResgroupGetResp{} if err := json.Unmarshal([]byte(resp), &rg); err != nil { - return err + return diag.FromErr(err) } d.Set("quota", parseQuota(rg.Quota)) } // re-read newly created RG to make sure schema contains complete and up to date set of specifications - return resourceResgroupRead(d, m) + return resourceResgroupRead(ctx, d, m) } -func resourceResgroupRead(d *schema.ResourceData, m interface{}) error { +func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceResgroupRead: called for RG name %s, account ID %d", d.Get("name").(string), d.Get("account_id").(int)) @@ -146,13 +159,13 @@ func resourceResgroupRead(d *schema.ResourceData, m interface{}) error { // if empty string is returned from utilityResgroupCheckPresence then there is no // such resource group and err tells so - just return it to the calling party d.SetId("") // ensure ID is empty - return err + return diag.FromErr(err) } - return flattenResgroup(d, rg_facts) + return diag.FromErr(flattenResgroup(d, rg_facts)) } -func resourceResgroupUpdate(d *schema.ResourceData, m interface{}) error { +func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceResgroupUpdate: called for RG name %s, account ID %d", d.Get("name").(string), d.Get("account_id").(int)) @@ -167,18 +180,18 @@ func resourceResgroupUpdate(d *schema.ResourceData, m interface{}) error { for _, attr := range []string{"def_net_type", "ipcidr", "ext_ip"} { attr_new, attr_old := d.GetChange("def_net_type") if attr_new.(string) != attr_old.(string) { - return fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing %s for existing RG is not allowed", d.Id(), attr) + return diag.FromErr(fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing %s for existing RG is not allowed", d.Id(), attr)) } } attr_new, attr_old := d.GetChange("ext_net_id") if attr_new.(int) != attr_old.(int) { - return fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing ext_net_id for existing RG is not allowed", d.Id()) + return diag.FromErr(fmt.Errorf("resourceResgroupUpdate: RG ID %s: changing ext_net_id for existing RG is not allowed", d.Id())) } do_general_update := false // will be true if general RG update is necessary (API rg/update) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) url_values := &url.Values{} url_values.Add("rgId", d.Id()) @@ -242,18 +255,18 @@ func resourceResgroupUpdate(d *schema.ResourceData, m interface{}) error { if do_general_update { log.Debugf("resourceResgroupUpdate: detected delta between new and old RG specs - updating the RG") - _, err := controller.decortAPICall("POST", ResgroupUpdateAPI, url_values) + _, err := c.DecortAPICall("POST", ResgroupUpdateAPI, url_values) if err != nil { - return err + return diag.FromErr(err) } } else { log.Debugf("resourceResgroupUpdate: no difference between old and new state - no update on the RG will be done") } - return resourceResgroupRead(d, m) + return resourceResgroupRead(ctx, d, m) } -func resourceResgroupDelete(d *schema.ResourceData, m interface{}) error { +func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { // NOTE: this method forcibly destroys target resource group with flag "permanently", so there is no way to // restore the destroyed resource group as well all Computes & VINSes that existed in it log.Debugf("resourceResgroupDelete: called for RG name %s, account ID %d", @@ -262,7 +275,7 @@ func resourceResgroupDelete(d *schema.ResourceData, m interface{}) error { rg_facts, err := utilityResgroupCheckPresence(d, m) if rg_facts == "" { if err != nil { - return err + return diag.FromErr(err) } // the target RG does not exist - in this case according to Terraform best practice // we exit from Destroy method without error @@ -275,10 +288,10 @@ func resourceResgroupDelete(d *schema.ResourceData, m interface{}) error { url_values.Add("permanently", "1") url_values.Add("reason", "Destroyed by DECORT Terraform provider") - controller := m.(*ControllerCfg) - _, err = controller.decortAPICall("POST", ResgroupDeleteAPI, url_values) + c := m.(*controller.ControllerCfg) + _, err = c.DecortAPICall("POST", ResgroupDeleteAPI, url_values) if err != nil { - return err + return diag.FromErr(err) } return nil @@ -296,26 +309,26 @@ func resourceResgroupExists(d *schema.ResourceData, m interface{}) (bool, error) return true, nil } -func resourceResgroup() *schema.Resource { +func ResourceResgroup() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceResgroupCreate, - Read: resourceResgroupRead, - Update: resourceResgroupUpdate, - Delete: resourceResgroupDelete, - Exists: resourceResgroupExists, + CreateContext: resourceResgroupCreate, + ReadContext: resourceResgroupRead, + UpdateContext: resourceResgroupUpdate, + DeleteContext: resourceResgroupDelete, + Exists: resourceResgroupExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout180s, - Read: &Timeout30s, - Update: &Timeout180s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout180s, + Read: &constants.Timeout30s, + Update: &constants.Timeout180s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: map[string]*schema.Schema{ diff --git a/decort/utility_rg.go b/internal/service/cloudapi/rg/utility_rg.go similarity index 80% rename from decort/utility_rg.go rename to internal/service/cloudapi/rg/utility_rg.go index 118c898..f2253e8 100644 --- a/decort/utility_rg.go +++ b/internal/service/cloudapi/rg/utility_rg.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package rg import ( "encoding/json" @@ -30,10 +37,10 @@ import ( "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // On success this function returns a string, as returned by API rg/get, which could be unmarshalled @@ -56,7 +63,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // method for the Terraform resource Exists method. // - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} // make it possible to use "read" & "check presence" functions with RG ID set so @@ -77,7 +84,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // go straight for the RG by its ID log.Debugf("utilityResgroupCheckPresence: locating RG by its ID %d", theId) urlValues.Add("rgId", fmt.Sprintf("%d", theId)) - rgFacts, err := controller.decortAPICall("POST", ResgroupGetAPI, urlValues) + rgFacts, err := c.DecortAPICall("POST", ResgroupGetAPI, urlValues) if err != nil { return "", err } @@ -94,7 +101,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // obtain Account ID by account name - it should not be zero on success urlValues.Add("includedeleted", "false") - apiResp, err := controller.decortAPICall("POST", ResgroupListAPI, urlValues) + apiResp, err := c.DecortAPICall("POST", ResgroupListAPI, urlValues) if err != nil { return "", err } @@ -118,7 +125,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // Namely, we need resource quota settings reqValues := &url.Values{} reqValues.Add("rgId", fmt.Sprintf("%d", item.ID)) - apiResp, err := controller.decortAPICall("POST", ResgroupGetAPI, reqValues) + apiResp, err := c.DecortAPICall("POST", ResgroupGetAPI, reqValues) if err != nil { return "", err } diff --git a/decort/utility_rg_list.go b/internal/service/cloudapi/rg/utility_rg_list.go similarity index 63% rename from decort/utility_rg_list.go rename to internal/service/cloudapi/rg/utility_rg_list.go index 78892f3..19a3b81 100644 --- a/decort/utility_rg_list.go +++ b/internal/service/cloudapi/rg/utility_rg_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,26 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package rg import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityRgListCheckPresence(d *schema.ResourceData, m interface{}) (ResgroupListResp, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} rgList := ResgroupListResp{} @@ -51,7 +59,7 @@ func utilityRgListCheckPresence(d *schema.ResourceData, m interface{}) (Resgroup } log.Debugf("utilityRgListCheckPresence: load rg list") - rgListRaw, err := controller.decortAPICall("POST", ResgroupListAPI, urlValues) + rgListRaw, err := c.DecortAPICall("POST", ResgroupListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/snapshot/api.go b/internal/service/cloudapi/snapshot/api.go new file mode 100644 index 0000000..9b8bdce --- /dev/null +++ b/internal/service/cloudapi/snapshot/api.go @@ -0,0 +1,37 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package snapshot + +const snapshotCreateAPI = "/restmachine/cloudapi/compute/snapshotCreate" +const snapshotDeleteAPI = "/restmachine/cloudapi/compute/snapshotDelete" +const snapshotRollbackAPI = "/restmachine/cloudapi/compute/snapshotRollback" +const snapshotListAPI = "/restmachine/cloudapi/compute/snapshotList" diff --git a/decort/data_source_snapshot_list.go b/internal/service/cloudapi/snapshot/data_source_snapshot_list.go similarity index 68% rename from decort/data_source_snapshot_list.go rename to internal/service/cloudapi/snapshot/data_source_snapshot_list.go index d6f2144..61a1cb5 100644 --- a/decort/data_source_snapshot_list.go +++ b/internal/service/cloudapi/snapshot/data_source_snapshot_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package snapshot import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenSnapshotList(gl SnapshotList) []map[string]interface{} { @@ -44,10 +55,10 @@ func flattenSnapshotList(gl SnapshotList) []map[string]interface{} { return res } -func dataSourceSnapshotListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { snapshotList, err := utilitySnapshotListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -104,15 +115,15 @@ func dataSourceSnapshotSchemaMake() map[string]*schema.Schema { } } -func dataSourceSnapshotList() *schema.Resource { +func DataSourceSnapshotList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSnapshotListRead, + ReadContext: dataSourceSnapshotListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceSnapshotListSchemaMake(), diff --git a/internal/service/cloudapi/snapshot/models.go b/internal/service/cloudapi/snapshot/models.go new file mode 100644 index 0000000..0152191 --- /dev/null +++ b/internal/service/cloudapi/snapshot/models.go @@ -0,0 +1,41 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package snapshot + +type Snapshot struct { + Disks []int `json:"disks"` + Guid string `json:"guid"` + Label string `json:"label"` + Timestamp uint64 `json:"timestamp"` +} + +type SnapshotList []Snapshot diff --git a/decort/resource_snapshot.go b/internal/service/cloudapi/snapshot/resource_snapshot.go similarity index 56% rename from decort/resource_snapshot.go rename to internal/service/cloudapi/snapshot/resource_snapshot.go index 7a75867..b208092 100644 --- a/decort/resource_snapshot.go +++ b/internal/service/cloudapi/snapshot/resource_snapshot.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,35 +18,43 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package snapshot import ( + "context" "net/url" "strconv" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceSnapshotCreate(d *schema.ResourceData, m interface{}) error { +func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSnapshotCreate: called for snapshot %s", d.Get("label").(string)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("label", d.Get("label").(string)) urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) - snapshotId, err := controller.decortAPICall("POST", snapshotCreateAPI, urlValues) + snapshotId, err := c.DecortAPICall("POST", snapshotCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } snapshotId = strings.ReplaceAll(snapshotId, "\"", "") @@ -52,18 +62,18 @@ func resourceSnapshotCreate(d *schema.ResourceData, m interface{}) error { d.SetId(snapshotId) d.Set("guid", snapshotId) - err = resourceSnapshotRead(d, m) - if err != nil { - return err + diagnostics := resourceSnapshotRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } -func resourceSnapshotRead(d *schema.ResourceData, m interface{}) error { +func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { snapshot, err := utilitySnapshotCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.Set("timestamp", snapshot.Timestamp) @@ -74,17 +84,17 @@ func resourceSnapshotRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceSnapshotDelete(d *schema.ResourceData, m interface{}) error { +func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSnapshotDelete: called for %s, id: %s", d.Get("label").(string), d.Id()) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) urlValues.Add("label", d.Get("label").(string)) - _, err := controller.decortAPICall("POST", snapshotDeleteAPI, urlValues) + _, err := c.DecortAPICall("POST", snapshotDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -103,23 +113,27 @@ func resourceSnapshotExists(d *schema.ResourceData, m interface{}) (bool, error) return true, nil } -func resourceSnapshotEdit(d *schema.ResourceData, m interface{}) error { - err := resourceSnapshotRead(d, m) - if err != nil { - return err +func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + if d.HasChange("rollback") { + if d.Get("rollback").(bool) { + err := resourceSnapshotRollback(d, m) + if err != nil { + return diag.FromErr(err) + } + } } return nil } -func resourceSnapshotRollback(d *schema.ResourceDiff, m interface{}) error { - c := m.(*ControllerCfg) +func resourceSnapshotRollback(d *schema.ResourceData, m interface{}) error { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) urlValues.Add("label", d.Get("label").(string)) - _, err := c.decortAPICall("POST", snapshotRollbackAPI, urlValues) + _, err := c.DecortAPICall("POST", snapshotRollbackAPI, urlValues) if err != nil { return err } @@ -166,38 +180,28 @@ func resourceSnapshotSchemaMake() map[string]*schema.Schema { } } -func resourceSnapshot() *schema.Resource { +func ResourceSnapshot() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceSnapshotCreate, - Read: resourceSnapshotRead, - Update: resourceSnapshotEdit, - Delete: resourceSnapshotDelete, - Exists: resourceSnapshotExists, + CreateContext: resourceSnapshotCreate, + ReadContext: resourceSnapshotRead, + UpdateContext: resourceSnapshotEdit, + DeleteContext: resourceSnapshotDelete, + Exists: resourceSnapshotExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, - CustomizeDiff: customdiff.All( - customdiff.IfValueChange("rollback", func(old, new, meta interface{}) bool { - o := old.(bool) - if o != new.(bool) && !o { - return true - } - return false - }, resourceSnapshotRollback), - ), - Schema: resourceSnapshotSchemaMake(), } } diff --git a/decort/utility_snapshot.go b/internal/service/cloudapi/snapshot/utility_snapshot.go similarity index 63% rename from decort/utility_snapshot.go rename to internal/service/cloudapi/snapshot/utility_snapshot.go index 6e7abbc..e126a10 100644 --- a/decort/utility_snapshot.go +++ b/internal/service/cloudapi/snapshot/utility_snapshot.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,18 +18,23 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package snapshot import ( "errors" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilitySnapshotCheckPresence(d *schema.ResourceData, m interface{}) (*Snapshot, error) { diff --git a/decort/utility_snapshot_list.go b/internal/service/cloudapi/snapshot/utility_snapshot_list.go similarity index 58% rename from decort/utility_snapshot_list.go rename to internal/service/cloudapi/snapshot/utility_snapshot_list.go index 9171d23..4f80c90 100644 --- a/decort/utility_snapshot_list.go +++ b/internal/service/cloudapi/snapshot/utility_snapshot_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,28 +18,34 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package snapshot import ( "encoding/json" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilitySnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (SnapshotList, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) - resp, err := controller.decortAPICall("POST", snapshotListAPI, urlValues) + resp, err := c.DecortAPICall("POST", snapshotListAPI, urlValues) if err != nil { return nil, err } @@ -48,7 +56,7 @@ func utilitySnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (Sn snapshotList := SnapshotList{} if err := json.Unmarshal([]byte(resp), &snapshotList); err != nil { - //return nil, errors.New(fmt.Sprint("Can not unmarshall data to snapshotList: ", resp, " ", snapshotList)) + return nil, err } diff --git a/internal/service/cloudapi/vgpu/api.go b/internal/service/cloudapi/vgpu/api.go new file mode 100644 index 0000000..ebd1104 --- /dev/null +++ b/internal/service/cloudapi/vgpu/api.go @@ -0,0 +1,34 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package vgpu + +const vgpuListAPI = "/restmachine/cloudbroker/vgpu/list" diff --git a/decort/data_source_vgpu.go b/internal/service/cloudapi/vgpu/data_source_vgpu.go similarity index 69% rename from decort/data_source_vgpu.go rename to internal/service/cloudapi/vgpu/data_source_vgpu.go index b1cf22b..0c66086 100644 --- a/decort/data_source_vgpu.go +++ b/internal/service/cloudapi/vgpu/data_source_vgpu.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,25 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package vgpu import ( + "context" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func dataSourceVGPURead(d *schema.ResourceData, m interface{}) error { +func dataSourceVGPURead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { vgpu, err := utilityVGPUCheckPresence(d, m) if vgpu == nil { d.SetId("") - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(vgpu.ID)) @@ -100,11 +109,11 @@ func dataSourceVGPUSchemaMake() map[string]*schema.Schema { } } -func dataSourceVGPU() *schema.Resource { +func DataSourceVGPU() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceVGPURead, + ReadContext: dataSourceVGPURead, Schema: dataSourceVGPUSchemaMake(), } diff --git a/internal/service/cloudapi/vgpu/models.go b/internal/service/cloudapi/vgpu/models.go new file mode 100644 index 0000000..9f96f47 --- /dev/null +++ b/internal/service/cloudapi/vgpu/models.go @@ -0,0 +1,44 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package vgpu + +type VGPU struct { + AccountID int `json:"accountId"` + ID int `json:"id"` + Mode string `json:"mode"` + PgpuID int `json:"pgpuid"` + ProfileID int `json:"profileId"` + RAM int `json:"ram"` + Status string `json:"status"` + Type string `json:"type"` + VmID int `json:"vmid"` +} diff --git a/decort/utility_vgpu.go b/internal/service/cloudapi/vgpu/utility_vgpu.go similarity index 65% rename from decort/utility_vgpu.go rename to internal/service/cloudapi/vgpu/utility_vgpu.go index a35ca71..fd00ee4 100644 --- a/decort/utility_vgpu.go +++ b/internal/service/cloudapi/vgpu/utility_vgpu.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Petr Krutov, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,24 +18,30 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package vgpu import ( "encoding/json" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilityVGPUCheckPresence(d *schema.ResourceData, m interface{}) (*VGPU, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("size", "50") @@ -51,7 +59,7 @@ func utilityVGPUCheckPresence(d *schema.ResourceData, m interface{}) (*VGPU, err for page := 1; ; page++ { urlValues.Set("page", strconv.Itoa(page)) - resp, err := controller.decortAPICall("POST", vgpuListAPI, urlValues) + resp, err := c.DecortAPICall("POST", vgpuListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/vins/api.go b/internal/service/cloudapi/vins/api.go new file mode 100644 index 0000000..4a21e3e --- /dev/null +++ b/internal/service/cloudapi/vins/api.go @@ -0,0 +1,44 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package vins + +const VinsListAPI = "/restmachine/cloudapi/vins/list" +const VinsGetAPI = "/restmachine/cloudapi/vins/get" +const VinsSearchAPI = "/restmachine/cloudapi/vins/search" + +const VinsCreateInAccountAPI = "/restmachine/cloudapi/vins/createInAccount" +const VinsCreateInRgAPI = "/restmachine/cloudapi/vins/createInRG" + +const VinsExtNetConnectAPI = "/restmachine/cloudapi/vins/extNetConnect" +const VinsExtNetDisconnectAPI = "/restmachine/cloudapi/vins/extNetDisconnect" + +const VinsDeleteAPI = "/restmachine/cloudapi/vins/delete" diff --git a/decort/data_source_vins.go b/internal/service/cloudapi/vins/data_source_vins.go similarity index 78% rename from decort/data_source_vins.go rename to internal/service/cloudapi/vins/data_source_vins.go index 61fd3c5..b6419b7 100644 --- a/decort/data_source_vins.go +++ b/internal/service/cloudapi/vins/data_source_vins.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2020-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,35 +18,43 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package vins import ( + "context" "encoding/json" "fmt" + "github.com/rudecs/terraform-provider-decort/internal/constants" log "github.com/sirupsen/logrus" // "net/url" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) // vins_facts is a response string from API vins/get -func flattenVins(d *schema.ResourceData, vins_facts string) error { +func flattenVins(d *schema.ResourceData, vins_facts string) diag.Diagnostics { // NOTE: this function modifies ResourceData argument - as such it should never be called // from resourceVinsExists(...) method // log.Debugf("flattenVins: ready to decode response body from API %s", vins_facts) vinsRecord := VinsRecord{} err := json.Unmarshal([]byte(vins_facts), &vinsRecord) if err != nil { - return err + return diag.FromErr(err) } log.Debugf("flattenVins: decoded ViNS name:ID %s:%d, account ID %d, RG ID %d", @@ -69,7 +79,7 @@ func flattenVins(d *schema.ResourceData, vins_facts string) error { d.Set("ext_ip_addr", extNetIP.(string)) d.Set("ext_net_id", int(extNetID.(float64))) } else { - return fmt.Errorf("Failed to unmarshal VNF GW Config - structure is invalid.") + return diag.Errorf("Failed to unmarshal VNF GW Config - structure is invalid.") } noExtNetConnection = false break @@ -86,27 +96,27 @@ func flattenVins(d *schema.ResourceData, vins_facts string) error { return nil } -func dataSourceVinsRead(d *schema.ResourceData, m interface{}) error { +func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { vinsFacts, err := utilityVinsCheckPresence(d, m) if vinsFacts == "" { // if empty string is returned from utilityVinsCheckPresence then there is no // such ViNS and err tells so - just return it to the calling party d.SetId("") // ensure ID is empty in this case - return err + return diag.FromErr(err) } return flattenVins(d, vinsFacts) } -func dataSourceVins() *schema.Resource { +func DataSourceVins() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceVinsRead, + ReadContext: dataSourceVinsRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: map[string]*schema.Schema{ diff --git a/decort/data_source_vins_list.go b/internal/service/cloudapi/vins/data_source_vins_list.go similarity index 75% rename from decort/data_source_vins_list.go rename to internal/service/cloudapi/vins/data_source_vins_list.go index 84a2c0b..76365db 100644 --- a/decort/data_source_vins_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package vins import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenVinsList(vl VinsList) []map[string]interface{} { @@ -55,10 +66,10 @@ func flattenVinsList(vl VinsList) []map[string]interface{} { return res } -func dataSourceVinsListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { vinsList, err := utilityVinsListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -162,15 +173,15 @@ func dataSourceVinsListSchemaMake() map[string]*schema.Schema { return res } -func dataSourceVinsList() *schema.Resource { +func DataSourceVinsList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceVinsListRead, + ReadContext: dataSourceVinsListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceVinsListSchemaMake(), diff --git a/internal/service/cloudapi/vins/models.go b/internal/service/cloudapi/vins/models.go new file mode 100644 index 0000000..e8b95d1 --- /dev/null +++ b/internal/service/cloudapi/vins/models.go @@ -0,0 +1,94 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package vins + +type Vins struct { + AccountId int `json:"accountId"` + AccountName string `json:"accountName"` + CreatedBy string `json:"createdBy"` + CreatedTime int `json:"createdTime"` + DeletedBy string `json:"deletedBy"` + DeletedTime int `json:"deletedTime"` + ExternalIP string `json:"externalIP"` + ID int `json:"id"` + Name string `json:"name"` + Network string `json:"network"` + RGID int `json:"rgId"` + RGName string `json:"rgName"` + Status string `json:"status"` + UpdatedBy string `json:"updatedBy"` + UpdatedTime int `json:"updatedTime"` + VXLanID int `json:"vxlanId"` +} + +type VinsList []Vins + +type VinsSearchResp []VinsSearchRecord + +type VnfRecord struct { + ID int `json:"id"` + AccountID int `json:"accountId"` + Type string `json:"type"` // "DHCP", "NAT", "GW" etc + Config map[string]interface{} `json:"config"` // NOTE: VNF specs vary by VNF type +} + +type VnfGwConfigRecord struct { // describes GW VNF config structure inside ViNS, as returned by API vins/get + ExtNetID int `json:"ext_net_id"` + ExtNetIP string `json:"ext_net_ip"` + ExtNetMask int `json:"ext_net_mask"` + DefaultGW string `json:"default_gw"` +} +type VinsRecord struct { // represents part of the response from API vins/get + ID int `json:"id"` + Name string `json:"name"` + IPCidr string `json:"network"` + VxLanID int `json:"vxlanId"` + ExternalIP string `json:"externalIP"` + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + RgID int `json:"rgid"` + RgName string `json:"rgName"` + VNFs map[string]VnfRecord `json:"vnfs"` + Desc string `json:"desc"` +} + +type VinsSearchRecord struct { + ID int `json:"id"` + Name string `json:"name"` + IPCidr string `json:"network"` + VxLanID int `json:"vxlanId"` + ExternalIP string `json:"externalIP"` + AccountID int `json:"accountId"` + AccountName string `json:"accountName"` + RgID int `json:"rgId"` + RgName string `json:"rgName"` +} diff --git a/decort/resource_vins.go b/internal/service/cloudapi/vins/resource_vins.go similarity index 78% rename from decort/resource_vins.go rename to internal/service/cloudapi/vins/resource_vins.go index cdfb5f6..fc0170d 100644 --- a/decort/resource_vins.go +++ b/internal/service/cloudapi/vins/resource_vins.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,25 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package vins import ( - // "encoding/json" + "context" "fmt" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - // "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func ipcidrDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool { @@ -49,13 +58,13 @@ func ipcidrDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool return true // suppress difference } -func resourceVinsCreate(d *schema.ResourceData, m interface{}) error { +func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceVinsCreate: called for ViNS name %s, Account ID %d, RG ID %d", d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int)) apiToCall := VinsCreateInAccountAPI - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("name").(string)) @@ -69,7 +78,7 @@ func resourceVinsCreate(d *schema.ResourceData, m interface{}) error { argVal, argSet = d.GetOk("account_id") if !argSet || argVal.(int) <= 0 { // No valid Account ID (and no RG ID either) - cannot create ViNS - return fmt.Errorf("resourceVinsCreate: ViNS name %s - no valid account and/or resource group ID specified", d.Id()) + return diag.Errorf("resourceVinsCreate: ViNS name %s - no valid account and/or resource group ID specified", d.Id()) } urlValues.Add("accountId", fmt.Sprintf("%d", argVal.(int))) } @@ -106,9 +115,9 @@ func resourceVinsCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("desc", argVal.(string)) } - apiResp, err := controller.decortAPICall("POST", apiToCall, urlValues) + apiResp, err := c.DecortAPICall("POST", apiToCall, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(apiResp) // update ID of the resource to tell Terraform that the ViNS resource exists @@ -120,29 +129,27 @@ func resourceVinsCreate(d *schema.ResourceData, m interface{}) error { // between ViNS resource and ViNS data source schemas // ViNS resource read function will also update resource ID on success, so that Terraform // will know the resource exists (however, we already did it a few lines before) - return dataSourceVinsRead(d, m) + return dataSourceVinsRead(ctx, d, m) } -func resourceVinsRead(d *schema.ResourceData, m interface{}) error { +func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { vinsFacts, err := utilityVinsCheckPresence(d, m) if vinsFacts == "" { // if empty string is returned from utilityVinsCheckPresence then there is no // such ViNS and err tells so - just return it to the calling party d.SetId("") // ensure ID is empty - return err + return diag.FromErr(err) } return flattenVins(d, vinsFacts) } -func resourceVinsUpdate(d *schema.ResourceData, m interface{}) error { +func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceVinsUpdate: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d", d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int)) - controller := m.(*ControllerCfg) - - d.Partial(true) + c := m.(*controller.ControllerCfg) // 1. Handle external network connection change oldExtNetId, newExtNedId := d.GetChange("ext_net_id") @@ -154,39 +161,35 @@ func resourceVinsUpdate(d *schema.ResourceData, m interface{}) error { if oldExtNetId.(int) > 0 { // there was preexisting external net connection - disconnect ViNS - _, err := controller.decortAPICall("POST", VinsExtNetDisconnectAPI, extnetParams) + _, err := c.DecortAPICall("POST", VinsExtNetDisconnectAPI, extnetParams) if err != nil { - return err + return diag.FromErr(err) } } if newExtNedId.(int) > 0 { // new external network connection requested - connect ViNS extnetParams.Add("netId", fmt.Sprintf("%d", newExtNedId.(int))) - _, err := controller.decortAPICall("POST", VinsExtNetConnectAPI, extnetParams) + _, err := c.DecortAPICall("POST", VinsExtNetConnectAPI, extnetParams) if err != nil { - return err + return diag.FromErr(err) } } - - d.SetPartial("ext_net_id") } - d.Partial(false) - // we may reuse dataSourceVinsRead here as we maintain similarity // between Compute resource and Compute data source schemas - return dataSourceVinsRead(d, m) + return dataSourceVinsRead(ctx, d, m) } -func resourceVinsDelete(d *schema.ResourceData, m interface{}) error { +func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceVinsDelete: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d", d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int)) vinsFacts, err := utilityVinsCheckPresence(d, m) if vinsFacts == "" { if err != nil { - return err + return diag.FromErr(err) } // the specified ViNS does not exist - in this case according to Terraform best practice // we exit from Destroy method without error @@ -198,10 +201,10 @@ func resourceVinsDelete(d *schema.ResourceData, m interface{}) error { params.Add("force", "1") // disconnect all computes before deleting ViNS params.Add("permanently", "1") // delete ViNS immediately bypassing recycle bin - controller := m.(*ControllerCfg) - _, err = controller.decortAPICall("POST", VinsDeleteAPI, params) + c := m.(*controller.ControllerCfg) + _, err = c.DecortAPICall("POST", VinsDeleteAPI, params) if err != nil { - return err + return diag.FromErr(err) } return nil @@ -294,26 +297,26 @@ func resourceVinsSchemaMake() map[string]*schema.Schema { return rets } -func resourceVins() *schema.Resource { +func ResourceVins() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceVinsCreate, - Read: resourceVinsRead, - Update: resourceVinsUpdate, - Delete: resourceVinsDelete, - Exists: resourceVinsExists, + CreateContext: resourceVinsCreate, + ReadContext: resourceVinsRead, + UpdateContext: resourceVinsUpdate, + DeleteContext: resourceVinsDelete, + Exists: resourceVinsExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout180s, - Read: &Timeout30s, - Update: &Timeout180s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout180s, + Read: &constants.Timeout30s, + Update: &constants.Timeout180s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceVinsSchemaMake(), diff --git a/decort/utility_vins.go b/internal/service/cloudapi/vins/utility_vins.go similarity index 82% rename from decort/utility_vins.go rename to internal/service/cloudapi/vins/utility_vins.go index 03a410c..c8e363b 100644 --- a/decort/utility_vins.go +++ b/internal/service/cloudapi/vins/utility_vins.go @@ -1,6 +1,8 @@ /* -Copyright (c) 2020-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package vins import ( "encoding/json" @@ -30,9 +37,10 @@ import ( "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // On success this function returns a string, as returned by API vins/get, which could be unmarshalled @@ -51,7 +59,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er // method for the Terraform resource Exists method. // - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} // make it possible to use "read" & "check presence" functions with ViNS ID set so @@ -72,7 +80,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er // ViNS ID is specified, try to get compute instance straight by this ID log.Debugf("utilityVinsCheckPresence: locating ViNS by its ID %d", theId) urlValues.Add("vinsId", fmt.Sprintf("%d", theId)) - vinsFacts, err := controller.decortAPICall("POST", VinsGetAPI, urlValues) + vinsFacts, err := c.DecortAPICall("POST", VinsGetAPI, urlValues) if err != nil { return "", err } @@ -103,7 +111,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er urlValues.Add("accountId", fmt.Sprintf("%d", accountId.(int))) } - apiResp, err := controller.decortAPICall("POST", VinsSearchAPI, urlValues) + apiResp, err := c.DecortAPICall("POST", VinsSearchAPI, urlValues) if err != nil { return "", err } @@ -132,7 +140,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er // manage ViNS, so we have to get detailed info by calling API vins/get rqValues := &url.Values{} rqValues.Add("vinsId", fmt.Sprintf("%d", item.ID)) - vinsGetResp, err := controller.decortAPICall("POST", VinsGetAPI, rqValues) + vinsGetResp, err := c.DecortAPICall("POST", VinsGetAPI, rqValues) if err != nil { return "", err } diff --git a/decort/utility_vins_list.go b/internal/service/cloudapi/vins/utility_vins_list.go similarity index 63% rename from decort/utility_vins_list.go rename to internal/service/cloudapi/vins/utility_vins_list.go index 7bdf083..c886c68 100644 --- a/decort/utility_vins_list.go +++ b/internal/service/cloudapi/vins/utility_vins_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package vins import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityVinsListCheckPresence(d *schema.ResourceData, m interface{}) (VinsList, error) { vinsList := VinsList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if includeDeleted, ok := d.GetOk("include_deleted"); ok { @@ -50,7 +58,7 @@ func utilityVinsListCheckPresence(d *schema.ResourceData, m interface{}) (VinsLi } log.Debugf("utilityVinsListCheckPresence") - vinsListRaw, err := controller.decortAPICall("POST", vinsListAPI, urlValues) + vinsListRaw, err := c.DecortAPICall("POST", VinsListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/grid/api.go b/internal/service/cloudbroker/grid/api.go new file mode 100644 index 0000000..9efebd9 --- /dev/null +++ b/internal/service/cloudbroker/grid/api.go @@ -0,0 +1,35 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package grid + +const GridListGetAPI = "/restmachine/cloudbroker/grid/list" +const GridGetAPI = "/restmachine/cloudbroker/grid/get" diff --git a/decort/data_source_grid.go b/internal/service/cloudbroker/grid/data_source_grid.go similarity index 61% rename from decort/data_source_grid.go rename to internal/service/cloudbroker/grid/data_source_grid.go index 2529e3f..7ba9abe 100644 --- a/decort/data_source_grid.go +++ b/internal/service/cloudbroker/grid/data_source_grid.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,18 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package grid import ( + "context" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenGrid(d *schema.ResourceData, grid *Grid) { @@ -39,10 +49,10 @@ func flattenGrid(d *schema.ResourceData, grid *Grid) { d.Set("id", grid.Id) } -func dataSourceGridRead(d *schema.ResourceData, m interface{}) error { +func dataSourceGridRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { grid, err := utilityGridCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(grid.Id)) flattenGrid(d, grid) @@ -83,15 +93,15 @@ func dataSourceGetGridSchemaMake() map[string]*schema.Schema { } } -func dataSourceGrid() *schema.Resource { +func DataSourceGrid() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceGridRead, + ReadContext: dataSourceGridRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceGetGridSchemaMake(), diff --git a/decort/data_source_grid_list.go b/internal/service/cloudbroker/grid/data_source_grid_list.go similarity index 68% rename from decort/data_source_grid_list.go rename to internal/service/cloudbroker/grid/data_source_grid_list.go index 3a420da..4521c90 100644 --- a/decort/data_source_grid_list.go +++ b/internal/service/cloudbroker/grid/data_source_grid_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package grid import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenGridList(gl GridList) []map[string]interface{} { @@ -46,10 +57,10 @@ func flattenGridList(gl GridList) []map[string]interface{} { return res } -func dataSourceGridListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { gridList, err := utilityGridListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -112,15 +123,15 @@ func dataSourceGridSchemaMake() map[string]*schema.Schema { } } -func dataSourceGridList() *schema.Resource { +func DataSourceGridList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceGridListRead, + ReadContext: dataSourceGridListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceGridListSchemaMake(), diff --git a/internal/service/cloudbroker/grid/models.go b/internal/service/cloudbroker/grid/models.go new file mode 100644 index 0000000..72e35cf --- /dev/null +++ b/internal/service/cloudbroker/grid/models.go @@ -0,0 +1,43 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package grid + +type Grid struct { + Flag string `json:"flag"` + Gid int `json:"gid"` + Guid int `json:"guid"` + Id int `json:"id"` + LocationCode string `json:"locationCode"` + Name string `json:"name"` +} + +type GridList []Grid diff --git a/decort/utility_grid.go b/internal/service/cloudbroker/grid/utility_grid.go similarity index 60% rename from decort/utility_grid.go rename to internal/service/cloudbroker/grid/utility_grid.go index 8500a5f..ef30e99 100644 --- a/decort/utility_grid.go +++ b/internal/service/cloudbroker/grid/utility_grid.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package grid import ( "encoding/json" @@ -30,14 +37,15 @@ import ( "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityGridCheckPresence(d *schema.ResourceData, m interface{}) (*Grid, error) { grid := &Grid{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if gridId, ok := d.GetOk("grid_id"); ok { @@ -47,7 +55,7 @@ func utilityGridCheckPresence(d *schema.ResourceData, m interface{}) (*Grid, err } log.Debugf("utilityGridCheckPresence: load grid") - gridRaw, err := controller.decortAPICall("POST", GridGetAPI, urlValues) + gridRaw, err := c.DecortAPICall("POST", GridGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_grid_list.go b/internal/service/cloudbroker/grid/utility_grid_list.go similarity index 61% rename from decort/utility_grid_list.go rename to internal/service/cloudbroker/grid/utility_grid_list.go index 202f6ad..c679411 100644 --- a/decort/utility_grid_list.go +++ b/internal/service/cloudbroker/grid/utility_grid_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package grid import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityGridListCheckPresence(d *schema.ResourceData, m interface{}) (GridList, error) { gridList := GridList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if page, ok := d.GetOk("page"); ok { @@ -47,7 +55,7 @@ func utilityGridListCheckPresence(d *schema.ResourceData, m interface{}) (GridLi } log.Debugf("utilityGridListCheckPresence: load grid list") - gridListRaw, err := controller.decortAPICall("POST", GridListGetAPI, urlValues) + gridListRaw, err := c.DecortAPICall("POST", GridListGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/image/api.go b/internal/service/cloudbroker/image/api.go new file mode 100644 index 0000000..a7610ff --- /dev/null +++ b/internal/service/cloudbroker/image/api.go @@ -0,0 +1,52 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package image + +const imageCreateAPI = "/restmachine/cloudbroker/image/createImage" +const imageSyncCreateAPI = "/restmachine/cloudbroker/image/syncCreateImage" +const imageCreateVirtualAPI = "/restmachine/cloudbroker/image/createVirtual" +const imageCreateCDROMAPI = "/restmachine/cloudbroker/image/createCDROMImage" +const imageListStacksApi = "/restmachine/cloudbroker/image/listStacks" +const imageGetAPI = "/restmachine/cloudbroker/image/get" +const imageListGetAPI = "/restmachine/cloudbroker/image/list" +const imageEditAPI = "/restmachine/cloudbroker/image/edit" +const imageDeleteAPI = "/restmachine/cloudbroker/image/delete" +const imageDeleteCDROMAPI = "/restmachine/cloudbroker/image/deleteCDROMImage" +const imageEnableAPI = "/restmachine/cloudbroker/image/enable" +const imageDisableAPI = "/restmachine/cloudbroker/image/disable" +const imageEditNameAPI = "/restmachine/cloudbroker/image/rename" +const imageLinkAPI = "/restmachine/cloudbroker/image/link" +const imageShareAPI = "/restmachine/cloudbroker/image/share" +const imageComputeciSetAPI = "/restmachine/cloudbroker/image/computeciSet" +const imageComputeciUnsetAPI = "/restmachine/cloudbroker/image/computeciUnset" +const imageUpdateNodesAPI = "/restmachine/cloudbroker/image/updateNodes" +const imageDeleteImagesAPI = "/restmachine/cloudbroker/image/deleteImages" diff --git a/decort/data_source_image.go b/internal/service/cloudbroker/image/data_source_image.go similarity index 86% rename from decort/data_source_image.go rename to internal/service/cloudbroker/image/data_source_image.go index 9a218e9..fe0ee4b 100644 --- a/decort/data_source_image.go +++ b/internal/service/cloudbroker/image/data_source_image.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,18 +18,27 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( + "context" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/flattens" ) func flattenImage(d *schema.ResourceData, image *Image) { @@ -66,16 +77,16 @@ func flattenImage(d *schema.ResourceData, image *Image) { d.Set("hot_resize", image.Hotresize) d.Set("history", flattenHistory(image.History)) d.Set("last_modified", image.LastModified) - d.Set("meta", flattenMeta(image.Meta)) + d.Set("meta", flattens.FlattenMeta(image.Meta)) d.Set("desc", image.Desc) d.Set("shared_with", image.SharedWith) } -func dataSourceImageRead(d *schema.ResourceData, m interface{}) error { +func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { image, err := utilityImageCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(image.Guid)) flattenImage(d, image) @@ -295,15 +306,15 @@ func dataSourceImageSchemaMake() map[string]*schema.Schema { } } -func dataSourceImage() *schema.Resource { +func DataSourceImage() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceImageRead, + ReadContext: dataSourceImageRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceImageSchemaMake(), diff --git a/decort/data_source_image_list.go b/internal/service/cloudbroker/image/data_source_image_list.go similarity index 74% rename from decort/data_source_image_list.go rename to internal/service/cloudbroker/image/data_source_image_list.go index ad6f6d9..1108d23 100644 --- a/decort/data_source_image_list.go +++ b/internal/service/cloudbroker/image/data_source_image_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenImageList(il ImageList) []map[string]interface{} { @@ -77,10 +88,10 @@ func flattenImageList(il ImageList) []map[string]interface{} { return res } -func dataSourceImageListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { imageList, err := utilityImageListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -124,15 +135,15 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema { return rets } -func dataSourceImageList() *schema.Resource { +func DataSourceImageList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceImageListRead, + ReadContext: dataSourceImageListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceImageListSchemaMake(), diff --git a/decort/data_source_image_list_stacks.go b/internal/service/cloudbroker/image/data_source_image_list_stacks.go similarity index 75% rename from decort/data_source_image_list_stacks.go rename to internal/service/cloudbroker/image/data_source_image_list_stacks.go index 7b37371..2a47dd5 100644 --- a/decort/data_source_image_list_stacks.go +++ b/internal/service/cloudbroker/image/data_source_image_list_stacks.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,26 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) func flattenImageListStacks(_ *schema.ResourceData, stack ImageListStacks) []map[string]interface{} { @@ -55,10 +66,10 @@ func flattenImageListStacks(_ *schema.ResourceData, stack ImageListStacks) []map return temp } -func dataSourceImageListStacksRead(d *schema.ResourceData, m interface{}) error { +func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { imageListStacks, err := utilityImageListStacksCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -166,15 +177,15 @@ func dataSourceImageListStacksSchemaMake() map[string]*schema.Schema { } } -func dataSourceImageListStacks() *schema.Resource { +func DataSourceImageListStacks() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceImageListStacksRead, + ReadContext: dataSourceImageListStacksRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceImageListStacksSchemaMake(), diff --git a/internal/service/cloudbroker/image/models.go b/internal/service/cloudbroker/image/models.go new file mode 100644 index 0000000..7c0f34b --- /dev/null +++ b/internal/service/cloudbroker/image/models.go @@ -0,0 +1,101 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package image + +type History struct { + Guid string `json:"guid"` + Id int `json:"id"` + Timestamp int64 `json:"timestamp"` +} + +type Image struct { + ImageId int `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Gid int `json:"gid"` + Guid int `json:"guid"` + Boottype string `json:"bootType"` + Imagetype string `json:"type"` + Drivers []string `json:"drivers"` + Hotresize bool `json:"hotResize"` + Bootable bool `json:"bootable"` + Username string `json:"username"` + Password string `json:"password"` + AccountId int `json:"accountId"` + UsernameDL string `json:"usernameDL"` + PasswordDL string `json:"passwordDL"` + SepId int `json:"sepId"` + PoolName string `json:"pool"` + Architecture string `json:"architecture"` + UNCPath string `json:"UNCPath"` + LinkTo int `json:"linkTo"` + Status string `json:"status"` + TechStatus string `json:"techStatus"` + Size int `json:"size"` + Version string `json:"version"` + Enabled bool `json:"enabled"` + ComputeciId int `json:"computeciId"` + Milestones int `json:"milestones"` + ProviderName string `json:"provider_name"` + PurgeAttempts int `json:"purgeAttempts"` + ReferenceId string `json:"referenceId"` + ResId string `json:"resId"` + ResName string `json:"resName"` + Rescuecd bool `json:"rescuecd"` + Meta []interface{} `json:"_meta"` + History []History `json:"history"` + LastModified int64 `json:"lastModified"` + Desc string `json:"desc"` + SharedWith []int `json:"sharedWith"` +} + +type ImageList []Image + +type ImageStack struct { + ApiURL string `json:"apiUrl"` + ApiKey string `json:"apikey"` + AppId string `json:"appId"` + Desc string `json:"desc"` + Drivers []string `json:"drivers"` + Error int `json:"error"` + Guid int `json:"guid"` + Id int `json:"id"` + Images []int `json:"images"` + Login string `json:"login"` + Name string `json:"name"` + Passwd string `json:"passwd"` + ReferenceId string `json:"referenceId"` + Status string `json:"status"` + Type string `json:"type"` +} + +type ImageListStacks []ImageStack diff --git a/decort/resource_cdrom_image.go b/internal/service/cloudbroker/image/resource_cdrom_image.go similarity index 73% rename from decort/resource_cdrom_image.go rename to internal/service/cloudbroker/image/resource_cdrom_image.go index df93a21..af794eb 100644 --- a/decort/resource_cdrom_image.go +++ b/internal/service/cloudbroker/image/resource_cdrom_image.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,35 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( + "context" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceCDROMImageCreate(d *schema.ResourceData, m interface{}) error { +func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceCDROMImageCreate: called for image %s", d.Get("name").(string)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("name").(string)) urlValues.Add("url", d.Get("url").(string)) @@ -80,9 +90,9 @@ func resourceCDROMImageCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("architecture", architecture.(string)) } - imageId, err := controller.decortAPICall("POST", imageCreateCDROMAPI, urlValues) + imageId, err := c.DecortAPICall("POST", imageCreateCDROMAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(imageId) @@ -90,33 +100,33 @@ func resourceCDROMImageCreate(d *schema.ResourceData, m interface{}) error { image, err := utilityImageCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(image.ImageId)) d.Set("bootable", image.Bootable) //d.Set("image_id", image.ImageId) - err = resourceImageRead(d, m) - if err != nil { - return err + diagnostics := resourceImageRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } -func resourceCDROMImageDelete(d *schema.ResourceData, m interface{}) error { +func resourceCDROMImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceCDROMImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id()) image, err := utilityImageCheckPresence(d, m) if image == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) @@ -124,9 +134,9 @@ func resourceCDROMImageDelete(d *schema.ResourceData, m interface{}) error { urlValues.Add("permanently", strconv.FormatBool(permanently.(bool))) } - _, err = controller.decortAPICall("POST", imageDeleteCDROMAPI, urlValues) + _, err = c.DecortAPICall("POST", imageDeleteCDROMAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -361,73 +371,27 @@ func resourceCDROMImageSchemaMake() map[string]*schema.Schema { } } -func resourceCDROMImage() *schema.Resource { +func ResourceCDROMImage() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceCDROMImageCreate, - Read: resourceImageRead, - Update: resourceImageEdit, - Delete: resourceCDROMImageDelete, - Exists: resourceImageExists, + CreateContext: resourceCDROMImageCreate, + ReadContext: resourceImageRead, + UpdateContext: resourceImageEdit, + DeleteContext: resourceCDROMImageDelete, + Exists: resourceImageExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, - }, - - CustomizeDiff: customdiff.All( - customdiff.IfValueChange("enabled", func(old, new, meta interface{}) bool { - return old.(bool) != new.(bool) - }, resourceImageChangeEnabled), - customdiff.IfValueChange("name", func(old, new, meta interface{}) bool { - return old.(string) != new.(string) && old.(string) != "" - }, resourceImageEditName), - customdiff.IfValueChange("shared_with", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - count := 0 - for i, v := range n { - if v.(int) == o[i].(int) { - count++ - } - } - return count == 0 - }, resourceImageShare), - customdiff.IfValueChange("computeci_id", func(old, new, meta interface{}) bool { - return old.(int) != new.(int) - }, resourceImageChangeComputeci), - customdiff.IfValueChange("enabled_stacks", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - count := 0 - for i, v := range n { - if v.(string) == o[i].(string) { - count++ - } - } - return count == 0 - }, resourceImageUpdateNodes), - ), + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, + }, Schema: resourceCDROMImageSchemaMake(), } diff --git a/decort/resource_delete_images.go b/internal/service/cloudbroker/image/resource_delete_images.go similarity index 56% rename from decort/resource_delete_images.go rename to internal/service/cloudbroker/image/resource_delete_images.go index 5c5cc19..5548285 100644 --- a/decort/resource_delete_images.go +++ b/internal/service/cloudbroker/image/resource_delete_images.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,42 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( + "context" "net/url" "strconv" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceCreateListImages(d *schema.ResourceData, m interface{}) error { +func resourceCreateListImages(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { id := uuid.New() d.SetId(id.String()) return nil } -func resourceDeleteListImages(d *schema.ResourceData, m interface{}) error { +func resourceDeleteListImages(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceDeleteListImages: start deleting...") - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} imageIds := d.Get("image_ids").([]interface{}) @@ -63,9 +74,9 @@ func resourceDeleteListImages(d *schema.ResourceData, m interface{}) error { urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool))) urlValues.Add("imageIds", temp) - _, err := c.decortAPICall("POST", imageDeleteImagesAPI, urlValues) + _, err := c.DecortAPICall("POST", imageDeleteImagesAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -73,7 +84,7 @@ func resourceDeleteListImages(d *schema.ResourceData, m interface{}) error { return nil } -func resourceReadListImages(d *schema.ResourceData, m interface{}) error { +func resourceReadListImages(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { return nil } @@ -106,24 +117,24 @@ func resourceDeleteImagesSchemaMake() map[string]*schema.Schema { } -func resourceDeleteImages() *schema.Resource { +func ResourceDeleteImages() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceCreateListImages, - Read: resourceReadListImages, - Delete: resourceDeleteListImages, + CreateContext: resourceCreateListImages, + ReadContext: resourceReadListImages, + DeleteContext: resourceDeleteListImages, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceDeleteImagesSchemaMake(), diff --git a/decort/resource_image.go b/internal/service/cloudbroker/image/resource_image.go similarity index 72% rename from decort/resource_image.go rename to internal/service/cloudbroker/image/resource_image.go index cd4b970..464e687 100644 --- a/decort/resource_image.go +++ b/internal/service/cloudbroker/image/resource_image.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,28 +18,37 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( + "context" "errors" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/flattens" log "github.com/sirupsen/logrus" ) -func resourceImageCreate(d *schema.ResourceData, m interface{}) error { +func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("name").(string)) urlValues.Add("url", d.Get("url").(string)) @@ -92,9 +103,9 @@ func resourceImageCreate(d *schema.ResourceData, m interface{}) error { } else { api = imageSyncCreateAPI } - imageId, err := controller.decortAPICall("POST", api, urlValues) + imageId, err := c.DecortAPICall("POST", api, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(imageId) @@ -102,28 +113,28 @@ func resourceImageCreate(d *schema.ResourceData, m interface{}) error { image, err := utilityImageCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(image.ImageId)) d.Set("bootable", image.Bootable) //d.Set("image_id", image.ImageId) - err = resourceImageRead(d, m) - if err != nil { - return err + diagnostics := resourceImageRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } -func resourceImageRead(d *schema.ResourceData, m interface{}) error { +func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageRead: called for %s id: %s", d.Get("name").(string), d.Id()) image, err := utilityImageCheckPresence(d, m) if image == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("name", image.Name) @@ -158,7 +169,7 @@ func resourceImageRead(d *schema.ResourceData, m interface{}) error { d.Set("res_name", image.ResName) d.Set("rescuecd", image.Rescuecd) d.Set("architecture", image.Architecture) - d.Set("meta", flattenMeta(image.Meta)) + d.Set("meta", flattens.FlattenMeta(image.Meta)) d.Set("hot_resize", image.Hotresize) d.Set("history", flattenHistory(image.History)) d.Set("last_modified", image.LastModified) @@ -168,18 +179,18 @@ func resourceImageRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceImageDelete(d *schema.ResourceData, m interface{}) error { +func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id()) image, err := utilityImageCheckPresence(d, m) if image == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) if reason, ok := d.GetOk("reason"); ok { @@ -191,9 +202,9 @@ func resourceImageDelete(d *schema.ResourceData, m interface{}) error { urlValues.Add("permanently", strconv.FormatBool(permanently.(bool))) } - _, err = controller.decortAPICall("POST", imageDeleteAPI, urlValues) + _, err = c.DecortAPICall("POST", imageDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -214,13 +225,13 @@ func resourceImageExists(d *schema.ResourceData, m interface{}) (bool, error) { return true, nil } -func resourceImageEditName(d *schema.ResourceDiff, m interface{}) error { +func resourceImageEditName(d *schema.ResourceData, m interface{}) error { log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id()) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) urlValues.Add("name", d.Get("name").(string)) - _, err := c.decortAPICall("POST", imageEditNameAPI, urlValues) + _, err := c.DecortAPICall("POST", imageEditNameAPI, urlValues) if err != nil { return err } @@ -228,40 +239,82 @@ func resourceImageEditName(d *schema.ResourceDiff, m interface{}) error { return nil } -func resourceImageEdit(d *schema.ResourceData, m interface{}) error { +func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id()) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} - urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) - urlValues.Add("name", d.Get("name").(string)) - urlValues.Add("username", d.Get("username").(string)) - urlValues.Add("password", d.Get("password").(string)) - urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - urlValues.Add("bootable", strconv.FormatBool(d.Get("bootable").(bool))) - urlValues.Add("hotresize", strconv.FormatBool(d.Get("hot_resize").(bool))) + if d.HasChange("enabled") { + err := resourceImageChangeEnabled(d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } - //_, err := c.decortAPICall("POST", imageEditAPI, urlValues) - _, err := c.decortAPICall("POST", imageEditAPI, urlValues) - if err != nil { - err = resourceImageRead(d, m) + if d.HasChange("name") { + err := resourceImageEditName(d, m) if err != nil { - return err + return diag.FromErr(err) } - return nil + urlValues = &url.Values{} } - err = resourceImageRead(d, m) - if err != nil { - return err + + if d.HasChange("shared_with") { + err := resourceImageShare(d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } + if d.HasChange("computeci_id") { + err := resourceImageChangeComputeci(d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } + + if d.HasChange("enabled_stacks") { + err := resourceImageUpdateNodes(d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } + + if d.HasChange("link_to") { + err := resourceImageLink(d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } + + if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize") { + + urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) + urlValues.Add("name", d.Get("name").(string)) + + urlValues.Add("username", d.Get("username").(string)) + urlValues.Add("password", d.Get("password").(string)) + urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) + urlValues.Add("bootable", strconv.FormatBool(d.Get("bootable").(bool))) + urlValues.Add("hotresize", strconv.FormatBool(d.Get("hot_resize").(bool))) + + _, err := c.DecortAPICall("POST", imageEditAPI, urlValues) + if err != nil { + return diag.FromErr(err) + } } return nil } -func resourceImageChangeEnabled(d *schema.ResourceDiff, m interface{}) error { +func resourceImageChangeEnabled(d *schema.ResourceData, m interface{}) error { var api string - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) if d.Get("enabled").(bool) { @@ -269,7 +322,7 @@ func resourceImageChangeEnabled(d *schema.ResourceDiff, m interface{}) error { } else { api = imageDisableAPI } - resp, err := c.decortAPICall("POST", api, urlValues) + resp, err := c.DecortAPICall("POST", api, urlValues) if err != nil { return err } @@ -283,13 +336,13 @@ func resourceImageChangeEnabled(d *schema.ResourceDiff, m interface{}) error { return nil } -func resourceImageLink(d *schema.ResourceDiff, m interface{}) error { +func resourceImageLink(d *schema.ResourceData, m interface{}) error { log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id()) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) urlValues.Add("targetId", strconv.Itoa(d.Get("link_to").(int))) - _, err := c.decortAPICall("POST", imageLinkAPI, urlValues) + _, err := c.DecortAPICall("POST", imageLinkAPI, urlValues) if err != nil { return err } @@ -297,9 +350,9 @@ func resourceImageLink(d *schema.ResourceDiff, m interface{}) error { return nil } -func resourceImageShare(d *schema.ResourceDiff, m interface{}) error { +func resourceImageShare(d *schema.ResourceData, m interface{}) error { log.Debugf("resourceImageShare: called for %s, id: %s", d.Get("name").(string), d.Id()) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) accIds := d.Get("shared_with").([]interface{}) @@ -316,7 +369,7 @@ func resourceImageShare(d *schema.ResourceDiff, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("accounts", temp) - _, err := c.decortAPICall("POST", imageShareAPI, urlValues) + _, err := c.DecortAPICall("POST", imageShareAPI, urlValues) if err != nil { return err } @@ -324,8 +377,8 @@ func resourceImageShare(d *schema.ResourceDiff, m interface{}) error { return nil } -func resourceImageChangeComputeci(d *schema.ResourceDiff, m interface{}) error { - c := m.(*ControllerCfg) +func resourceImageChangeComputeci(d *schema.ResourceData, m interface{}) error { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) @@ -340,7 +393,7 @@ func resourceImageChangeComputeci(d *schema.ResourceDiff, m interface{}) error { api = imageComputeciSetAPI } - _, err := c.decortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall("POST", api, urlValues) if err != nil { return err } @@ -348,9 +401,9 @@ func resourceImageChangeComputeci(d *schema.ResourceDiff, m interface{}) error { return nil } -func resourceImageUpdateNodes(d *schema.ResourceDiff, m interface{}) error { +func resourceImageUpdateNodes(d *schema.ResourceData, m interface{}) error { log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id()) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) enabledStacks := d.Get("enabled_stacks").([]interface{}) @@ -365,7 +418,7 @@ func resourceImageUpdateNodes(d *schema.ResourceDiff, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("enabledStacks", temp) - _, err := c.decortAPICall("POST", imageUpdateNodesAPI, urlValues) + _, err := c.DecortAPICall("POST", imageUpdateNodesAPI, urlValues) if err != nil { return err } @@ -616,73 +669,27 @@ func resourceImageSchemaMake() map[string]*schema.Schema { } } -func resourceImage() *schema.Resource { +func ResourceImage() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceImageCreate, - Read: resourceImageRead, - Update: resourceImageEdit, - Delete: resourceImageDelete, - Exists: resourceImageExists, + CreateContext: resourceImageCreate, + ReadContext: resourceImageRead, + UpdateContext: resourceImageEdit, + DeleteContext: resourceImageDelete, + Exists: resourceImageExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, - }, - CustomizeDiff: customdiff.All( - customdiff.IfValueChange("enabled", func(old, new, meta interface{}) bool { - return old.(bool) != new.(bool) - }, resourceImageChangeEnabled), - customdiff.IfValueChange("name", func(old, new, meta interface{}) bool { - return old.(string) != new.(string) && old.(string) != "" - }, resourceImageEditName), - customdiff.IfValueChange("shared_with", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - - count := 0 - for i, v := range n { - if v.(int) == o[i].(int) { - count++ - } - } - return count == 0 - }, resourceImageShare), - customdiff.IfValueChange("computeci_id", func(old, new, meta interface{}) bool { - return old.(int) != new.(int) - }, resourceImageChangeComputeci), - customdiff.IfValueChange("enabled_stacks", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - count := 0 - for i, v := range n { - if v.(string) == o[i].(string) { - count++ - } - } - return count == 0 - }, resourceImageUpdateNodes), - ), + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, + }, Schema: resourceImageSchemaMake(), } diff --git a/decort/resource_virtual_image.go b/internal/service/cloudbroker/image/resource_virtual_image.go similarity index 70% rename from decort/resource_virtual_image.go rename to internal/service/cloudbroker/image/resource_virtual_image.go index 5097db1..f778367 100644 --- a/decort/resource_virtual_image.go +++ b/internal/service/cloudbroker/image/resource_virtual_image.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,34 +18,42 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( + "context" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceVirtualImageCreate(d *schema.ResourceData, m interface{}) error { +func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string)) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("name").(string)) urlValues.Add("targetId", strconv.Itoa(d.Get("target_id").(int))) - imageId, err := controller.decortAPICall("POST", imageCreateVirtualAPI, urlValues) + imageId, err := c.DecortAPICall("POST", imageCreateVirtualAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(imageId) @@ -51,16 +61,16 @@ func resourceVirtualImageCreate(d *schema.ResourceData, m interface{}) error { image, err := utilityImageCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(image.ImageId)) d.Set("bootable", image.Bootable) //d.Set("image_id", image.ImageId) - err = resourceImageRead(d, m) - if err != nil { - return err + diagnostics := resourceImageRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil @@ -308,77 +318,28 @@ func resourceVirtualImageSchemaMake() map[string]*schema.Schema { } } -func resourceVirtualImage() *schema.Resource { +func ResourceVirtualImage() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceVirtualImageCreate, - Read: resourceImageRead, - Update: resourceImageEdit, - Delete: resourceImageDelete, - Exists: resourceImageExists, + CreateContext: resourceVirtualImageCreate, + ReadContext: resourceImageRead, + UpdateContext: resourceImageEdit, + DeleteContext: resourceImageDelete, + Exists: resourceImageExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, - CustomizeDiff: customdiff.All( - customdiff.IfValueChange("enabled", func(old, new, meta interface{}) bool { - return old.(bool) != new.(bool) - }, resourceImageChangeEnabled), - customdiff.IfValueChange("link_to", func(old, new, meta interface{}) bool { - return old.(int) != new.(int) - }, resourceImageLink), - customdiff.IfValueChange("name", func(old, new, meta interface{}) bool { - return old.(string) != new.(string) && old.(string) != "" - }, resourceImageEditName), - customdiff.IfValueChange("shared_with", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - count := 0 - for i, v := range n { - if v.(int) == o[i].(int) { - count++ - } - } - return count == 0 - }, resourceImageShare), - customdiff.IfValueChange("computeci_id", func(old, new, meta interface{}) bool { - return old.(int) != new.(int) - }, resourceImageChangeComputeci), - customdiff.IfValueChange("enabled_stacks", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - count := 0 - for i, v := range n { - if v.(string) == o[i].(string) { - count++ - } - } - return count == 0 - }, resourceImageUpdateNodes), - ), - Schema: resourceVirtualImageSchemaMake(), } } diff --git a/decort/utility_image.go b/internal/service/cloudbroker/image/utility_image.go similarity index 61% rename from decort/utility_image.go rename to internal/service/cloudbroker/image/utility_image.go index 3b20243..10c30ed 100644 --- a/decort/utility_image.go +++ b/internal/service/cloudbroker/image/utility_image.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +18,18 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( "encoding/json" @@ -31,11 +38,12 @@ import ( "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilityImageCheckPresence(d *schema.ResourceData, m interface{}) (*Image, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if (strconv.Itoa(d.Get("image_id").(int))) != "0" { @@ -44,7 +52,7 @@ func utilityImageCheckPresence(d *schema.ResourceData, m interface{}) (*Image, e urlValues.Add("imageId", d.Id()) } - resp, err := controller.decortAPICall("POST", imageGetAPI, urlValues) + resp, err := c.DecortAPICall("POST", imageGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_image_list.go b/internal/service/cloudbroker/image/utility_image_list.go similarity index 64% rename from decort/utility_image_list.go rename to internal/service/cloudbroker/image/utility_image_list.go index bc80677..dffabdf 100644 --- a/decort/utility_image_list.go +++ b/internal/service/cloudbroker/image/utility_image_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityImageListCheckPresence(d *schema.ResourceData, m interface{}) (ImageList, error) { imageList := ImageList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if sepId, ok := d.GetOk("sep_id"); ok { @@ -54,7 +62,7 @@ func utilityImageListCheckPresence(d *schema.ResourceData, m interface{}) (Image } log.Debugf("utilityImageListCheckPresence: load image list") - imageListRaw, err := controller.decortAPICall("POST", imageListGetAPI, urlValues) + imageListRaw, err := c.DecortAPICall("POST", imageListGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_image_list_stacks.go b/internal/service/cloudbroker/image/utility_image_list_stacks.go similarity index 59% rename from decort/utility_image_list_stacks.go rename to internal/service/cloudbroker/image/utility_image_list_stacks.go index c2ebd10..8062078 100644 --- a/decort/utility_image_list_stacks.go +++ b/internal/service/cloudbroker/image/utility_image_list_stacks.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,33 +18,39 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package image import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityImageListStacksCheckPresence(d *schema.ResourceData, m interface{}) (ImageListStacks, error) { imageListStacks := ImageListStacks{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) log.Debugf("utilityImageListStacksCheckPresence: load image list") - imageListRaw, err := controller.decortAPICall("POST", imageListStacksApi, urlValues) + imageListRaw, err := c.DecortAPICall("POST", imageListStacksApi, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/pcidevice/api.go b/internal/service/cloudbroker/pcidevice/api.go new file mode 100644 index 0000000..02a466a --- /dev/null +++ b/internal/service/cloudbroker/pcidevice/api.go @@ -0,0 +1,38 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package pcidevice + +const pcideviceListAPI = "/restmachine/cloudbroker/pcidevice/list" +const pcideviceDisableAPI = "/restmachine/cloudbroker/pcidevice/disable" +const pcideviceEnableAPI = "/restmachine/cloudbroker/pcidevice/enable" +const pcideviceCreateAPI = "/restmachine/cloudbroker/pcidevice/create" +const pcideviceDeleteAPI = "/restmachine/cloudbroker/pcidevice/delete" diff --git a/decort/data_source_pcidevice.go b/internal/service/cloudbroker/pcidevice/data_source_pcidevice.go similarity index 65% rename from decort/data_source_pcidevice.go rename to internal/service/cloudbroker/pcidevice/data_source_pcidevice.go index e3fa314..880ff91 100644 --- a/decort/data_source_pcidevice.go +++ b/internal/service/cloudbroker/pcidevice/data_source_pcidevice.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,28 +18,37 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package pcidevice import ( + "context" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/flattens" ) -func dataSourcePcideviceRead(d *schema.ResourceData, m interface{}) error { +func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { pcidevice, err := utilityPcideviceCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.Set("ckey", pcidevice.CKey) - d.Set("meta", flattenMeta(pcidevice.Meta)) + d.Set("meta", flattens.FlattenMeta(pcidevice.Meta)) d.Set("compute_id", pcidevice.Computeid) d.Set("description", pcidevice.Description) d.Set("guid", pcidevice.Guid) @@ -112,15 +123,15 @@ func dataSourcePcideviceSchemaMake() map[string]*schema.Schema { return rets } -func dataSourcePcidevice() *schema.Resource { +func DataSourcePcidevice() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourcePcideviceRead, + ReadContext: dataSourcePcideviceRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourcePcideviceSchemaMake(), diff --git a/decort/data_source_pcidevice_list.go b/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go similarity index 69% rename from decort/data_source_pcidevice_list.go rename to internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go index 2ee469d..b570cbf 100644 --- a/decort/data_source_pcidevice_list.go +++ b/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,17 +18,27 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package pcidevice import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/flattens" ) func flattenPcideviceList(pl PcideviceList) []map[string]interface{} { @@ -34,7 +46,7 @@ func flattenPcideviceList(pl PcideviceList) []map[string]interface{} { for _, item := range pl { temp := map[string]interface{}{ "ckey": item.CKey, - "meta": flattenMeta(item.Meta), + "meta": flattens.FlattenMeta(item.Meta), "compute_id": item.Computeid, "description": item.Description, "guid": item.Guid, @@ -51,10 +63,10 @@ func flattenPcideviceList(pl PcideviceList) []map[string]interface{} { return res } -func dataSourcePcideviceListRead(d *schema.ResourceData, m interface{}) error { +func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { pcideviceList, err := utilityPcideviceListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.Set("items", flattenPcideviceList(pcideviceList)) @@ -136,15 +148,15 @@ func dataSourcePcideviceListSchemaMake() map[string]*schema.Schema { return rets } -func dataSourcePcideviceList() *schema.Resource { +func DataSourcePcideviceList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourcePcideviceListRead, + ReadContext: dataSourcePcideviceListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourcePcideviceListSchemaMake(), diff --git a/internal/service/cloudbroker/pcidevice/models.go b/internal/service/cloudbroker/pcidevice/models.go new file mode 100644 index 0000000..f6dc1f8 --- /dev/null +++ b/internal/service/cloudbroker/pcidevice/models.go @@ -0,0 +1,49 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package pcidevice + +type Pcidevice struct { + CKey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + Computeid int `json:"computeId"` + Description string `json:"description"` + Guid int `json:"guid"` + HwPath string `json:"hwPath"` + ID int `json:"id"` + Name string `json:"name"` + RgID int `json:"rgId"` + StackID int `json:"stackId"` + Status string `json:"status"` + SystemName string `json:"systemName"` +} + +type PcideviceList []Pcidevice diff --git a/decort/resource_pcidevice.go b/internal/service/cloudbroker/pcidevice/resource_pcidevice.go similarity index 61% rename from decort/resource_pcidevice.go rename to internal/service/cloudbroker/pcidevice/resource_pcidevice.go index 470ddb1..63408a2 100644 --- a/decort/resource_pcidevice.go +++ b/internal/service/cloudbroker/pcidevice/resource_pcidevice.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,43 +18,52 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package pcidevice import ( - "errors" + "context" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/flattens" log "github.com/sirupsen/logrus" ) -func resourcePcideviceCreate(d *schema.ResourceData, m interface{}) error { +func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string)) if deviceId, ok := d.GetOk("device_id"); ok { if exists, err := resourcePcideviceExists(d, m); exists { if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(deviceId.(int))) - err = resourcePcideviceRead(d, m) - if err != nil { - return err + diagnostics := resourcePcideviceRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } - return errors.New("provided device id does not exist") + return diag.Errorf("provided device id does not exist") } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("name").(string)) urlValues.Add("hwPath", d.Get("hw_path").(string)) @@ -63,31 +74,31 @@ func resourcePcideviceCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("description", description.(string)) } - pcideviceId, err := controller.decortAPICall("POST", pcideviceCreateAPI, urlValues) + pcideviceId, err := c.DecortAPICall("POST", pcideviceCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(pcideviceId) d.Set("device_id", pcideviceId) - err = resourcePcideviceRead(d, m) - if err != nil { - return err + diagnostics := resourcePcideviceRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } -func resourcePcideviceRead(d *schema.ResourceData, m interface{}) error { +func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { pcidevice, err := utilityPcideviceCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(pcidevice.ID)) d.Set("ckey", pcidevice.CKey) - d.Set("meta", flattenMeta(pcidevice.Meta)) + d.Set("meta", flattens.FlattenMeta(pcidevice.Meta)) d.Set("compute_id", pcidevice.Computeid) d.Set("description", pcidevice.Description) d.Set("guid", pcidevice.Guid) @@ -102,17 +113,17 @@ func resourcePcideviceRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourcePcideviceDelete(d *schema.ResourceData, m interface{}) error { +func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourcePcideviceDelete: called for %s, id: %s", d.Get("name").(string), d.Id()) - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("deviceId", d.Id()) urlValues.Add("force", strconv.FormatBool(d.Get("force").(bool))) - _, err := controller.decortAPICall("POST", pcideviceDeleteAPI, urlValues) + _, err := c.DecortAPICall("POST", pcideviceDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -132,10 +143,10 @@ func resourcePcideviceExists(d *schema.ResourceData, m interface{}) (bool, error return true, nil } -func resourcePcideviceEdit(d *schema.ResourceData, m interface{}) error { +func resourcePcideviceEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { if d.HasChange("enable") { state := d.Get("enable").(bool) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} api := "" @@ -147,15 +158,15 @@ func resourcePcideviceEdit(d *schema.ResourceData, m interface{}) error { api = pcideviceDisableAPI } - _, err := c.decortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall("POST", api, urlValues) if err != nil { - return err + return diag.FromErr(err) } } - err := resourcePcideviceRead(d, m) - if err != nil { - return err + diagnostics := resourcePcideviceRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil @@ -236,26 +247,26 @@ func resourcePcideviceSchemaMake() map[string]*schema.Schema { } } -func resourcePcidevice() *schema.Resource { +func ResourcePcidevice() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourcePcideviceCreate, - Read: resourcePcideviceRead, - Update: resourcePcideviceEdit, - Delete: resourcePcideviceDelete, - Exists: resourcePcideviceExists, + CreateContext: resourcePcideviceCreate, + ReadContext: resourcePcideviceRead, + UpdateContext: resourcePcideviceEdit, + DeleteContext: resourcePcideviceDelete, + Exists: resourcePcideviceExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourcePcideviceSchemaMake(), diff --git a/decort/utility_pcidevice.go b/internal/service/cloudbroker/pcidevice/utility_pcidevice.go similarity index 64% rename from decort/utility_pcidevice.go rename to internal/service/cloudbroker/pcidevice/utility_pcidevice.go index 5709ea0..fb4ffcd 100644 --- a/decort/utility_pcidevice.go +++ b/internal/service/cloudbroker/pcidevice/utility_pcidevice.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,18 +18,23 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package pcidevice import ( "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilityPcideviceCheckPresence(d *schema.ResourceData, m interface{}) (*Pcidevice, error) { diff --git a/decort/utility_pcidevice_list.go b/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go similarity index 55% rename from decort/utility_pcidevice_list.go rename to internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go index e4f7580..1dd503d 100644 --- a/decort/utility_pcidevice_list.go +++ b/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package pcidevice import ( "encoding/json" "net/url" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilityPcideviceListCheckPresence(_ *schema.ResourceData, m interface{}) (PcideviceList, error) { pcideviceList := PcideviceList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} - pcideviceListRaw, err := controller.decortAPICall("POST", pcideviceListAPI, urlValues) + pcideviceListRaw, err := c.DecortAPICall("POST", pcideviceListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/sep/api.go b/internal/service/cloudbroker/sep/api.go new file mode 100644 index 0000000..5febab6 --- /dev/null +++ b/internal/service/cloudbroker/sep/api.go @@ -0,0 +1,59 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package sep + +const sepAddConsumerNodesAPI = "/restmachine/cloudbroker/sep/addConsumerNodes" +const sepDelConsumerNodesAPI = "/restmachine/cloudbroker/sep/delConsumerNodes" +const sepAddProviderNodesAPI = "/restmachine/cloudbroker/sep/addProviderNodes" + +const sepConfigFieldEditAPI = "/restmachine/cloudbroker/sep/configFieldEdit" +const sepConfigInsertAPI = "/restmachine/cloudbroker/sep/configInsert" +const sepConfigValidateAPI = "/restmachine/cloudbroker/sep/configValidate" + +const sepConsumptionAPI = "/restmachine/cloudbroker/sep/consumption" + +const sepDecommissionAPI = "/restmachine/cloudbroker/sep/decommission" + +const sepEnableAPI = "/restmachine/cloudbroker/sep/enable" +const sepDisableAPI = "/restmachine/cloudbroker/sep/disable" + +const sepDiskListAPI = "/restmachine/cloudbroker/sep/diskList" + +const sepGetAPI = "/restmachine/cloudbroker/sep/get" +const sepGetConfigAPI = "/restmachine/cloudbroker/sep/getConfig" +const sepGetPoolAPI = "/restmachine/cloudbroker/sep/getPool" + +const sepCreateAPI = "/restmachine/cloudbroker/sep/create" +const sepDeleteAPI = "/restmachine/cloudbroker/sep/delete" +const sepListAPI = "/restmachine/cloudbroker/sep/list" + +const sepUpdateCapacityLimitAPI = "/restmachine/cloudbroker/sep/updateCapacityLimit" diff --git a/decort/data_source_sep.go b/internal/service/cloudbroker/sep/data_source_sep.go similarity index 68% rename from decort/data_source_sep.go rename to internal/service/cloudbroker/sep/data_source_sep.go index 4dab665..76d3ea8 100644 --- a/decort/data_source_sep.go +++ b/internal/service/cloudbroker/sep/data_source_sep.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,31 +18,40 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" "encoding/json" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/flattens" ) -func dataSourceSepRead(d *schema.ResourceData, m interface{}) error { +func dataSourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { desSep, err := utilitySepCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) d.Set("ckey", desSep.Ckey) - d.Set("meta", flattenMeta(desSep.Meta)) + d.Set("meta", flattens.FlattenMeta(desSep.Meta)) d.Set("consumed_by", desSep.ConsumedBy) d.Set("desc", desSep.Desc) d.Set("gid", desSep.Gid) @@ -129,15 +140,15 @@ func dataSourceSepCSchemaMake() map[string]*schema.Schema { } } -func dataSourceSep() *schema.Resource { +func DataSourceSep() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSepRead, + ReadContext: dataSourceSepRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceSepCSchemaMake(), diff --git a/decort/data_source_sep_config.go b/internal/service/cloudbroker/sep/data_source_sep_config.go similarity index 56% rename from decort/data_source_sep_config.go rename to internal/service/cloudbroker/sep/data_source_sep_config.go index dcf1ec0..2d8d4ed 100644 --- a/decort/data_source_sep_config.go +++ b/internal/service/cloudbroker/sep/data_source_sep_config.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,25 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" "encoding/json" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceSepConfigRead(d *schema.ResourceData, m interface{}) error { +func dataSourceSepConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { sepConfig, err := utilitySepConfigCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() @@ -61,15 +71,15 @@ func dataSourceSepConfigSchemaMake() map[string]*schema.Schema { } } -func dataSourceSepConfig() *schema.Resource { +func DataSourceSepConfig() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSepConfigRead, + ReadContext: dataSourceSepConfigRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceSepConfigSchemaMake(), diff --git a/decort/data_source_sep_consumption.go b/internal/service/cloudbroker/sep/data_source_sep_consumption.go similarity index 78% rename from decort/data_source_sep_consumption.go rename to internal/service/cloudbroker/sep/data_source_sep_consumption.go index bd2c898..c4aa957 100644 --- a/decort/data_source_sep_consumption.go +++ b/internal/service/cloudbroker/sep/data_source_sep_consumption.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceSepConsumptionRead(d *schema.ResourceData, m interface{}) error { +func dataSourceSepConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { sepCons, err := utilitySepConsumptionCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -179,15 +190,15 @@ func dataSourceSepConsumptionSchemaMake() map[string]*schema.Schema { } } -func dataSourceSepConsumption() *schema.Resource { +func DataSourceSepConsumption() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSepConsumptionRead, + ReadContext: dataSourceSepConsumptionRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceSepConsumptionSchemaMake(), diff --git a/decort/data_source_sep_disk_list.go b/internal/service/cloudbroker/sep/data_source_sep_disk_list.go similarity index 58% rename from decort/data_source_sep_disk_list.go rename to internal/service/cloudbroker/sep/data_source_sep_disk_list.go index 128aa22..8e0fe92 100644 --- a/decort/data_source_sep_disk_list.go +++ b/internal/service/cloudbroker/sep/data_source_sep_disk_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,23 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" + "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceSepDiskListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceSepDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { sepDiskList, err := utilitySepDiskListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -66,15 +77,15 @@ func dataSourceSepDiskListSchemaMake() map[string]*schema.Schema { return rets } -func dataSourceSepDiskList() *schema.Resource { +func DataSourceSepDiskList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSepDiskListRead, + ReadContext: dataSourceSepDiskListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceSepDiskListSchemaMake(), diff --git a/decort/data_source_sep_list.go b/internal/service/cloudbroker/sep/data_source_sep_list.go similarity index 72% rename from decort/data_source_sep_list.go rename to internal/service/cloudbroker/sep/data_source_sep_list.go index 89f0340..fe9bd5d 100644 --- a/decort/data_source_sep_list.go +++ b/internal/service/cloudbroker/sep/data_source_sep_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,19 +18,28 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" "encoding/json" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/flattens" ) func flattenSepList(sl SepList) []map[string]interface{} { @@ -37,7 +48,7 @@ func flattenSepList(sl SepList) []map[string]interface{} { data, _ := json.Marshal(item.Config) temp := map[string]interface{}{ "ckey": item.Ckey, - "meta": flattenMeta(item.Meta), + "meta": flattens.FlattenMeta(item.Meta), "consumed_by": item.ConsumedBy, "desc": item.Desc, "gid": item.Gid, @@ -57,10 +68,10 @@ func flattenSepList(sl SepList) []map[string]interface{} { return res } -func dataSourceSepListRead(d *schema.ResourceData, m interface{}) error { +func dataSourceSepListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { sepList, err := utilitySepListCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -164,15 +175,15 @@ func dataSourceSepShortSchemaMake() map[string]*schema.Schema { } } -func dataSourceSepList() *schema.Resource { +func DataSourceSepList() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSepListRead, + ReadContext: dataSourceSepListRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceSepListSchemaMake(), diff --git a/decort/data_source_sep_pool.go b/internal/service/cloudbroker/sep/data_source_sep_pool.go similarity index 57% rename from decort/data_source_sep_pool.go rename to internal/service/cloudbroker/sep/data_source_sep_pool.go index 6f401ba..92238e8 100644 --- a/decort/data_source_sep_pool.go +++ b/internal/service/cloudbroker/sep/data_source_sep_pool.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,25 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" "encoding/json" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" ) -func dataSourceSepPoolRead(d *schema.ResourceData, m interface{}) error { +func dataSourceSepPoolRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { sepPool, err := utilitySepPoolCheckPresence(d, m) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) @@ -64,15 +74,15 @@ func dataSourceSepPoolSchemaMake() map[string]*schema.Schema { } } -func dataSourceSepPool() *schema.Resource { +func DataSourceSepPool() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Read: dataSourceSepPoolRead, + ReadContext: dataSourceSepPoolRead, Timeouts: &schema.ResourceTimeout{ - Read: &Timeout30s, - Default: &Timeout60s, + Read: &constants.Timeout30s, + Default: &constants.Timeout60s, }, Schema: dataSourceSepPoolSchemaMake(), diff --git a/internal/service/cloudbroker/sep/models.go b/internal/service/cloudbroker/sep/models.go new file mode 100644 index 0000000..e955887 --- /dev/null +++ b/internal/service/cloudbroker/sep/models.go @@ -0,0 +1,77 @@ +/* +Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. +Authors: +Petr Krutov, +Stanislav Solovev, + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. + +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki +*/ + +package sep + +///Sep Models +type SepConsumptionInd struct { + DiskCount int `json:"disk_count"` + DiskUsage int `json:"disk_usage"` + SnapshotCount int `json:"snapshot_count"` + SnapshotUsage int `json:"snapshot_usage"` + Usage int `json:"usage"` + UsageLimit int `json:"usage_limit"` +} + +type SepConsumptionTotal struct { + CapacityLimit int `json:"capacity_limit"` + SepConsumptionInd +} + +type SepConsumption struct { + Total SepConsumptionTotal `json:"total"` + Type string `json:"type"` + ByPool map[string]SepConsumptionInd `json:"byPool"` +} + +type SepDiskList []int + +type Sep struct { + Ckey string `json:"_ckey"` + Meta []interface{} `json:"_meta"` + ConsumedBy []int `json:"consumedBy"` + Desc string `json:"desc"` + Gid int `json:"gid"` + Guid int `json:"guid"` + Id int `json:"id"` + Milestones int `json:"milestones"` + Name string `json:"name"` + ObjStatus string `json:"objStatus"` + ProvidedBy []int `json:"providedBy"` + TechStatus string `json:"techStatus"` + Type string `json:"type"` + Config SepConfig `json:"config"` +} + +type SepConfig map[string]interface{} + +type SepList []Sep +type SepPool map[string]interface{} diff --git a/decort/resource_sep.go b/internal/service/cloudbroker/sep/resource_sep.go similarity index 69% rename from decort/resource_sep.go rename to internal/service/cloudbroker/sep/resource_sep.go index d3608e3..95c341f 100644 --- a/decort/resource_sep.go +++ b/internal/service/cloudbroker/sep/resource_sep.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,46 +18,55 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" "encoding/json" "errors" "net/url" "strconv" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" + "github.com/rudecs/terraform-provider-decort/internal/flattens" log "github.com/sirupsen/logrus" ) -func resourceSepCreate(d *schema.ResourceData, m interface{}) error { +func resourceSepCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepCreate: called for sep %s", d.Get("name").(string)) if sepId, ok := d.GetOk("sep_id"); ok { if exists, err := resourceSepExists(d, m); exists { if err != nil { - return err + return diag.FromErr(err) } d.SetId(strconv.Itoa(sepId.(int))) - err = resourceSepRead(d, m) - if err != nil { - return err + diagnostics := resourceSepRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } - return errors.New("provided sep id does not exist") + return diag.Errorf("provided sep id does not exist") } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("name", d.Get("name").(string)) @@ -98,18 +109,18 @@ func resourceSepCreate(d *schema.ResourceData, m interface{}) error { temp = "[" + temp + "]" urlValues.Add("provider_nids", temp) - sepId, err := controller.decortAPICall("POST", sepCreateAPI, urlValues) + sepId, err := c.DecortAPICall("POST", sepCreateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(sepId) d.Set("sep_id", sepId) - err = resourceSepRead(d, m) - if err != nil { - return err + diagnostics := resourceSepRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } d.SetId(id.String()) @@ -117,17 +128,17 @@ func resourceSepCreate(d *schema.ResourceData, m interface{}) error { return nil } -func resourceSepRead(d *schema.ResourceData, m interface{}) error { +func resourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepRead: called for %s id: %d", d.Get("name").(string), d.Get("sep_id").(int)) sep, err := utilitySepCheckPresence(d, m) if sep == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("ckey", sep.Ckey) - d.Set("meta", flattenMeta(sep.Meta)) + d.Set("meta", flattens.FlattenMeta(sep.Meta)) d.Set("consumed_by", sep.ConsumedBy) d.Set("desc", sep.Desc) d.Set("gid", sep.Gid) @@ -145,24 +156,24 @@ func resourceSepRead(d *schema.ResourceData, m interface{}) error { return nil } -func resourceSepDelete(d *schema.ResourceData, m interface{}) error { +func resourceSepDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepDelete: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) sepDes, err := utilitySepCheckPresence(d, m) if sepDes == nil { if err != nil { - return err + return diag.FromErr(err) } return nil } - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - _, err = controller.decortAPICall("POST", sepDeleteAPI, urlValues) + _, err = c.DecortAPICall("POST", sepDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -183,9 +194,9 @@ func resourceSepExists(d *schema.ResourceData, m interface{}) (bool, error) { return true, nil } -func resourceSepEdit(d *schema.ResourceData, m interface{}) error { +func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepEdit: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if d.HasChange("decommission") { @@ -193,9 +204,9 @@ func resourceSepEdit(d *schema.ResourceData, m interface{}) error { if decommission { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("clear_physically", strconv.FormatBool(d.Get("clear_physically").(bool))) - _, err := c.decortAPICall("POST", sepDecommissionAPI, urlValues) + _, err := c.DecortAPICall("POST", sepDecommissionAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } } @@ -205,9 +216,9 @@ func resourceSepEdit(d *schema.ResourceData, m interface{}) error { updCapacityLimit := d.Get("upd_capacity_limit").(bool) if updCapacityLimit { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - _, err := c.decortAPICall("POST", sepUpdateCapacityLimitAPI, urlValues) + _, err := c.DecortAPICall("POST", sepUpdateCapacityLimitAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } } @@ -216,13 +227,13 @@ func resourceSepEdit(d *schema.ResourceData, m interface{}) error { if d.HasChange("config") { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("config", d.Get("config").(string)) - _, err := c.decortAPICall("POST", sepConfigValidateAPI, urlValues) + _, err := c.DecortAPICall("POST", sepConfigValidateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } - _, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues) + _, err = c.DecortAPICall("POST", sepConfigInsertAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } @@ -236,24 +247,48 @@ func resourceSepEdit(d *schema.ResourceData, m interface{}) error { urlValues.Add("field_value", field["field_value"].(string)) urlValues.Add("field_type", field["field_type"].(string)) - _, err := c.decortAPICall("POST", sepConfigFieldEditAPI, urlValues) + _, err := c.DecortAPICall("POST", sepConfigFieldEditAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } urlValues = &url.Values{} - if err := resourceSepRead(d, m); err != nil { - return err + if d.HasChange("enable") { + err := resourceSepChangeEnabled(d, m) + if err != nil { + return diag.FromErr(err) + } + } + + urlValues = &url.Values{} + if d.HasChange("consumed_by") { + err := resourceSepUpdateNodes(d, m) + if err != nil { + return diag.FromErr(err) + } + } + + urlValues = &url.Values{} + if d.HasChange("provided_by") { + err := resourceSepUpdateProviders(d, m) + if err != nil { + return diag.FromErr(err) + } + } + + urlValues = &url.Values{} + if diagnostics := resourceSepRead(ctx, d, m); diagnostics != nil { + return diagnostics } return nil } -func resourceSepChangeEnabled(d *schema.ResourceDiff, m interface{}) error { +func resourceSepChangeEnabled(d *schema.ResourceData, m interface{}) error { var api string - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) if d.Get("enable").(bool) { @@ -261,7 +296,7 @@ func resourceSepChangeEnabled(d *schema.ResourceDiff, m interface{}) error { } else { api = sepDisableAPI } - resp, err := c.decortAPICall("POST", api, urlValues) + resp, err := c.DecortAPICall("POST", api, urlValues) if err != nil { return err } @@ -275,9 +310,9 @@ func resourceSepChangeEnabled(d *schema.ResourceDiff, m interface{}) error { return nil } -func resourceSepUpdateNodes(d *schema.ResourceDiff, m interface{}) error { +func resourceSepUpdateNodes(d *schema.ResourceData, m interface{}) error { log.Debugf("resourceSepUpdateNodes: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} t1, t2 := d.GetChange("consumed_by") @@ -310,7 +345,7 @@ func resourceSepUpdateNodes(d *schema.ResourceDiff, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("consumer_nids", temp) - _, err := c.decortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall("POST", api, urlValues) if err != nil { return err } @@ -327,9 +362,9 @@ func findElInt(sl []interface{}, el interface{}) bool { return false } -func resourceSepUpdateProviders(d *schema.ResourceDiff, m interface{}) error { +func resourceSepUpdateProviders(d *schema.ResourceData, m interface{}) error { log.Debugf("resourceSepUpdateProviders: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) providerIds := d.Get("provided_by").([]interface{}) @@ -344,7 +379,7 @@ func resourceSepUpdateProviders(d *schema.ResourceDiff, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("provider_nids", temp) - _, err := c.decortAPICall("POST", sepAddProviderNodesAPI, urlValues) + _, err := c.DecortAPICall("POST", sepAddProviderNodesAPI, urlValues) if err != nil { return err } @@ -481,68 +516,28 @@ func resourceSepSchemaMake() map[string]*schema.Schema { } } -func resourceSep() *schema.Resource { +func ResourceSep() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceSepCreate, - Read: resourceSepRead, - Update: resourceSepEdit, - Delete: resourceSepDelete, - Exists: resourceSepExists, + CreateContext: resourceSepCreate, + ReadContext: resourceSepRead, + UpdateContext: resourceSepEdit, + DeleteContext: resourceSepDelete, + Exists: resourceSepExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceSepSchemaMake(), - - CustomizeDiff: customdiff.All( - customdiff.IfValueChange("enable", func(old, new, meta interface{}) bool { - return old.(bool) != new.(bool) - }, resourceSepChangeEnabled), - customdiff.IfValueChange("consumed_by", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - count := 0 - for i, v := range n { - if v.(int) == o[i].(int) { - count++ - } - } - return count == 0 - }, resourceSepUpdateNodes), - customdiff.IfValueChange("provided_by", func(old, new, meta interface{}) bool { - o := old.([]interface{}) - n := new.([]interface{}) - - if len(o) != len(n) { - return true - } else if len(o) == 0 { - return false - } - count := 0 - for i, v := range n { - if v.(int) == o[i].(int) { - count++ - } - } - return count == 0 - }, resourceSepUpdateProviders), - ), } } diff --git a/decort/resource_sep_config.go b/internal/service/cloudbroker/sep/resource_sep_config.go similarity index 57% rename from decort/resource_sep_config.go rename to internal/service/cloudbroker/sep/resource_sep_config.go index c16b0f0..dca075f 100644 --- a/decort/resource_sep_config.go +++ b/internal/service/cloudbroker/sep/resource_sep_config.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,62 +18,70 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( + "context" "encoding/json" - "errors" "net/url" "strconv" "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/constants" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" ) -func resourceSepConfigCreate(d *schema.ResourceData, m interface{}) error { +func resourceSepConfigCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepConfigCreate: called for sep id %d", d.Get("sep_id").(int)) if _, ok := d.GetOk("sep_id"); ok { if exists, err := resourceSepConfigExists(d, m); exists { if err != nil { - return err + return diag.FromErr(err) } id := uuid.New() d.SetId(id.String()) - err = resourceSepConfigRead(d, m) - if err != nil { - return err + diagnostics := resourceSepConfigRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil } - return errors.New("provided sep id config does not exist") + return diag.Errorf("provided sep id config does not exist") } - return resourceSepConfigRead(d, m) + return resourceSepConfigRead(ctx, d, m) } -func resourceSepConfigRead(d *schema.ResourceData, m interface{}) error { +func resourceSepConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepConfigRead: called for sep id: %d", d.Get("sep_id").(int)) sepConfig, err := utilitySepConfigCheckPresence(d, m) if sepConfig == nil { d.SetId("") - return err + return diag.FromErr(err) } data, _ := json.Marshal(sepConfig) d.Set("config", string(data)) return nil } -func resourceSepConfigDelete(d *schema.ResourceData, m interface{}) error { +func resourceSepConfigDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { d.SetId("") return nil } @@ -90,21 +100,21 @@ func resourceSepConfigExists(d *schema.ResourceData, m interface{}) (bool, error return true, nil } -func resourceSepConfigEdit(d *schema.ResourceData, m interface{}) error { +func resourceSepConfigEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepConfigEdit: called for sep id: %d", d.Get("sep_id").(int)) - c := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if d.HasChange("config") { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("config", d.Get("config").(string)) - _, err := c.decortAPICall("POST", sepConfigValidateAPI, urlValues) + _, err := c.DecortAPICall("POST", sepConfigValidateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } - _, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues) + _, err = c.DecortAPICall("POST", sepConfigInsertAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } @@ -118,15 +128,15 @@ func resourceSepConfigEdit(d *schema.ResourceData, m interface{}) error { urlValues.Add("field_value", field["field_value"].(string)) urlValues.Add("field_type", field["field_type"].(string)) - _, err := c.decortAPICall("POST", sepConfigFieldEditAPI, urlValues) + _, err := c.DecortAPICall("POST", sepConfigFieldEditAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } - err := resourceSepConfigRead(d, m) - if err != nil { - return err + diagnostics := resourceSepConfigRead(ctx, d, m) + if diagnostics != nil { + return diagnostics } return nil @@ -168,26 +178,26 @@ func resourceSepConfigSchemaMake() map[string]*schema.Schema { } } -func resourceSepConfig() *schema.Resource { +func ResourceSepConfig() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Create: resourceSepConfigCreate, - Read: resourceSepConfigRead, - Update: resourceSepConfigEdit, - Delete: resourceSepConfigDelete, - Exists: resourceSepConfigExists, + CreateContext: resourceSepConfigCreate, + ReadContext: resourceSepConfigRead, + UpdateContext: resourceSepConfigEdit, + DeleteContext: resourceSepConfigDelete, + Exists: resourceSepConfigExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ - Create: &Timeout60s, - Read: &Timeout30s, - Update: &Timeout60s, - Delete: &Timeout60s, - Default: &Timeout60s, + Create: &constants.Timeout60s, + Read: &constants.Timeout30s, + Update: &constants.Timeout60s, + Delete: &constants.Timeout60s, + Default: &constants.Timeout60s, }, Schema: resourceSepConfigSchemaMake(), diff --git a/decort/utility_sep.go b/internal/service/cloudbroker/sep/utility_sep.go similarity index 59% rename from decort/utility_sep.go rename to internal/service/cloudbroker/sep/utility_sep.go index 20dbf3d..a8f3f9d 100644 --- a/decort/utility_sep.go +++ b/internal/service/cloudbroker/sep/utility_sep.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,26 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sep := &Sep{} @@ -47,7 +55,7 @@ func utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error } log.Debugf("utilitySepCheckPresence: load sep") - sepRaw, err := controller.decortAPICall("POST", sepGetAPI, urlValues) + sepRaw, err := c.DecortAPICall("POST", sepGetAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_sep_config.go b/internal/service/cloudbroker/sep/utility_sep_config.go similarity index 59% rename from decort/utility_sep_config.go rename to internal/service/cloudbroker/sep/utility_sep_config.go index ac98899..d63f19f 100644 --- a/decort/utility_sep_config.go +++ b/internal/service/cloudbroker/sep/utility_sep_config.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,26 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepConfig, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sepConfig := SepConfig{} @@ -43,7 +51,7 @@ func utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepCo urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) log.Debugf("utilitySepConfigCheckPresence: load sep config") - sepConfigRaw, err := controller.decortAPICall("POST", sepGetConfigAPI, urlValues) + sepConfigRaw, err := c.DecortAPICall("POST", sepGetConfigAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_sep_consumption.go b/internal/service/cloudbroker/sep/utility_sep_consumption.go similarity index 57% rename from decort/utility_sep_consumption.go rename to internal/service/cloudbroker/sep/utility_sep_consumption.go index 413344c..5ce0d8e 100644 --- a/decort/utility_sep_consumption.go +++ b/internal/service/cloudbroker/sep/utility_sep_consumption.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,31 +18,37 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( "encoding/json" "net/url" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" ) func utilitySepConsumptionCheckPresence(d *schema.ResourceData, m interface{}) (*SepConsumption, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sepCons := &SepConsumption{} urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - sepConsRaw, err := controller.decortAPICall("POST", sepConsumptionAPI, urlValues) + sepConsRaw, err := c.DecortAPICall("POST", sepConsumptionAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_sep_disk_list.go b/internal/service/cloudbroker/sep/utility_sep_disk_list.go similarity index 60% rename from decort/utility_sep_disk_list.go rename to internal/service/cloudbroker/sep/utility_sep_disk_list.go index 064d144..2a2676a 100644 --- a/decort/utility_sep_disk_list.go +++ b/internal/service/cloudbroker/sep/utility_sep_disk_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,26 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilitySepDiskListCheckPresence(d *schema.ResourceData, m interface{}) ([]int, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sepDiskList := SepDiskList{} @@ -47,7 +55,7 @@ func utilitySepDiskListCheckPresence(d *schema.ResourceData, m interface{}) ([]i } log.Debugf("utilitySepDiskListCheckPresence: load sep") - sepDiskListRaw, err := controller.decortAPICall("POST", sepDiskListAPI, urlValues) + sepDiskListRaw, err := c.DecortAPICall("POST", sepDiskListAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_sep_list.go b/internal/service/cloudbroker/sep/utility_sep_list.go similarity index 61% rename from decort/utility_sep_list.go rename to internal/service/cloudbroker/sep/utility_sep_list.go index 30f7df6..ab1fd2f 100644 --- a/decort/utility_sep_list.go +++ b/internal/service/cloudbroker/sep/utility_sep_list.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,27 +18,33 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList, error) { sepList := SepList{} - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if page, ok := d.GetOk("page"); ok { @@ -47,7 +55,7 @@ func utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList } log.Debugf("utilitySepListCheckPresence: load image list") - sepListRaw, err := controller.decortAPICall("POST", sepListAPI, urlValues) + sepListRaw, err := c.DecortAPICall("POST", sepListAPI, urlValues) if err != nil { return nil, err } diff --git a/decort/utility_sep_pool.go b/internal/service/cloudbroker/sep/utility_sep_pool.go similarity index 59% rename from decort/utility_sep_pool.go rename to internal/service/cloudbroker/sep/utility_sep_pool.go index 048bc4b..a9064fc 100644 --- a/decort/utility_sep_pool.go +++ b/internal/service/cloudbroker/sep/utility_sep_pool.go @@ -1,6 +1,8 @@ /* Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Stanislav Solovev, , +Authors: +Petr Krutov, +Stanislav Solovev, Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,26 +18,32 @@ limitations under the License. */ /* -This file is part of Terraform (by Hashicorp) provider for Digital Energy Cloud Orchestration -Technology platfom. +Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud +Orchestration Technology) with Terraform by Hashicorp. -Visit https://github.com/rudecs/terraform-provider-decort for full source code package and updates. +Source code: https://github.com/rudecs/terraform-provider-decort + +Please see README.md to learn where to place source code so that it +builds seamlessly. + +Documentation: https://github.com/rudecs/terraform-provider-decort/wiki */ -package decort +package sep import ( "encoding/json" "net/url" "strconv" + "github.com/rudecs/terraform-provider-decort/internal/controller" log "github.com/sirupsen/logrus" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool, error) { - controller := m.(*ControllerCfg) + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sepPool := SepPool{} @@ -44,7 +52,7 @@ func utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool urlValues.Add("pool_name", d.Get("pool_name").(string)) log.Debugf("utilitySepDesPoolCheckPresence: load sep") - sepPoolRaw, err := controller.decortAPICall("POST", sepGetPoolAPI, urlValues) + sepPoolRaw, err := c.DecortAPICall("POST", sepGetPoolAPI, urlValues) if err != nil { return nil, err } From 9a7642cf332bf3971a13e9eaa63ae3a584d65b0c Mon Sep 17 00:00:00 2001 From: stSolo Date: Wed, 29 Jun 2022 16:22:31 +0300 Subject: [PATCH 3/3] Add context to DecortAPICall method --- go.mod | 1 + internal/controller/controller.go | 3 +- internal/location/location.go | 5 +- internal/provider/provider.go | 5 +- .../cloudapi/account/data_source_account.go | 2 +- .../data_source_account_audits_list.go | 2 +- .../data_source_account_computes_list.go | 2 +- .../data_source_account_consumed_units.go | 2 +- ...a_source_account_consumed_units_by_type.go | 2 +- .../data_source_account_deleted_list.go | 2 +- .../account/data_source_account_disks_list.go | 2 +- .../data_source_account_flipgroups_list.go | 2 +- .../account/data_source_account_list.go | 2 +- .../data_source_account_reserved_units.go | 2 +- .../account/data_source_account_rg_list.go | 2 +- .../data_source_account_templates_list.go | 2 +- .../account/data_source_account_vins_list.go | 2 +- .../cloudapi/account/resource_account.go | 31 +++++----- .../cloudapi/account/utility_account.go | 5 +- .../account/utility_account_audits_list.go | 5 +- .../account/utility_account_computes_list.go | 5 +- .../account/utility_account_consumed_units.go | 5 +- .../utility_account_consumed_units_by_type.go | 5 +- .../account/utility_account_deleted_list.go | 5 +- .../account/utility_account_disks_list.go | 5 +- .../account/utility_account_flip_groups.go | 5 +- .../cloudapi/account/utility_account_list.go | 5 +- .../account/utility_account_reserved_units.go | 5 +- .../account/utility_account_rg_list.go | 5 +- .../account/utility_account_templates_list.go | 5 +- .../account/utility_account_vins_list.go | 5 +- .../cloudapi/bservice/data_source_bservice.go | 2 +- .../data_source_bservice_deleted_list.go | 2 +- .../bservice/data_source_bservice_group.go | 2 +- .../bservice/data_source_bservice_list.go | 2 +- .../data_source_bservice_snapshot_list.go | 2 +- .../cloudapi/bservice/resource_bservice.go | 27 +++++---- .../bservice/resource_bservice_group.go | 31 +++++----- .../utility_bservicce_deleted_list.go | 5 +- .../cloudapi/bservice/utility_bservice.go | 5 +- .../bservice/utility_bservice_group.go | 5 +- .../bservice/utility_bservice_list.go | 5 +- .../utility_bservice_snapshot_list.go | 5 +- .../cloudapi/disks/data_source_disk.go | 2 +- .../cloudapi/disks/data_source_disk_list.go | 2 +- .../service/cloudapi/disks/resource_disk.go | 17 +++--- .../service/cloudapi/disks/utility_disk.go | 7 ++- .../cloudapi/disks/utility_disk_list.go | 5 +- .../cloudapi/extnet/data_source_extnet.go | 2 +- .../data_source_extnet_computes_list.go | 2 +- .../extnet/data_source_extnet_default.go | 2 +- .../extnet/data_source_extnet_list.go | 2 +- .../service/cloudapi/extnet/utility_extnet.go | 5 +- .../extnet/utility_extnet_computes_list.go | 5 +- .../cloudapi/extnet/utility_extnet_default.go | 5 +- .../cloudapi/extnet/utility_extnet_list.go | 5 +- internal/service/cloudapi/k8s/resource_k8s.go | 33 +++++------ .../service/cloudapi/k8s/resource_k8s_wg.go | 19 +++--- internal/service/cloudapi/k8s/utility_k8s.go | 5 +- .../service/cloudapi/k8s/utility_k8s_wg.go | 5 +- .../cloudapi/kvmvm/data_source_compute.go | 2 +- .../cloudapi/kvmvm/resource_compute.go | 58 ++++++------------- .../service/cloudapi/kvmvm/utility_compute.go | 25 ++++---- internal/service/cloudapi/pfw/resource_pfw.go | 15 +++-- internal/service/cloudapi/pfw/utility_pfw.go | 5 +- .../service/cloudapi/rg/data_source_rg.go | 2 +- .../cloudapi/rg/data_source_rg_list.go | 2 +- internal/service/cloudapi/rg/resource_rg.go | 17 +++--- internal/service/cloudapi/rg/utility_rg.go | 9 +-- .../service/cloudapi/rg/utility_rg_list.go | 5 +- .../snapshot/data_source_snapshot_list.go | 2 +- .../cloudapi/snapshot/resource_snapshot.go | 17 +++--- .../cloudapi/snapshot/utility_snapshot.go | 5 +- .../snapshot/utility_snapshot_list.go | 5 +- .../service/cloudapi/vgpu/data_source_vgpu.go | 2 +- .../service/cloudapi/vgpu/utility_vgpu.go | 5 +- .../service/cloudapi/vins/data_source_vins.go | 2 +- .../cloudapi/vins/data_source_vins_list.go | 2 +- .../service/cloudapi/vins/resource_vins.go | 17 +++--- .../service/cloudapi/vins/utility_vins.go | 9 +-- .../cloudapi/vins/utility_vins_list.go | 5 +- .../cloudbroker/grid/data_source_grid.go | 2 +- .../cloudbroker/grid/data_source_grid_list.go | 2 +- .../service/cloudbroker/grid/utility_grid.go | 5 +- .../cloudbroker/grid/utility_grid_list.go | 5 +- .../cloudbroker/image/data_source_image.go | 2 +- .../image/data_source_image_list.go | 2 +- .../image/data_source_image_list_stacks.go | 2 +- .../cloudbroker/image/resource_cdrom_image.go | 9 ++- .../image/resource_delete_images.go | 2 +- .../cloudbroker/image/resource_image.go | 53 +++++++++-------- .../image/resource_virtual_image.go | 5 +- .../cloudbroker/image/utility_image.go | 5 +- .../cloudbroker/image/utility_image_list.go | 5 +- .../image/utility_image_list_stacks.go | 5 +- .../pcidevice/data_source_pcidevice.go | 2 +- .../pcidevice/data_source_pcidevice_list.go | 2 +- .../pcidevice/resource_pcidevice.go | 15 +++-- .../pcidevice/utility_pcidevice.go | 5 +- .../pcidevice/utility_pcidevice_list.go | 5 +- .../cloudbroker/sep/data_source_sep.go | 2 +- .../cloudbroker/sep/data_source_sep_config.go | 2 +- .../sep/data_source_sep_consumption.go | 2 +- .../sep/data_source_sep_disk_list.go | 2 +- .../cloudbroker/sep/data_source_sep_list.go | 2 +- .../cloudbroker/sep/data_source_sep_pool.go | 2 +- .../service/cloudbroker/sep/resource_sep.go | 43 +++++++------- .../cloudbroker/sep/resource_sep_config.go | 15 +++-- .../service/cloudbroker/sep/utility_sep.go | 5 +- .../cloudbroker/sep/utility_sep_config.go | 5 +- .../sep/utility_sep_consumption.go | 5 +- .../cloudbroker/sep/utility_sep_disk_list.go | 5 +- .../cloudbroker/sep/utility_sep_list.go | 5 +- .../cloudbroker/sep/utility_sep_pool.go | 5 +- 114 files changed, 406 insertions(+), 390 deletions(-) diff --git a/go.mod b/go.mod index 8663324..1028826 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,5 @@ require ( github.com/hashicorp/terraform-plugin-docs v0.5.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0 // indirect github.com/sirupsen/logrus v1.7.0 + golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect ) diff --git a/internal/controller/controller.go b/internal/controller/controller.go index d36389e..ca9d3e3 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -21,6 +21,7 @@ package controller import ( "bytes" + "context" "crypto/tls" "fmt" "io/ioutil" @@ -325,7 +326,7 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) { return true, nil } -func (config *ControllerCfg) DecortAPICall(method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam +func (config *ControllerCfg) DecortAPICall(ctx context.Context, method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam // This is a convenience wrapper around standard HTTP request methods that is aware of the // authorization mode for which the provider was initialized and compiles request accordingly. diff --git a/internal/location/location.go b/internal/location/location.go index a5333a9..8305d5f 100644 --- a/internal/location/location.go +++ b/internal/location/location.go @@ -20,6 +20,7 @@ limitations under the License. package location import ( + "context" "encoding/json" "fmt" "net/url" @@ -30,13 +31,13 @@ import ( var DefaultGridID int -func UtilityLocationGetDefaultGridID(m interface{}) (int, error) { +func UtilityLocationGetDefaultGridID(ctx context.Context, m interface{}) (int, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} log.Debug("utilityLocationGetDefaultGridID: retrieving locations list") - apiResp, err := c.DecortAPICall("POST", LocationsListAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", LocationsListAPI, urlValues) if err != nil { return 0, err } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index ec3d24d..c6c76f1 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -25,6 +25,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "golang.org/x/net/context" "github.com/rudecs/terraform-provider-decort/internal/controller" "github.com/rudecs/terraform-provider-decort/internal/location" @@ -122,7 +123,9 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { return nil, err } - gridId, err := location.UtilityLocationGetDefaultGridID(decsController) + ctx := context.Background() + + gridId, err := location.UtilityLocationGetDefaultGridID(ctx, decsController) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/data_source_account.go b/internal/service/cloudapi/account/data_source_account.go index 85f4003..f3b2c6e 100644 --- a/internal/service/cloudapi/account/data_source_account.go +++ b/internal/service/cloudapi/account/data_source_account.go @@ -42,7 +42,7 @@ import ( ) func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - acc, err := utilityAccountCheckPresence(d, m) + acc, err := utilityAccountCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_audits_list.go b/internal/service/cloudapi/account/data_source_account_audits_list.go index 6351c70..d904d12 100644 --- a/internal/service/cloudapi/account/data_source_account_audits_list.go +++ b/internal/service/cloudapi/account/data_source_account_audits_list.go @@ -57,7 +57,7 @@ func flattenAccountAuditsList(aal AccountAuditsList) []map[string]interface{} { } func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountAuditsList, err := utilityAccountAuditsListCheckPresence(d, m) + accountAuditsList, err := utilityAccountAuditsListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_computes_list.go b/internal/service/cloudapi/account/data_source_account_computes_list.go index 9828c2a..39eda42 100644 --- a/internal/service/cloudapi/account/data_source_account_computes_list.go +++ b/internal/service/cloudapi/account/data_source_account_computes_list.go @@ -72,7 +72,7 @@ func flattenAccountComputesList(acl AccountComputesList) []map[string]interface{ } func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountComputesList, err := utilityAccountComputesListCheckPresence(d, m) + accountComputesList, err := utilityAccountComputesListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_consumed_units.go b/internal/service/cloudapi/account/data_source_account_consumed_units.go index 52b9f19..bfcc492 100644 --- a/internal/service/cloudapi/account/data_source_account_consumed_units.go +++ b/internal/service/cloudapi/account/data_source_account_consumed_units.go @@ -41,7 +41,7 @@ import ( ) func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(d, m) + accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_consumed_units_by_type.go b/internal/service/cloudapi/account/data_source_account_consumed_units_by_type.go index 877608e..1528efb 100644 --- a/internal/service/cloudapi/account/data_source_account_consumed_units_by_type.go +++ b/internal/service/cloudapi/account/data_source_account_consumed_units_by_type.go @@ -41,7 +41,7 @@ import ( ) func dataSourceAccountConsumedUnitsByTypeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - result, err := utilityAccountConsumedUnitsByTypeCheckPresence(d, m) + result, err := utilityAccountConsumedUnitsByTypeCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_deleted_list.go b/internal/service/cloudapi/account/data_source_account_deleted_list.go index 0dc1d3f..04120b4 100644 --- a/internal/service/cloudapi/account/data_source_account_deleted_list.go +++ b/internal/service/cloudapi/account/data_source_account_deleted_list.go @@ -41,7 +41,7 @@ import ( ) func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountDeletedList, err := utilityAccountDeletedListCheckPresence(d, m) + accountDeletedList, err := utilityAccountDeletedListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_disks_list.go b/internal/service/cloudapi/account/data_source_account_disks_list.go index 9871eed..fcc12b3 100644 --- a/internal/service/cloudapi/account/data_source_account_disks_list.go +++ b/internal/service/cloudapi/account/data_source_account_disks_list.go @@ -57,7 +57,7 @@ func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} { } func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountDisksList, err := utilityAccountDisksListCheckPresence(d, m) + accountDisksList, err := utilityAccountDisksListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_flipgroups_list.go b/internal/service/cloudapi/account/data_source_account_flipgroups_list.go index 09bc65b..3bcc489 100644 --- a/internal/service/cloudapi/account/data_source_account_flipgroups_list.go +++ b/internal/service/cloudapi/account/data_source_account_flipgroups_list.go @@ -73,7 +73,7 @@ func flattenAccountFlipGroupsList(afgl AccountFlipGroupsList) []map[string]inter } func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(d, m) + accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_list.go b/internal/service/cloudapi/account/data_source_account_list.go index df625d0..d5370df 100644 --- a/internal/service/cloudapi/account/data_source_account_list.go +++ b/internal/service/cloudapi/account/data_source_account_list.go @@ -119,7 +119,7 @@ func flattenAccountList(al AccountList) []map[string]interface{} { */ func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountList, err := utilityAccountListCheckPresence(d, m) + accountList, err := utilityAccountListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_reserved_units.go b/internal/service/cloudapi/account/data_source_account_reserved_units.go index d708129..3d345ea 100644 --- a/internal/service/cloudapi/account/data_source_account_reserved_units.go +++ b/internal/service/cloudapi/account/data_source_account_reserved_units.go @@ -41,7 +41,7 @@ import ( ) func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(d, m) + accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_rg_list.go b/internal/service/cloudapi/account/data_source_account_rg_list.go index 29f885f..c9b94d4 100644 --- a/internal/service/cloudapi/account/data_source_account_rg_list.go +++ b/internal/service/cloudapi/account/data_source_account_rg_list.go @@ -86,7 +86,7 @@ func flattenAccRGResources(argr AccountRGResources) []map[string]interface{} { } func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountRGList, err := utilityAccountRGListCheckPresence(d, m) + accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_templates_list.go b/internal/service/cloudapi/account/data_source_account_templates_list.go index 113d9a7..92a6293 100644 --- a/internal/service/cloudapi/account/data_source_account_templates_list.go +++ b/internal/service/cloudapi/account/data_source_account_templates_list.go @@ -62,7 +62,7 @@ func flattenAccountTemplatesList(atl AccountTemplatesList) []map[string]interfac } func dataSourceAccountTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(d, m) + accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/data_source_account_vins_list.go b/internal/service/cloudapi/account/data_source_account_vins_list.go index 6542018..b631e35 100644 --- a/internal/service/cloudapi/account/data_source_account_vins_list.go +++ b/internal/service/cloudapi/account/data_source_account_vins_list.go @@ -69,7 +69,7 @@ func flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} { } func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - accountVinsList, err := utilityAccountVinsListCheckPresence(d, m) + accountVinsList, err := utilityAccountVinsListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/account/resource_account.go b/internal/service/cloudapi/account/resource_account.go index 14a1222..5aa57f7 100644 --- a/internal/service/cloudapi/account/resource_account.go +++ b/internal/service/cloudapi/account/resource_account.go @@ -50,7 +50,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf log.Debugf("resourceAccountCreate") if accountId, ok := d.GetOk("account_id"); ok { - if exists, err := resourceAccountExists(d, m); exists { + if exists, err := resourceAccountExists(ctx, d, m); exists { if err != nil { return diag.FromErr(err) } @@ -133,7 +133,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf } } - accountId, err := c.DecortAPICall("POST", accountCreateAPI, urlValues) + accountId, err := c.DecortAPICall(ctx, "POST", accountCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -155,7 +155,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceAccountRead") - acc, err := utilityAccountCheckPresence(d, m) + acc, err := utilityAccountCheckPresence(ctx, d, m) if acc == nil { d.SetId("") return diag.FromErr(err) @@ -194,7 +194,7 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interfac func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceAccountDelete") - account, err := utilityAccountCheckPresence(d, m) + account, err := utilityAccountCheckPresence(ctx, d, m) if account == nil { if err != nil { return diag.FromErr(err) @@ -207,7 +207,7 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool))) - _, err = c.DecortAPICall("POST", accountDeleteAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", accountDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -216,10 +216,10 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf return nil } -func resourceAccountExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceAccountExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceAccountExists") - account, err := utilityAccountCheckPresence(d, m) + account, err := utilityAccountCheckPresence(ctx, d, m) if account == nil { if err != nil { return false, err @@ -243,7 +243,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac } urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.DecortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return diag.FromErr(err) } @@ -254,7 +254,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac if d.HasChange("account_name") { urlValues.Add("name", d.Get("account_name").(string)) urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -318,7 +318,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac } urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -329,7 +329,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac if d.HasChange("send_access_emails") { urlValues.Add("sendAccessEmails", strconv.FormatBool(d.Get("send_access_emails").(bool))) urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -341,7 +341,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac restore := d.Get("restore").(bool) if restore { urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) - _, err := c.DecortAPICall("POST", accountRestoreAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", accountRestoreAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -379,7 +379,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("userId", userConv["user_id"].(string)) urlValues.Add("recursivedelete", strconv.FormatBool(userConv["recursive_delete"].(bool))) - _, err := c.DecortAPICall("POST", accountDeleteUserAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", accountDeleteUserAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -394,7 +394,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("userId", userConv["user_id"].(string)) urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string))) - _, err := c.DecortAPICall("POST", accountAddUserAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", accountAddUserAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -409,7 +409,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) urlValues.Add("userId", userConv["user_id"].(string)) urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string))) - _, err := c.DecortAPICall("POST", accountUpdateUserAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", accountUpdateUserAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -786,7 +786,6 @@ func ResourceAccount() *schema.Resource { ReadContext: resourceAccountRead, UpdateContext: resourceAccountEdit, DeleteContext: resourceAccountDelete, - Exists: resourceAccountExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/account/utility_account.go b/internal/service/cloudapi/account/utility_account.go index 5d89df6..092162b 100644 --- a/internal/service/cloudapi/account/utility_account.go +++ b/internal/service/cloudapi/account/utility_account.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (*AccountWithResources, error) { +func utilityAccountCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*AccountWithResources, error) { account := &AccountWithResources{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -54,7 +55,7 @@ func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (*Accoun } log.Debugf("utilityAccountCheckPresence: load account") - accountRaw, err := c.DecortAPICall("POST", accountGetAPI, urlValues) + accountRaw, err := c.DecortAPICall(ctx, "POST", accountGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_audits_list.go b/internal/service/cloudapi/account/utility_account_audits_list.go index dc61dc8..c89cedd 100644 --- a/internal/service/cloudapi/account/utility_account_audits_list.go +++ b/internal/service/cloudapi/account/utility_account_audits_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountAuditsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountAuditsList, error) { +func utilityAccountAuditsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountAuditsList, error) { accountAuditsList := AccountAuditsList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountAuditsListCheckPresence(d *schema.ResourceData, m interface{} urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountAuditsListCheckPresence: load account list") - accountAuditsListRaw, err := c.DecortAPICall("POST", accountAuditsAPI, urlValues) + accountAuditsListRaw, err := c.DecortAPICall(ctx, "POST", accountAuditsAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_computes_list.go b/internal/service/cloudapi/account/utility_account_computes_list.go index 957af49..9b746da 100644 --- a/internal/service/cloudapi/account/utility_account_computes_list.go +++ b/internal/service/cloudapi/account/utility_account_computes_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountComputesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountComputesList, error) { +func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountComputesList, error) { accountComputesList := AccountComputesList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountComputesListCheckPresence(d *schema.ResourceData, m interface urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountComputesListCheckPresence: load account list") - accountComputesListRaw, err := c.DecortAPICall("POST", accountListComputesAPI, urlValues) + accountComputesListRaw, err := c.DecortAPICall(ctx, "POST", accountListComputesAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_consumed_units.go b/internal/service/cloudapi/account/utility_account_consumed_units.go index 295a4fe..5c610fb 100644 --- a/internal/service/cloudapi/account/utility_account_consumed_units.go +++ b/internal/service/cloudapi/account/utility_account_consumed_units.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountConsumedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { +func utilityAccountConsumedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { accountConsumedUnits := &ResourceLimits{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountConsumedUnitsCheckPresence(d *schema.ResourceData, m interfac urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountConsumedUnitsCheckPresence: load account list") - accountConsumedUnitsRaw, err := c.DecortAPICall("POST", accountGetConsumedUnitsAPI, urlValues) + accountConsumedUnitsRaw, err := c.DecortAPICall(ctx, "POST", accountGetConsumedUnitsAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_consumed_units_by_type.go b/internal/service/cloudapi/account/utility_account_consumed_units_by_type.go index f102c01..1dc9d6b 100644 --- a/internal/service/cloudapi/account/utility_account_consumed_units_by_type.go +++ b/internal/service/cloudapi/account/utility_account_consumed_units_by_type.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "net/url" "strconv" "strings" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountConsumedUnitsByTypeCheckPresence(d *schema.ResourceData, m interface{}) (float64, error) { +func utilityAccountConsumedUnitsByTypeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (float64, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountConsumedUnitsByTypeCheckPresence(d *schema.ResourceData, m in urlValues.Add("cutype", strings.ToUpper(d.Get("cu_type").(string))) log.Debugf("utilityAccountConsumedUnitsByTypeCheckPresence") - resultRaw, err := c.DecortAPICall("POST", accountGetConsumedUnitsByTypeAPI, urlValues) + resultRaw, err := c.DecortAPICall(ctx, "POST", accountGetConsumedUnitsByTypeAPI, urlValues) if err != nil { return 0, err } diff --git a/internal/service/cloudapi/account/utility_account_deleted_list.go b/internal/service/cloudapi/account/utility_account_deleted_list.go index 2395001..f9a8b50 100644 --- a/internal/service/cloudapi/account/utility_account_deleted_list.go +++ b/internal/service/cloudapi/account/utility_account_deleted_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { +func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { accountDeletedList := AccountCloudApiList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{ } log.Debugf("utilityAccountDeletedListCheckPresence: load") - accountDeletedListRaw, err := c.DecortAPICall("POST", accountListDeletedAPI, urlValues) + accountDeletedListRaw, err := c.DecortAPICall(ctx, "POST", accountListDeletedAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_disks_list.go b/internal/service/cloudapi/account/utility_account_disks_list.go index 4c0dbd3..7cea8a2 100644 --- a/internal/service/cloudapi/account/utility_account_disks_list.go +++ b/internal/service/cloudapi/account/utility_account_disks_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountDisksListCheckPresence(d *schema.ResourceData, m interface{}) (AccountDisksList, error) { +func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountDisksList, error) { accountDisksList := AccountDisksList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountDisksListCheckPresence(d *schema.ResourceData, m interface{}) urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountDisksListCheckPresence: load account list") - accountDisksListRaw, err := c.DecortAPICall("POST", accountListDisksAPI, urlValues) + accountDisksListRaw, err := c.DecortAPICall(ctx, "POST", accountListDisksAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_flip_groups.go b/internal/service/cloudapi/account/utility_account_flip_groups.go index d2862b5..1585f6b 100644 --- a/internal/service/cloudapi/account/utility_account_flip_groups.go +++ b/internal/service/cloudapi/account/utility_account_flip_groups.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountFlipGroupsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountFlipGroupsList, error) { +func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountFlipGroupsList, error) { accountFlipGroupsList := AccountFlipGroupsList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountFlipGroupsListCheckPresence(d *schema.ResourceData, m interfa urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountFlipGroupsListCheckPresence") - accountFlipGroupsListRaw, err := c.DecortAPICall("POST", accountListFlipGroupsAPI, urlValues) + accountFlipGroupsListRaw, err := c.DecortAPICall(ctx, "POST", accountListFlipGroupsAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_list.go b/internal/service/cloudapi/account/utility_account_list.go index 3d814ff..2eb7d36 100644 --- a/internal/service/cloudapi/account/utility_account_list.go +++ b/internal/service/cloudapi/account/utility_account_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { +func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) { accountList := AccountCloudApiList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (Acc } log.Debugf("utilityAccountListCheckPresence: load account list") - accountListRaw, err := c.DecortAPICall("POST", accountListAPI, urlValues) + accountListRaw, err := c.DecortAPICall(ctx, "POST", accountListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_reserved_units.go b/internal/service/cloudapi/account/utility_account_reserved_units.go index 599964c..5474a12 100644 --- a/internal/service/cloudapi/account/utility_account_reserved_units.go +++ b/internal/service/cloudapi/account/utility_account_reserved_units.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountReservedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { +func utilityAccountReservedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ResourceLimits, error) { accountReservedUnits := &ResourceLimits{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountReservedUnitsCheckPresence(d *schema.ResourceData, m interfac urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountReservedUnitsCheckPresence: load units") - accountReservedUnitsRaw, err := c.DecortAPICall("POST", accountGetReservedUnitsAPI, urlValues) + accountReservedUnitsRaw, err := c.DecortAPICall(ctx, "POST", accountGetReservedUnitsAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_rg_list.go b/internal/service/cloudapi/account/utility_account_rg_list.go index 266ba1c..41c1a76 100644 --- a/internal/service/cloudapi/account/utility_account_rg_list.go +++ b/internal/service/cloudapi/account/utility_account_rg_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountRGListCheckPresence(d *schema.ResourceData, m interface{}) (AccountRGList, error) { +func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountRGList, error) { accountRGList := AccountRGList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountRGListCheckPresence(d *schema.ResourceData, m interface{}) (A urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountRGListCheckPresence: load account list") - accountRGListRaw, err := c.DecortAPICall("POST", accountListRGAPI, urlValues) + accountRGListRaw, err := c.DecortAPICall(ctx, "POST", accountListRGAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_templates_list.go b/internal/service/cloudapi/account/utility_account_templates_list.go index 76f9930..47c13db 100644 --- a/internal/service/cloudapi/account/utility_account_templates_list.go +++ b/internal/service/cloudapi/account/utility_account_templates_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountTemplatesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountTemplatesList, error) { +func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountTemplatesList, error) { accountTemplatesList := AccountTemplatesList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountTemplatesListCheckPresence(d *schema.ResourceData, m interfac urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountTemplatesListCheckPresence: load") - accountTemplatesListRaw, err := c.DecortAPICall("POST", accountListTemplatesAPI, urlValues) + accountTemplatesListRaw, err := c.DecortAPICall(ctx, "POST", accountListTemplatesAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/account/utility_account_vins_list.go b/internal/service/cloudapi/account/utility_account_vins_list.go index 72fc5d6..db2e931 100644 --- a/internal/service/cloudapi/account/utility_account_vins_list.go +++ b/internal/service/cloudapi/account/utility_account_vins_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package account import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityAccountVinsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountVinsList, error) { +func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountVinsList, error) { accountVinsList := AccountVinsList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityAccountVinsListCheckPresence(d *schema.ResourceData, m interface{}) urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityAccountVinsListCheckPresence: load account list") - accountVinsListRaw, err := c.DecortAPICall("POST", accountListVinsAPI, urlValues) + accountVinsListRaw, err := c.DecortAPICall(ctx, "POST", accountListVinsAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/bservice/data_source_bservice.go b/internal/service/cloudapi/bservice/data_source_bservice.go index ef1fc17..513e0b9 100644 --- a/internal/service/cloudapi/bservice/data_source_bservice.go +++ b/internal/service/cloudapi/bservice/data_source_bservice.go @@ -41,7 +41,7 @@ import ( ) func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - bs, err := utilityBasicServiceCheckPresence(d, m) + bs, err := utilityBasicServiceCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go b/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go index 4341c43..9be56bf 100644 --- a/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_deleted_list.go @@ -41,7 +41,7 @@ import ( ) func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(d, m) + basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/bservice/data_source_bservice_group.go b/internal/service/cloudapi/bservice/data_source_bservice_group.go index f333d1c..eaac251 100644 --- a/internal/service/cloudapi/bservice/data_source_bservice_group.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_group.go @@ -41,7 +41,7 @@ import ( ) func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - bsg, err := utilityBasicServiceGroupCheckPresence(d, m) + bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/bservice/data_source_bservice_list.go b/internal/service/cloudapi/bservice/data_source_bservice_list.go index d3b2e43..0a367a7 100644 --- a/internal/service/cloudapi/bservice/data_source_bservice_list.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_list.go @@ -73,7 +73,7 @@ func flattenBasicServiceList(bsl BasicServiceList) []map[string]interface{} { } func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - basicServiceList, err := utilityBasicServiceListCheckPresence(d, m) + basicServiceList, err := utilityBasicServiceListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go b/internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go index 93fe820..ab601e2 100644 --- a/internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go +++ b/internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go @@ -41,7 +41,7 @@ import ( ) func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(d, m) + basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/bservice/resource_bservice.go b/internal/service/cloudapi/bservice/resource_bservice.go index 7456728..9ce62e4 100644 --- a/internal/service/cloudapi/bservice/resource_bservice.go +++ b/internal/service/cloudapi/bservice/resource_bservice.go @@ -48,7 +48,7 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i log.Debugf("resourceBasicServiceCreate") if serviceId, ok := d.GetOk("service_id"); ok { - if exists, err := resourceBasicServiceExists(d, m); exists { + if exists, err := resourceBasicServiceExists(ctx, d, m); exists { if err != nil { return diag.FromErr(err) } @@ -78,7 +78,7 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i urlValues.Add("sshUser", sshUser.(string)) } - serviceId, err := c.DecortAPICall("POST", bserviceCreateAPI, urlValues) + serviceId, err := c.DecortAPICall(ctx, "POST", bserviceCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -100,7 +100,7 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceRead") - bs, err := utilityBasicServiceCheckPresence(d, m) + bs, err := utilityBasicServiceCheckPresence(ctx, d, m) if bs == nil { d.SetId("") return diag.FromErr(err) @@ -143,7 +143,7 @@ func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m int func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceDelete") - bs, err := utilityBasicServiceCheckPresence(d, m) + bs, err := utilityBasicServiceCheckPresence(ctx, d, m) if bs == nil { if err != nil { return diag.FromErr(err) @@ -156,7 +156,7 @@ func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m i urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool))) - _, err = c.DecortAPICall("POST", bserviceDeleteAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", bserviceDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -165,10 +165,10 @@ func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m i return nil } -func resourceBasicServiceExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceBasicServiceExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceBasicServiceExists") - bservice, err := utilityBasicServiceCheckPresence(d, m) + bservice, err := utilityBasicServiceCheckPresence(ctx, d, m) if bservice == nil { if err != nil { return false, err @@ -192,7 +192,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int } urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) - _, err := c.DecortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return diag.FromErr(err) } @@ -204,7 +204,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int restore := d.Get("restore").(bool) if restore { urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) - _, err := c.DecortAPICall("POST", bserviceRestoreAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceRestoreAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -221,7 +221,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int } urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) - _, err := c.DecortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return diag.FromErr(err) } @@ -257,7 +257,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int snapshotConv := snapshot.(map[string]interface{}) urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("label", snapshotConv["label"].(string)) - _, err := c.DecortAPICall("POST", bserviceSnapshotDeleteAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -271,7 +271,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int snapshotConv := snapshot.(map[string]interface{}) urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("label", snapshotConv["label"].(string)) - _, err := c.DecortAPICall("POST", bserviceSnapshotCreateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -285,7 +285,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int snapshotConv := snapshot.(map[string]interface{}) urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("label", snapshotConv["label"].(string)) - _, err := c.DecortAPICall("POST", bserviceSnapshotRollbackAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotRollbackAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -545,7 +545,6 @@ func ResourceBasicService() *schema.Resource { ReadContext: resourceBasicServiceRead, UpdateContext: resourceBasicServiceEdit, DeleteContext: resourceBasicServiceDelete, - Exists: resourceBasicServiceExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/bservice/resource_bservice_group.go b/internal/service/cloudapi/bservice/resource_bservice_group.go index aa2d5a3..47271c8 100644 --- a/internal/service/cloudapi/bservice/resource_bservice_group.go +++ b/internal/service/cloudapi/bservice/resource_bservice_group.go @@ -51,7 +51,7 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData if compgroupId, ok := d.GetOk("compgroup_id"); ok { if _, ok := d.GetOk("service_id"); ok { - if exists, err := resourceBasicServiceGroupExists(d, m); exists { + if exists, err := resourceBasicServiceGroupExists(ctx, d, m); exists { if err != nil { return diag.FromErr(err) } @@ -119,7 +119,7 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData urlValues.Add("extnets", temp) } - compgroupId, err := c.DecortAPICall("POST", bserviceGroupAddAPI, urlValues) + compgroupId, err := c.DecortAPICall(ctx, "POST", bserviceGroupAddAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -141,7 +141,7 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceGroupRead") - bsg, err := utilityBasicServiceGroupCheckPresence(d, m) + bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m) if bsg == nil { d.SetId("") return diag.FromErr(err) @@ -185,7 +185,7 @@ func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceBasicServiceGroupDelete") - bsg, err := utilityBasicServiceGroupCheckPresence(d, m) + bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m) if bsg == nil { if err != nil { return diag.FromErr(err) @@ -198,7 +198,7 @@ func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) - _, err = c.DecortAPICall("POST", bserviceGroupRemoveAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", bserviceGroupRemoveAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -207,10 +207,10 @@ func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData return nil } -func resourceBasicServiceGroupExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceBasicServiceGroupExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceBasicServiceGroupExists") - bserviceGroup, err := utilityBasicServiceGroupCheckPresence(d, m) + bserviceGroup, err := utilityBasicServiceGroupCheckPresence(ctx, d, m) if bserviceGroup == nil { if err != nil { return false, err @@ -232,7 +232,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("count", strconv.Itoa(d.Get("comp_count").(int))) urlValues.Add("mode", strings.ToUpper(d.Get("mode").(string))) - _, err := c.DecortAPICall("POST", bserviceGroupResizeAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceGroupResizeAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -251,7 +251,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) - _, err := c.DecortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return diag.FromErr(err) } @@ -270,7 +270,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) - _, err := c.DecortAPICall("POST", bserviceGroupUpdateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -296,7 +296,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("extnets", temp) - _, err := c.DecortAPICall("POST", bserviceGroupUpdateExtnetAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateExtnetAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -322,7 +322,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("vinses", temp) - _, err := c.DecortAPICall("POST", bserviceGroupUpdateVinsAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateVinsAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -356,7 +356,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("parentId", strconv.Itoa(parentConv)) - _, err := c.DecortAPICall("POST", bserviceGroupParentRemoveAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceGroupParentRemoveAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -371,7 +371,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int))) urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("parentId", strconv.Itoa(parentConv)) - _, err := c.DecortAPICall("POST", bserviceGroupParentAddAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceGroupParentAddAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -389,7 +389,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData, urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int))) urlValues.Add("computeId", strconv.Itoa(rc.(int))) - _, err := c.DecortAPICall("POST", bserviceGroupComputeRemoveAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", bserviceGroupComputeRemoveAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -652,7 +652,6 @@ func ResourceBasicServiceGroup() *schema.Resource { ReadContext: resourceBasicServiceGroupRead, UpdateContext: resourceBasicServiceGroupEdit, DeleteContext: resourceBasicServiceGroupDelete, - Exists: resourceBasicServiceGroupExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go b/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go index 29d1b7f..114bda1 100644 --- a/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go +++ b/internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package bservice import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) { +func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceList, error) { basicServiceDeletedList := BasicServiceList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -61,7 +62,7 @@ func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m inter } log.Debugf("utilityBasicServiceDeletedListCheckPresence") - basicServiceDeletedListRaw, err := c.DecortAPICall("POST", bserviceListDeletedAPI, urlValues) + basicServiceDeletedListRaw, err := c.DecortAPICall(ctx, "POST", bserviceListDeletedAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/bservice/utility_bservice.go b/internal/service/cloudapi/bservice/utility_bservice.go index 57ff329..d2fc168 100644 --- a/internal/service/cloudapi/bservice/utility_bservice.go +++ b/internal/service/cloudapi/bservice/utility_bservice.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package bservice import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceExtend, error) { +func utilityBasicServiceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*BasicServiceExtend, error) { bservice := &BasicServiceExtend{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -54,7 +55,7 @@ func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*B } log.Debugf("utilityBasicServiceCheckPresence") - bserviceRaw, err := c.DecortAPICall("POST", bserviceGetAPI, urlValues) + bserviceRaw, err := c.DecortAPICall(ctx, "POST", bserviceGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/bservice/utility_bservice_group.go b/internal/service/cloudapi/bservice/utility_bservice_group.go index b91d2a7..613258c 100644 --- a/internal/service/cloudapi/bservice/utility_bservice_group.go +++ b/internal/service/cloudapi/bservice/utility_bservice_group.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package bservice import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceGroup, error) { +func utilityBasicServiceGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*BasicServiceGroup, error) { bserviceGroup := &BasicServiceGroup{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{} } log.Debugf("utilityBasicServiceGroupCheckPresence") - bserviceGroupRaw, err := c.DecortAPICall("POST", bserviceGroupGetAPI, urlValues) + bserviceGroupRaw, err := c.DecortAPICall(ctx, "POST", bserviceGroupGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/bservice/utility_bservice_list.go b/internal/service/cloudapi/bservice/utility_bservice_list.go index 73ec82d..f828fa3 100644 --- a/internal/service/cloudapi/bservice/utility_bservice_list.go +++ b/internal/service/cloudapi/bservice/utility_bservice_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package bservice import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) { +func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceList, error) { basicServiceList := BasicServiceList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -61,7 +62,7 @@ func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{}) } log.Debugf("utilityBasicServiceListCheckPresence") - basicServiceListRaw, err := c.DecortAPICall("POST", bserviceListAPI, urlValues) + basicServiceListRaw, err := c.DecortAPICall(ctx, "POST", bserviceListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go b/internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go index 3bacdbe..4b7c983 100644 --- a/internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go +++ b/internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package bservice import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceSnapshots, error) { +func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceSnapshots, error) { basicServiceSnapshotList := BasicServiceSnapshots{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -52,7 +53,7 @@ func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m inte } log.Debugf("utilityBasicServiceSnapshotListCheckPresence") - basicServiceSnapshotListRaw, err := c.DecortAPICall("POST", bserviceSnapshotListAPI, urlValues) + basicServiceSnapshotListRaw, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/disks/data_source_disk.go b/internal/service/cloudapi/disks/data_source_disk.go index acaeb0a..46b8cdd 100644 --- a/internal/service/cloudapi/disks/data_source_disk.go +++ b/internal/service/cloudapi/disks/data_source_disk.go @@ -82,7 +82,7 @@ func flattenDisk(d *schema.ResourceData, disk_facts string) error { } func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - disk_facts, err := utilityDiskCheckPresence(d, m) + disk_facts, err := utilityDiskCheckPresence(ctx, d, m) if disk_facts == "" { // if empty string is returned from utilityDiskCheckPresence then there is no // such Disk and err tells so - just return it to the calling party diff --git a/internal/service/cloudapi/disks/data_source_disk_list.go b/internal/service/cloudapi/disks/data_source_disk_list.go index 86914ef..dc73729 100644 --- a/internal/service/cloudapi/disks/data_source_disk_list.go +++ b/internal/service/cloudapi/disks/data_source_disk_list.go @@ -120,7 +120,7 @@ func flattendDiskSnapshotList(sl SnapshotRecordList) []interface{} { } func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - diskList, err := utilityDiskListCheckPresence(d, m) + diskList, err := utilityDiskListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/disks/resource_disk.go b/internal/service/cloudapi/disks/resource_disk.go index b29f199..1fe2b4a 100644 --- a/internal/service/cloudapi/disks/resource_disk.go +++ b/internal/service/cloudapi/disks/resource_disk.go @@ -73,7 +73,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface urlValues.Add("description", argVal.(string)) } - apiResp, err := c.DecortAPICall("POST", DisksCreateAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", DisksCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -91,7 +91,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface } func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - diskFacts, err := utilityDiskCheckPresence(d, m) + diskFacts, err := utilityDiskCheckPresence(ctx, d, m) if diskFacts == "" { // if empty string is returned from utilityDiskCheckPresence then there is no // such Disk and err tells so - just return it to the calling party @@ -121,7 +121,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface sizeParams := &url.Values{} sizeParams.Add("diskId", d.Id()) sizeParams.Add("size", fmt.Sprintf("%d", newSize.(int))) - _, err := c.DecortAPICall("POST", DisksResizeAPI, sizeParams) + _, err := c.DecortAPICall(ctx, "POST", DisksResizeAPI, sizeParams) if err != nil { return diag.FromErr(err) } @@ -137,7 +137,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface renameParams := &url.Values{} renameParams.Add("diskId", d.Id()) renameParams.Add("name", newName.(string)) - _, err := c.DecortAPICall("POST", DisksRenameAPI, renameParams) + _, err := c.DecortAPICall(ctx, "POST", DisksRenameAPI, renameParams) if err != nil { return diag.FromErr(err) } @@ -165,7 +165,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface log.Debugf("resourceDiskDelete: called for Disk ID / name %d / %s, Account ID %d", d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int)) - diskFacts, err := utilityDiskCheckPresence(d, m) + diskFacts, err := utilityDiskCheckPresence(ctx, d, m) if diskFacts == "" { if err != nil { return diag.FromErr(err) @@ -187,7 +187,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface params.Add("permanently", "1") c := m.(*controller.ControllerCfg) - _, err = c.DecortAPICall("POST", DisksDeleteAPI, params) + _, err = c.DecortAPICall(ctx, "POST", DisksDeleteAPI, params) if err != nil { return diag.FromErr(err) } @@ -195,12 +195,12 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface return nil } -func resourceDiskExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceDiskExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { // Reminder: according to Terraform rules, this function should not modify its ResourceData argument log.Debugf("resourceDiskExists: called for Disk ID / name %d / %s, Account ID %d", d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int)) - diskFacts, err := utilityDiskCheckPresence(d, m) + diskFacts, err := utilityDiskCheckPresence(ctx, d, m) if diskFacts == "" { if err != nil { return false, err @@ -320,7 +320,6 @@ func ResourceDisk() *schema.Resource { ReadContext: resourceDiskRead, UpdateContext: resourceDiskUpdate, DeleteContext: resourceDiskDelete, - Exists: resourceDiskExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/disks/utility_disk.go b/internal/service/cloudapi/disks/utility_disk.go index a76edf0..73053a8 100644 --- a/internal/service/cloudapi/disks/utility_disk.go +++ b/internal/service/cloudapi/disks/utility_disk.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package disks import ( + "context" "encoding/json" "fmt" "net/url" @@ -43,7 +44,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, error) { +func utilityDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { // This function tries to locate Disk by one of the following algorithms depending on // the parameters passed: // - if disk ID is specified -> by disk ID @@ -81,7 +82,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er // disk ID is specified, try to get disk instance straight by this ID log.Debugf("utilityDiskCheckPresence: locating disk by its ID %d", theId) urlValues.Add("diskId", fmt.Sprintf("%d", theId)) - diskFacts, err := c.DecortAPICall("POST", DisksGetAPI, urlValues) + diskFacts, err := c.DecortAPICall(ctx, "POST", DisksGetAPI, urlValues) if err != nil { return "", err } @@ -100,7 +101,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er // obtain Account ID by account name - it should not be zero on success urlValues.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int))) - diskFacts, err := c.DecortAPICall("POST", DisksListAPI, urlValues) + diskFacts, err := c.DecortAPICall(ctx, "POST", DisksListAPI, urlValues) if err != nil { return "", err } diff --git a/internal/service/cloudapi/disks/utility_disk_list.go b/internal/service/cloudapi/disks/utility_disk_list.go index 9100172..50d3cf4 100644 --- a/internal/service/cloudapi/disks/utility_disk_list.go +++ b/internal/service/cloudapi/disks/utility_disk_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package disks import ( + "context" "encoding/json" "net/url" "strconv" @@ -43,7 +44,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksListResp, error) { +func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (DisksListResp, error) { diskList := DisksListResp{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -62,7 +63,7 @@ func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksL } log.Debugf("utilityDiskListCheckPresence: load grid list") - diskListRaw, err := c.DecortAPICall("POST", DisksListAPI, urlValues) + diskListRaw, err := c.DecortAPICall(ctx, "POST", DisksListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/extnet/data_source_extnet.go b/internal/service/cloudapi/extnet/data_source_extnet.go index ec16727..9744b3c 100644 --- a/internal/service/cloudapi/extnet/data_source_extnet.go +++ b/internal/service/cloudapi/extnet/data_source_extnet.go @@ -42,7 +42,7 @@ import ( ) func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - e, err := utilityExtnetCheckPresence(d, m) + e, err := utilityExtnetCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/extnet/data_source_extnet_computes_list.go b/internal/service/cloudapi/extnet/data_source_extnet_computes_list.go index 521f2a7..2ab06e4 100644 --- a/internal/service/cloudapi/extnet/data_source_extnet_computes_list.go +++ b/internal/service/cloudapi/extnet/data_source_extnet_computes_list.go @@ -72,7 +72,7 @@ func flattenExtnetComputesList(ecl ExtnetComputesList) []map[string]interface{} } func dataSourceExtnetComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - extnetComputesList, err := utilityExtnetComputesListCheckPresence(d, m) + extnetComputesList, err := utilityExtnetComputesListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/extnet/data_source_extnet_default.go b/internal/service/cloudapi/extnet/data_source_extnet_default.go index bf14365..22463eb 100644 --- a/internal/service/cloudapi/extnet/data_source_extnet_default.go +++ b/internal/service/cloudapi/extnet/data_source_extnet_default.go @@ -42,7 +42,7 @@ import ( ) func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - extnetId, err := utilityExtnetDefaultCheckPresence(d, m) + extnetId, err := utilityExtnetDefaultCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/extnet/data_source_extnet_list.go b/internal/service/cloudapi/extnet/data_source_extnet_list.go index 4d88625..1984b13 100644 --- a/internal/service/cloudapi/extnet/data_source_extnet_list.go +++ b/internal/service/cloudapi/extnet/data_source_extnet_list.go @@ -54,7 +54,7 @@ func flattenExtnetList(el ExtnetList) []map[string]interface{} { } func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - extnetList, err := utilityExtnetListCheckPresence(d, m) + extnetList, err := utilityExtnetListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/extnet/utility_extnet.go b/internal/service/cloudapi/extnet/utility_extnet.go index 037dcf9..b3c05d4 100644 --- a/internal/service/cloudapi/extnet/utility_extnet.go +++ b/internal/service/cloudapi/extnet/utility_extnet.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package extnet import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityExtnetCheckPresence(d *schema.ResourceData, m interface{}) (*ExtnetDetailed, error) { +func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ExtnetDetailed, error) { extnet := &ExtnetDetailed{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityExtnetCheckPresence(d *schema.ResourceData, m interface{}) (*ExtnetD urlValues.Add("net_id", strconv.Itoa(d.Get("net_id").(int))) log.Debugf("utilityExtnetCheckPresence") - extnetRaw, err := c.DecortAPICall("POST", extnetGetAPI, urlValues) + extnetRaw, err := c.DecortAPICall(ctx, "POST", extnetGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/extnet/utility_extnet_computes_list.go b/internal/service/cloudapi/extnet/utility_extnet_computes_list.go index 69f0c5e..68f3d83 100644 --- a/internal/service/cloudapi/extnet/utility_extnet_computes_list.go +++ b/internal/service/cloudapi/extnet/utility_extnet_computes_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package extnet import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityExtnetComputesListCheckPresence(d *schema.ResourceData, m interface{}) (ExtnetComputesList, error) { +func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ExtnetComputesList, error) { extnetComputesList := ExtnetComputesList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityExtnetComputesListCheckPresence(d *schema.ResourceData, m interface{ urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int))) log.Debugf("utilityExtnetComputesListCheckPresence") - extnetComputesListRaw, err := c.DecortAPICall("POST", extnetListComputesAPI, urlValues) + extnetComputesListRaw, err := c.DecortAPICall(ctx, "POST", extnetListComputesAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/extnet/utility_extnet_default.go b/internal/service/cloudapi/extnet/utility_extnet_default.go index cdf6686..7b7257b 100644 --- a/internal/service/cloudapi/extnet/utility_extnet_default.go +++ b/internal/service/cloudapi/extnet/utility_extnet_default.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package extnet import ( + "context" "net/url" "github.com/rudecs/terraform-provider-decort/internal/controller" @@ -40,12 +41,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityExtnetDefaultCheckPresence(_ *schema.ResourceData, m interface{}) (string, error) { +func utilityExtnetDefaultCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} log.Debugf("utilityExtnetDefaultCheckPresence") - res, err := c.DecortAPICall("POST", extnetGetDefaultAPI, urlValues) + res, err := c.DecortAPICall(ctx, "POST", extnetGetDefaultAPI, urlValues) if err != nil { return "", err } diff --git a/internal/service/cloudapi/extnet/utility_extnet_list.go b/internal/service/cloudapi/extnet/utility_extnet_list.go index 56411bf..91b2d5a 100644 --- a/internal/service/cloudapi/extnet/utility_extnet_list.go +++ b/internal/service/cloudapi/extnet/utility_extnet_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package extnet import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityExtnetListCheckPresence(d *schema.ResourceData, m interface{}) (ExtnetList, error) { +func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ExtnetList, error) { extnetList := ExtnetList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -58,7 +59,7 @@ func utilityExtnetListCheckPresence(d *schema.ResourceData, m interface{}) (Extn } log.Debugf("utilityExtnetListCheckPresence") - extnetListRaw, err := c.DecortAPICall("POST", extnetListAPI, urlValues) + extnetListRaw, err := c.DecortAPICall(ctx, "POST", extnetListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/k8s/resource_k8s.go b/internal/service/cloudapi/k8s/resource_k8s.go index 59d240c..a7f6301 100644 --- a/internal/service/cloudapi/k8s/resource_k8s.go +++ b/internal/service/cloudapi/k8s/resource_k8s.go @@ -94,7 +94,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{ //urlValues.Add("desc", desc.(string)) //} - resp, err := c.DecortAPICall("POST", K8sCreateAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", K8sCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -103,7 +103,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{ urlValues.Add("auditId", strings.Trim(resp, `"`)) for { - resp, err := c.DecortAPICall("POST", AsyncTaskGetAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", AsyncTaskGetAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -126,7 +126,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{ time.Sleep(time.Second * 10) } - k8s, err := utilityK8sCheckPresence(d, m) + k8s, err := utilityK8sCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -136,7 +136,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{ urlValues = &url.Values{} urlValues.Add("lbId", strconv.Itoa(k8s.LbID)) - resp, err = c.DecortAPICall("POST", LbGetAPI, urlValues) + resp, err = c.DecortAPICall(ctx, "POST", LbGetAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -150,7 +150,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{ urlValues = &url.Values{} urlValues.Add("k8sId", d.Id()) - kubeconfig, err := c.DecortAPICall("POST", K8sGetConfigAPI, urlValues) + kubeconfig, err := c.DecortAPICall(ctx, "POST", K8sGetConfigAPI, urlValues) if err != nil { log.Warnf("could not get kubeconfig: %v", err) } @@ -162,7 +162,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) - k8s, err := utilityK8sCheckPresence(d, m) + k8s, err := utilityK8sCheckPresence(ctx, d, m) if k8s == nil { d.SetId("") return diag.FromErr(err) @@ -180,7 +180,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) urlValues := &url.Values{} urlValues.Add("lbId", strconv.Itoa(k8s.LbID)) - resp, err := c.DecortAPICall("POST", LbGetAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", LbGetAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -194,7 +194,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) urlValues = &url.Values{} urlValues.Add("k8sId", d.Id()) - kubeconfig, err := c.DecortAPICall("POST", K8sGetConfigAPI, urlValues) + kubeconfig, err := c.DecortAPICall(ctx, "POST", K8sGetConfigAPI, urlValues) if err != nil { log.Warnf("could not get kubeconfig: %v", err) } @@ -213,14 +213,14 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{ urlValues.Add("k8sId", d.Id()) urlValues.Add("name", d.Get("name").(string)) - _, err := c.DecortAPICall("POST", K8sUpdateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", K8sUpdateAPI, urlValues) if err != nil { return diag.FromErr(err) } } if d.HasChange("workers") { - k8s, err := utilityK8sCheckPresence(d, m) + k8s, err := utilityK8sCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -234,13 +234,13 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{ if newWorkers.Num > wg.Num { urlValues.Add("num", strconv.Itoa(newWorkers.Num-wg.Num)) - if _, err := c.DecortAPICall("POST", K8sWorkerAddAPI, urlValues); err != nil { + if _, err := c.DecortAPICall(ctx, "POST", K8sWorkerAddAPI, urlValues); err != nil { return diag.FromErr(err) } } else { for i := wg.Num - 1; i >= newWorkers.Num; i-- { urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID)) - if _, err := c.DecortAPICall("POST", K8sWorkerDeleteAPI, urlValues); err != nil { + if _, err := c.DecortAPICall(ctx, "POST", K8sWorkerDeleteAPI, urlValues); err != nil { return diag.FromErr(err) } } @@ -253,7 +253,7 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{ func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) - k8s, err := utilityK8sCheckPresence(d, m) + k8s, err := utilityK8sCheckPresence(ctx, d, m) if k8s == nil { if err != nil { return diag.FromErr(err) @@ -266,7 +266,7 @@ func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{ urlValues.Add("k8sId", d.Id()) urlValues.Add("permanently", "true") - _, err = c.DecortAPICall("POST", K8sDeleteAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", K8sDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -274,10 +274,10 @@ func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{ return nil } -func resourceK8sExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceK8sExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceK8sExists: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) - k8s, err := utilityK8sCheckPresence(d, m) + k8s, err := utilityK8sCheckPresence(ctx, d, m) if k8s == nil { return false, err } @@ -385,7 +385,6 @@ func ResourceK8s() *schema.Resource { ReadContext: resourceK8sRead, UpdateContext: resourceK8sUpdate, DeleteContext: resourceK8sDelete, - Exists: resourceK8sExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/k8s/resource_k8s_wg.go b/internal/service/cloudapi/k8s/resource_k8s_wg.go index 420130d..d1eeafb 100644 --- a/internal/service/cloudapi/k8s/resource_k8s_wg.go +++ b/internal/service/cloudapi/k8s/resource_k8s_wg.go @@ -55,7 +55,7 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac urlValues.Add("workerRam", strconv.Itoa(d.Get("ram").(int))) urlValues.Add("workerDisk", strconv.Itoa(d.Get("disk").(int))) - resp, err := c.DecortAPICall("POST", K8sWgCreateAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", K8sWgCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -97,7 +97,7 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int)) - wg, err := utilityK8sWgCheckPresence(d, m) + wg, err := utilityK8sWgCheckPresence(ctx, d, m) if wg == nil { d.SetId("") return diag.FromErr(err) @@ -117,7 +117,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac c := m.(*controller.ControllerCfg) - wg, err := utilityK8sWgCheckPresence(d, m) + wg, err := utilityK8sWgCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -128,14 +128,14 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac if newNum := d.Get("num").(int); newNum > wg.Num { urlValues.Add("num", strconv.Itoa(newNum-wg.Num)) - _, err := c.DecortAPICall("POST", K8sWorkerAddAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", K8sWorkerAddAPI, urlValues) if err != nil { return diag.FromErr(err) } } else { for i := wg.Num - 1; i >= newNum; i-- { urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID)) - _, err := c.DecortAPICall("POST", K8sWorkerDeleteAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", K8sWorkerDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -148,7 +148,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceK8sWgDelete: called with k8s id %d", d.Get("k8s_id").(int)) - wg, err := utilityK8sWgCheckPresence(d, m) + wg, err := utilityK8sWgCheckPresence(ctx, d, m) if wg == nil { if err != nil { return diag.FromErr(err) @@ -161,7 +161,7 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int))) urlValues.Add("workersGroupId", strconv.Itoa(wg.ID)) - _, err = c.DecortAPICall("POST", K8sWgDeleteAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", K8sWgDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -169,10 +169,10 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac return nil } -func resourceK8sWgExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceK8sWgExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceK8sWgExists: called with k8s id %d", d.Get("k8s_id").(int)) - wg, err := utilityK8sWgCheckPresence(d, m) + wg, err := utilityK8sWgCheckPresence(ctx, d, m) if wg == nil { if err != nil { return false, err @@ -240,7 +240,6 @@ func ResourceK8sWg() *schema.Resource { ReadContext: resourceK8sWgRead, UpdateContext: resourceK8sWgUpdate, DeleteContext: resourceK8sWgDelete, - Exists: resourceK8sWgExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/k8s/utility_k8s.go b/internal/service/cloudapi/k8s/utility_k8s.go index b9a5db7..2c4270c 100644 --- a/internal/service/cloudapi/k8s/utility_k8s.go +++ b/internal/service/cloudapi/k8s/utility_k8s.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package k8s import ( + "context" "encoding/json" "net/url" @@ -39,12 +40,12 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilityK8sCheckPresence(d *schema.ResourceData, m interface{}) (*K8sRecord, error) { +func utilityK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8sRecord, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("k8sId", d.Id()) - resp, err := c.DecortAPICall("POST", K8sGetAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", K8sGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/k8s/utility_k8s_wg.go b/internal/service/cloudapi/k8s/utility_k8s_wg.go index e95f6c6..9aef352 100644 --- a/internal/service/cloudapi/k8s/utility_k8s_wg.go +++ b/internal/service/cloudapi/k8s/utility_k8s_wg.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package k8s import ( + "context" "encoding/json" "net/url" "strconv" @@ -40,12 +41,12 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilityK8sWgCheckPresence(d *schema.ResourceData, m interface{}) (*K8sNodeRecord, error) { +func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8sNodeRecord, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int))) - resp, err := c.DecortAPICall("POST", K8sGetAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", K8sGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/kvmvm/data_source_compute.go b/internal/service/cloudapi/kvmvm/data_source_compute.go index 6e66b98..7738409 100644 --- a/internal/service/cloudapi/kvmvm/data_source_compute.go +++ b/internal/service/cloudapi/kvmvm/data_source_compute.go @@ -196,7 +196,7 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error { } func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - compFacts, err := utilityComputeCheckPresence(d, m) + compFacts, err := utilityComputeCheckPresence(ctx, d, m) if compFacts == "" { // if empty string is returned from utilityComputeCheckPresence then there is no // such Compute and err tells so - just return it to the calling party diff --git a/internal/service/cloudapi/kvmvm/resource_compute.go b/internal/service/cloudapi/kvmvm/resource_compute.go index 575c2a8..75dde35 100644 --- a/internal/service/cloudapi/kvmvm/resource_compute.go +++ b/internal/service/cloudapi/kvmvm/resource_compute.go @@ -112,7 +112,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf } } - apiResp, err := c.DecortAPICall("POST", computeCreateAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", computeCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -124,41 +124,26 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf log.Debugf("resourceComputeCreate: new simple Compute ID %d, name %s created", compId, d.Get("name").(string)) // Configure data disks if any - extraDisksOk := true argVal, argSet = d.GetOk("extra_disks") if argSet && argVal.(*schema.Set).Len() > 0 { // urlValues.Add("desc", argVal.(string)) log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len()) - err = utilityComputeExtraDisksConfigure(d, m, false) // do_delta=false, as we are working on a new compute + err = utilityComputeExtraDisksConfigure(ctx, d, m, false) // do_delta=false, as we are working on a new compute if err != nil { log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", compId, err) - extraDisksOk = false + return diag.FromErr(err) } } - if extraDisksOk { - d.SetPartial("extra_disks") - } - // Configure external networks if any - netsOk := true argVal, argSet = d.GetOk("network") if argSet && argVal.(*schema.Set).Len() > 0 { log.Debugf("resourceComputeCreate: calling utilityComputeNetworksConfigure to attach %d network(s)", argVal.(*schema.Set).Len()) - err = utilityComputeNetworksConfigure(d, m, false) // do_delta=false, as we are working on a new compute + err = utilityComputeNetworksConfigure(ctx, d, m, false) // do_delta=false, as we are working on a new compute if err != nil { log.Errorf("resourceComputeCreate: error when attaching networks to a new Compute ID %d: %s", compId, err) - netsOk = false + return diag.FromErr(err) } } - if netsOk { - // there were no errors reported when configuring networks - d.SetPartial("network") - } - - if extraDisksOk && netsOk { - // if there were no errors in setting any of the subresources, we may leave Partial mode - d.Partial(false) - } // Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface), // now we need to start it before we report the sequence complete @@ -166,7 +151,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf reqValues := &url.Values{} reqValues.Add("computeId", fmt.Sprintf("%d", compId)) log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", compId) - if _, err := c.DecortAPICall("POST", ComputeStartAPI, reqValues); err != nil { + if _, err := c.DecortAPICall(ctx, "POST", ComputeStartAPI, reqValues); err != nil { return diag.FromErr(err) } } @@ -184,7 +169,7 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac log.Debugf("resourceComputeRead: called for Compute name %s, RG ID %d", d.Get("name").(string), d.Get("rg_id").(int)) - compFacts, err := utilityComputeCheckPresence(d, m) + compFacts, err := utilityComputeCheckPresence(ctx, d, m) if compFacts == "" { if err != nil { return diag.FromErr(err) @@ -222,8 +207,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf doUpdate := false params.Add("computeId", d.Id()) - d.Partial(true) - oldCpu, newCpu := d.GetChange("cpu") if oldCpu.(int) != newCpu.(int) { params.Add("cpu", fmt.Sprintf("%d", newCpu.(int))) @@ -245,13 +228,10 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf oldCpu.(int), newCpu.(int), oldRam.(int), newRam.(int)) params.Add("force", "true") - _, err := c.DecortAPICall("POST", ComputeResizeAPI, params) + _, err := c.DecortAPICall(ctx, "POST", ComputeResizeAPI, params) if err != nil { return diag.FromErr(err) } - - d.SetPartial("cpu") - d.SetPartial("ram") } // 2. Resize (grow) Boot disk @@ -262,23 +242,22 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf bdsParams.Add("size", fmt.Sprintf("%d", newSize.(int))) log.Debugf("resourceComputeUpdate: compute ID %s, boot disk ID %d resize %d -> %d", d.Id(), d.Get("boot_disk_id").(int), oldSize.(int), newSize.(int)) - _, err := c.DecortAPICall("POST", DisksResizeAPI, bdsParams) + _, err := c.DecortAPICall(ctx, "POST", DisksResizeAPI, bdsParams) if err != nil { return diag.FromErr(err) } - d.SetPartial("boot_disk_size") } else if oldSize.(int) > newSize.(int) { log.Warnf("resourceComputeUpdate: compute ID %s - shrinking boot disk is not allowed", d.Id()) } // 3. Calculate and apply changes to data disks - err := utilityComputeExtraDisksConfigure(d, m, true) // pass do_delta = true to apply changes, if any + err := utilityComputeExtraDisksConfigure(ctx, d, m, true) // pass do_delta = true to apply changes, if any if err != nil { return diag.FromErr(err) } // 4. Calculate and apply changes to network connections - err = utilityComputeNetworksConfigure(d, m, true) // pass do_delta = true to apply changes, if any + err = utilityComputeNetworksConfigure(ctx, d, m, true) // pass do_delta = true to apply changes, if any if err != nil { return diag.FromErr(err) } @@ -287,11 +266,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf params := &url.Values{} params.Add("computeId", d.Id()) if d.Get("started").(bool) { - if _, err := c.DecortAPICall("POST", ComputeStartAPI, params); err != nil { + if _, err := c.DecortAPICall(ctx, "POST", ComputeStartAPI, params); err != nil { return diag.FromErr(err) } } else { - if _, err := c.DecortAPICall("POST", ComputeStopAPI, params); err != nil { + if _, err := c.DecortAPICall(ctx, "POST", ComputeStopAPI, params); err != nil { return diag.FromErr(err) } } @@ -310,7 +289,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf log.Debugf("resourceComputeDelete: called for Compute name %s, RG ID %d", d.Get("name").(string), d.Get("rg_id").(int)) - compFacts, err := utilityComputeCheckPresence(d, m) + compFacts, err := utilityComputeCheckPresence(ctx, d, m) if compFacts == "" { if err != nil { return diag.FromErr(err) @@ -340,7 +319,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf detachParams.Add("computeId", d.Id()) detachParams.Add("diskId", fmt.Sprintf("%d", diskFacts.ID)) - _, err = c.DecortAPICall("POST", ComputeDiskDetachAPI, detachParams) + _, err = c.DecortAPICall(ctx, "POST", ComputeDiskDetachAPI, detachParams) if err != nil { // We do not fail compute deletion on data disk detach errors log.Errorf("resourceComputeDelete: error when detaching Disk ID %d: %s", diskFacts.ID, err) @@ -353,7 +332,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf params.Add("permanently", "1") // TODO: this is for the upcoming API update - params.Add("detachdisks", "1") - _, err = c.DecortAPICall("POST", ComputeDeleteAPI, params) + _, err = c.DecortAPICall(ctx, "POST", ComputeDeleteAPI, params) if err != nil { return diag.FromErr(err) } @@ -361,12 +340,12 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf return nil } -func resourceComputeExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceComputeExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { // Reminder: according to Terraform rules, this function should not modify its ResourceData argument log.Debugf("resourceComputeExist: called for Compute name %s, RG ID %d", d.Get("name").(string), d.Get("rg_id").(int)) - compFacts, err := utilityComputeCheckPresence(d, m) + compFacts, err := utilityComputeCheckPresence(ctx, d, m) if compFacts == "" { if err != nil { return false, err @@ -384,7 +363,6 @@ func ResourceCompute() *schema.Resource { ReadContext: resourceComputeRead, UpdateContext: resourceComputeUpdate, DeleteContext: resourceComputeDelete, - Exists: resourceComputeExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/kvmvm/utility_compute.go b/internal/service/cloudapi/kvmvm/utility_compute.go index 894e81d..0bf64ea 100644 --- a/internal/service/cloudapi/kvmvm/utility_compute.go +++ b/internal/service/cloudapi/kvmvm/utility_compute.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package kvmvm import ( + "context" "encoding/json" "fmt" "net/url" @@ -43,7 +44,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do_delta bool) error { +func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error { // d is filled with data according to computeResource schema, so extra disks config is retrieved via "extra_disks" key // If do_delta is true, this function will identify changes between new and existing specs for extra disks and try to // update compute configuration accordingly @@ -71,7 +72,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do urlValues := &url.Values{} urlValues.Add("computeId", d.Id()) urlValues.Add("diskId", fmt.Sprintf("%d", disk.(int))) - _, err := c.DecortAPICall("POST", ComputeDiskAttachAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", ComputeDiskAttachAPI, urlValues) if err != nil { // failed to attach extra disk - partial resource update apiErrCount++ @@ -94,7 +95,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do urlValues := &url.Values{} urlValues.Add("computeId", d.Id()) urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int))) - _, err := c.DecortAPICall("POST", ComputeDiskDetachAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", ComputeDiskDetachAPI, urlValues) if err != nil { // failed to detach disk - there will be partial resource update log.Errorf("utilityComputeExtraDisksConfigure: failed to detach disk ID %d from Compute ID %s: %s", diskId.(int), d.Id(), err) @@ -109,7 +110,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do urlValues := &url.Values{} urlValues.Add("computeId", d.Id()) urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int))) - _, err := c.DecortAPICall("POST", ComputeDiskAttachAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", ComputeDiskAttachAPI, urlValues) if err != nil { // failed to attach disk - there will be partial resource update log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err) @@ -127,7 +128,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do return nil } -func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_delta bool) error { +func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error { // "d" is filled with data according to computeResource schema, so extra networks config is retrieved via "network" key // If do_delta is true, this function will identify changes between new and existing specs for network and try to // update compute configuration accordingly @@ -156,7 +157,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d if ipSet { urlValues.Add("ipAddr", ipaddr.(string)) } - _, err := c.DecortAPICall("POST", ComputeNetAttachAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", ComputeNetAttachAPI, urlValues) if err != nil { // failed to attach network - partial resource update apiErrCount++ @@ -180,7 +181,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d urlValues.Add("computeId", d.Id()) urlValues.Add("ipAddr", net_data["ip_address"].(string)) urlValues.Add("mac", net_data["mac"].(string)) - _, err := c.DecortAPICall("POST", ComputeNetDetachAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", ComputeNetDetachAPI, urlValues) if err != nil { // failed to detach this network - there will be partial resource update log.Errorf("utilityComputeNetworksConfigure: failed to detach net ID %d of type %s from Compute ID %s: %s", @@ -201,7 +202,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d if net_data["ip_address"].(string) != "" { urlValues.Add("ipAddr", net_data["ip_address"].(string)) } - _, err := c.DecortAPICall("POST", ComputeNetAttachAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", ComputeNetAttachAPI, urlValues) if err != nil { // failed to attach this network - there will be partial resource update log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s", @@ -220,7 +221,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d return nil } -func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, error) { +func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { // This function tries to locate Compute by one of the following approaches: // - if compute_id is specified - locate by compute ID // - if compute_name is specified - locate by a combination of compute name and resource @@ -255,7 +256,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, // compute ID is specified, try to get compute instance straight by this ID log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", theId) urlValues.Add("computeId", fmt.Sprintf("%d", theId)) - computeFacts, err := c.DecortAPICall("POST", ComputeGetAPI, urlValues) + computeFacts, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues) if err != nil { return "", err } @@ -275,7 +276,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, } urlValues.Add("rgId", fmt.Sprintf("%d", rgId)) - apiResp, err := c.DecortAPICall("POST", RgListComputesAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", RgListComputesAPI, urlValues) if err != nil { return "", err } @@ -297,7 +298,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, // we found the Compute we need - now get detailed information via compute/get API cgetValues := &url.Values{} cgetValues.Add("computeId", fmt.Sprintf("%d", item.ID)) - apiResp, err = c.DecortAPICall("POST", ComputeGetAPI, cgetValues) + apiResp, err = c.DecortAPICall(ctx, "POST", ComputeGetAPI, cgetValues) if err != nil { return "", err } diff --git a/internal/service/cloudapi/pfw/resource_pfw.go b/internal/service/cloudapi/pfw/resource_pfw.go index 381bcb2..199187b 100644 --- a/internal/service/cloudapi/pfw/resource_pfw.go +++ b/internal/service/cloudapi/pfw/resource_pfw.go @@ -59,14 +59,14 @@ func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{ urlValues.Add("publicPortEnd", strconv.Itoa(portEnd.(int))) } - pfwId, err := c.DecortAPICall("POST", ComputePfwAddAPI, urlValues) + pfwId, err := c.DecortAPICall(ctx, "POST", ComputePfwAddAPI, urlValues) if err != nil { return diag.FromErr(err) } d.SetId(fmt.Sprintf("%d-%s", d.Get("compute_id").(int), pfwId)) - pfw, err := utilityPfwCheckPresence(d, m) + pfw, err := utilityPfwCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -82,7 +82,7 @@ func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{ func resourcePfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourcePfwRead: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id()) - pfw, err := utilityPfwCheckPresence(d, m) + pfw, err := utilityPfwCheckPresence(ctx, d, m) if pfw == nil { d.SetId("") return diag.FromErr(err) @@ -101,7 +101,7 @@ func resourcePfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourcePfwDelete: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id()) - pfw, err := utilityPfwCheckPresence(d, m) + pfw, err := utilityPfwCheckPresence(ctx, d, m) if pfw == nil { if err != nil { return diag.FromErr(err) @@ -114,7 +114,7 @@ func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{ urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) urlValues.Add("ruleId", strconv.Itoa(pfw.ID)) - _, err = c.DecortAPICall("POST", ComputePfwDelAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", ComputePfwDelAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -122,10 +122,10 @@ func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{ return nil } -func resourcePfwExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourcePfwExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourcePfwExists: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id()) - pfw, err := utilityPfwCheckPresence(d, m) + pfw, err := utilityPfwCheckPresence(ctx, d, m) if pfw == nil { if err != nil { return false, err @@ -193,7 +193,6 @@ func ResourcePfw() *schema.Resource { CreateContext: resourcePfwCreate, ReadContext: resourcePfwRead, DeleteContext: resourcePfwDelete, - Exists: resourcePfwExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/pfw/utility_pfw.go b/internal/service/cloudapi/pfw/utility_pfw.go index af7937f..0f5729f 100644 --- a/internal/service/cloudapi/pfw/utility_pfw.go +++ b/internal/service/cloudapi/pfw/utility_pfw.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package pfw import ( + "context" "encoding/json" "net/url" "strconv" @@ -41,12 +42,12 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilityPfwCheckPresence(d *schema.ResourceData, m interface{}) (*PfwRecord, error) { +func utilityPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*PfwRecord, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) - resp, err := c.DecortAPICall("POST", ComputePfwListAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", ComputePfwListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/rg/data_source_rg.go b/internal/service/cloudapi/rg/data_source_rg.go index 33f7f0e..09d42ec 100644 --- a/internal/service/cloudapi/rg/data_source_rg.go +++ b/internal/service/cloudapi/rg/data_source_rg.go @@ -83,7 +83,7 @@ func flattenResgroup(d *schema.ResourceData, rg_facts string) error { } func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - rg_facts, err := utilityResgroupCheckPresence(d, m) + rg_facts, err := utilityResgroupCheckPresence(ctx, d, m) if rg_facts == "" { // if empty string is returned from utilityResgroupCheckPresence then there is no // such resource group and err tells so - just return it to the calling party diff --git a/internal/service/cloudapi/rg/data_source_rg_list.go b/internal/service/cloudapi/rg/data_source_rg_list.go index cfd71ba..b33c5ea 100644 --- a/internal/service/cloudapi/rg/data_source_rg_list.go +++ b/internal/service/cloudapi/rg/data_source_rg_list.go @@ -108,7 +108,7 @@ func flattenRgResourceLimits(rl ResourceLimits) []map[string]interface{} { } func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - rgList, err := utilityRgListCheckPresence(d, m) + rgList, err := utilityRgListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/rg/resource_rg.go b/internal/service/cloudapi/rg/resource_rg.go index 815c427..d893334 100644 --- a/internal/service/cloudapi/rg/resource_rg.go +++ b/internal/service/cloudapi/rg/resource_rg.go @@ -125,7 +125,7 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter url_values.Add("extIp", ext_ip.(string)) } - api_resp, err := c.DecortAPICall("POST", ResgroupCreateAPI, url_values) + api_resp, err := c.DecortAPICall(ctx, "POST", ResgroupCreateAPI, url_values) if err != nil { return diag.FromErr(err) } @@ -133,7 +133,7 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter d.SetId(api_resp) // rg/create API returns ID of the newly creted resource group on success // rg.ID, _ = strconv.Atoi(api_resp) if !set_quota { - resp, err := utilityResgroupCheckPresence(d, m) + resp, err := utilityResgroupCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -154,7 +154,7 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa log.Debugf("resourceResgroupRead: called for RG name %s, account ID %d", d.Get("name").(string), d.Get("account_id").(int)) - rg_facts, err := utilityResgroupCheckPresence(d, m) + rg_facts, err := utilityResgroupCheckPresence(ctx, d, m) if rg_facts == "" { // if empty string is returned from utilityResgroupCheckPresence then there is no // such resource group and err tells so - just return it to the calling party @@ -255,7 +255,7 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter if do_general_update { log.Debugf("resourceResgroupUpdate: detected delta between new and old RG specs - updating the RG") - _, err := c.DecortAPICall("POST", ResgroupUpdateAPI, url_values) + _, err := c.DecortAPICall(ctx, "POST", ResgroupUpdateAPI, url_values) if err != nil { return diag.FromErr(err) } @@ -272,7 +272,7 @@ func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m inter log.Debugf("resourceResgroupDelete: called for RG name %s, account ID %d", d.Get("name").(string), d.Get("account_id").(int)) - rg_facts, err := utilityResgroupCheckPresence(d, m) + rg_facts, err := utilityResgroupCheckPresence(ctx, d, m) if rg_facts == "" { if err != nil { return diag.FromErr(err) @@ -289,7 +289,7 @@ func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m inter url_values.Add("reason", "Destroyed by DECORT Terraform provider") c := m.(*controller.ControllerCfg) - _, err = c.DecortAPICall("POST", ResgroupDeleteAPI, url_values) + _, err = c.DecortAPICall(ctx, "POST", ResgroupDeleteAPI, url_values) if err != nil { return diag.FromErr(err) } @@ -297,9 +297,9 @@ func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m inter return nil } -func resourceResgroupExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceResgroupExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { // Reminder: according to Terraform rules, this function should NOT modify ResourceData argument - rg_facts, err := utilityResgroupCheckPresence(d, m) + rg_facts, err := utilityResgroupCheckPresence(ctx, d, m) if rg_facts == "" { if err != nil { return false, err @@ -317,7 +317,6 @@ func ResourceResgroup() *schema.Resource { ReadContext: resourceResgroupRead, UpdateContext: resourceResgroupUpdate, DeleteContext: resourceResgroupDelete, - Exists: resourceResgroupExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/rg/utility_rg.go b/internal/service/cloudapi/rg/utility_rg.go index f2253e8..c7c3b94 100644 --- a/internal/service/cloudapi/rg/utility_rg.go +++ b/internal/service/cloudapi/rg/utility_rg.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package rg import ( + "context" "encoding/json" "fmt" "net/url" @@ -45,7 +46,7 @@ import ( // On success this function returns a string, as returned by API rg/get, which could be unmarshalled // into ResgroupGetResp structure -func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string, error) { +func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { // This function tries to locate resource group by one of the following algorithms depending // on the parameters passed: // - if resource group ID is specified -> by RG ID @@ -84,7 +85,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // go straight for the RG by its ID log.Debugf("utilityResgroupCheckPresence: locating RG by its ID %d", theId) urlValues.Add("rgId", fmt.Sprintf("%d", theId)) - rgFacts, err := c.DecortAPICall("POST", ResgroupGetAPI, urlValues) + rgFacts, err := c.DecortAPICall(ctx, "POST", ResgroupGetAPI, urlValues) if err != nil { return "", err } @@ -101,7 +102,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // obtain Account ID by account name - it should not be zero on success urlValues.Add("includedeleted", "false") - apiResp, err := c.DecortAPICall("POST", ResgroupListAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", ResgroupListAPI, urlValues) if err != nil { return "", err } @@ -125,7 +126,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string // Namely, we need resource quota settings reqValues := &url.Values{} reqValues.Add("rgId", fmt.Sprintf("%d", item.ID)) - apiResp, err := c.DecortAPICall("POST", ResgroupGetAPI, reqValues) + apiResp, err := c.DecortAPICall(ctx, "POST", ResgroupGetAPI, reqValues) if err != nil { return "", err } diff --git a/internal/service/cloudapi/rg/utility_rg_list.go b/internal/service/cloudapi/rg/utility_rg_list.go index 19a3b81..3342105 100644 --- a/internal/service/cloudapi/rg/utility_rg_list.go +++ b/internal/service/cloudapi/rg/utility_rg_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package rg import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityRgListCheckPresence(d *schema.ResourceData, m interface{}) (ResgroupListResp, error) { +func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ResgroupListResp, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -59,7 +60,7 @@ func utilityRgListCheckPresence(d *schema.ResourceData, m interface{}) (Resgroup } log.Debugf("utilityRgListCheckPresence: load rg list") - rgListRaw, err := c.DecortAPICall("POST", ResgroupListAPI, urlValues) + rgListRaw, err := c.DecortAPICall(ctx, "POST", ResgroupListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/snapshot/data_source_snapshot_list.go b/internal/service/cloudapi/snapshot/data_source_snapshot_list.go index 61a1cb5..0fe01c1 100644 --- a/internal/service/cloudapi/snapshot/data_source_snapshot_list.go +++ b/internal/service/cloudapi/snapshot/data_source_snapshot_list.go @@ -56,7 +56,7 @@ func flattenSnapshotList(gl SnapshotList) []map[string]interface{} { } func dataSourceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - snapshotList, err := utilitySnapshotListCheckPresence(d, m) + snapshotList, err := utilitySnapshotListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/snapshot/resource_snapshot.go b/internal/service/cloudapi/snapshot/resource_snapshot.go index b208092..9a8fbc7 100644 --- a/internal/service/cloudapi/snapshot/resource_snapshot.go +++ b/internal/service/cloudapi/snapshot/resource_snapshot.go @@ -52,7 +52,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m inter urlValues.Add("label", d.Get("label").(string)) urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) - snapshotId, err := c.DecortAPICall("POST", snapshotCreateAPI, urlValues) + snapshotId, err := c.DecortAPICall(ctx, "POST", snapshotCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -71,7 +71,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m inter } func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - snapshot, err := utilitySnapshotCheckPresence(d, m) + snapshot, err := utilitySnapshotCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -92,7 +92,7 @@ func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m inter urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) urlValues.Add("label", d.Get("label").(string)) - _, err := c.DecortAPICall("POST", snapshotDeleteAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", snapshotDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -101,8 +101,8 @@ func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m inter return nil } -func resourceSnapshotExists(d *schema.ResourceData, m interface{}) (bool, error) { - snapshot, err := utilitySnapshotCheckPresence(d, m) +func resourceSnapshotExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { + snapshot, err := utilitySnapshotCheckPresence(ctx, d, m) if err != nil { return false, err } @@ -116,7 +116,7 @@ func resourceSnapshotExists(d *schema.ResourceData, m interface{}) (bool, error) func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { if d.HasChange("rollback") { if d.Get("rollback").(bool) { - err := resourceSnapshotRollback(d, m) + err := resourceSnapshotRollback(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -126,14 +126,14 @@ func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interfa return nil } -func resourceSnapshotRollback(d *schema.ResourceData, m interface{}) error { +func resourceSnapshotRollback(ctx context.Context, d *schema.ResourceData, m interface{}) error { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) urlValues.Add("label", d.Get("label").(string)) - _, err := c.DecortAPICall("POST", snapshotRollbackAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", snapshotRollbackAPI, urlValues) if err != nil { return err } @@ -188,7 +188,6 @@ func ResourceSnapshot() *schema.Resource { ReadContext: resourceSnapshotRead, UpdateContext: resourceSnapshotEdit, DeleteContext: resourceSnapshotDelete, - Exists: resourceSnapshotExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/snapshot/utility_snapshot.go b/internal/service/cloudapi/snapshot/utility_snapshot.go index e126a10..b99509b 100644 --- a/internal/service/cloudapi/snapshot/utility_snapshot.go +++ b/internal/service/cloudapi/snapshot/utility_snapshot.go @@ -32,13 +32,14 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package snapshot import ( + "context" "errors" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilitySnapshotCheckPresence(d *schema.ResourceData, m interface{}) (*Snapshot, error) { - snapShotList, err := utilitySnapshotListCheckPresence(d, m) +func utilitySnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Snapshot, error) { + snapShotList, err := utilitySnapshotListCheckPresence(ctx, d, m) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/snapshot/utility_snapshot_list.go b/internal/service/cloudapi/snapshot/utility_snapshot_list.go index 4f80c90..e06ac5b 100644 --- a/internal/service/cloudapi/snapshot/utility_snapshot_list.go +++ b/internal/service/cloudapi/snapshot/utility_snapshot_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package snapshot import ( + "context" "encoding/json" "net/url" "strconv" @@ -40,12 +41,12 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilitySnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (SnapshotList, error) { +func utilitySnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SnapshotList, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int))) - resp, err := c.DecortAPICall("POST", snapshotListAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", snapshotListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/vgpu/data_source_vgpu.go b/internal/service/cloudapi/vgpu/data_source_vgpu.go index 0c66086..763b26d 100644 --- a/internal/service/cloudapi/vgpu/data_source_vgpu.go +++ b/internal/service/cloudapi/vgpu/data_source_vgpu.go @@ -40,7 +40,7 @@ import ( ) func dataSourceVGPURead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - vgpu, err := utilityVGPUCheckPresence(d, m) + vgpu, err := utilityVGPUCheckPresence(ctx, d, m) if vgpu == nil { d.SetId("") return diag.FromErr(err) diff --git a/internal/service/cloudapi/vgpu/utility_vgpu.go b/internal/service/cloudapi/vgpu/utility_vgpu.go index fd00ee4..65366cd 100644 --- a/internal/service/cloudapi/vgpu/utility_vgpu.go +++ b/internal/service/cloudapi/vgpu/utility_vgpu.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package vgpu import ( + "context" "encoding/json" "net/url" "strconv" @@ -40,7 +41,7 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilityVGPUCheckPresence(d *schema.ResourceData, m interface{}) (*VGPU, error) { +func utilityVGPUCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*VGPU, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("size", "50") @@ -59,7 +60,7 @@ func utilityVGPUCheckPresence(d *schema.ResourceData, m interface{}) (*VGPU, err for page := 1; ; page++ { urlValues.Set("page", strconv.Itoa(page)) - resp, err := c.DecortAPICall("POST", vgpuListAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", vgpuListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudapi/vins/data_source_vins.go b/internal/service/cloudapi/vins/data_source_vins.go index b6419b7..2bcd362 100644 --- a/internal/service/cloudapi/vins/data_source_vins.go +++ b/internal/service/cloudapi/vins/data_source_vins.go @@ -97,7 +97,7 @@ func flattenVins(d *schema.ResourceData, vins_facts string) diag.Diagnostics { } func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - vinsFacts, err := utilityVinsCheckPresence(d, m) + vinsFacts, err := utilityVinsCheckPresence(ctx, d, m) if vinsFacts == "" { // if empty string is returned from utilityVinsCheckPresence then there is no // such ViNS and err tells so - just return it to the calling party diff --git a/internal/service/cloudapi/vins/data_source_vins_list.go b/internal/service/cloudapi/vins/data_source_vins_list.go index 76365db..2178eb5 100644 --- a/internal/service/cloudapi/vins/data_source_vins_list.go +++ b/internal/service/cloudapi/vins/data_source_vins_list.go @@ -67,7 +67,7 @@ func flattenVinsList(vl VinsList) []map[string]interface{} { } func dataSourceVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - vinsList, err := utilityVinsListCheckPresence(d, m) + vinsList, err := utilityVinsListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudapi/vins/resource_vins.go b/internal/service/cloudapi/vins/resource_vins.go index fc0170d..22729f6 100644 --- a/internal/service/cloudapi/vins/resource_vins.go +++ b/internal/service/cloudapi/vins/resource_vins.go @@ -115,7 +115,7 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface urlValues.Add("desc", argVal.(string)) } - apiResp, err := c.DecortAPICall("POST", apiToCall, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", apiToCall, urlValues) if err != nil { return diag.FromErr(err) } @@ -133,7 +133,7 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface } func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - vinsFacts, err := utilityVinsCheckPresence(d, m) + vinsFacts, err := utilityVinsCheckPresence(ctx, d, m) if vinsFacts == "" { // if empty string is returned from utilityVinsCheckPresence then there is no // such ViNS and err tells so - just return it to the calling party @@ -161,7 +161,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface if oldExtNetId.(int) > 0 { // there was preexisting external net connection - disconnect ViNS - _, err := c.DecortAPICall("POST", VinsExtNetDisconnectAPI, extnetParams) + _, err := c.DecortAPICall(ctx, "POST", VinsExtNetDisconnectAPI, extnetParams) if err != nil { return diag.FromErr(err) } @@ -170,7 +170,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface if newExtNedId.(int) > 0 { // new external network connection requested - connect ViNS extnetParams.Add("netId", fmt.Sprintf("%d", newExtNedId.(int))) - _, err := c.DecortAPICall("POST", VinsExtNetConnectAPI, extnetParams) + _, err := c.DecortAPICall(ctx, "POST", VinsExtNetConnectAPI, extnetParams) if err != nil { return diag.FromErr(err) } @@ -186,7 +186,7 @@ func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface log.Debugf("resourceVinsDelete: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d", d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int)) - vinsFacts, err := utilityVinsCheckPresence(d, m) + vinsFacts, err := utilityVinsCheckPresence(ctx, d, m) if vinsFacts == "" { if err != nil { return diag.FromErr(err) @@ -202,7 +202,7 @@ func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface params.Add("permanently", "1") // delete ViNS immediately bypassing recycle bin c := m.(*controller.ControllerCfg) - _, err = c.DecortAPICall("POST", VinsDeleteAPI, params) + _, err = c.DecortAPICall(ctx, "POST", VinsDeleteAPI, params) if err != nil { return diag.FromErr(err) } @@ -210,12 +210,12 @@ func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface return nil } -func resourceVinsExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceVinsExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { // Reminder: according to Terraform rules, this function should not modify its ResourceData argument log.Debugf("resourceVinsExists: called for ViNS name %s, Account ID %d, RG ID %d", d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int)) - vinsFacts, err := utilityVinsCheckPresence(d, m) + vinsFacts, err := utilityVinsCheckPresence(ctx, d, m) if vinsFacts == "" { if err != nil { return false, err @@ -305,7 +305,6 @@ func ResourceVins() *schema.Resource { ReadContext: resourceVinsRead, UpdateContext: resourceVinsUpdate, DeleteContext: resourceVinsDelete, - Exists: resourceVinsExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudapi/vins/utility_vins.go b/internal/service/cloudapi/vins/utility_vins.go index c8e363b..a53ea85 100644 --- a/internal/service/cloudapi/vins/utility_vins.go +++ b/internal/service/cloudapi/vins/utility_vins.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package vins import ( + "context" "encoding/json" "fmt" "net/url" @@ -45,7 +46,7 @@ import ( // On success this function returns a string, as returned by API vins/get, which could be unmarshalled // into VinsGetResp structure -func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, error) { +func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { // This function tries to locate ViNS by one of the following algorithms depending // on the parameters passed: // - if resource group ID is specified -> it looks for a ViNS at the RG level @@ -80,7 +81,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er // ViNS ID is specified, try to get compute instance straight by this ID log.Debugf("utilityVinsCheckPresence: locating ViNS by its ID %d", theId) urlValues.Add("vinsId", fmt.Sprintf("%d", theId)) - vinsFacts, err := c.DecortAPICall("POST", VinsGetAPI, urlValues) + vinsFacts, err := c.DecortAPICall(ctx, "POST", VinsGetAPI, urlValues) if err != nil { return "", err } @@ -111,7 +112,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er urlValues.Add("accountId", fmt.Sprintf("%d", accountId.(int))) } - apiResp, err := c.DecortAPICall("POST", VinsSearchAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", VinsSearchAPI, urlValues) if err != nil { return "", err } @@ -140,7 +141,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er // manage ViNS, so we have to get detailed info by calling API vins/get rqValues := &url.Values{} rqValues.Add("vinsId", fmt.Sprintf("%d", item.ID)) - vinsGetResp, err := c.DecortAPICall("POST", VinsGetAPI, rqValues) + vinsGetResp, err := c.DecortAPICall(ctx, "POST", VinsGetAPI, rqValues) if err != nil { return "", err } diff --git a/internal/service/cloudapi/vins/utility_vins_list.go b/internal/service/cloudapi/vins/utility_vins_list.go index c886c68..4746f23 100644 --- a/internal/service/cloudapi/vins/utility_vins_list.go +++ b/internal/service/cloudapi/vins/utility_vins_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package vins import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityVinsListCheckPresence(d *schema.ResourceData, m interface{}) (VinsList, error) { +func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (VinsList, error) { vinsList := VinsList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -58,7 +59,7 @@ func utilityVinsListCheckPresence(d *schema.ResourceData, m interface{}) (VinsLi } log.Debugf("utilityVinsListCheckPresence") - vinsListRaw, err := c.DecortAPICall("POST", VinsListAPI, urlValues) + vinsListRaw, err := c.DecortAPICall(ctx, "POST", VinsListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/grid/data_source_grid.go b/internal/service/cloudbroker/grid/data_source_grid.go index 7ba9abe..634d987 100644 --- a/internal/service/cloudbroker/grid/data_source_grid.go +++ b/internal/service/cloudbroker/grid/data_source_grid.go @@ -50,7 +50,7 @@ func flattenGrid(d *schema.ResourceData, grid *Grid) { } func dataSourceGridRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - grid, err := utilityGridCheckPresence(d, m) + grid, err := utilityGridCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/grid/data_source_grid_list.go b/internal/service/cloudbroker/grid/data_source_grid_list.go index 4521c90..476a739 100644 --- a/internal/service/cloudbroker/grid/data_source_grid_list.go +++ b/internal/service/cloudbroker/grid/data_source_grid_list.go @@ -58,7 +58,7 @@ func flattenGridList(gl GridList) []map[string]interface{} { } func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - gridList, err := utilityGridListCheckPresence(d, m) + gridList, err := utilityGridListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/grid/utility_grid.go b/internal/service/cloudbroker/grid/utility_grid.go index ef30e99..8b7698e 100644 --- a/internal/service/cloudbroker/grid/utility_grid.go +++ b/internal/service/cloudbroker/grid/utility_grid.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package grid import ( + "context" "encoding/json" "errors" "net/url" @@ -43,7 +44,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityGridCheckPresence(d *schema.ResourceData, m interface{}) (*Grid, error) { +func utilityGridCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Grid, error) { grid := &Grid{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilityGridCheckPresence(d *schema.ResourceData, m interface{}) (*Grid, err } log.Debugf("utilityGridCheckPresence: load grid") - gridRaw, err := c.DecortAPICall("POST", GridGetAPI, urlValues) + gridRaw, err := c.DecortAPICall(ctx, "POST", GridGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/grid/utility_grid_list.go b/internal/service/cloudbroker/grid/utility_grid_list.go index c679411..a81e06c 100644 --- a/internal/service/cloudbroker/grid/utility_grid_list.go +++ b/internal/service/cloudbroker/grid/utility_grid_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package grid import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityGridListCheckPresence(d *schema.ResourceData, m interface{}) (GridList, error) { +func utilityGridListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (GridList, error) { gridList := GridList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilityGridListCheckPresence(d *schema.ResourceData, m interface{}) (GridLi } log.Debugf("utilityGridListCheckPresence: load grid list") - gridListRaw, err := c.DecortAPICall("POST", GridListGetAPI, urlValues) + gridListRaw, err := c.DecortAPICall(ctx, "POST", GridListGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/image/data_source_image.go b/internal/service/cloudbroker/image/data_source_image.go index fe0ee4b..8b0b92c 100644 --- a/internal/service/cloudbroker/image/data_source_image.go +++ b/internal/service/cloudbroker/image/data_source_image.go @@ -83,7 +83,7 @@ func flattenImage(d *schema.ResourceData, image *Image) { } func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) diff --git a/internal/service/cloudbroker/image/data_source_image_list.go b/internal/service/cloudbroker/image/data_source_image_list.go index 1108d23..5e7f7ae 100644 --- a/internal/service/cloudbroker/image/data_source_image_list.go +++ b/internal/service/cloudbroker/image/data_source_image_list.go @@ -89,7 +89,7 @@ func flattenImageList(il ImageList) []map[string]interface{} { } func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - imageList, err := utilityImageListCheckPresence(d, m) + imageList, err := utilityImageListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/image/data_source_image_list_stacks.go b/internal/service/cloudbroker/image/data_source_image_list_stacks.go index 2a47dd5..c672748 100644 --- a/internal/service/cloudbroker/image/data_source_image_list_stacks.go +++ b/internal/service/cloudbroker/image/data_source_image_list_stacks.go @@ -67,7 +67,7 @@ func flattenImageListStacks(_ *schema.ResourceData, stack ImageListStacks) []map } func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - imageListStacks, err := utilityImageListStacksCheckPresence(d, m) + imageListStacks, err := utilityImageListStacksCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/image/resource_cdrom_image.go b/internal/service/cloudbroker/image/resource_cdrom_image.go index af794eb..8b0068c 100644 --- a/internal/service/cloudbroker/image/resource_cdrom_image.go +++ b/internal/service/cloudbroker/image/resource_cdrom_image.go @@ -90,7 +90,7 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int urlValues.Add("architecture", architecture.(string)) } - imageId, err := c.DecortAPICall("POST", imageCreateCDROMAPI, urlValues) + imageId, err := c.DecortAPICall(ctx, "POST", imageCreateCDROMAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -98,7 +98,7 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int d.SetId(imageId) d.Set("image_id", imageId) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -118,7 +118,7 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int func resourceCDROMImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceCDROMImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id()) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if image == nil { if err != nil { return diag.FromErr(err) @@ -134,7 +134,7 @@ func resourceCDROMImageDelete(ctx context.Context, d *schema.ResourceData, m int urlValues.Add("permanently", strconv.FormatBool(permanently.(bool))) } - _, err = c.DecortAPICall("POST", imageDeleteCDROMAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", imageDeleteCDROMAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -379,7 +379,6 @@ func ResourceCDROMImage() *schema.Resource { ReadContext: resourceImageRead, UpdateContext: resourceImageEdit, DeleteContext: resourceCDROMImageDelete, - Exists: resourceImageExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudbroker/image/resource_delete_images.go b/internal/service/cloudbroker/image/resource_delete_images.go index 5548285..233191a 100644 --- a/internal/service/cloudbroker/image/resource_delete_images.go +++ b/internal/service/cloudbroker/image/resource_delete_images.go @@ -74,7 +74,7 @@ func resourceDeleteListImages(ctx context.Context, d *schema.ResourceData, m int urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool))) urlValues.Add("imageIds", temp) - _, err := c.DecortAPICall("POST", imageDeleteImagesAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", imageDeleteImagesAPI, urlValues) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/image/resource_image.go b/internal/service/cloudbroker/image/resource_image.go index 464e687..b578709 100644 --- a/internal/service/cloudbroker/image/resource_image.go +++ b/internal/service/cloudbroker/image/resource_image.go @@ -103,7 +103,7 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac } else { api = imageSyncCreateAPI } - imageId, err := c.DecortAPICall("POST", api, urlValues) + imageId, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return diag.FromErr(err) } @@ -111,7 +111,7 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac d.SetId(imageId) d.Set("image_id", imageId) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -131,7 +131,7 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageRead: called for %s id: %s", d.Get("name").(string), d.Id()) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if image == nil { d.SetId("") return diag.FromErr(err) @@ -182,7 +182,7 @@ func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{ func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id()) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if image == nil { if err != nil { return diag.FromErr(err) @@ -202,7 +202,7 @@ func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interfac urlValues.Add("permanently", strconv.FormatBool(permanently.(bool))) } - _, err = c.DecortAPICall("POST", imageDeleteAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", imageDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -211,10 +211,10 @@ func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interfac return nil } -func resourceImageExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceImageExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceImageExists: called for %s, id: %s", d.Get("name").(string), d.Id()) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if image == nil { if err != nil { return false, err @@ -225,13 +225,13 @@ func resourceImageExists(d *schema.ResourceData, m interface{}) (bool, error) { return true, nil } -func resourceImageEditName(d *schema.ResourceData, m interface{}) error { +func resourceImageEditName(ctx context.Context, d *schema.ResourceData, m interface{}) error { log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id()) c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) urlValues.Add("name", d.Get("name").(string)) - _, err := c.DecortAPICall("POST", imageEditNameAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", imageEditNameAPI, urlValues) if err != nil { return err } @@ -245,7 +245,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{ urlValues := &url.Values{} if d.HasChange("enabled") { - err := resourceImageChangeEnabled(d, m) + err := resourceImageChangeEnabled(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -253,7 +253,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{ } if d.HasChange("name") { - err := resourceImageEditName(d, m) + err := resourceImageEditName(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -261,14 +261,14 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{ } if d.HasChange("shared_with") { - err := resourceImageShare(d, m) + err := resourceImageShare(ctx, d, m) if err != nil { return diag.FromErr(err) } urlValues = &url.Values{} } if d.HasChange("computeci_id") { - err := resourceImageChangeComputeci(d, m) + err := resourceImageChangeComputeci(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -276,7 +276,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{ } if d.HasChange("enabled_stacks") { - err := resourceImageUpdateNodes(d, m) + err := resourceImageUpdateNodes(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -284,7 +284,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{ } if d.HasChange("link_to") { - err := resourceImageLink(d, m) + err := resourceImageLink(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -302,7 +302,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{ urlValues.Add("bootable", strconv.FormatBool(d.Get("bootable").(bool))) urlValues.Add("hotresize", strconv.FormatBool(d.Get("hot_resize").(bool))) - _, err := c.DecortAPICall("POST", imageEditAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", imageEditAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -311,7 +311,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{ return nil } -func resourceImageChangeEnabled(d *schema.ResourceData, m interface{}) error { +func resourceImageChangeEnabled(ctx context.Context, d *schema.ResourceData, m interface{}) error { var api string c := m.(*controller.ControllerCfg) @@ -322,7 +322,7 @@ func resourceImageChangeEnabled(d *schema.ResourceData, m interface{}) error { } else { api = imageDisableAPI } - resp, err := c.DecortAPICall("POST", api, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return err } @@ -336,13 +336,13 @@ func resourceImageChangeEnabled(d *schema.ResourceData, m interface{}) error { return nil } -func resourceImageLink(d *schema.ResourceData, m interface{}) error { +func resourceImageLink(ctx context.Context, d *schema.ResourceData, m interface{}) error { log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id()) c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) urlValues.Add("targetId", strconv.Itoa(d.Get("link_to").(int))) - _, err := c.DecortAPICall("POST", imageLinkAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", imageLinkAPI, urlValues) if err != nil { return err } @@ -350,7 +350,7 @@ func resourceImageLink(d *schema.ResourceData, m interface{}) error { return nil } -func resourceImageShare(d *schema.ResourceData, m interface{}) error { +func resourceImageShare(ctx context.Context, d *schema.ResourceData, m interface{}) error { log.Debugf("resourceImageShare: called for %s, id: %s", d.Get("name").(string), d.Id()) c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -369,7 +369,7 @@ func resourceImageShare(d *schema.ResourceData, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("accounts", temp) - _, err := c.DecortAPICall("POST", imageShareAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", imageShareAPI, urlValues) if err != nil { return err } @@ -377,7 +377,7 @@ func resourceImageShare(d *schema.ResourceData, m interface{}) error { return nil } -func resourceImageChangeComputeci(d *schema.ResourceData, m interface{}) error { +func resourceImageChangeComputeci(ctx context.Context, d *schema.ResourceData, m interface{}) error { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -393,7 +393,7 @@ func resourceImageChangeComputeci(d *schema.ResourceData, m interface{}) error { api = imageComputeciSetAPI } - _, err := c.DecortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return err } @@ -401,7 +401,7 @@ func resourceImageChangeComputeci(d *schema.ResourceData, m interface{}) error { return nil } -func resourceImageUpdateNodes(d *schema.ResourceData, m interface{}) error { +func resourceImageUpdateNodes(ctx context.Context, d *schema.ResourceData, m interface{}) error { log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id()) c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -418,7 +418,7 @@ func resourceImageUpdateNodes(d *schema.ResourceData, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("enabledStacks", temp) - _, err := c.DecortAPICall("POST", imageUpdateNodesAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", imageUpdateNodesAPI, urlValues) if err != nil { return err } @@ -677,7 +677,6 @@ func ResourceImage() *schema.Resource { ReadContext: resourceImageRead, UpdateContext: resourceImageEdit, DeleteContext: resourceImageDelete, - Exists: resourceImageExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudbroker/image/resource_virtual_image.go b/internal/service/cloudbroker/image/resource_virtual_image.go index f778367..ec540d7 100644 --- a/internal/service/cloudbroker/image/resource_virtual_image.go +++ b/internal/service/cloudbroker/image/resource_virtual_image.go @@ -51,7 +51,7 @@ func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m i urlValues.Add("name", d.Get("name").(string)) urlValues.Add("targetId", strconv.Itoa(d.Get("target_id").(int))) - imageId, err := c.DecortAPICall("POST", imageCreateVirtualAPI, urlValues) + imageId, err := c.DecortAPICall(ctx, "POST", imageCreateVirtualAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -59,7 +59,7 @@ func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m i d.SetId(imageId) d.Set("image_id", imageId) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -326,7 +326,6 @@ func ResourceVirtualImage() *schema.Resource { ReadContext: resourceImageRead, UpdateContext: resourceImageEdit, DeleteContext: resourceImageDelete, - Exists: resourceImageExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudbroker/image/utility_image.go b/internal/service/cloudbroker/image/utility_image.go index 10c30ed..04981da 100644 --- a/internal/service/cloudbroker/image/utility_image.go +++ b/internal/service/cloudbroker/image/utility_image.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package image import ( + "context" "encoding/json" "errors" "fmt" @@ -42,7 +43,7 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilityImageCheckPresence(d *schema.ResourceData, m interface{}) (*Image, error) { +func utilityImageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Image, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -52,7 +53,7 @@ func utilityImageCheckPresence(d *schema.ResourceData, m interface{}) (*Image, e urlValues.Add("imageId", d.Id()) } - resp, err := c.DecortAPICall("POST", imageGetAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", imageGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/image/utility_image_list.go b/internal/service/cloudbroker/image/utility_image_list.go index dffabdf..42adce0 100644 --- a/internal/service/cloudbroker/image/utility_image_list.go +++ b/internal/service/cloudbroker/image/utility_image_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package image import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityImageListCheckPresence(d *schema.ResourceData, m interface{}) (ImageList, error) { +func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ImageList, error) { imageList := ImageList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -62,7 +63,7 @@ func utilityImageListCheckPresence(d *schema.ResourceData, m interface{}) (Image } log.Debugf("utilityImageListCheckPresence: load image list") - imageListRaw, err := c.DecortAPICall("POST", imageListGetAPI, urlValues) + imageListRaw, err := c.DecortAPICall(ctx, "POST", imageListGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/image/utility_image_list_stacks.go b/internal/service/cloudbroker/image/utility_image_list_stacks.go index 8062078..3b5a51a 100644 --- a/internal/service/cloudbroker/image/utility_image_list_stacks.go +++ b/internal/service/cloudbroker/image/utility_image_list_stacks.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package image import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityImageListStacksCheckPresence(d *schema.ResourceData, m interface{}) (ImageListStacks, error) { +func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ImageListStacks, error) { imageListStacks := ImageListStacks{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -50,7 +51,7 @@ func utilityImageListStacksCheckPresence(d *schema.ResourceData, m interface{}) urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int))) log.Debugf("utilityImageListStacksCheckPresence: load image list") - imageListRaw, err := c.DecortAPICall("POST", imageListStacksApi, urlValues) + imageListRaw, err := c.DecortAPICall(ctx, "POST", imageListStacksApi, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/pcidevice/data_source_pcidevice.go b/internal/service/cloudbroker/pcidevice/data_source_pcidevice.go index 880ff91..90a9ac3 100644 --- a/internal/service/cloudbroker/pcidevice/data_source_pcidevice.go +++ b/internal/service/cloudbroker/pcidevice/data_source_pcidevice.go @@ -42,7 +42,7 @@ import ( ) func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - pcidevice, err := utilityPcideviceCheckPresence(d, m) + pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go b/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go index b570cbf..ce9baef 100644 --- a/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go +++ b/internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go @@ -64,7 +64,7 @@ func flattenPcideviceList(pl PcideviceList) []map[string]interface{} { } func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - pcideviceList, err := utilityPcideviceListCheckPresence(d, m) + pcideviceList, err := utilityPcideviceListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/pcidevice/resource_pcidevice.go b/internal/service/cloudbroker/pcidevice/resource_pcidevice.go index 63408a2..dbf033c 100644 --- a/internal/service/cloudbroker/pcidevice/resource_pcidevice.go +++ b/internal/service/cloudbroker/pcidevice/resource_pcidevice.go @@ -48,7 +48,7 @@ func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m inte log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string)) if deviceId, ok := d.GetOk("device_id"); ok { - if exists, err := resourcePcideviceExists(d, m); exists { + if exists, err := resourcePcideviceExists(ctx, d, m); exists { if err != nil { return diag.FromErr(err) } @@ -74,7 +74,7 @@ func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m inte urlValues.Add("description", description.(string)) } - pcideviceId, err := c.DecortAPICall("POST", pcideviceCreateAPI, urlValues) + pcideviceId, err := c.DecortAPICall(ctx, "POST", pcideviceCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -91,7 +91,7 @@ func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m inte } func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - pcidevice, err := utilityPcideviceCheckPresence(d, m) + pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -121,7 +121,7 @@ func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m inte urlValues.Add("deviceId", d.Id()) urlValues.Add("force", strconv.FormatBool(d.Get("force").(bool))) - _, err := c.DecortAPICall("POST", pcideviceDeleteAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", pcideviceDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -131,8 +131,8 @@ func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m inte return nil } -func resourcePcideviceExists(d *schema.ResourceData, m interface{}) (bool, error) { - pcidevice, err := utilityPcideviceCheckPresence(d, m) +func resourcePcideviceExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { + pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m) if err != nil { return false, err } @@ -158,7 +158,7 @@ func resourcePcideviceEdit(ctx context.Context, d *schema.ResourceData, m interf api = pcideviceDisableAPI } - _, err := c.DecortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return diag.FromErr(err) } @@ -255,7 +255,6 @@ func ResourcePcidevice() *schema.Resource { ReadContext: resourcePcideviceRead, UpdateContext: resourcePcideviceEdit, DeleteContext: resourcePcideviceDelete, - Exists: resourcePcideviceExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudbroker/pcidevice/utility_pcidevice.go b/internal/service/cloudbroker/pcidevice/utility_pcidevice.go index fb4ffcd..9b22947 100644 --- a/internal/service/cloudbroker/pcidevice/utility_pcidevice.go +++ b/internal/service/cloudbroker/pcidevice/utility_pcidevice.go @@ -32,13 +32,14 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package pcidevice import ( + "context" "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilityPcideviceCheckPresence(d *schema.ResourceData, m interface{}) (*Pcidevice, error) { - pcideviceList, err := utilityPcideviceListCheckPresence(d, m) +func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Pcidevice, error) { + pcideviceList, err := utilityPcideviceListCheckPresence(ctx, d, m) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go b/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go index 1dd503d..ada9adc 100644 --- a/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go +++ b/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package pcidevice import ( + "context" "encoding/json" "net/url" @@ -39,12 +40,12 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilityPcideviceListCheckPresence(_ *schema.ResourceData, m interface{}) (PcideviceList, error) { +func utilityPcideviceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (PcideviceList, error) { pcideviceList := PcideviceList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} - pcideviceListRaw, err := c.DecortAPICall("POST", pcideviceListAPI, urlValues) + pcideviceListRaw, err := c.DecortAPICall(ctx, "POST", pcideviceListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/sep/data_source_sep.go b/internal/service/cloudbroker/sep/data_source_sep.go index 76d3ea8..80a187a 100644 --- a/internal/service/cloudbroker/sep/data_source_sep.go +++ b/internal/service/cloudbroker/sep/data_source_sep.go @@ -43,7 +43,7 @@ import ( ) func dataSourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - desSep, err := utilitySepCheckPresence(d, m) + desSep, err := utilitySepCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/sep/data_source_sep_config.go b/internal/service/cloudbroker/sep/data_source_sep_config.go index 2d8d4ed..def1007 100644 --- a/internal/service/cloudbroker/sep/data_source_sep_config.go +++ b/internal/service/cloudbroker/sep/data_source_sep_config.go @@ -42,7 +42,7 @@ import ( ) func dataSourceSepConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sepConfig, err := utilitySepConfigCheckPresence(d, m) + sepConfig, err := utilitySepConfigCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/sep/data_source_sep_consumption.go b/internal/service/cloudbroker/sep/data_source_sep_consumption.go index c4aa957..1b3406b 100644 --- a/internal/service/cloudbroker/sep/data_source_sep_consumption.go +++ b/internal/service/cloudbroker/sep/data_source_sep_consumption.go @@ -41,7 +41,7 @@ import ( ) func dataSourceSepConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sepCons, err := utilitySepConsumptionCheckPresence(d, m) + sepCons, err := utilitySepConsumptionCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/sep/data_source_sep_disk_list.go b/internal/service/cloudbroker/sep/data_source_sep_disk_list.go index 8e0fe92..4df4366 100644 --- a/internal/service/cloudbroker/sep/data_source_sep_disk_list.go +++ b/internal/service/cloudbroker/sep/data_source_sep_disk_list.go @@ -41,7 +41,7 @@ import ( ) func dataSourceSepDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sepDiskList, err := utilitySepDiskListCheckPresence(d, m) + sepDiskList, err := utilitySepDiskListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/sep/data_source_sep_list.go b/internal/service/cloudbroker/sep/data_source_sep_list.go index fe9bd5d..c8b7e41 100644 --- a/internal/service/cloudbroker/sep/data_source_sep_list.go +++ b/internal/service/cloudbroker/sep/data_source_sep_list.go @@ -69,7 +69,7 @@ func flattenSepList(sl SepList) []map[string]interface{} { } func dataSourceSepListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sepList, err := utilitySepListCheckPresence(d, m) + sepList, err := utilitySepListCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/sep/data_source_sep_pool.go b/internal/service/cloudbroker/sep/data_source_sep_pool.go index 92238e8..d045d14 100644 --- a/internal/service/cloudbroker/sep/data_source_sep_pool.go +++ b/internal/service/cloudbroker/sep/data_source_sep_pool.go @@ -42,7 +42,7 @@ import ( ) func dataSourceSepPoolRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - sepPool, err := utilitySepPoolCheckPresence(d, m) + sepPool, err := utilitySepPoolCheckPresence(ctx, d, m) if err != nil { return diag.FromErr(err) } diff --git a/internal/service/cloudbroker/sep/resource_sep.go b/internal/service/cloudbroker/sep/resource_sep.go index 95c341f..25b54cf 100644 --- a/internal/service/cloudbroker/sep/resource_sep.go +++ b/internal/service/cloudbroker/sep/resource_sep.go @@ -51,7 +51,7 @@ func resourceSepCreate(ctx context.Context, d *schema.ResourceData, m interface{ log.Debugf("resourceSepCreate: called for sep %s", d.Get("name").(string)) if sepId, ok := d.GetOk("sep_id"); ok { - if exists, err := resourceSepExists(d, m); exists { + if exists, err := resourceSepExists(ctx, d, m); exists { if err != nil { return diag.FromErr(err) } @@ -109,7 +109,7 @@ func resourceSepCreate(ctx context.Context, d *schema.ResourceData, m interface{ temp = "[" + temp + "]" urlValues.Add("provider_nids", temp) - sepId, err := c.DecortAPICall("POST", sepCreateAPI, urlValues) + sepId, err := c.DecortAPICall(ctx, "POST", sepCreateAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -131,7 +131,7 @@ func resourceSepCreate(ctx context.Context, d *schema.ResourceData, m interface{ func resourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepRead: called for %s id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - sep, err := utilitySepCheckPresence(d, m) + sep, err := utilitySepCheckPresence(ctx, d, m) if sep == nil { d.SetId("") return diag.FromErr(err) @@ -159,7 +159,7 @@ func resourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) func resourceSepDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepDelete: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - sepDes, err := utilitySepCheckPresence(d, m) + sepDes, err := utilitySepCheckPresence(ctx, d, m) if sepDes == nil { if err != nil { return diag.FromErr(err) @@ -171,7 +171,7 @@ func resourceSepDelete(ctx context.Context, d *schema.ResourceData, m interface{ urlValues := &url.Values{} urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - _, err = c.DecortAPICall("POST", sepDeleteAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", sepDeleteAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -180,10 +180,10 @@ func resourceSepDelete(ctx context.Context, d *schema.ResourceData, m interface{ return nil } -func resourceSepExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceSepExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceSepExists: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) - sepDes, err := utilitySepCheckPresence(d, m) + sepDes, err := utilitySepCheckPresence(ctx, d, m) if sepDes == nil { if err != nil { return false, err @@ -204,7 +204,7 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) if decommission { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("clear_physically", strconv.FormatBool(d.Get("clear_physically").(bool))) - _, err := c.DecortAPICall("POST", sepDecommissionAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", sepDecommissionAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -216,7 +216,7 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) updCapacityLimit := d.Get("upd_capacity_limit").(bool) if updCapacityLimit { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - _, err := c.DecortAPICall("POST", sepUpdateCapacityLimitAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", sepUpdateCapacityLimitAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -227,11 +227,11 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) if d.HasChange("config") { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("config", d.Get("config").(string)) - _, err := c.DecortAPICall("POST", sepConfigValidateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", sepConfigValidateAPI, urlValues) if err != nil { return diag.FromErr(err) } - _, err = c.DecortAPICall("POST", sepConfigInsertAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", sepConfigInsertAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -247,7 +247,7 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) urlValues.Add("field_value", field["field_value"].(string)) urlValues.Add("field_type", field["field_type"].(string)) - _, err := c.DecortAPICall("POST", sepConfigFieldEditAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", sepConfigFieldEditAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -255,7 +255,7 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) urlValues = &url.Values{} if d.HasChange("enable") { - err := resourceSepChangeEnabled(d, m) + err := resourceSepChangeEnabled(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -263,7 +263,7 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) urlValues = &url.Values{} if d.HasChange("consumed_by") { - err := resourceSepUpdateNodes(d, m) + err := resourceSepUpdateNodes(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -271,7 +271,7 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) urlValues = &url.Values{} if d.HasChange("provided_by") { - err := resourceSepUpdateProviders(d, m) + err := resourceSepUpdateProviders(ctx, d, m) if err != nil { return diag.FromErr(err) } @@ -285,7 +285,7 @@ func resourceSepEdit(ctx context.Context, d *schema.ResourceData, m interface{}) return nil } -func resourceSepChangeEnabled(d *schema.ResourceData, m interface{}) error { +func resourceSepChangeEnabled(ctx context.Context, d *schema.ResourceData, m interface{}) error { var api string c := m.(*controller.ControllerCfg) @@ -296,7 +296,7 @@ func resourceSepChangeEnabled(d *schema.ResourceData, m interface{}) error { } else { api = sepDisableAPI } - resp, err := c.DecortAPICall("POST", api, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return err } @@ -310,7 +310,7 @@ func resourceSepChangeEnabled(d *schema.ResourceData, m interface{}) error { return nil } -func resourceSepUpdateNodes(d *schema.ResourceData, m interface{}) error { +func resourceSepUpdateNodes(ctx context.Context, d *schema.ResourceData, m interface{}) error { log.Debugf("resourceSepUpdateNodes: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -345,7 +345,7 @@ func resourceSepUpdateNodes(d *schema.ResourceData, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("consumer_nids", temp) - _, err := c.DecortAPICall("POST", api, urlValues) + _, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { return err } @@ -362,7 +362,7 @@ func findElInt(sl []interface{}, el interface{}) bool { return false } -func resourceSepUpdateProviders(d *schema.ResourceData, m interface{}) error { +func resourceSepUpdateProviders(ctx context.Context, d *schema.ResourceData, m interface{}) error { log.Debugf("resourceSepUpdateProviders: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int)) c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -379,7 +379,7 @@ func resourceSepUpdateProviders(d *schema.ResourceData, m interface{}) error { } temp = "[" + temp + "]" urlValues.Add("provider_nids", temp) - _, err := c.DecortAPICall("POST", sepAddProviderNodesAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", sepAddProviderNodesAPI, urlValues) if err != nil { return err } @@ -524,7 +524,6 @@ func ResourceSep() *schema.Resource { ReadContext: resourceSepRead, UpdateContext: resourceSepEdit, DeleteContext: resourceSepDelete, - Exists: resourceSepExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudbroker/sep/resource_sep_config.go b/internal/service/cloudbroker/sep/resource_sep_config.go index dca075f..f48b51d 100644 --- a/internal/service/cloudbroker/sep/resource_sep_config.go +++ b/internal/service/cloudbroker/sep/resource_sep_config.go @@ -49,7 +49,7 @@ func resourceSepConfigCreate(ctx context.Context, d *schema.ResourceData, m inte log.Debugf("resourceSepConfigCreate: called for sep id %d", d.Get("sep_id").(int)) if _, ok := d.GetOk("sep_id"); ok { - if exists, err := resourceSepConfigExists(d, m); exists { + if exists, err := resourceSepConfigExists(ctx, d, m); exists { if err != nil { return diag.FromErr(err) } @@ -71,7 +71,7 @@ func resourceSepConfigCreate(ctx context.Context, d *schema.ResourceData, m inte func resourceSepConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceSepConfigRead: called for sep id: %d", d.Get("sep_id").(int)) - sepConfig, err := utilitySepConfigCheckPresence(d, m) + sepConfig, err := utilitySepConfigCheckPresence(ctx, d, m) if sepConfig == nil { d.SetId("") return diag.FromErr(err) @@ -86,10 +86,10 @@ func resourceSepConfigDelete(ctx context.Context, d *schema.ResourceData, m inte return nil } -func resourceSepConfigExists(d *schema.ResourceData, m interface{}) (bool, error) { +func resourceSepConfigExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { log.Debugf("resourceSepConfigExists: called for sep id: %d", d.Get("sep_id").(int)) - sepDesConfig, err := utilitySepConfigCheckPresence(d, m) + sepDesConfig, err := utilitySepConfigCheckPresence(ctx, d, m) if sepDesConfig == nil { if err != nil { return false, err @@ -108,11 +108,11 @@ func resourceSepConfigEdit(ctx context.Context, d *schema.ResourceData, m interf if d.HasChange("config") { urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) urlValues.Add("config", d.Get("config").(string)) - _, err := c.DecortAPICall("POST", sepConfigValidateAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", sepConfigValidateAPI, urlValues) if err != nil { return diag.FromErr(err) } - _, err = c.DecortAPICall("POST", sepConfigInsertAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", sepConfigInsertAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -128,7 +128,7 @@ func resourceSepConfigEdit(ctx context.Context, d *schema.ResourceData, m interf urlValues.Add("field_value", field["field_value"].(string)) urlValues.Add("field_type", field["field_type"].(string)) - _, err := c.DecortAPICall("POST", sepConfigFieldEditAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", sepConfigFieldEditAPI, urlValues) if err != nil { return diag.FromErr(err) } @@ -186,7 +186,6 @@ func ResourceSepConfig() *schema.Resource { ReadContext: resourceSepConfigRead, UpdateContext: resourceSepConfigEdit, DeleteContext: resourceSepConfigDelete, - Exists: resourceSepConfigExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/internal/service/cloudbroker/sep/utility_sep.go b/internal/service/cloudbroker/sep/utility_sep.go index a8f3f9d..724fcdf 100644 --- a/internal/service/cloudbroker/sep/utility_sep.go +++ b/internal/service/cloudbroker/sep/utility_sep.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package sep import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error) { +func utilitySepCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Sep, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilitySepCheckPresence(d *schema.ResourceData, m interface{}) (*Sep, error } log.Debugf("utilitySepCheckPresence: load sep") - sepRaw, err := c.DecortAPICall("POST", sepGetAPI, urlValues) + sepRaw, err := c.DecortAPICall(ctx, "POST", sepGetAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/sep/utility_sep_config.go b/internal/service/cloudbroker/sep/utility_sep_config.go index d63f19f..e4e247c 100644 --- a/internal/service/cloudbroker/sep/utility_sep_config.go +++ b/internal/service/cloudbroker/sep/utility_sep_config.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package sep import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepConfig, error) { +func utilitySepConfigCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SepConfig, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -51,7 +52,7 @@ func utilitySepConfigCheckPresence(d *schema.ResourceData, m interface{}) (SepCo urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) log.Debugf("utilitySepConfigCheckPresence: load sep config") - sepConfigRaw, err := c.DecortAPICall("POST", sepGetConfigAPI, urlValues) + sepConfigRaw, err := c.DecortAPICall(ctx, "POST", sepGetConfigAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/sep/utility_sep_consumption.go b/internal/service/cloudbroker/sep/utility_sep_consumption.go index 5ce0d8e..88b0985 100644 --- a/internal/service/cloudbroker/sep/utility_sep_consumption.go +++ b/internal/service/cloudbroker/sep/utility_sep_consumption.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package sep import ( + "context" "encoding/json" "net/url" "strconv" @@ -40,7 +41,7 @@ import ( "github.com/rudecs/terraform-provider-decort/internal/controller" ) -func utilitySepConsumptionCheckPresence(d *schema.ResourceData, m interface{}) (*SepConsumption, error) { +func utilitySepConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*SepConsumption, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -48,7 +49,7 @@ func utilitySepConsumptionCheckPresence(d *schema.ResourceData, m interface{}) ( urlValues.Add("sep_id", strconv.Itoa(d.Get("sep_id").(int))) - sepConsRaw, err := c.DecortAPICall("POST", sepConsumptionAPI, urlValues) + sepConsRaw, err := c.DecortAPICall(ctx, "POST", sepConsumptionAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/sep/utility_sep_disk_list.go b/internal/service/cloudbroker/sep/utility_sep_disk_list.go index 2a2676a..47b0aa8 100644 --- a/internal/service/cloudbroker/sep/utility_sep_disk_list.go +++ b/internal/service/cloudbroker/sep/utility_sep_disk_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package sep import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilitySepDiskListCheckPresence(d *schema.ResourceData, m interface{}) ([]int, error) { +func utilitySepDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]int, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilitySepDiskListCheckPresence(d *schema.ResourceData, m interface{}) ([]i } log.Debugf("utilitySepDiskListCheckPresence: load sep") - sepDiskListRaw, err := c.DecortAPICall("POST", sepDiskListAPI, urlValues) + sepDiskListRaw, err := c.DecortAPICall(ctx, "POST", sepDiskListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/sep/utility_sep_list.go b/internal/service/cloudbroker/sep/utility_sep_list.go index ab1fd2f..96dbe0e 100644 --- a/internal/service/cloudbroker/sep/utility_sep_list.go +++ b/internal/service/cloudbroker/sep/utility_sep_list.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package sep import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList, error) { +func utilitySepListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SepList, error) { sepList := SepList{} c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -55,7 +56,7 @@ func utilitySepListCheckPresence(d *schema.ResourceData, m interface{}) (SepList } log.Debugf("utilitySepListCheckPresence: load image list") - sepListRaw, err := c.DecortAPICall("POST", sepListAPI, urlValues) + sepListRaw, err := c.DecortAPICall(ctx, "POST", sepListAPI, urlValues) if err != nil { return nil, err } diff --git a/internal/service/cloudbroker/sep/utility_sep_pool.go b/internal/service/cloudbroker/sep/utility_sep_pool.go index a9064fc..4270569 100644 --- a/internal/service/cloudbroker/sep/utility_sep_pool.go +++ b/internal/service/cloudbroker/sep/utility_sep_pool.go @@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki package sep import ( + "context" "encoding/json" "net/url" "strconv" @@ -42,7 +43,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool, error) { +func utilitySepPoolCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SepPool, error) { c := m.(*controller.ControllerCfg) urlValues := &url.Values{} @@ -52,7 +53,7 @@ func utilitySepPoolCheckPresence(d *schema.ResourceData, m interface{}) (SepPool urlValues.Add("pool_name", d.Get("pool_name").(string)) log.Debugf("utilitySepDesPoolCheckPresence: load sep") - sepPoolRaw, err := c.DecortAPICall("POST", sepGetPoolAPI, urlValues) + sepPoolRaw, err := c.DecortAPICall(ctx, "POST", sepGetPoolAPI, urlValues) if err != nil { return nil, err }