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/decort/utility_extnet_default.go b/decort/utility_extnet_default.go deleted file mode 100644 index a76b93c..0000000 --- a/decort/utility_extnet_default.go +++ /dev/null @@ -1,46 +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 ( - "net/url" - - log "github.com/sirupsen/logrus" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func utilityExtnetDefaultCheckPresence(_ *schema.ResourceData, m interface{}) (string, error) { - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - log.Debugf("utilityExtnetDefaultCheckPresence") - res, err := controller.decortAPICall("POST", extnetGetDefaultAPI, urlValues) - if err != nil { - return "", err - } - - return res, nil -} diff --git a/decort/utility_pcidevice_list.go b/decort/utility_pcidevice_list.go deleted file mode 100644 index e4f7580..0000000 --- a/decort/utility_pcidevice_list.go +++ /dev/null @@ -1,50 +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 ( - "encoding/json" - "net/url" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func utilityPcideviceListCheckPresence(_ *schema.ResourceData, m interface{}) (PcideviceList, error) { - pcideviceList := PcideviceList{} - controller := m.(*ControllerCfg) - urlValues := &url.Values{} - - pcideviceListRaw, err := controller.decortAPICall("POST", pcideviceListAPI, urlValues) - if err != nil { - return nil, err - } - - err = json.Unmarshal([]byte(pcideviceListRaw), &pcideviceList) - if err != nil { - return nil, err - } - - return pcideviceList, nil -} diff --git a/go.mod b/go.mod index 6221e3f..1028826 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ 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 + golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect ) 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..ca9d3e3 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,17 +17,11 @@ 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" + "context" "crypto/tls" "fmt" "io/ioutil" @@ -41,8 +37,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 +186,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 +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/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..8305d5f 100644 --- a/decort/utility_location.go +++ b/internal/location/location.go @@ -1,65 +1,60 @@ -/* -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 ( + "context" + "encoding/json" + "fmt" + "net/url" + + "github.com/rudecs/terraform-provider-decort/internal/controller" + log "github.com/sirupsen/logrus" +) + +var DefaultGridID int + +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(ctx, "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..c6c76f1 --- /dev/null +++ b/internal/provider/provider.go @@ -0,0 +1,137 @@ +/* +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" + "golang.org/x/net/context" + + "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 + } + + ctx := context.Background() + + gridId, err := location.UtilityLocationGetDefaultGridID(ctx, 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 85% rename from decort/data_source_account.go rename to internal/service/cloudapi/account/data_source_account.go index 39ef95c..f3b2c6e 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 { - acc, err := utilityAccountCheckPresence(d, m) +func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + acc, err := utilityAccountCheckPresence(ctx, 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..d904d12 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 { - accountAuditsList, err := utilityAccountAuditsListCheckPresence(d, m) +func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountAuditsList, err := utilityAccountAuditsListCheckPresence(ctx, 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..39eda42 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 { - accountComputesList, err := utilityAccountComputesListCheckPresence(d, m) +func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountComputesList, err := utilityAccountComputesListCheckPresence(ctx, 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..bfcc492 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 { - accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(d, m) +func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(ctx, 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 53% 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..1528efb 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 { - result, err := utilityAccountConsumedUnitsByTypeCheckPresence(d, m) +func dataSourceAccountConsumedUnitsByTypeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + result, err := utilityAccountConsumedUnitsByTypeCheckPresence(ctx, 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..04120b4 --- /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(ctx, 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 65% rename from decort/data_source_account_disks_list.go rename to internal/service/cloudapi/account/data_source_account_disks_list.go index def9676..fcc12b3 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 { - accountDisksList, err := utilityAccountDisksListCheckPresence(d, m) +func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountDisksList, err := utilityAccountDisksListCheckPresence(ctx, 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 76% rename from decort/data_source_account_flipgroups_list.go rename to internal/service/cloudapi/account/data_source_account_flipgroups_list.go index dd83716..3bcc489 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 { - accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(d, m) +func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(ctx, 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 78% rename from decort/data_source_account_list.go rename to internal/service/cloudapi/account/data_source_account_list.go index b587bda..d5370df 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 { - accountList, err := utilityAccountListCheckPresence(d, m) +func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountList, err := utilityAccountListCheckPresence(ctx, 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..3d345ea 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 { - accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(d, m) +func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(ctx, 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 82% rename from decort/data_source_account_rg_list.go rename to internal/service/cloudapi/account/data_source_account_rg_list.go index 40e2284..c9b94d4 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 { - accountRGList, err := utilityAccountRGListCheckPresence(d, m) +func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountRGList, err := utilityAccountRGListCheckPresence(ctx, 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..92a6293 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 { - accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(d, m) +func dataSourceAccountTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(ctx, 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 74% rename from decort/data_source_account_vins_list.go rename to internal/service/cloudapi/account/data_source_account_vins_list.go index e9d50e7..b631e35 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 { - accountVinsList, err := utilityAccountVinsListCheckPresence(d, m) +func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + accountVinsList, err := utilityAccountVinsListCheckPresence(ctx, 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 80% rename from decort/resource_account.go rename to internal/service/cloudapi/account/resource_account.go index 66fc97c..5aa57f7 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 exists, err := resourceAccountExists(ctx, 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(ctx, "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) + acc, err := utilityAccountCheckPresence(ctx, 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,35 +191,35 @@ 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) + account, err := utilityAccountCheckPresence(ctx, 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(ctx, "POST", accountDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") 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 @@ -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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "POST", accountUpdateUserAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -767,26 +778,25 @@ 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, 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 57% rename from decort/utility_account.go rename to internal/service/cloudapi/account/utility_account.go index 136a939..092162b 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,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 account import ( + "context" "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) { +func utilityAccountCheckPresence(ctx context.Context, 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 +55,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(ctx, "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 53% rename from decort/utility_account_audits_list.go rename to internal/service/cloudapi/account/utility_account_audits_list.go index 283c513..c89cedd 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,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 account import ( + "context" "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) { +func utilityAccountAuditsListCheckPresence(ctx context.Context, 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(ctx, "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 53% rename from decort/utility_account_computes_list.go rename to internal/service/cloudapi/account/utility_account_computes_list.go index 6c92590..9b746da 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,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 account import ( + "context" "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) { +func utilityAccountComputesListCheckPresence(ctx context.Context, 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(ctx, "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 53% rename from decort/utility_account_consumed_units.go rename to internal/service/cloudapi/account/utility_account_consumed_units.go index b5cdd1e..5c610fb 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,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 account import ( + "context" "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) { +func utilityAccountConsumedUnitsCheckPresence(ctx context.Context, 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(ctx, "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 52% 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..1dc9d6b 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,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 account import ( + "context" "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) +func utilityAccountConsumedUnitsByTypeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (float64, error) { + 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(ctx, "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 55% rename from decort/utility_account_deleted_list.go rename to internal/service/cloudapi/account/utility_account_deleted_list.go index 7c82750..f9a8b50 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,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 account import ( + "context" "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) { +func utilityAccountDeletedListCheckPresence(ctx context.Context, 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 +56,7 @@ func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{ } log.Debugf("utilityAccountDeletedListCheckPresence: load") - accountDeletedListRaw, err := controller.decortAPICall("POST", accountListDeletedAPI, urlValues) + accountDeletedListRaw, err := c.DecortAPICall(ctx, "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 53% rename from decort/utility_account_disks_list.go rename to internal/service/cloudapi/account/utility_account_disks_list.go index 941a2bc..7cea8a2 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,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 account import ( + "context" "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) { +func utilityAccountDisksListCheckPresence(ctx context.Context, 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(ctx, "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 53% rename from decort/utility_account_flip_groups.go rename to internal/service/cloudapi/account/utility_account_flip_groups.go index df2c36b..1585f6b 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,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 account import ( + "context" "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) { +func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, 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(ctx, "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 66% rename from decort/utility_account_list.go rename to internal/service/cloudapi/account/utility_account_list.go index 0dd3514..2eb7d36 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,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 account import ( + "context" "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) { +func utilityAccountListCheckPresence(ctx context.Context, 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 +56,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(ctx, "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 53% rename from decort/utility_account_reserved_units.go rename to internal/service/cloudapi/account/utility_account_reserved_units.go index 31bd4b9..5474a12 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,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 account import ( + "context" "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) { +func utilityAccountReservedUnitsCheckPresence(ctx context.Context, 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(ctx, "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 53% rename from decort/utility_account_rg_list.go rename to internal/service/cloudapi/account/utility_account_rg_list.go index 0145b3a..41c1a76 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,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 account import ( + "context" "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) { +func utilityAccountRGListCheckPresence(ctx context.Context, 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(ctx, "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 53% rename from decort/utility_account_templates_list.go rename to internal/service/cloudapi/account/utility_account_templates_list.go index 2dd3a2e..47c13db 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,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 account import ( + "context" "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) { +func utilityAccountTemplatesListCheckPresence(ctx context.Context, 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(ctx, "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 53% rename from decort/utility_account_vins_list.go rename to internal/service/cloudapi/account/utility_account_vins_list.go index 31291ff..db2e931 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,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 account import ( + "context" "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) { +func utilityAccountVinsListCheckPresence(ctx context.Context, 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(ctx, "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 81% rename from decort/data_source_bservice.go rename to internal/service/cloudapi/bservice/data_source_bservice.go index a013981..513e0b9 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 { - bs, err := utilityBasicServiceCheckPresence(d, m) +func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + bs, err := utilityBasicServiceCheckPresence(ctx, 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..9be56bf --- /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(ctx, 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..eaac251 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 { - bsg, err := utilityBasicServiceGroupCheckPresence(d, m) +func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + bsg, err := utilityBasicServiceGroupCheckPresence(ctx, 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 78% rename from decort/data_source_bservice_list.go rename to internal/service/cloudapi/bservice/data_source_bservice_list.go index 21ead41..0a367a7 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 { - basicServiceList, err := utilityBasicServiceListCheckPresence(d, m) +func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + basicServiceList, err := utilityBasicServiceListCheckPresence(ctx, 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 60% rename from decort/data_source_bservice_snapshot_list.go rename to internal/service/cloudapi/bservice/data_source_bservice_snapshot_list.go index 306ce99..ab601e2 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 { - basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(d, m) +func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(ctx, 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 74% rename from decort/resource_bservice.go rename to internal/service/cloudapi/bservice/resource_bservice.go index 9f0df09..9ce62e4 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 exists, err := resourceBasicServiceExists(ctx, 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(ctx, "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) + bs, err := utilityBasicServiceCheckPresence(ctx, d, m) if bs == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("account_id", bs.AccountId) @@ -130,35 +140,35 @@ 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) + bs, err := utilityBasicServiceCheckPresence(ctx, 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(ctx, "POST", bserviceDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") 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 @@ -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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "POST", bserviceSnapshotRollbackAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -527,26 +537,25 @@ 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, 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 76% rename from decort/resource_bservice_group.go rename to internal/service/cloudapi/bservice/resource_bservice_group.go index 6bbff5a..47271c8 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 exists, err := resourceBasicServiceGroupExists(ctx, 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(ctx, "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) + bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m) if bsg == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("account_id", bsg.AccountId) @@ -172,35 +182,35 @@ 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) + bsg, err := utilityBasicServiceGroupCheckPresence(ctx, 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(ctx, "POST", bserviceGroupRemoveAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") 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 @@ -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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "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(ctx, "POST", bserviceGroupComputeRemoveAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } urlValues = &url.Values{} @@ -634,26 +644,25 @@ 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, 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 59% rename from decort/utility_bservicce_deleted_list.go rename to internal/service/cloudapi/bservice/utility_bservicce_deleted_list.go index d52ebee..114bda1 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,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 bservice import ( + "context" "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) { +func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, 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 +62,7 @@ func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m inter } log.Debugf("utilityBasicServiceDeletedListCheckPresence") - basicServiceDeletedListRaw, err := controller.decortAPICall("POST", bserviceListDeletedAPI, urlValues) + basicServiceDeletedListRaw, err := c.DecortAPICall(ctx, "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 54% rename from decort/utility_bservice.go rename to internal/service/cloudapi/bservice/utility_bservice.go index 65c41d8..d2fc168 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,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 bservice import ( + "context" "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) { +func utilityBasicServiceCheckPresence(ctx context.Context, 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 +55,7 @@ func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*B } log.Debugf("utilityBasicServiceCheckPresence") - bserviceRaw, err := controller.decortAPICall("POST", bserviceGetAPI, urlValues) + bserviceRaw, err := c.DecortAPICall(ctx, "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 56% rename from decort/utility_bservice_group.go rename to internal/service/cloudapi/bservice/utility_bservice_group.go index 6f75dc0..613258c 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,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 bservice import ( + "context" "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) { +func utilityBasicServiceGroupCheckPresence(ctx context.Context, 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 +56,7 @@ func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{} } log.Debugf("utilityBasicServiceGroupCheckPresence") - bserviceGroupRaw, err := controller.decortAPICall("POST", bserviceGroupGetAPI, urlValues) + bserviceGroupRaw, err := c.DecortAPICall(ctx, "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 59% rename from decort/utility_bservice_list.go rename to internal/service/cloudapi/bservice/utility_bservice_list.go index efbe623..f828fa3 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,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 bservice import ( + "context" "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) { +func utilityBasicServiceListCheckPresence(ctx context.Context, 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 +62,7 @@ func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{}) } log.Debugf("utilityBasicServiceListCheckPresence") - basicServiceListRaw, err := controller.decortAPICall("POST", bserviceListAPI, urlValues) + basicServiceListRaw, err := c.DecortAPICall(ctx, "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 54% rename from decort/utility_bservice_snapshot_list.go rename to internal/service/cloudapi/bservice/utility_bservice_snapshot_list.go index 1f310f3..4b7c983 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,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 bservice import ( + "context" "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) { +func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, 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 +53,7 @@ func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m inte } log.Debugf("utilityBasicServiceSnapshotListCheckPresence") - basicServiceSnapshotListRaw, err := controller.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/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 68% rename from decort/data_source_disk.go rename to internal/service/cloudapi/disks/data_source_disk.go index 8236f4a..46b8cdd 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 { - disk_facts, err := utilityDiskCheckPresence(d, m) +func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + 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 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 85% rename from decort/data_source_disk_list.go rename to internal/service/cloudapi/disks/data_source_disk_list.go index fa118aa..dc73729 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 { - diskList, err := utilityDiskListCheckPresence(d, m) +func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + diskList, err := utilityDiskListCheckPresence(ctx, 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 74% rename from decort/resource_disk.go rename to internal/service/cloudapi/disks/resource_disk.go index efee695..1fe2b4a 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(ctx, "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 { - diskFacts, err := utilityDiskCheckPresence(d, m) +func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + 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 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(ctx, "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(ctx, "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 @@ -158,10 +165,10 @@ func resourceDiskDelete(d *schema.ResourceData, m interface{}) error { 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 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,21 +186,21 @@ 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(ctx, "POST", DisksDeleteAPI, params) if err != nil { - return err + return diag.FromErr(err) } 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 @@ -305,26 +312,25 @@ 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, 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 80% rename from decort/utility_disk.go rename to internal/service/cloudapi/disks/utility_disk.go index c9a8605..73053a8 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,26 +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 disks import ( + "context" "encoding/json" "fmt" "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) { +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 @@ -52,7 +61,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 +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 := controller.decortAPICall("POST", DisksGetAPI, urlValues) + diskFacts, err := c.DecortAPICall(ctx, "POST", DisksGetAPI, urlValues) if err != nil { return "", err } @@ -92,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 := controller.decortAPICall("POST", DisksListAPI, urlValues) + diskFacts, err := c.DecortAPICall(ctx, "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 59% rename from decort/utility_disk_list.go rename to internal/service/cloudapi/disks/utility_disk_list.go index 447f92c..50d3cf4 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,28 +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 disks import ( + "context" "encoding/json" "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 utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksListResp, error) { +func utilityDiskListCheckPresence(ctx context.Context, 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 +63,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(ctx, "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..9744b3c 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 { - e, err := utilityExtnetCheckPresence(d, m) +func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + e, err := utilityExtnetCheckPresence(ctx, 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..2ab06e4 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 { - extnetComputesList, err := utilityExtnetComputesListCheckPresence(d, m) +func dataSourceExtnetComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + extnetComputesList, err := utilityExtnetComputesListCheckPresence(ctx, 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 50% rename from decort/data_source_extnet_default.go rename to internal/service/cloudapi/extnet/data_source_extnet_default.go index de5585f..22463eb 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 { - extnetId, err := utilityExtnetDefaultCheckPresence(d, m) +func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + extnetId, err := utilityExtnetDefaultCheckPresence(ctx, 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 63% rename from decort/data_source_extnet_list.go rename to internal/service/cloudapi/extnet/data_source_extnet_list.go index 4789f33..1984b13 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 { - extnetList, err := utilityExtnetListCheckPresence(d, m) +func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + extnetList, err := utilityExtnetListCheckPresence(ctx, 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 52% rename from decort/utility_extnet.go rename to internal/service/cloudapi/extnet/utility_extnet.go index f7cb0b4..b3c05d4 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,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" "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) { +func utilityExtnetCheckPresence(ctx context.Context, 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(ctx, "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 53% rename from decort/utility_extnet_computes_list.go rename to internal/service/cloudapi/extnet/utility_extnet_computes_list.go index 2f5c629..68f3d83 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,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" "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) { +func utilityExtnetComputesListCheckPresence(ctx context.Context, 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(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 new file mode 100644 index 0000000..7b7257b --- /dev/null +++ b/internal/service/cloudapi/extnet/utility_extnet_default.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 extnet + +import ( + "context" + "net/url" + + "github.com/rudecs/terraform-provider-decort/internal/controller" + log "github.com/sirupsen/logrus" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +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(ctx, "POST", extnetGetDefaultAPI, urlValues) + if err != nil { + return "", err + } + + return res, nil +} diff --git a/decort/utility_extnet_list.go b/internal/service/cloudapi/extnet/utility_extnet_list.go similarity index 57% rename from decort/utility_extnet_list.go rename to internal/service/cloudapi/extnet/utility_extnet_list.go index a0abe60..91b2d5a 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,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 ( + "context" "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) { +func utilityExtnetListCheckPresence(ctx context.Context, 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 +59,7 @@ func utilityExtnetListCheckPresence(d *schema.ResourceData, m interface{}) (Extn } log.Debugf("utilityExtnetListCheckPresence") - extnetListRaw, err := controller.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/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 70% rename from decort/resource_k8s.go rename to internal/service/cloudapi/k8s/resource_k8s.go index e0f3cb0..a7f6301 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(ctx, "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(ctx, "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))) @@ -115,9 +126,9 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error { time.Sleep(time.Second * 10) } - k8s, err := utilityK8sCheckPresence(d, m) + k8s, err := utilityK8sCheckPresence(ctx, 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(ctx, "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(ctx, "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) + k8s, err := utilityK8sCheckPresence(ctx, 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(ctx, "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(ctx, "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(ctx, "POST", K8sUpdateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } if d.HasChange("workers") { - k8s, err := utilityK8sCheckPresence(d, m) + k8s, err := utilityK8sCheckPresence(ctx, 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(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 := controller.decortAPICall("POST", K8sWorkerDeleteAPI, urlValues); err != nil { - return err + if _, err := c.DecortAPICall(ctx, "POST", K8sWorkerDeleteAPI, urlValues); err != nil { + return diag.FromErr(err) } } } @@ -239,34 +250,34 @@ 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) + k8s, err := utilityK8sCheckPresence(ctx, 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(ctx, "POST", K8sDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } 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 } @@ -366,26 +377,25 @@ 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, 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 65% rename from decort/resource_k8s_wg.go rename to internal/service/cloudapi/k8s/resource_k8s_wg.go index d9f4054..d1eeafb 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(ctx, "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) + wg, err := utilityK8sWgCheckPresence(ctx, 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) + wg, err := utilityK8sWgCheckPresence(ctx, 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(ctx, "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(ctx, "POST", K8sWorkerDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } } } @@ -134,34 +145,34 @@ 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) + wg, err := utilityK8sWgCheckPresence(ctx, 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(ctx, "POST", K8sWgDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } 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 @@ -221,26 +232,25 @@ 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, 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 52% rename from decort/utility_k8s.go rename to internal/service/cloudapi/k8s/utility_k8s.go index 2a3fcdb..2c4270c 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,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 ( + "context" "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) +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 := controller.decortAPICall("POST", K8sGetAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "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 56% rename from decort/utility_k8s_wg.go rename to internal/service/cloudapi/k8s/utility_k8s_wg.go index f4ed797..9aef352 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,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" "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) +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 := controller.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/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..7738409 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 { - compFacts, err := utilityComputeCheckPresence(d, m) +func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + 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 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 78% rename from decort/resource_compute.go rename to internal/service/cloudapi/kvmvm/resource_compute.go index ea43785..75dde35 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,64 +112,38 @@ func resourceComputeCreate(d *schema.ResourceData, m interface{}) error { } } - apiResp, err := controller.decortAPICall("POST", computeCreateAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "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)) // 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 = controller.utilityComputeExtraDisksConfigure(d, 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 = controller.utilityComputeNetworksConfigure(d, 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 @@ -167,8 +151,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(ctx, "POST", ComputeStartAPI, reqValues); err != nil { + return diag.FromErr(err) } } @@ -178,24 +162,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) + compFacts, err := utilityComputeCheckPresence(ctx, 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 +188,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 @@ -223,8 +207,6 @@ func resourceComputeUpdate(d *schema.ResourceData, m interface{}) error { 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))) @@ -246,12 +228,10 @@ 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(ctx, "POST", ComputeResizeAPI, params) if err != nil { - return err + return diag.FromErr(err) } - d.SetPartial("cpu") - d.SetPartial("ram") } // 2. Resize (grow) Boot disk @@ -262,54 +242,46 @@ 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(ctx, "POST", DisksResizeAPI, bdsParams) if err != nil { - return err + 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 := controller.utilityComputeExtraDisksConfigure(d, 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 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(ctx, 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(ctx, "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(ctx, "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 @@ -317,17 +289,17 @@ func resourceComputeDelete(d *schema.ResourceData, m interface{}) error { 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 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 +319,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(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) @@ -360,20 +332,20 @@ 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(ctx, "POST", ComputeDeleteAPI, params) if err != nil { - return err + return diag.FromErr(err) } 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 @@ -383,26 +355,25 @@ 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, 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 +394,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 +402,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 +430,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 +440,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 84% rename from decort/utility_compute.go rename to internal/service/cloudapi/kvmvm/utility_compute.go index d8b559d..0bf64ea 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,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 kvmvm import ( + "context" "encoding/json" "fmt" "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(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 @@ -45,6 +53,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 +72,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(ctx, "POST", ComputeDiskAttachAPI, urlValues) if err != nil { // failed to attach extra disk - partial resource update apiErrCount++ @@ -85,7 +95,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(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) @@ -100,7 +110,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(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) @@ -118,13 +128,15 @@ func (ctrl *ControllerCfg) utilityComputeExtraDisksConfigure(d *schema.ResourceD return nil } -func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceData, 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 // 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 +157,7 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat if ipSet { urlValues.Add("ipAddr", ipaddr.(string)) } - _, err := ctrl.decortAPICall("POST", ComputeNetAttachAPI, urlValues) + _, err := c.DecortAPICall(ctx, "POST", ComputeNetAttachAPI, urlValues) if err != nil { // failed to attach network - partial resource update apiErrCount++ @@ -169,7 +181,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(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", @@ -190,7 +202,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(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", @@ -209,7 +221,7 @@ func (ctrl *ControllerCfg) utilityComputeNetworksConfigure(d *schema.ResourceDat 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 @@ -223,7 +235,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 +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 := controller.decortAPICall("POST", ComputeGetAPI, urlValues) + computeFacts, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues) if err != nil { return "", err } @@ -264,7 +276,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(ctx, "POST", RgListComputesAPI, urlValues) if err != nil { return "", err } @@ -286,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 = controller.decortAPICall("POST", ComputeGetAPI, cgetValues) + apiResp, err = c.DecortAPICall(ctx, "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 64% rename from decort/resource_pfw.go rename to internal/service/cloudapi/pfw/resource_pfw.go index 314bc1a..199187b 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(ctx, "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) + pfw, err := utilityPfwCheckPresence(ctx, 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) + pfw, err := utilityPfwCheckPresence(ctx, d, m) if pfw == nil { d.SetId("") - return err + return diag.FromErr(err) } d.Set("compute_id", pfw.ComputeID) @@ -87,34 +98,34 @@ 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) + pfw, err := utilityPfwCheckPresence(ctx, 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(ctx, "POST", ComputePfwDelAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } 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 @@ -175,25 +186,24 @@ 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, 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 57% rename from decort/utility_pfw.go rename to internal/service/cloudapi/pfw/utility_pfw.go index ea125fb..0f5729f 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,29 +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 pfw import ( + "context" "encoding/json" "net/url" "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) +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 := controller.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/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 67% rename from decort/data_source_rg.go rename to internal/service/cloudapi/rg/data_source_rg.go index c1ae000..09d42ec 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 { - rg_facts, err := utilityResgroupCheckPresence(d, m) +func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + 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 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 83% rename from decort/data_source_rg_list.go rename to internal/service/cloudapi/rg/data_source_rg_list.go index 73afce5..b33c5ea 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 { - rgList, err := utilityRgListCheckPresence(d, m) +func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + rgList, err := utilityRgListCheckPresence(ctx, 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 77% rename from decort/resource_rg.go rename to internal/service/cloudapi/rg/resource_rg.go index cf5a9bc..d893334 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,47 +125,47 @@ 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(ctx, "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 // rg.ID, _ = strconv.Atoi(api_resp) if !set_quota { - resp, err := utilityResgroupCheckPresence(d, m) + resp, err := utilityResgroupCheckPresence(ctx, 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)) - 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 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,27 +255,27 @@ 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(ctx, "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", 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 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,18 +288,18 @@ 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(ctx, "POST", ResgroupDeleteAPI, url_values) if err != nil { - return err + return diag.FromErr(err) } 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 @@ -296,26 +309,25 @@ 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, 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 78% rename from decort/utility_rg.go rename to internal/service/cloudapi/rg/utility_rg.go index 118c898..c7c3b94 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,29 +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 rg import ( + "context" "encoding/json" "fmt" "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 // 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 @@ -56,7 +64,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 +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 := controller.decortAPICall("POST", ResgroupGetAPI, urlValues) + rgFacts, err := c.DecortAPICall(ctx, "POST", ResgroupGetAPI, urlValues) if err != nil { return "", err } @@ -94,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 := controller.decortAPICall("POST", ResgroupListAPI, urlValues) + apiResp, err := c.DecortAPICall(ctx, "POST", ResgroupListAPI, urlValues) if err != nil { return "", err } @@ -118,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 := controller.decortAPICall("POST", ResgroupGetAPI, reqValues) + apiResp, err := c.DecortAPICall(ctx, "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 58% rename from decort/utility_rg_list.go rename to internal/service/cloudapi/rg/utility_rg_list.go index 78892f3..3342105 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,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 rg import ( + "context" "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) +func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ResgroupListResp, error) { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} rgList := ResgroupListResp{} @@ -51,7 +60,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(ctx, "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 66% rename from decort/data_source_snapshot_list.go rename to internal/service/cloudapi/snapshot/data_source_snapshot_list.go index d6f2144..0fe01c1 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 { - snapshotList, err := utilitySnapshotListCheckPresence(d, m) +func dataSourceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + snapshotList, err := utilitySnapshotListCheckPresence(ctx, 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 52% rename from decort/resource_snapshot.go rename to internal/service/cloudapi/snapshot/resource_snapshot.go index 7a75867..9a8fbc7 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(ctx, "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 { - snapshot, err := utilitySnapshotCheckPresence(d, m) +func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + snapshot, err := utilitySnapshotCheckPresence(ctx, d, m) if err != nil { - return err + return diag.FromErr(err) } d.Set("timestamp", snapshot.Timestamp) @@ -74,25 +84,25 @@ 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(ctx, "POST", snapshotDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") 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 } @@ -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(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + } } return nil } -func resourceSnapshotRollback(d *schema.ResourceDiff, m interface{}) error { - c := m.(*ControllerCfg) +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 } @@ -166,38 +180,27 @@ 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, 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 53% rename from decort/utility_snapshot.go rename to internal/service/cloudapi/snapshot/utility_snapshot.go index 6e7abbc..b99509b 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,22 +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 snapshot import ( + "context" "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) { - 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/decort/utility_snapshot_list.go b/internal/service/cloudapi/snapshot/utility_snapshot_list.go similarity index 51% rename from decort/utility_snapshot_list.go rename to internal/service/cloudapi/snapshot/utility_snapshot_list.go index 9171d23..e06ac5b 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,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 snapshot import ( + "context" "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) +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 := controller.decortAPICall("POST", snapshotListAPI, urlValues) + resp, err := c.DecortAPICall(ctx, "POST", snapshotListAPI, urlValues) if err != nil { return nil, err } @@ -48,7 +57,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 67% rename from decort/data_source_vgpu.go rename to internal/service/cloudapi/vgpu/data_source_vgpu.go index b1cf22b..763b26d 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 { - vgpu, err := utilityVGPUCheckPresence(d, m) +func dataSourceVGPURead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + vgpu, err := utilityVGPUCheckPresence(ctx, 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 60% rename from decort/utility_vgpu.go rename to internal/service/cloudapi/vgpu/utility_vgpu.go index a35ca71..65366cd 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,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 vgpu import ( + "context" "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) +func utilityVGPUCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*VGPU, error) { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} urlValues.Add("size", "50") @@ -51,7 +60,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(ctx, "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 77% rename from decort/data_source_vins.go rename to internal/service/cloudapi/vins/data_source_vins.go index 61fd3c5..2bcd362 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 { - vinsFacts, err := utilityVinsCheckPresence(d, m) +func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + 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 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 74% rename from decort/data_source_vins_list.go rename to internal/service/cloudapi/vins/data_source_vins_list.go index 84a2c0b..2178eb5 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 { - vinsList, err := utilityVinsListCheckPresence(d, m) +func dataSourceVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + vinsList, err := utilityVinsListCheckPresence(ctx, 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 76% rename from decort/resource_vins.go rename to internal/service/cloudapi/vins/resource_vins.go index cdfb5f6..22729f6 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(ctx, "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 { - vinsFacts, err := utilityVinsCheckPresence(d, m) +func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + 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 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(ctx, "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(ctx, "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) + vinsFacts, err := utilityVinsCheckPresence(ctx, 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,21 +201,21 @@ 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(ctx, "POST", VinsDeleteAPI, params) if err != nil { - return err + return diag.FromErr(err) } 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 @@ -294,26 +297,25 @@ 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, 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 80% rename from decort/utility_vins.go rename to internal/service/cloudapi/vins/utility_vins.go index 03a410c..a53ea85 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,28 +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 vins import ( + "context" "encoding/json" "fmt" "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 // 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 @@ -51,7 +60,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 +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 := controller.decortAPICall("POST", VinsGetAPI, urlValues) + vinsFacts, err := c.DecortAPICall(ctx, "POST", VinsGetAPI, urlValues) if err != nil { return "", err } @@ -103,7 +112,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(ctx, "POST", VinsSearchAPI, urlValues) if err != nil { return "", err } @@ -132,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 := controller.decortAPICall("POST", VinsGetAPI, rqValues) + vinsGetResp, err := c.DecortAPICall(ctx, "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 58% rename from decort/utility_vins_list.go rename to internal/service/cloudapi/vins/utility_vins_list.go index 7bdf083..4746f23 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,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 vins import ( + "context" "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) { +func utilityVinsListCheckPresence(ctx context.Context, 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 +59,7 @@ func utilityVinsListCheckPresence(d *schema.ResourceData, m interface{}) (VinsLi } log.Debugf("utilityVinsListCheckPresence") - vinsListRaw, err := controller.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/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 60% rename from decort/data_source_grid.go rename to internal/service/cloudbroker/grid/data_source_grid.go index 2529e3f..634d987 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 { - grid, err := utilityGridCheckPresence(d, m) +func dataSourceGridRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + grid, err := utilityGridCheckPresence(ctx, 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 66% rename from decort/data_source_grid_list.go rename to internal/service/cloudbroker/grid/data_source_grid_list.go index 3a420da..476a739 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 { - gridList, err := utilityGridListCheckPresence(d, m) +func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + gridList, err := utilityGridListCheckPresence(ctx, 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 55% rename from decort/utility_grid.go rename to internal/service/cloudbroker/grid/utility_grid.go index 8500a5f..8b7698e 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,28 +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 grid import ( + "context" "encoding/json" "errors" "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) { +func utilityGridCheckPresence(ctx context.Context, 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 +56,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(ctx, "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 55% rename from decort/utility_grid_list.go rename to internal/service/cloudbroker/grid/utility_grid_list.go index 202f6ad..a81e06c 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,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 grid import ( + "context" "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) { +func utilityGridListCheckPresence(ctx context.Context, 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 +56,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(ctx, "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..8b0b92c 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 { - image, err := utilityImageCheckPresence(d, m) +func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + image, err := utilityImageCheckPresence(ctx, 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 73% rename from decort/data_source_image_list.go rename to internal/service/cloudbroker/image/data_source_image_list.go index ad6f6d9..5e7f7ae 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 { - imageList, err := utilityImageListCheckPresence(d, m) +func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + imageList, err := utilityImageListCheckPresence(ctx, 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 73% rename from decort/data_source_image_list_stacks.go rename to internal/service/cloudbroker/image/data_source_image_list_stacks.go index 7b37371..c672748 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 { - imageListStacks, err := utilityImageListStacksCheckPresence(d, m) +func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + imageListStacks, err := utilityImageListStacksCheckPresence(ctx, 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 72% rename from decort/resource_cdrom_image.go rename to internal/service/cloudbroker/image/resource_cdrom_image.go index df93a21..8b0068c 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,43 +90,43 @@ func resourceCDROMImageCreate(d *schema.ResourceData, m interface{}) error { urlValues.Add("architecture", architecture.(string)) } - imageId, err := controller.decortAPICall("POST", imageCreateCDROMAPI, urlValues) + imageId, err := c.DecortAPICall(ctx, "POST", imageCreateCDROMAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(imageId) d.Set("image_id", imageId) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, 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) + image, err := utilityImageCheckPresence(ctx, 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(ctx, "POST", imageDeleteCDROMAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -361,73 +371,26 @@ 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, 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..233191a 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(ctx, "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 69% rename from decort/resource_image.go rename to internal/service/cloudbroker/image/resource_image.go index cd4b970..b578709 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,38 +103,38 @@ func resourceImageCreate(d *schema.ResourceData, m interface{}) error { } else { api = imageSyncCreateAPI } - imageId, err := controller.decortAPICall("POST", api, urlValues) + imageId, err := c.DecortAPICall(ctx, "POST", api, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(imageId) d.Set("image_id", imageId) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, 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) + image, err := utilityImageCheckPresence(ctx, 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) + image, err := utilityImageCheckPresence(ctx, 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,19 +202,19 @@ func resourceImageDelete(d *schema.ResourceData, m interface{}) error { urlValues.Add("permanently", strconv.FormatBool(permanently.(bool))) } - _, err = controller.decortAPICall("POST", imageDeleteAPI, urlValues) + _, err = c.DecortAPICall(ctx, "POST", imageDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") 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 @@ -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(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.(*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(ctx, "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(ctx, 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(ctx, 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(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } + if d.HasChange("computeci_id") { + err := resourceImageChangeComputeci(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } + + if d.HasChange("enabled_stacks") { + err := resourceImageUpdateNodes(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + urlValues = &url.Values{} + } + + if d.HasChange("link_to") { + err := resourceImageLink(ctx, 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(ctx, "POST", imageEditAPI, urlValues) + if err != nil { + return diag.FromErr(err) + } } return nil } -func resourceImageChangeEnabled(d *schema.ResourceDiff, m interface{}) error { +func resourceImageChangeEnabled(ctx context.Context, 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(ctx, "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(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.(*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(ctx, "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(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.(*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(ctx, "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(ctx context.Context, 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(ctx, "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(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.(*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(ctx, "POST", imageUpdateNodesAPI, urlValues) if err != nil { return err } @@ -616,73 +669,26 @@ 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, 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 69% rename from decort/resource_virtual_image.go rename to internal/service/cloudbroker/image/resource_virtual_image.go index 5097db1..ec540d7 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,51 +18,59 @@ 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(ctx, "POST", imageCreateVirtualAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId(imageId) d.Set("image_id", imageId) - image, err := utilityImageCheckPresence(d, m) + image, err := utilityImageCheckPresence(ctx, 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,27 @@ 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, 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 56% rename from decort/utility_image.go rename to internal/service/cloudbroker/image/utility_image.go index 3b20243..04981da 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,26 +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 ( + "context" "encoding/json" "errors" "fmt" "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) +func utilityImageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Image, error) { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} if (strconv.Itoa(d.Get("image_id").(int))) != "0" { @@ -44,7 +53,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(ctx, "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 59% rename from decort/utility_image_list.go rename to internal/service/cloudbroker/image/utility_image_list.go index bc80677..42adce0 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,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 image import ( + "context" "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) { +func utilityImageListCheckPresence(ctx context.Context, 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 +63,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(ctx, "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 53% rename from decort/utility_image_list_stacks.go rename to internal/service/cloudbroker/image/utility_image_list_stacks.go index c2ebd10..3b5a51a 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,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 image import ( + "context" "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) { +func utilityImageListStacksCheckPresence(ctx context.Context, 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(ctx, "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 63% rename from decort/data_source_pcidevice.go rename to internal/service/cloudbroker/pcidevice/data_source_pcidevice.go index e3fa314..90a9ac3 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 { - pcidevice, err := utilityPcideviceCheckPresence(d, m) +func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + pcidevice, err := utilityPcideviceCheckPresence(ctx, 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 67% rename from decort/data_source_pcidevice_list.go rename to internal/service/cloudbroker/pcidevice/data_source_pcidevice_list.go index 2ee469d..ce9baef 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 { - pcideviceList, err := utilityPcideviceListCheckPresence(d, m) +func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + pcideviceList, err := utilityPcideviceListCheckPresence(ctx, 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 58% rename from decort/resource_pcidevice.go rename to internal/service/cloudbroker/pcidevice/resource_pcidevice.go index 470ddb1..dbf033c 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 exists, err := resourcePcideviceExists(ctx, 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(ctx, "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 { - pcidevice, err := utilityPcideviceCheckPresence(d, m) +func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + pcidevice, err := utilityPcideviceCheckPresence(ctx, 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(ctx, "POST", pcideviceDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") @@ -120,8 +131,8 @@ func resourcePcideviceDelete(d *schema.ResourceData, m interface{}) error { 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 } @@ -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(ctx, "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,25 @@ 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, 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 54% rename from decort/utility_pcidevice.go rename to internal/service/cloudbroker/pcidevice/utility_pcidevice.go index 5709ea0..9b22947 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,22 +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 pcidevice import ( + "context" "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) { - 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 new file mode 100644 index 0000000..ada9adc --- /dev/null +++ b/internal/service/cloudbroker/pcidevice/utility_pcidevice_list.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 pcidevice + +import ( + "context" + "encoding/json" + "net/url" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/rudecs/terraform-provider-decort/internal/controller" +) + +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(ctx, "POST", pcideviceListAPI, urlValues) + if err != nil { + return nil, err + } + + err = json.Unmarshal([]byte(pcideviceListRaw), &pcideviceList) + if err != nil { + return nil, err + } + + return pcideviceList, nil +} 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 67% rename from decort/data_source_sep.go rename to internal/service/cloudbroker/sep/data_source_sep.go index 4dab665..80a187a 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 { - desSep, err := utilitySepCheckPresence(d, m) +func dataSourceSepRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + desSep, err := utilitySepCheckPresence(ctx, 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 53% rename from decort/data_source_sep_config.go rename to internal/service/cloudbroker/sep/data_source_sep_config.go index dcf1ec0..def1007 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 { - sepConfig, err := utilitySepConfigCheckPresence(d, m) +func dataSourceSepConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + sepConfig, err := utilitySepConfigCheckPresence(ctx, 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 77% rename from decort/data_source_sep_consumption.go rename to internal/service/cloudbroker/sep/data_source_sep_consumption.go index bd2c898..1b3406b 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 { - sepCons, err := utilitySepConsumptionCheckPresence(d, m) +func dataSourceSepConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + sepCons, err := utilitySepConsumptionCheckPresence(ctx, 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 55% rename from decort/data_source_sep_disk_list.go rename to internal/service/cloudbroker/sep/data_source_sep_disk_list.go index 128aa22..4df4366 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 { - sepDiskList, err := utilitySepDiskListCheckPresence(d, m) +func dataSourceSepDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + sepDiskList, err := utilitySepDiskListCheckPresence(ctx, 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 71% rename from decort/data_source_sep_list.go rename to internal/service/cloudbroker/sep/data_source_sep_list.go index 89f0340..c8b7e41 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 { - sepList, err := utilitySepListCheckPresence(d, m) +func dataSourceSepListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + sepList, err := utilitySepListCheckPresence(ctx, 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 54% rename from decort/data_source_sep_pool.go rename to internal/service/cloudbroker/sep/data_source_sep_pool.go index 6f401ba..d045d14 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 { - sepPool, err := utilitySepPoolCheckPresence(d, m) +func dataSourceSepPoolRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + sepPool, err := utilitySepPoolCheckPresence(ctx, 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 66% rename from decort/resource_sep.go rename to internal/service/cloudbroker/sep/resource_sep.go index d3608e3..25b54cf 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 exists, err := resourceSepExists(ctx, 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(ctx, "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) + sep, err := utilitySepCheckPresence(ctx, 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,34 +156,34 @@ 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) + sepDes, err := utilitySepCheckPresence(ctx, 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(ctx, "POST", sepDeleteAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } d.SetId("") 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 @@ -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(ctx, "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(ctx, "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(ctx, "POST", sepConfigValidateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } - _, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues) + _, err = c.DecortAPICall(ctx, "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(ctx, "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(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + } + + urlValues = &url.Values{} + if d.HasChange("consumed_by") { + err := resourceSepUpdateNodes(ctx, d, m) + if err != nil { + return diag.FromErr(err) + } + } + + urlValues = &url.Values{} + if d.HasChange("provided_by") { + err := resourceSepUpdateProviders(ctx, 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(ctx context.Context, 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(ctx, "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(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.(*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(ctx, "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(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.(*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(ctx, "POST", sepAddProviderNodesAPI, urlValues) if err != nil { return err } @@ -481,68 +516,27 @@ 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, 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 52% rename from decort/resource_sep_config.go rename to internal/service/cloudbroker/sep/resource_sep_config.go index c16b0f0..f48b51d 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,70 +18,78 @@ 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 exists, err := resourceSepConfigExists(ctx, 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) + sepConfig, err := utilitySepConfigCheckPresence(ctx, 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 } -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 @@ -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(ctx, "POST", sepConfigValidateAPI, urlValues) if err != nil { - return err + return diag.FromErr(err) } - _, err = c.decortAPICall("POST", sepConfigInsertAPI, urlValues) + _, err = c.DecortAPICall(ctx, "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(ctx, "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,25 @@ 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, 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 54% rename from decort/utility_sep.go rename to internal/service/cloudbroker/sep/utility_sep.go index 20dbf3d..724fcdf 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,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" "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) +func utilitySepCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Sep, error) { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sep := &Sep{} @@ -47,7 +56,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(ctx, "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 53% rename from decort/utility_sep_config.go rename to internal/service/cloudbroker/sep/utility_sep_config.go index ac98899..e4e247c 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,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" "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) +func utilitySepConfigCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SepConfig, error) { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sepConfig := SepConfig{} @@ -43,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 := controller.decortAPICall("POST", sepGetConfigAPI, urlValues) + sepConfigRaw, err := c.DecortAPICall(ctx, "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 50% rename from decort/utility_sep_consumption.go rename to internal/service/cloudbroker/sep/utility_sep_consumption.go index 413344c..88b0985 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,38 @@ 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" "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) +func utilitySepConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*SepConsumption, error) { + 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(ctx, "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 55% rename from decort/utility_sep_disk_list.go rename to internal/service/cloudbroker/sep/utility_sep_disk_list.go index 064d144..47b0aa8 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,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" "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) +func utilitySepDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]int, error) { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sepDiskList := SepDiskList{} @@ -47,7 +56,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(ctx, "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 55% rename from decort/utility_sep_list.go rename to internal/service/cloudbroker/sep/utility_sep_list.go index 30f7df6..96dbe0e 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,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 sep import ( + "context" "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) { +func utilitySepListCheckPresence(ctx context.Context, 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 +56,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(ctx, "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 54% rename from decort/utility_sep_pool.go rename to internal/service/cloudbroker/sep/utility_sep_pool.go index 048bc4b..4270569 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,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" "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) +func utilitySepPoolCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SepPool, error) { + c := m.(*controller.ControllerCfg) urlValues := &url.Values{} sepPool := SepPool{} @@ -44,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 := controller.decortAPICall("POST", sepGetPoolAPI, urlValues) + sepPoolRaw, err := c.DecortAPICall(ctx, "POST", sepGetPoolAPI, urlValues) if err != nil { return nil, err }