parent
							
								
									294680282e
								
							
						
					
					
						commit
						e2ee45ee14
					
				| @ -1,8 +1,24 @@ | ||||
| ## Version 4.5.0 | ||||
| ## Version 4.5.1 | ||||
| 
 | ||||
| ## Feature | ||||
| - Added support for authorization using the Basis.Virtual Security system. Add client and config | ||||
| - Refactoring BVS config | ||||
| - Added and updated data sources and resources for cloudbroker groups: | ||||
|     * account | ||||
|     * audit | ||||
|     * disks | ||||
|     * extnet | ||||
|     * flipgroup | ||||
|     * grid | ||||
|     * image | ||||
|     * k8ci | ||||
|     * k8s | ||||
|     * kvmvm (compute) | ||||
|     * lb (load balancer) | ||||
|     * pcidevice | ||||
|     * rg (resource group) | ||||
|     * sep | ||||
|     * stack | ||||
|     * vins | ||||
| 
 | ||||
| ### Bugfix | ||||
| - Fixed bservice and rg schema and flatten in cloudapi | ||||
| - Add stateUpgrader for k8s_cp in cloudapi/k8s | ||||
| - Fixed description update for compute in cloudapi/kvmvm | ||||
|  | ||||
| @ -1,161 +1,254 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| 
 | ||||
| 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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/extnet" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/locations" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/stack" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" | ||||
| 
 | ||||
| 	cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" | ||||
| 	// cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
 | ||||
| 	cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" | ||||
| 	// cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup"
 | ||||
| 	// cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid"
 | ||||
| 	// cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
 | ||||
| 	// cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb"
 | ||||
| 	// cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
 | ||||
| 	// cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg"
 | ||||
| 	// cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep"
 | ||||
| 	// cb_stack "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/stack"
 | ||||
| 	// cb_vgpu "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vgpu"
 | ||||
| ) | ||||
| 
 | ||||
| func newDataSourcesMap() map[string]*schema.Resource { | ||||
| 	return map[string]*schema.Resource{ | ||||
| 		"decort_account":                           account.DataSourceAccount(), | ||||
| 		"decort_resgroup":                          rg.DataSourceResgroup(), | ||||
| 		"decort_kvmvm":                             kvmvm.DataSourceCompute(), | ||||
| 		"decort_kvmvm_list":                        kvmvm.DataSourceComputeList(), | ||||
| 		"decort_kvmvm_audits":                      kvmvm.DataSourceComputeAudits(), | ||||
| 		"decort_kvmvm_get_audits":                  kvmvm.DataSourceComputeGetAudits(), | ||||
| 		"decort_kvmvm_get_console_url":             kvmvm.DataSourceComputeGetConsoleUrl(), | ||||
| 		"decort_kvmvm_get_log":                     kvmvm.DataSourceComputeGetLog(), | ||||
| 		"decort_kvmvm_pfw_list":                    kvmvm.DataSourceComputePfwList(), | ||||
| 		"decort_kvmvm_user_list":                   kvmvm.DataSourceComputeUserList(), | ||||
| 		"decort_kvmvm_snapshot_usage":              kvmvm.DataSourceComputeSnapshotUsage(), | ||||
| 		"decort_k8s":                               k8s.DataSourceK8s(), | ||||
| 		"decort_k8s_list":                          k8s.DataSourceK8sList(), | ||||
| 		"decort_k8s_list_deleted":                  k8s.DataSourceK8sListDeleted(), | ||||
| 		"decort_k8s_wg":                            k8s.DataSourceK8sWg(), | ||||
| 		"decort_k8s_wg_list":                       k8s.DataSourceK8sWgList(), | ||||
| 		"decort_k8s_computes":                      k8s.DataSourceK8sComputes(), | ||||
| 		"decort_k8ci_list":                         k8s.DataSourceK8CIList(), | ||||
| 		"decort_vins":                              vins.DataSourceVins(), | ||||
| 		"decort_vins_list":                         vins.DataSourceVinsList(), | ||||
| 		"decort_vins_audits":                       vins.DataSourceVinsAudits(), | ||||
| 		"decort_vins_ip_list":                      vins.DataSourceVinsIpList(), | ||||
| 		"decort_vins_list_deleted":                 vins.DataSourceVinsListDeleted(), | ||||
| 		"decort_vins_ext_net_list":                 vins.DataSourceVinsExtNetList(), | ||||
| 		"decort_vins_nat_rule_list":                vins.DataSourceVinsNatRuleList(), | ||||
| 		"decort_vins_static_route_list":            vins.DataSourceStaticRouteList(), | ||||
| 		"decort_vins_static_route":                 vins.DataSourceStaticRoute(), | ||||
| 		"decort_snapshot_list":                     snapshot.DataSourceSnapshotList(), | ||||
| 		"decort_disk":                              disks.DataSourceDisk(), | ||||
| 		"decort_disk_list":                         disks.DataSourceDiskList(), | ||||
| 		"decort_rg_list":                           rg.DataSourceRgList(), | ||||
| 		"decort_rg_affinity_group_computes":        rg.DataSourceRgAffinityGroupComputes(), | ||||
| 		"decort_rg_affinity_groups_list":           rg.DataSourceRgAffinityGroupsList(), | ||||
| 		"decort_rg_affinity_groups_get":            rg.DataSourceRgAffinityGroupsGet(), | ||||
| 		"decort_rg_audits":                         rg.DataSourceRgAudits(), | ||||
| 		"decort_rg_list_computes":                  rg.DataSourceRgListComputes(), | ||||
| 		"decort_rg_list_deleted":                   rg.DataSourceRgListDeleted(), | ||||
| 		"decort_rg_list_lb":                        rg.DataSourceRgListLb(), | ||||
| 		"decort_rg_list_pfw":                       rg.DataSourceRgListPfw(), | ||||
| 		"decort_rg_list_vins":                      rg.DataSourceRgListVins(), | ||||
| 		"decort_rg_usage":                          rg.DataSourceRgUsage(), | ||||
| 		"decort_disk_list_types_detailed":          disks.DataSourceDiskListTypesDetailed(), | ||||
| 		"decort_disk_list_types":                   disks.DataSourceDiskListTypes(), | ||||
| 		"decort_disk_list_deleted":                 disks.DataSourceDiskListDeleted(), | ||||
| 		"decort_disk_list_unattached":              disks.DataSourceDiskListUnattached(), | ||||
| 		"decort_disk_snapshot":                     disks.DataSourceDiskSnapshot(), | ||||
| 		"decort_disk_snapshot_list":                disks.DataSourceDiskSnapshotList(), | ||||
| 		"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_locations_list":                    locations.DataSourceLocationsList(), | ||||
| 		"decort_location_url":                      locations.DataSourceLocationUrl(), | ||||
| 		"decort_image_list":                        image.DataSourceImageList(), | ||||
| 		"decort_image":                             image.DataSourceImage(), | ||||
| 		"decort_lb":                                lb.DataSourceLB(), | ||||
| 		"decort_lb_list":                           lb.DataSourceLBList(), | ||||
| 		"decort_lb_list_deleted":                   lb.DataSourceLBListDeleted(), | ||||
| 		"decort_flipgroup":                         flipgroup.DataSourceFlipgroup(), | ||||
| 		"decort_flipgroup_list":                    flipgroup.DataSourceFlipGroupList(), | ||||
| 		"decort_stack":                             stack.DataSourceStack(), | ||||
| 		"decort_stack_list":                        stack.DataSourceStackList(), | ||||
| 		"decort_account_resource_consumption_list": account.DataSourceAccountResourceConsumptionList(), | ||||
| 		"decort_account_resource_consumption_get":  account.DataSourceAccountResourceConsumptionGet(), | ||||
| 		"decort_kvmvm_list_deleted":                kvmvm.DataSourceComputeListDeleted(), | ||||
| 		"decort_kvmvm_vgpu_list":                   kvmvm.DataSourceComputeVGPUList(), | ||||
| 		"decort_kvmvm_pci_device_list":             kvmvm.DataSourceComputePCIDeviceList(), | ||||
| 		"decort_k8s_wg_cloud_init":                 k8s.DataSourceK8sWgCloudInit(), | ||||
| 		"decort_rg_resource_consumption_list":      rg.DataSourceRGResourceConsumptionList(), | ||||
| 		"decort_rg_resource_consumption_get":       rg.DataSourceRGResourceConsumptionGet(), | ||||
| 
 | ||||
| 		"decort_cb_account":                           cb_account.DataSourceAccount(), | ||||
| 		"decort_cb_account_list":                      cb_account.DataSourceAccountList(), | ||||
| 		"decort_cb_account_computes_list":             cb_account.DataSourceAccountComputesList(), | ||||
| 		"decort_cb_account_deleted_list":              cb_account.DataSourceAccountDeletedList(), | ||||
| 		"decort_cb_account_disks_list":                cb_account.DataSourceAccountDisksList(), | ||||
| 		"decort_cb_account_flipgroups_list":           cb_account.DataSourceAccountFlipGroupsList(), | ||||
| 		"decort_cb_account_rg_list":                   cb_account.DataSourceAccountRGList(), | ||||
| 		"decort_cb_account_vins_list":                 cb_account.DataSourceAccountVinsList(), | ||||
| 		"decort_cb_account_resource_consumption_get":  cb_account.DataSourceAccountResourceConsumptionGet(), | ||||
| 		"decort_cb_account_resource_consumption_list": cb_account.DataSourceAccountResourceConsumptionList(), | ||||
| 		"decort_cb_account_audits_list":               cb_account.DataSourceAccountAuditsList(), | ||||
| 		"decort_cb_extnet":                            cb_extnet.DataSourceExtnetCB(), | ||||
| 		"decort_cb_extnet_list":                       cb_extnet.DataSourceExtnetListCB(), | ||||
| 		"decort_cb_extnet_default":                    cb_extnet.DataSourceExtnetDefaultCB(), | ||||
| 		"decort_cb_extnet_static_route_list":          cb_extnet.DataSourceStaticRouteList(), | ||||
| 		"decort_cb_extnet_static_route":               cb_extnet.DataSourceStaticRoute(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| 
 | ||||
| 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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/extnet" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/locations" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/stack" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" | ||||
| 
 | ||||
| 	cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" | ||||
| 	cb_audit "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/audit" | ||||
| 	cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" | ||||
| 	cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" | ||||
| 	cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup" | ||||
| 	cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid" | ||||
| 	cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" | ||||
| 	cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm" | ||||
| 	cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb" | ||||
| 	cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice" | ||||
| 	cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg" | ||||
| 	cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep" | ||||
| 	cb_stack "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/stack" | ||||
| 	cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins" | ||||
| 
 | ||||
| 	// cb_vgpu "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vgpu"
 | ||||
| 	cb_k8ci "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8ci" | ||||
| 	cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s" | ||||
| ) | ||||
| 
 | ||||
| func newDataSourcesMap() map[string]*schema.Resource { | ||||
| 	return map[string]*schema.Resource{ | ||||
| 		"decort_account":                           account.DataSourceAccount(), | ||||
| 		"decort_resgroup":                          rg.DataSourceResgroup(), | ||||
| 		"decort_kvmvm":                             kvmvm.DataSourceCompute(), | ||||
| 		"decort_kvmvm_list":                        kvmvm.DataSourceComputeList(), | ||||
| 		"decort_kvmvm_audits":                      kvmvm.DataSourceComputeAudits(), | ||||
| 		"decort_kvmvm_get_audits":                  kvmvm.DataSourceComputeGetAudits(), | ||||
| 		"decort_kvmvm_get_console_url":             kvmvm.DataSourceComputeGetConsoleUrl(), | ||||
| 		"decort_kvmvm_get_log":                     kvmvm.DataSourceComputeGetLog(), | ||||
| 		"decort_kvmvm_pfw_list":                    kvmvm.DataSourceComputePfwList(), | ||||
| 		"decort_kvmvm_user_list":                   kvmvm.DataSourceComputeUserList(), | ||||
| 		"decort_kvmvm_snapshot_usage":              kvmvm.DataSourceComputeSnapshotUsage(), | ||||
| 		"decort_k8s":                               k8s.DataSourceK8s(), | ||||
| 		"decort_k8s_list":                          k8s.DataSourceK8sList(), | ||||
| 		"decort_k8s_list_deleted":                  k8s.DataSourceK8sListDeleted(), | ||||
| 		"decort_k8s_wg":                            k8s.DataSourceK8sWg(), | ||||
| 		"decort_k8s_wg_list":                       k8s.DataSourceK8sWgList(), | ||||
| 		"decort_k8s_computes":                      k8s.DataSourceK8sComputes(), | ||||
| 		"decort_k8ci_list":                         k8s.DataSourceK8CIList(), | ||||
| 		"decort_vins":                              vins.DataSourceVins(), | ||||
| 		"decort_vins_list":                         vins.DataSourceVinsList(), | ||||
| 		"decort_vins_audits":                       vins.DataSourceVinsAudits(), | ||||
| 		"decort_vins_ip_list":                      vins.DataSourceVinsIpList(), | ||||
| 		"decort_vins_list_deleted":                 vins.DataSourceVinsListDeleted(), | ||||
| 		"decort_vins_ext_net_list":                 vins.DataSourceVinsExtNetList(), | ||||
| 		"decort_vins_nat_rule_list":                vins.DataSourceVinsNatRuleList(), | ||||
| 		"decort_vins_static_route_list":            vins.DataSourceStaticRouteList(), | ||||
| 		"decort_vins_static_route":                 vins.DataSourceStaticRoute(), | ||||
| 		"decort_snapshot_list":                     snapshot.DataSourceSnapshotList(), | ||||
| 		"decort_disk":                              disks.DataSourceDisk(), | ||||
| 		"decort_disk_list":                         disks.DataSourceDiskList(), | ||||
| 		"decort_rg_list":                           rg.DataSourceRgList(), | ||||
| 		"decort_rg_affinity_group_computes":        rg.DataSourceRgAffinityGroupComputes(), | ||||
| 		"decort_rg_affinity_groups_list":           rg.DataSourceRgAffinityGroupsList(), | ||||
| 		"decort_rg_affinity_groups_get":            rg.DataSourceRgAffinityGroupsGet(), | ||||
| 		"decort_rg_audits":                         rg.DataSourceRgAudits(), | ||||
| 		"decort_rg_list_computes":                  rg.DataSourceRgListComputes(), | ||||
| 		"decort_rg_list_deleted":                   rg.DataSourceRgListDeleted(), | ||||
| 		"decort_rg_list_lb":                        rg.DataSourceRgListLb(), | ||||
| 		"decort_rg_list_pfw":                       rg.DataSourceRgListPfw(), | ||||
| 		"decort_rg_list_vins":                      rg.DataSourceRgListVins(), | ||||
| 		"decort_rg_usage":                          rg.DataSourceRgUsage(), | ||||
| 		"decort_disk_list_types_detailed":          disks.DataSourceDiskListTypesDetailed(), | ||||
| 		"decort_disk_list_types":                   disks.DataSourceDiskListTypes(), | ||||
| 		"decort_disk_list_deleted":                 disks.DataSourceDiskListDeleted(), | ||||
| 		"decort_disk_list_unattached":              disks.DataSourceDiskListUnattached(), | ||||
| 		"decort_disk_snapshot":                     disks.DataSourceDiskSnapshot(), | ||||
| 		"decort_disk_snapshot_list":                disks.DataSourceDiskSnapshotList(), | ||||
| 		"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_locations_list":                    locations.DataSourceLocationsList(), | ||||
| 		"decort_location_url":                      locations.DataSourceLocationUrl(), | ||||
| 		"decort_image_list":                        image.DataSourceImageList(), | ||||
| 		"decort_image":                             image.DataSourceImage(), | ||||
| 		"decort_lb":                                lb.DataSourceLB(), | ||||
| 		"decort_lb_list":                           lb.DataSourceLBList(), | ||||
| 		"decort_lb_list_deleted":                   lb.DataSourceLBListDeleted(), | ||||
| 		"decort_flipgroup":                         flipgroup.DataSourceFlipgroup(), | ||||
| 		"decort_flipgroup_list":                    flipgroup.DataSourceFlipGroupList(), | ||||
| 		"decort_stack":                             stack.DataSourceStack(), | ||||
| 		"decort_stack_list":                        stack.DataSourceStackList(), | ||||
| 		"decort_account_resource_consumption_list": account.DataSourceAccountResourceConsumptionList(), | ||||
| 		"decort_account_resource_consumption_get":  account.DataSourceAccountResourceConsumptionGet(), | ||||
| 		"decort_kvmvm_list_deleted":                kvmvm.DataSourceComputeListDeleted(), | ||||
| 		"decort_kvmvm_vgpu_list":                   kvmvm.DataSourceComputeVGPUList(), | ||||
| 		"decort_kvmvm_pci_device_list":             kvmvm.DataSourceComputePCIDeviceList(), | ||||
| 		"decort_k8s_wg_cloud_init":                 k8s.DataSourceK8sWgCloudInit(), | ||||
| 		"decort_rg_resource_consumption_list":      rg.DataSourceRGResourceConsumptionList(), | ||||
| 		"decort_rg_resource_consumption_get":       rg.DataSourceRGResourceConsumptionGet(), | ||||
| 
 | ||||
| 		"decort_cb_account":                           cb_account.DataSourceAccount(), | ||||
| 		"decort_cb_account_list":                      cb_account.DataSourceAccountList(), | ||||
| 		"decort_cb_account_computes_list":             cb_account.DataSourceAccountComputesList(), | ||||
| 		"decort_cb_account_list_deleted":              cb_account.DataSourceAccountDeletedList(), | ||||
| 		"decort_cb_account_disks_list":                cb_account.DataSourceAccountDisksList(), | ||||
| 		"decort_cb_account_flipgroups_list":           cb_account.DataSourceAccountFlipGroupsList(), | ||||
| 		"decort_cb_account_rg_list":                   cb_account.DataSourceAccountRGList(), | ||||
| 		"decort_cb_account_vins_list":                 cb_account.DataSourceAccountVinsList(), | ||||
| 		"decort_cb_account_resource_consumption_get":  cb_account.DataSourceAccountResourceConsumptionGet(), | ||||
| 		"decort_cb_account_resource_consumption_list": cb_account.DataSourceAccountResourceConsumptionList(), | ||||
| 		"decort_cb_account_audits_list":               cb_account.DataSourceAccountAuditsList(), | ||||
| 		"decort_cb_audit":                             cb_audit.DataSourceAudit(), | ||||
| 		"decort_cb_audit_list":                        cb_audit.DataSourceAuditList(), | ||||
| 		"decort_cb_audit_linked_jobs":                 cb_audit.DataSourceAuditLinkedJobs(), | ||||
| 		"decort_cb_extnet":                            cb_extnet.DataSourceExtnetCB(), | ||||
| 		"decort_cb_extnet_list":                       cb_extnet.DataSourceExtnetListCB(), | ||||
| 		"decort_cb_extnet_default":                    cb_extnet.DataSourceExtnetDefaultCB(), | ||||
| 		"decort_cb_extnet_static_route_list":          cb_extnet.DataSourceStaticRouteList(), | ||||
| 		"decort_cb_extnet_static_route":               cb_extnet.DataSourceStaticRoute(), | ||||
| 		"decort_cb_image":                             cb_image.DataSourceImage(), | ||||
| 		"decort_cb_grid":                              cb_grid.DataSourceGrid(), | ||||
| 		"decort_cb_grid_get_status":                   cb_grid.DataSourceGridGetStatus(), | ||||
| 		"decort_cb_grid_post_status":                  cb_grid.DataSourceGridPostStatus(), | ||||
| 		"decort_cb_grid_get_diagnosis":                cb_grid.DataSourceGridGetDiagnosis(), | ||||
| 		"decort_cb_grid_post_diagnosis":               cb_grid.DataSourceGridPostDiagnosis(), | ||||
| 		"decort_cb_grid_list":                         cb_grid.DataSourceGridList(), | ||||
| 		"decort_cb_grid_list_emails":                  cb_grid.DataSourceGridListEmails(), | ||||
| 		"decort_cb_grid_list_consumption":             cb_grid.DataSourceGridListConsumption(), | ||||
| 		"decort_cb_grid_get_consumption":              cb_grid.DataSourceGridGetConsumption(), | ||||
| 		"decort_cb_image_list":                        cb_image.DataSourceImageList(), | ||||
| 		"decort_cb_image_list_stacks":                 cb_image.DataSourceImageListStacks(), | ||||
| 		"decort_cb_kvmvm":                             cb_kvmvm.DataSourceCompute(), | ||||
| 		"decort_cb_kvmvm_affinity_relations":          cb_kvmvm.DataSourceComputeAffinityRelations(), | ||||
| 		"decort_cb_kvmvm_audits":                      cb_kvmvm.DataSourceComputeAudits(), | ||||
| 		"decort_cb_kvmvm_boot_order_get":              cb_kvmvm.DataSourceComputeBootOrderGet(), | ||||
| 		"decort_cb_kvmvm_get_audits":                  cb_kvmvm.DataSourceComputeGetAudits(), | ||||
| 		"decort_cb_kvmvm_get_console_url":             cb_kvmvm.DataSourceComputeGetConsoleUrl(), | ||||
| 		"decort_cb_kvmvm_get_log":                     cb_kvmvm.DataSourceComputeGetLog(), | ||||
| 		"decort_cb_kvmvm_list":                        cb_kvmvm.DataSourceComputeList(), | ||||
| 		"decort_cb_kvmvm_list_deleted":                cb_kvmvm.DataSourceComputeListDeleted(), | ||||
| 		"decort_cb_kvmvm_migrate_storage_info":        cb_kvmvm.DataSourceComputeMigrateStorageInfo(), | ||||
| 		"decort_cb_kvmvm_pci_device_list":             cb_kvmvm.DataSourceComputePCIDeviceList(), | ||||
| 		"decort_cb_kvmvm_pfw_list":                    cb_kvmvm.DataSourceComputePfwList(), | ||||
| 		"decort_cb_kvmvm_snapshot_list":               cb_kvmvm.DataSourceComputeSnapshotList(), | ||||
| 		"decort_cb_kvmvm_snapshot_usage":              cb_kvmvm.DataSourceComputeSnapshotUsage(), | ||||
| 		"decort_cb_kvmvm_user_list":                   cb_kvmvm.DataSourceComputeUserList(), | ||||
| 		"decort_cb_kvmvm_vgpu_list":                   cb_kvmvm.DataSourceComputeVGPUList(), | ||||
| 		"decort_cb_disk":                              cb_disks.DataSourceDisk(), | ||||
| 		"decort_cb_disk_list":                         cb_disks.DataSourceDiskList(), | ||||
| 		"decort_cb_disk_list_deleted":                 cb_disks.DataSourceDiskListDeleted(), | ||||
| 		"decort_cb_disk_list_types":                   cb_disks.DataSourceDiskListTypes(), | ||||
| 		"decort_cb_disk_list_types_detailed":          cb_disks.DataSourceDiskListTypesDetailed(), | ||||
| 		"decort_cb_disk_list_unattached":              cb_disks.DataSourceDiskListUnattached(), | ||||
| 		"decort_cb_disk_snapshot":                     cb_disks.DataSourceDiskSnapshot(), | ||||
| 		"decort_cb_disk_snapshot_list":                cb_disks.DataSourceDiskSnapshotList(), | ||||
| 		"decort_cb_pcidevice":                         cb_pcidevice.DataSourcePcidevice(), | ||||
| 		"decort_cb_pcidevice_list":                    cb_pcidevice.DataSourcePcideviceList(), | ||||
| 		"decort_cb_rg":                                cb_rg.DataSourceResgroup(), | ||||
| 		"decort_cb_rg_affinity_group_computes":        cb_rg.DataSourceRgAffinityGroupComputes(), | ||||
| 		"decort_cb_rg_affinity_groups_get":            cb_rg.DataSourceRgAffinityGroupsGet(), | ||||
| 		"decort_cb_rg_affinity_groups_list":           cb_rg.DataSourceRgAffinityGroupsList(), | ||||
| 		"decort_cb_rg_resource_consumption_get":       cb_rg.DataSourceRGResourceConsumptionGet(), | ||||
| 		"decort_cb_rg_resource_consumption_list":      cb_rg.DataSourceRGResourceConsumptionList(), | ||||
| 		"decort_cb_rg_audits":                         cb_rg.DataSourceRgAudits(), | ||||
| 		"decort_cb_rg_list":                           cb_rg.DataSourceRgList(), | ||||
| 		"decort_cb_rg_list_deleted":                   cb_rg.DataSourceRgListDeleted(), | ||||
| 		"decort_cb_rg_list_computes":                  cb_rg.DataSourceRgListComputes(), | ||||
| 		"decort_cb_rg_list_lb":                        cb_rg.DataSourceRgListLb(), | ||||
| 		"decort_cb_rg_list_pfw":                       cb_rg.DataSourceRgListPfw(), | ||||
| 		"decort_cb_rg_list_vins":                      cb_rg.DataSourceRgListVins(), | ||||
| 		"decort_cb_rg_usage":                          cb_rg.DataSourceRgUsage(), | ||||
| 		"decort_cb_sep_list":                          cb_sep.DataSourceSepList(), | ||||
| 		"decort_cb_sep":                               cb_sep.DataSourceSep(), | ||||
| 		"decort_cb_sep_consumption":                   cb_sep.DataSourceSepConsumption(), | ||||
| 		"decort_cb_sep_disk_list":                     cb_sep.DataSourceSepDiskList(), | ||||
| 		"decort_cb_sep_config":                        cb_sep.DataSourceSepConfig(), | ||||
| 		"decort_cb_sep_pool":                          cb_sep.DataSourceSepPool(), | ||||
| 		"decort_cb_lb":                                cb_lb.DataSourceLB(), | ||||
| 		"decort_cb_lb_list":                           cb_lb.DataSourceLBList(), | ||||
| 		"decort_cb_lb_list_deleted":                   cb_lb.DataSourceLBListDeleted(), | ||||
| 		"decort_cb_flipgroup_list":                    cb_flipgroup.DataSourceFlipgroupList(), | ||||
| 		"decort_cb_flipgroup":                         cb_flipgroup.DataSourceFlipgroup(), | ||||
| 		"decort_cb_stack_list":                        cb_stack.DataSourceStacksList(), | ||||
| 		"decort_cb_stack":                             cb_stack.DataSourceStack(), | ||||
| 		"decort_cb_vins":                              cb_vins.DataSourceVins(), | ||||
| 		"decort_cb_vins_list":                         cb_vins.DataSourceVinsList(), | ||||
| 		"decort_cb_vins_audits":                       cb_vins.DataSourceVinsAudits(), | ||||
| 		"decort_cb_vins_ip_list":                      cb_vins.DataSourceVinsIpList(), | ||||
| 		"decort_cb_vins_list_deleted":                 cb_vins.DataSourceVinsListDeleted(), | ||||
| 		"decort_cb_vins_ext_net_list":                 cb_vins.DataSourceVinsExtNetList(), | ||||
| 		"decort_cb_vins_nat_rule_list":                cb_vins.DataSourceVinsNatRuleList(), | ||||
| 		"decort_cb_vins_static_route":                 cb_vins.DataSourceStaticRoute(), | ||||
| 		"decort_cb_vins_static_route_list":            cb_vins.DataSourceStaticRouteList(), | ||||
| 		"decort_cb_k8ci":                              cb_k8ci.DataSourceK8CI(), | ||||
| 		"decort_cb_k8ci_list":                         cb_k8ci.DataSourceK8CIList(), | ||||
| 		"decort_cb_k8ci_list_deleted":                 cb_k8ci.DataSourceK8CIListDeleted(), | ||||
| 		"decort_cb_k8s":                               cb_k8s.DataSourceK8s(), | ||||
| 		"decort_cb_k8s_list":                          cb_k8s.DataSourceK8sList(), | ||||
| 		"decort_cb_k8s_list_deleted":                  cb_k8s.DataSourceK8sListDeleted(), | ||||
| 		"decort_cb_k8s_wg":                            cb_k8s.DataSourceK8sWg(), | ||||
| 		"decort_cb_k8s_wg_cloud_init":                 cb_k8s.DataSourceK8sWgCloudInit(), | ||||
| 		"decort_cb_k8s_wg_list":                       cb_k8s.DataSourceK8sWgList(), | ||||
| 		"decort_cb_k8s_computes":                      cb_k8s.DataSourceK8sComputes(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,150 +1,168 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| 
 | ||||
| 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" | ||||
| 
 | ||||
| 	"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" | ||||
| 	"golang.org/x/net/context" | ||||
| 
 | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/location" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs" | ||||
| ) | ||||
| 
 | ||||
| func Provider() *schema.Provider { | ||||
| 	return &schema.Provider{ | ||||
| 		Schema: map[string]*schema.Schema{ | ||||
| 			"authenticator": { | ||||
| 				Type:         schema.TypeString, | ||||
| 				Required:     true, | ||||
| 				StateFunc:    statefuncs.StateFuncToLower, | ||||
| 				ValidateFunc: validation.StringInSlice([]string{"decs3o", "legacy", "jwt", "bvs"}, true), // ignore case while validating
 | ||||
| 				Description:  "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'decs3o', 'legacy', 'jwt' or 'bvs'.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"oauth2_url": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				StateFunc:   statefuncs.StateFuncToLower, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil), | ||||
| 				Description: "OAuth2 application URL in 'decs3o' and 'bvs' authentication mode.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"controller_url": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Required:    true, | ||||
| 				ForceNew:    true, | ||||
| 				StateFunc:   statefuncs.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.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"bvs_user": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_USER", nil), | ||||
| 				Description: "User name for DECORT cloud API operations in 'bvs' authentication mode.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"bvs_password": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_PASSWORD", nil), | ||||
| 				Description: "User password for DECORT cloud API operations in 'bvs' authentication mode.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"domain": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_DOMAIN", nil), | ||||
| 				Description: "User password for DECORT cloud API operations in 'bvs' 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 'decs3o' and 'bvs' 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 'decs3o' and 'bvs' 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: newResourcesMap(), | ||||
| 
 | ||||
| 		DataSourcesMap: newDataSourcesMap(), | ||||
| 
 | ||||
| 		ConfigureContextFunc: providerConfigure, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { | ||||
| 	decsController, err := controller.ControllerConfigure(d) | ||||
| 	if err != nil { | ||||
| 		return nil, diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	gridId, err := location.UtilityLocationGetDefaultGridID(ctx, decsController) | ||||
| 	if err != nil { | ||||
| 		return nil, diag.FromErr(err) | ||||
| 	} | ||||
| 	if gridId == 0 { | ||||
| 		return nil, diag.FromErr(fmt.Errorf("providerConfigure: invalid default Grid ID = 0")) | ||||
| 	} | ||||
| 
 | ||||
| 	return decsController, nil | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| 
 | ||||
| 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" | ||||
| 
 | ||||
| 	"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" | ||||
| 	"golang.org/x/net/context" | ||||
| 
 | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/location" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs" | ||||
| ) | ||||
| 
 | ||||
| func Provider() *schema.Provider { | ||||
| 	return &schema.Provider{ | ||||
| 		Schema: map[string]*schema.Schema{ | ||||
| 			"authenticator": { | ||||
| 				Type:         schema.TypeString, | ||||
| 				Required:     true, | ||||
| 				StateFunc:    statefuncs.StateFuncToLower, | ||||
| 				ValidateFunc: validation.StringInSlice([]string{"decs3o", "legacy", "jwt", "bvs"}, true), // ignore case while validating
 | ||||
| 				Description:  "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'decs3o', 'legacy', 'jwt' or 'bvs'.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"oauth2_url": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				StateFunc:   statefuncs.StateFuncToLower, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil), | ||||
| 				Description: "OAuth2 application URL in 'decs3o' and 'bvs' authentication mode.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"controller_url": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Required:    true, | ||||
| 				ForceNew:    true, | ||||
| 				StateFunc:   statefuncs.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.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"bvs_user": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_USER", nil), | ||||
| 				Description: "User name for DECORT cloud API operations in 'bvs' authentication mode.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"bvs_password": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_PASSWORD", nil), | ||||
| 				Description: "User password for DECORT cloud API operations in 'bvs' authentication mode.", | ||||
| 			}, | ||||
| 
 | ||||
| 			"domain": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				DefaultFunc: schema.EnvDefaultFunc("DECORT_DOMAIN", nil), | ||||
| 				Description: "User password for DECORT cloud API operations in 'bvs' 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 'decs3o' and 'bvs' 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 'decs3o' and 'bvs' 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!", | ||||
| 			}, | ||||
| 
 | ||||
| 			"path_cfg": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				Description: "The path of the configuration file entry", | ||||
| 			}, | ||||
| 
 | ||||
| 			"path_token": { | ||||
| 				Type:        schema.TypeString, | ||||
| 				Optional:    true, | ||||
| 				Description: "The path of the token file entry", | ||||
| 			}, | ||||
| 
 | ||||
| 			"time_to_refresh": { | ||||
| 				Type:        schema.TypeInt, | ||||
| 				Optional:    true, | ||||
| 				Description: "The number of minutes before the expiration of the token, a refresh will be made", | ||||
| 			}, | ||||
| 		}, | ||||
| 
 | ||||
| 		ResourcesMap: newResourcesMap(), | ||||
| 
 | ||||
| 		DataSourcesMap: newDataSourcesMap(), | ||||
| 
 | ||||
| 		ConfigureContextFunc: providerConfigure, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { | ||||
| 	decsController, err := controller.ControllerConfigure(d) | ||||
| 	if err != nil { | ||||
| 		return nil, diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	gridId, err := location.UtilityLocationGetDefaultGridID(ctx, decsController) | ||||
| 	if err != nil { | ||||
| 		return nil, diag.FromErr(err) | ||||
| 	} | ||||
| 	if gridId == 0 { | ||||
| 		return nil, diag.FromErr(fmt.Errorf("providerConfigure: invalid default Grid ID = 0")) | ||||
| 	} | ||||
| 
 | ||||
| 	return decsController, nil | ||||
| } | ||||
|  | ||||
| @ -1,104 +1,103 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| 
 | ||||
| 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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/pfw" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" | ||||
| 
 | ||||
| 	cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" | ||||
| 	// cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
 | ||||
| 	cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" | ||||
| 	// cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup"
 | ||||
| 	// cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
 | ||||
| 	// cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s"
 | ||||
| 	// cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm"
 | ||||
| 	// cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb"
 | ||||
| 	// cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
 | ||||
| 	// cb_pfw "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pfw"
 | ||||
| 	// cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg"
 | ||||
| 	// cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep"
 | ||||
| 	// cb_snapshot "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/snapshot"
 | ||||
| 	// cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins"
 | ||||
| ) | ||||
| 
 | ||||
| func newResourcesMap() map[string]*schema.Resource { | ||||
| 	return map[string]*schema.Resource{ | ||||
| 		"decort_resgroup":          rg.ResourceResgroup(), | ||||
| 		"decort_kvmvm":             kvmvm.ResourceCompute(), | ||||
| 		"decort_disk":              disks.ResourceDisk(), | ||||
| 		"decort_disk_snapshot":     disks.ResourceDiskSnapshot(), | ||||
| 		"decort_vins":              vins.ResourceVins(), | ||||
| 		"decort_pfw":               pfw.ResourcePfw(), | ||||
| 		"decort_k8s":               k8s.ResourceK8s(), | ||||
| 		"decort_k8s_wg":            k8s.ResourceK8sWg(), | ||||
| 		"decort_k8s_cp":            k8s.ResourceK8sCP(), | ||||
| 		"decort_snapshot":          snapshot.ResourceSnapshot(), | ||||
| 		"decort_account":           account.ResourceAccount(), | ||||
| 		"decort_bservice":          bservice.ResourceBasicService(), | ||||
| 		"decort_bservice_group":    bservice.ResourceBasicServiceGroup(), | ||||
| 		"decort_image":             image.ResourceImage(), | ||||
| 		"decort_image_virtual":     image.ResourceImageVirtual(), | ||||
| 		"decort_lb":                lb.ResourceLB(), | ||||
| 		"decort_lb_backend":        lb.ResourceLBBackend(), | ||||
| 		"decort_lb_backend_server": lb.ResourceLBBackendServer(), | ||||
| 		"decort_lb_frontend":       lb.ResourceLBFrontend(), | ||||
| 		"decort_lb_frontend_bind":  lb.ResourceLBFrontendBind(), | ||||
| 		"decort_flipgroup":         flipgroup.ResourceFlipgroup(), | ||||
| 		"decort_vins_static_route": vins.ResourceStaticRoute(), | ||||
| 
 | ||||
| 		"decort_cb_account": cb_account.ResourceAccount(), | ||||
| 		"decort_cb_extnet":  cb_extnet.ResourceExtnetCB(), | ||||
| 		// "decort_cb_disk":                cb_disks.ResourceDisk(),
 | ||||
| 		// "decort_cb_image":               cb_image.ResourceImage(),
 | ||||
| 		// "decort_cb_virtual_image":       cb_image.ResourceVirtualImage(),
 | ||||
| 		// "decort_cb_cdrom_image":         cb_image.ResourceCDROMImage(),
 | ||||
| 		// "decort_cb_delete_images":       cb_image.ResourceDeleteImages(),
 | ||||
| 		// "decort_cb_pcidevice":           cb_pcidevice.ResourcePcidevice(),
 | ||||
| 		// "decort_cb_sep":                 cb_sep.ResourceSep(),
 | ||||
| 		// "decort_cb_sep_config":          cb_sep.ResourceSepConfig(),
 | ||||
| 		// "decort_cb_resgroup":            cb_rg.ResourceResgroup(),
 | ||||
| 		// "decort_cb_kvmvm":               cb_kvmvm.ResourceCompute(),
 | ||||
| 		// "decort_cb_vins":                cb_vins.ResourceVins(),
 | ||||
| 		// "decort_cb_pfw":                 cb_pfw.ResourcePfw(),
 | ||||
| 		// "decort_cb_k8s":                 cb_k8s.ResourceK8s(),
 | ||||
| 		// "decort_cb_k8s_wg":              cb_k8s.ResourceK8sWg(),
 | ||||
| 		// "decort_cb_snapshot":            cb_snapshot.ResourceSnapshot(),
 | ||||
| 		// "decort_cb_flipgroup":           cb_flipgroup.ResourceFlipgroup(),
 | ||||
| 		// "decort_cb_lb":                  cb_lb.ResourceLB(),
 | ||||
| 		// "decort_cb_lb_backend":          cb_lb.ResourceLBBackend(),
 | ||||
| 		// "decort_cb_lb_backend_server":   cb_lb.ResourceLBBackendServer(),
 | ||||
| 		// "decort_cb_lb_frontend":         cb_lb.ResourceLBFrontend(),
 | ||||
| 		// "decort_cb_lb_frontend_bind":    cb_lb.ResourceLBFrontendBind(),
 | ||||
| 		"decort_cb_extnet_static_route": cb_extnet.ResourceStaticRoute(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Kasim Baybikov, <kmbaybikov@basistech.ru> | ||||
| 
 | ||||
| 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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/pfw" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" | ||||
| 
 | ||||
| 	cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" | ||||
| 	cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" | ||||
| 	cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" | ||||
| 	cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup" | ||||
| 	cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" | ||||
| 	cb_k8ci "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8ci" | ||||
| 	cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s" | ||||
| 	cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm" | ||||
| 	cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb" | ||||
| 	cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice" | ||||
| 	cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg" | ||||
| 	cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep" | ||||
| 	cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins" | ||||
| ) | ||||
| 
 | ||||
| func newResourcesMap() map[string]*schema.Resource { | ||||
| 	return map[string]*schema.Resource{ | ||||
| 		"decort_resgroup":          rg.ResourceResgroup(), | ||||
| 		"decort_kvmvm":             kvmvm.ResourceCompute(), | ||||
| 		"decort_disk":              disks.ResourceDisk(), | ||||
| 		"decort_disk_snapshot":     disks.ResourceDiskSnapshot(), | ||||
| 		"decort_vins":              vins.ResourceVins(), | ||||
| 		"decort_pfw":               pfw.ResourcePfw(), | ||||
| 		"decort_k8s":               k8s.ResourceK8s(), | ||||
| 		"decort_k8s_wg":            k8s.ResourceK8sWg(), | ||||
| 		"decort_k8s_cp":            k8s.ResourceK8sCP(), | ||||
| 		"decort_snapshot":          snapshot.ResourceSnapshot(), | ||||
| 		"decort_account":           account.ResourceAccount(), | ||||
| 		"decort_bservice":          bservice.ResourceBasicService(), | ||||
| 		"decort_bservice_group":    bservice.ResourceBasicServiceGroup(), | ||||
| 		"decort_image":             image.ResourceImage(), | ||||
| 		"decort_image_virtual":     image.ResourceImageVirtual(), | ||||
| 		"decort_lb":                lb.ResourceLB(), | ||||
| 		"decort_lb_backend":        lb.ResourceLBBackend(), | ||||
| 		"decort_lb_backend_server": lb.ResourceLBBackendServer(), | ||||
| 		"decort_lb_frontend":       lb.ResourceLBFrontend(), | ||||
| 		"decort_lb_frontend_bind":  lb.ResourceLBFrontendBind(), | ||||
| 		"decort_flipgroup":         flipgroup.ResourceFlipgroup(), | ||||
| 		"decort_vins_static_route": vins.ResourceStaticRoute(), | ||||
| 
 | ||||
| 		"decort_cb_account":             cb_account.ResourceAccount(), | ||||
| 		"decort_cb_extnet":              cb_extnet.ResourceExtnetCB(), | ||||
| 		"decort_cb_extnet_static_route": cb_extnet.ResourceStaticRoute(), | ||||
| 		"decort_cb_disk":                cb_disks.ResourceDisk(), | ||||
| 		"decort_cb_disk_snapshot":       cb_disks.ResourceDiskSnapshot(), | ||||
| 		"decort_cb_image":               cb_image.ResourceImage(), | ||||
| 		"decort_cb_virtual_image":       cb_image.ResourceVirtualImage(), | ||||
| 		"decort_cb_cdrom_image":         cb_image.ResourceCDROMImage(), | ||||
| 		"decort_cb_pcidevice":           cb_pcidevice.ResourcePcidevice(), | ||||
| 		"decort_cb_sep":                 cb_sep.ResourceSep(), | ||||
| 		"decort_cb_sep_config":          cb_sep.ResourceSepConfig(), | ||||
| 		"decort_cb_kvmvm":               cb_kvmvm.ResourceCompute(), | ||||
| 		"decort_cb_vins":                cb_vins.ResourceVins(), | ||||
| 		"decort_cb_k8ci":                cb_k8ci.ResourceK8CI(), | ||||
| 		"decort_cb_k8s_cp":              cb_k8s.ResourceK8sCP(), | ||||
| 		"decort_cb_k8s_wg":              cb_k8s.ResourceK8sWg(), | ||||
| 		"decort_cb_vins_static_route":   cb_vins.ResourceStaticRoute(), | ||||
| 		"decort_cb_flipgroup":           cb_flipgroup.ResourceFlipgroup(), | ||||
| 		"decort_cb_lb":                  cb_lb.ResourceLB(), | ||||
| 		"decort_cb_lb_backend":          cb_lb.ResourceLBBackend(), | ||||
| 		"decort_cb_lb_backend_server":   cb_lb.ResourceLBBackendServer(), | ||||
| 		"decort_cb_lb_frontend":         cb_lb.ResourceLBFrontend(), | ||||
| 		"decort_cb_lb_frontend_bind":    cb_lb.ResourceLBFrontendBind(), | ||||
| 		"decort_cb_rg":                  cb_rg.ResourceResgroup(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,109 +1,70 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountAuditsList, err := utilityAccountAuditsListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountAuditsList(accountAuditsList)) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountAuditsListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "ID of the account", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "Search Result", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"call": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"responsetime": { | ||||
| 						Type:     schema.TypeFloat, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"statuscode": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"timestamp": { | ||||
| 						Type:     schema.TypeFloat, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"user": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountAuditsList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountAuditsListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountAuditsListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountAuditsList, err := utilityAccountAuditsListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountAuditsList(accountAuditsList)) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountAuditsList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountAuditsListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountAuditsListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,225 +1,71 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountComputesList, err := utilityAccountComputesListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountComputesList(accountComputesList)) | ||||
| 	d.Set("entry_count", accountComputesList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "ID of the account", | ||||
| 		}, | ||||
| 		"compute_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by compute ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by compute name", | ||||
| 		}, | ||||
| 		"rg_name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by RG name", | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by RG ID", | ||||
| 		}, | ||||
| 		"tech_status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by tech. status", | ||||
| 		}, | ||||
| 		"ip_address": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by IP address", | ||||
| 		}, | ||||
| 		"extnet_name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by extnet name", | ||||
| 		}, | ||||
| 		"extnet_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by extnet ID", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "Search Result", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"account_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"cpus": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"compute_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"compute_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"ram": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"registered": { | ||||
| 						Type:     schema.TypeBool, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"rg_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"rg_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"tech_status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"total_disks_size": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"updated_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"updated_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"user_managed": { | ||||
| 						Type:     schema.TypeBool, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"vins_connected": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| func DataSourceAccountComputesList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountComputesListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountComputesListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountComputesList, err := utilityAccountComputesListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountComputesList(accountComputesList)) | ||||
| 	d.Set("entry_count", accountComputesList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountComputesList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountComputesListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountComputesListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,284 +1,71 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func DataSourceAccountDeletedList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountDeletedListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountListDeletedSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 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", flattenListDeleted(accountDeletedList)) | ||||
| 	d.Set("entry_count", accountDeletedList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountListDeletedSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"by_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by name", | ||||
| 		}, | ||||
| 		"acl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ACL", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"dc_location": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"ckey": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"meta": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeString, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"acl": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"explicit": { | ||||
| 									Type:     schema.TypeBool, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"guid": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"right": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"status": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"type": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"user_group_id": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"company": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"companyurl": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"cpu_allocation_parameter": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"cpu_allocation_ratio": { | ||||
| 						Type:     schema.TypeFloat, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deactivation_time": { | ||||
| 						Type:     schema.TypeFloat, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"displayname": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"resource_limits": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"cu_c": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_d": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_dm": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_i": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_m": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_np": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"gpu_units": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"resource_types": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeString, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"send_access_emails": { | ||||
| 						Type:     schema.TypeBool, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"uniq_pools": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeString, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"updated_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"version": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"vins": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeInt, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/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 { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenListDeleted(accountDeletedList)) | ||||
| 	d.Set("entry_count", accountDeletedList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountDeletedList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountDeletedListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountListDeletedSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,151 +1,70 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountDisksList, err := utilityAccountDisksListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountDisksList(accountDisksList)) | ||||
| 	d.Set("entry_count", accountDisksList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "ID of the account", | ||||
| 		}, | ||||
| 		"disk_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by disk ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by disk name", | ||||
| 		}, | ||||
| 		"disk_max_size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by disk max size", | ||||
| 		}, | ||||
| 		"type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by disk type", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "Search Result", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"disk_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"disk_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"pool_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"sep_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"shareable": { | ||||
| 						Type:     schema.TypeBool, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"size_max": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"type": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountDisksList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountDisksListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountDisksListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountDisksList, err := utilityAccountDisksListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountDisksList(accountDisksList)) | ||||
| 	d.Set("entry_count", accountDisksList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountDisksList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountDisksListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountDisksListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,218 +1,71 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList)) | ||||
| 	d.Set("entry_count", accountFlipGroupsList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "ID of the account", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by name", | ||||
| 		}, | ||||
| 		"vins_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ViNS ID", | ||||
| 		}, | ||||
| 		"vins_name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ViNS name", | ||||
| 		}, | ||||
| 		"extnet_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by extnet ID", | ||||
| 		}, | ||||
| 		"by_ip": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by IP", | ||||
| 		}, | ||||
| 		"flipgroup_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by flipgroup ID", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "Search Result", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"account_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"client_type": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"conn_type": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"default_gw": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"desc": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"gid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"fg_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"ip": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"milestones": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"fg_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"net_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"net_type": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"netmask": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"updated_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"updated_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountFlipGroupsList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountFlipGroupsListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountFlipGroupsListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList)) | ||||
| 	d.Set("entry_count", accountFlipGroupsList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountFlipGroupsList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountFlipGroupsListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountFlipGroupsListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,292 +1,72 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Nikita Sorokin, <nesorokin@basistech.ru> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func DataSourceAccountList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountList, err := utilityAccountListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountList(accountList)) | ||||
| 	d.Set("entry_count", accountList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"by_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by name", | ||||
| 		}, | ||||
| 		"acl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ACL", | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by status", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"dc_location": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"ckey": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"meta": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeString, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"acl": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"explicit": { | ||||
| 									Type:     schema.TypeBool, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"guid": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"right": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"status": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"type": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"user_group_id": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"company": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"companyurl": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"cpu_allocation_parameter": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"cpu_allocation_ratio": { | ||||
| 						Type:     schema.TypeFloat, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deactivation_time": { | ||||
| 						Type:     schema.TypeFloat, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"displayname": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"resource_limits": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"cu_c": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_d": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_dm": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_i": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_m": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"cu_np": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"gpu_units": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"resource_types": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeString, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"send_access_emails": { | ||||
| 						Type:     schema.TypeBool, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"uniq_pools": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeString, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"updated_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"version": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"vins": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeInt, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| Nikita Sorokin, <nesorokin@basistech.ru> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountList, err := utilityAccountListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountList(accountList)) | ||||
| 	d.Set("entry_count", accountList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,362 +1,71 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func DataSourceAccountRGList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountRGListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountRGListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountRGList(accountRGList)) | ||||
| 	d.Set("entry_count", accountRGList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "ID of the account", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by RG ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by name", | ||||
| 		}, | ||||
| 		"vins_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ViNS ID", | ||||
| 		}, | ||||
| 		"vm_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by VM ID", | ||||
| 		}, | ||||
| 
 | ||||
| 		"status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by status", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "Search Result", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: dataSourceAccountRGSchemaMake(), | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Optional: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountRGSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"computes": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"started": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"stopped": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"resources": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"consumed": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"cpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disksize": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disksizemax": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"extips": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"exttraffic": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"gpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ram": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"seps": { | ||||
| 									Type:     schema.TypeList, | ||||
| 									Computed: true, | ||||
| 									Elem: &schema.Resource{ | ||||
| 										Schema: map[string]*schema.Schema{ | ||||
| 											"sep_id": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"data_name": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size_max": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 										}, | ||||
| 									}, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"limits": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"cpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disksize": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disksizemax": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"extips": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"exttraffic": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"gpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ram": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"seps": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"reserved": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"cpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disksize": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disksizemax": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"extips": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"exttraffic": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"gpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ram": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"seps": { | ||||
| 									Type:     schema.TypeList, | ||||
| 									Computed: true, | ||||
| 									Elem: &schema.Resource{ | ||||
| 										Schema: map[string]*schema.Schema{ | ||||
| 											"sep_id": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"data_name": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size_max": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 										}, | ||||
| 									}, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"created_by": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"created_time": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"deleted_by": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"deleted_time": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"milestones": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rg_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"updated_by": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"updated_time": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"vinses": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountRGList(accountRGList)) | ||||
| 	d.Set("entry_count", accountRGList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountRGList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountRGListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountRGListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,192 +1,71 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountVinsList, err := utilityAccountVinsListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountVinsList(accountVinsList)) | ||||
| 	d.Set("entry_count", accountVinsList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "ID of the account", | ||||
| 		}, | ||||
| 		"vins_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by ViNS ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by name", | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by RG ID", | ||||
| 		}, | ||||
| 		"ext_ip": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Filter by external IP", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "Search Result", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"account_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"computes": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"created_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"external_ip": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"vin_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"vin_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"network": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"pri_vnf_dev_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"rg_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"rg_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"updated_by": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"updated_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountVinsList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountVinsListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountVinsListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/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" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	accountVinsList, err := utilityAccountVinsListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenAccountVinsList(accountVinsList)) | ||||
| 	d.Set("entry_count", accountVinsList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceAccountVinsList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceAccountVinsListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceAccountVinsListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,541 +1,342 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package account | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" | ||||
| ) | ||||
| 
 | ||||
| func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourseAccountCreate") | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	req := account.CreateRequest{} | ||||
| 
 | ||||
| 	req.Name = d.Get("account_name").(string) | ||||
| 	req.Username = d.Get("username").(string) | ||||
| 
 | ||||
| 	if emailaddress, ok := d.GetOk("emailaddress"); ok { | ||||
| 		req.EmailAddress = emailaddress.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok { | ||||
| 		req.SendAccessEmails = sendAccessEmails.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	if uniqPools, ok := d.GetOk("uniq_pools"); ok { | ||||
| 		uniqPools := uniqPools.([]interface{}) | ||||
| 		for _, pool := range uniqPools { | ||||
| 			req.UniqPools = append(req.UniqPools, pool.(string)) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if resLimits, ok := d.GetOk("resource_limits"); ok { | ||||
| 		resLimits := resLimits.([]interface{})[0] | ||||
| 		resLimitsConv := resLimits.(map[string]interface{}) | ||||
| 		if resLimitsConv["cu_m"] != nil { | ||||
| 			maxMemCap := int64(resLimitsConv["cu_m"].(float64)) | ||||
| 			if maxMemCap == 0 { | ||||
| 				req.MaxMemoryCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxMemoryCapacity = maxMemCap | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_dm"] != nil { | ||||
| 			maxDiskCap := int64(resLimitsConv["cu_dm"].(float64)) | ||||
| 			if maxDiskCap == 0 { | ||||
| 				req.MaxVDiskCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxVDiskCapacity = maxDiskCap | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_c"] != nil { | ||||
| 			maxCPUCap := int64(resLimitsConv["cu_c"].(float64)) | ||||
| 			if maxCPUCap == 0 { | ||||
| 				req.MaxCPUCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxCPUCapacity = maxCPUCap | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_i"] != nil { | ||||
| 			maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64)) | ||||
| 			if maxNumPublicIP == 0 { | ||||
| 				req.MaxNumPublicIP = -1 | ||||
| 			} else { | ||||
| 				req.MaxNumPublicIP = maxNumPublicIP | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_np"] != nil { | ||||
| 			maxNP := int64(resLimitsConv["cu_np"].(float64)) | ||||
| 			if maxNP == 0 { | ||||
| 				req.MaxNetworkPeerTransfer = -1 | ||||
| 			} else { | ||||
| 				req.MaxNetworkPeerTransfer = maxNP | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["gpu_units"] != nil { | ||||
| 			gpuUnits := int64(resLimitsConv["gpu_units"].(float64)) | ||||
| 			if gpuUnits == 0 { | ||||
| 				req.GPUUnits = -1 | ||||
| 			} else { | ||||
| 				req.GPUUnits = gpuUnits | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	accountId, err := c.CloudBroker().Account().Create(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(accountId, 10)) | ||||
| 
 | ||||
| 	var w dc.Warnings | ||||
| 
 | ||||
| 	if users, ok := d.GetOk("users"); ok { | ||||
| 		addedUsers := users.([]interface{}) | ||||
| 
 | ||||
| 		for _, user := range addedUsers { | ||||
| 			userConv := user.(map[string]interface{}) | ||||
| 
 | ||||
| 			req := account.AddUserRequest{ | ||||
| 				AccountID:  accountId, | ||||
| 				Username:   userConv["user_id"].(string), | ||||
| 				AccessType: userConv["access_type"].(string), | ||||
| 			} | ||||
| 
 | ||||
| 			_, err := c.CloudBroker().Account().AddUser(ctx, req) | ||||
| 			if err != nil { | ||||
| 				w.Add(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if cpuAllocationParameter, ok := d.GetOk("cpu_allocation_parameter"); ok { | ||||
| 		cpuAllocationParameter := cpuAllocationParameter.(string) | ||||
| 
 | ||||
| 		req := account.SetCPUAllocationParameterRequest{ | ||||
| 			AccountID:   accountId, | ||||
| 			StrictLoose: cpuAllocationParameter, | ||||
| 		} | ||||
| 
 | ||||
| 		log.Debugf("setting account cpu allocation parameter") | ||||
| 		_, err := c.CloudBroker().Account().SetCPUAllocationParameter(ctx, req) | ||||
| 		if err != nil { | ||||
| 			w.Add(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if cpuAllocationRatio, ok := d.GetOk("cpu_allocation_ratio"); ok { | ||||
| 		cpuAllocationRatio := cpuAllocationRatio.(float64) | ||||
| 
 | ||||
| 		req := account.SetCPUAllocationRatioRequest{ | ||||
| 			AccountID: accountId, | ||||
| 			Ratio:     cpuAllocationRatio, | ||||
| 		} | ||||
| 
 | ||||
| 		log.Debugf("setting account cpu allocation ratio") | ||||
| 		_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, req) | ||||
| 		if err != nil { | ||||
| 			w.Add(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if !d.Get("enable").(bool) { | ||||
| 		_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{ | ||||
| 			AccountID: accountId, | ||||
| 		}) | ||||
| 
 | ||||
| 		if err != nil { | ||||
| 			w.Add(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	diags := resourceAccountRead(ctx, d, m) | ||||
| 	diags = append(diags, w.Get()...) | ||||
| 
 | ||||
| 	return diags | ||||
| } | ||||
| 
 | ||||
| func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceAccountRead") | ||||
| 
 | ||||
| 	acc, err := utilityAccountCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	flattenResourceAccount(d, acc) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceAccountDelete") | ||||
| 
 | ||||
| 	accountData, err := utilityAccountCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := account.DeleteRequest{ | ||||
| 		AccountID:   accountData.ID, | ||||
| 		Permanently: d.Get("permanently").(bool), | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().Account().Delete(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceAccountUpdate") | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	acc, err := utilityAccountCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	accountId, _ := strconv.ParseUint(d.Id(), 10, 64) | ||||
| 
 | ||||
| 	hasChanged := false | ||||
| 
 | ||||
| 	switch acc.Status { | ||||
| 	case status.Destroyed: | ||||
| 		d.SetId("") | ||||
| 		// return resourceAccountCreate(ctx, d, m)
 | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	case status.Destroying: | ||||
| 		return diag.Errorf("The account is in progress with status: %s", acc.Status) | ||||
| 	case status.Deleted: | ||||
| 		_, err := c.CloudBroker().Account().Restore(ctx, account.RestoreRequest{ | ||||
| 			AccountID: accountId, | ||||
| 		}) | ||||
| 
 | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 
 | ||||
| 		hasChanged = true | ||||
| 	case status.Disabled: | ||||
| 		log.Debugf("The account is in status: %s, troubles may occur with update. Please, enable account first.", acc.Status) | ||||
| 	case status.Confirmed: | ||||
| 	} | ||||
| 
 | ||||
| 	if hasChanged { | ||||
| 		acc, err = utilityAccountCheckPresence(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			d.SetId("") | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enable") { | ||||
| 		enable := d.Get("enable").(bool) | ||||
| 
 | ||||
| 		if enable && acc.Status == status.Disabled { | ||||
| 			_, err := c.CloudBroker().Account().Enable(ctx, account.EnableRequest{ | ||||
| 				AccountID: accountId, | ||||
| 			}) | ||||
| 
 | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 		} else if !enable && acc.Status == status.Enabled { | ||||
| 			_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{ | ||||
| 				AccountID: accountId, | ||||
| 			}) | ||||
| 
 | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	req := account.UpdateRequest{ | ||||
| 		AccountID: accountId, | ||||
| 	} | ||||
| 
 | ||||
| 	updated := false | ||||
| 
 | ||||
| 	if d.HasChange("account_name") { | ||||
| 		req.Name = d.Get("account_name").(string) | ||||
| 		updated = true | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("send_access_emails") { | ||||
| 		req.SendAccessEmails = d.Get("send_access_emails").(bool) | ||||
| 		updated = true | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("uniq_pools") { | ||||
| 		uniq_pools := d.Get("uniq_pools").([]interface{}) | ||||
| 
 | ||||
| 		for _, pool := range uniq_pools { | ||||
| 			req.UniqPools = append(req.UniqPools, pool.(string)) | ||||
| 		} | ||||
| 
 | ||||
| 		updated = true | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("resource_limits") { | ||||
| 		resLimit := d.Get("resource_limits").([]interface{})[0] | ||||
| 		resLimitConv := resLimit.(map[string]interface{}) | ||||
| 
 | ||||
| 		if resLimitConv["cu_m"] != nil { | ||||
| 			maxMemCap := int(resLimitConv["cu_m"].(float64)) | ||||
| 			if maxMemCap == 0 { | ||||
| 				req.MaxMemoryCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxMemoryCapacity = int64(maxMemCap) | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitConv["cu_dm"] != nil { | ||||
| 			maxDiskCap := int(resLimitConv["cu_dm"].(float64)) | ||||
| 			if maxDiskCap == 0 { | ||||
| 				req.MaxVDiskCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxVDiskCapacity = int64(maxDiskCap) | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitConv["cu_c"] != nil { | ||||
| 			maxCPUCap := int(resLimitConv["cu_c"].(float64)) | ||||
| 			if maxCPUCap == 0 { | ||||
| 				req.MaxCPUCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxCPUCapacity = int64(maxCPUCap) | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitConv["cu_i"] != nil { | ||||
| 			maxNumPublicIP := int(resLimitConv["cu_i"].(float64)) | ||||
| 			if maxNumPublicIP == 0 { | ||||
| 				req.MaxNumPublicIP = -1 | ||||
| 			} else { | ||||
| 				req.MaxNumPublicIP = int64(maxNumPublicIP) | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitConv["cu_np"] != nil { | ||||
| 			maxNP := int(resLimitConv["cu_np"].(float64)) | ||||
| 			if maxNP == 0 { | ||||
| 				req.MaxNetworkPeerTransfer = -1 | ||||
| 			} else { | ||||
| 				req.MaxNetworkPeerTransfer = int64(maxNP) | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitConv["gpu_units"] != nil { | ||||
| 			gpuUnits := int(resLimitConv["gpu_units"].(float64)) | ||||
| 			if gpuUnits == 0 { | ||||
| 				req.GPUUnits = -1 | ||||
| 			} else { | ||||
| 				req.GPUUnits = int64(gpuUnits) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		updated = true | ||||
| 	} | ||||
| 
 | ||||
| 	if updated { | ||||
| 		_, err := c.CloudBroker().Account().Update(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("cpu_allocation_parameter") { | ||||
| 		cpuAllocationParameter := d.Get("cpu_allocation_parameter").(string) | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Account().SetCPUAllocationParameter(ctx, account.SetCPUAllocationParameterRequest{ | ||||
| 			AccountID:   acc.ID, | ||||
| 			StrictLoose: cpuAllocationParameter, | ||||
| 		}) | ||||
| 
 | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("cpu_allocation_ratio") { | ||||
| 		cpuAllocacationRatio := d.Get("cpu_allocation_ratio").(float64) | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, account.SetCPUAllocationRatioRequest{ | ||||
| 			AccountID: acc.ID, | ||||
| 			Ratio:     cpuAllocacationRatio, | ||||
| 		}) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("users") { | ||||
| 		deletedUsers := make([]interface{}, 0) | ||||
| 		addedUsers := make([]interface{}, 0) | ||||
| 		updatedUsers := make([]interface{}, 0) | ||||
| 
 | ||||
| 		old, new := d.GetChange("users") | ||||
| 		oldConv := old.([]interface{}) | ||||
| 		newConv := new.([]interface{}) | ||||
| 		for _, el := range oldConv { | ||||
| 			if !isContainsUser(newConv, el) { | ||||
| 				deletedUsers = append(deletedUsers, el) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		for _, el := range newConv { | ||||
| 			if !isContainsUser(oldConv, el) { | ||||
| 				duplicate := false | ||||
| 				for _, user := range acc.ACL { | ||||
| 					if user.UserGroupID == el.(map[string]interface{})["user_id"].(string) { | ||||
| 						duplicate = true | ||||
| 					} | ||||
| 				} | ||||
| 				if !duplicate { | ||||
| 					addedUsers = append(addedUsers, el) | ||||
| 				} else if isChangedUser(oldConv, el) { | ||||
| 					updatedUsers = append(updatedUsers, el) | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		for _, user := range deletedUsers { | ||||
| 			userConv := user.(map[string]interface{}) | ||||
| 
 | ||||
| 			_, err := c.CloudBroker().Account().DeleteUser(ctx, account.DeleteUserRequest{ | ||||
| 				AccountID:       accountId, | ||||
| 				UserName:        userConv["user_id"].(string), | ||||
| 				RecursiveDelete: userConv["recursive_delete"].(bool), | ||||
| 			}) | ||||
| 
 | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		for _, user := range addedUsers { | ||||
| 			userConv := user.(map[string]interface{}) | ||||
| 
 | ||||
| 			_, err := c.CloudBroker().Account().AddUser(ctx, account.AddUserRequest{ | ||||
| 				AccountID:  accountId, | ||||
| 				Username:   userConv["user_id"].(string), | ||||
| 				AccessType: strings.ToUpper(userConv["access_type"].(string)), | ||||
| 			}) | ||||
| 
 | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		for _, user := range updatedUsers { | ||||
| 			userConv := user.(map[string]interface{}) | ||||
| 
 | ||||
| 			_, err := c.CloudBroker().Account().UpdateUser(ctx, account.UpdateUserRequest{ | ||||
| 				AccountID:  accountId, | ||||
| 				UserID:     userConv["user_id"].(string), | ||||
| 				AccessType: strings.ToUpper(userConv["access_type"].(string)), | ||||
| 			}) | ||||
| 
 | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return resourceAccountRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| func isContainsUser(els []interface{}, el interface{}) bool { | ||||
| 	for _, elOld := range els { | ||||
| 		elOldConv := elOld.(map[string]interface{}) | ||||
| 		elConv := el.(map[string]interface{}) | ||||
| 		if elOldConv["user_id"].(string) == elConv["user_id"].(string) { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
| 
 | ||||
| func isChangedUser(els []interface{}, el interface{}) bool { | ||||
| 	for _, elOld := range els { | ||||
| 		elOldConv := elOld.(map[string]interface{}) | ||||
| 		elConv := el.(map[string]interface{}) | ||||
| 		if elOldConv["user_id"].(string) == elConv["user_id"].(string) && | ||||
| 			(!strings.EqualFold(elOldConv["access_type"].(string), elConv["access_type"].(string)) || | ||||
| 				elOldConv["recursive_delete"].(bool) != elConv["recursive_delete"].(bool)) { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
| 
 | ||||
| func ResourceAccount() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceAccountCreate, | ||||
| 		ReadContext:   resourceAccountRead, | ||||
| 		UpdateContext: resourceAccountUpdate, | ||||
| 		DeleteContext: resourceAccountDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceAccountSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package account | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" | ||||
| ) | ||||
| 
 | ||||
| func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourseAccountCreate") | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	req := account.CreateRequest{ | ||||
| 		Name:     d.Get("account_name").(string), | ||||
| 		Username: d.Get("username").(string), | ||||
| 	} | ||||
| 
 | ||||
| 	if emailaddress, ok := d.GetOk("emailaddress"); ok { | ||||
| 		req.EmailAddress = emailaddress.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	if sendAccessEmails, ok := d.GetOk("send_access_emails"); ok { | ||||
| 		req.SendAccessEmails = sendAccessEmails.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	if uniqPools, ok := d.GetOk("uniq_pools"); ok { | ||||
| 		uniqPools := uniqPools.([]interface{}) | ||||
| 		for _, pool := range uniqPools { | ||||
| 			req.UniqPools = append(req.UniqPools, pool.(string)) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if resLimits, ok := d.GetOk("resource_limits"); ok { | ||||
| 		resLimits := resLimits.([]interface{})[0] | ||||
| 		resLimitsConv := resLimits.(map[string]interface{}) | ||||
| 		if resLimitsConv["cu_m"] != nil { | ||||
| 			maxMemCap := int64(resLimitsConv["cu_m"].(float64)) | ||||
| 			if maxMemCap == 0 { | ||||
| 				req.MaxMemoryCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxMemoryCapacity = maxMemCap | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_dm"] != nil { | ||||
| 			maxDiskCap := int64(resLimitsConv["cu_dm"].(float64)) | ||||
| 			if maxDiskCap == 0 { | ||||
| 				req.MaxVDiskCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxVDiskCapacity = maxDiskCap | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_c"] != nil { | ||||
| 			maxCPUCap := int64(resLimitsConv["cu_c"].(float64)) | ||||
| 			if maxCPUCap == 0 { | ||||
| 				req.MaxCPUCapacity = -1 | ||||
| 			} else { | ||||
| 				req.MaxCPUCapacity = maxCPUCap | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_i"] != nil { | ||||
| 			maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64)) | ||||
| 			if maxNumPublicIP == 0 { | ||||
| 				req.MaxNumPublicIP = -1 | ||||
| 			} else { | ||||
| 				req.MaxNumPublicIP = maxNumPublicIP | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["cu_np"] != nil { | ||||
| 			maxNP := int64(resLimitsConv["cu_np"].(float64)) | ||||
| 			if maxNP == 0 { | ||||
| 				req.MaxNetworkPeerTransfer = -1 | ||||
| 			} else { | ||||
| 				req.MaxNetworkPeerTransfer = maxNP | ||||
| 			} | ||||
| 		} | ||||
| 		if resLimitsConv["gpu_units"] != nil { | ||||
| 			gpuUnits := int64(resLimitsConv["gpu_units"].(float64)) | ||||
| 			if gpuUnits == 0 { | ||||
| 				req.GPUUnits = -1 | ||||
| 			} else { | ||||
| 				req.GPUUnits = gpuUnits | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	accountId, err := c.CloudBroker().Account().Create(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(accountId, 10)) | ||||
| 
 | ||||
| 	var w dc.Warnings | ||||
| 
 | ||||
| 	if users, ok := d.GetOk("users"); ok { | ||||
| 		addedUsers := users.([]interface{}) | ||||
| 
 | ||||
| 		for _, user := range addedUsers { | ||||
| 			userConv := user.(map[string]interface{}) | ||||
| 
 | ||||
| 			req := account.AddUserRequest{ | ||||
| 				AccountID:  accountId, | ||||
| 				Username:   userConv["user_id"].(string), | ||||
| 				AccessType: userConv["access_type"].(string), | ||||
| 			} | ||||
| 
 | ||||
| 			_, err := c.CloudBroker().Account().AddUser(ctx, req) | ||||
| 			if err != nil { | ||||
| 				w.Add(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if cpuAllocationParameter, ok := d.GetOk("cpu_allocation_parameter"); ok { | ||||
| 		cpuAllocationParameter := cpuAllocationParameter.(string) | ||||
| 
 | ||||
| 		req := account.SetCPUAllocationParameterRequest{ | ||||
| 			AccountID:   accountId, | ||||
| 			StrictLoose: cpuAllocationParameter, | ||||
| 		} | ||||
| 
 | ||||
| 		log.Debugf("setting account cpu allocation parameter") | ||||
| 		_, err := c.CloudBroker().Account().SetCPUAllocationParameter(ctx, req) | ||||
| 		if err != nil { | ||||
| 			w.Add(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if cpuAllocationRatio, ok := d.GetOk("cpu_allocation_ratio"); ok { | ||||
| 		cpuAllocationRatio := cpuAllocationRatio.(float64) | ||||
| 
 | ||||
| 		req := account.SetCPUAllocationRatioRequest{ | ||||
| 			AccountID: accountId, | ||||
| 			Ratio:     cpuAllocationRatio, | ||||
| 		} | ||||
| 
 | ||||
| 		log.Debugf("setting account cpu allocation ratio") | ||||
| 		_, err := c.CloudBroker().Account().SetCPUAllocationRatio(ctx, req) | ||||
| 		if err != nil { | ||||
| 			w.Add(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if !d.Get("enable").(bool) { | ||||
| 		_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{ | ||||
| 			AccountID: accountId, | ||||
| 		}) | ||||
| 
 | ||||
| 		if err != nil { | ||||
| 			w.Add(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return append(resourceAccountRead(ctx, d, m), w.Get()...) | ||||
| } | ||||
| 
 | ||||
| func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceAccountRead") | ||||
| 
 | ||||
| 	acc, err := utilityAccountCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	flattenResourceAccount(d, acc) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceAccountDelete") | ||||
| 
 | ||||
| 	accountData, err := utilityAccountCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := account.DeleteRequest{ | ||||
| 		AccountID:   accountData.ID, | ||||
| 		Permanently: d.Get("permanently").(bool), | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().Account().Delete(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceAccountUpdate") | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	acc, err := utilityAccountCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	accountId, _ := strconv.ParseUint(d.Id(), 10, 64) | ||||
| 
 | ||||
| 	hasChanged := false | ||||
| 
 | ||||
| 	switch acc.Status { | ||||
| 	case status.Destroyed: | ||||
| 		d.SetId("") | ||||
| 		// return resourceAccountCreate(ctx, d, m)
 | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	case status.Destroying: | ||||
| 		return diag.Errorf("The account is in progress with status: %s", acc.Status) | ||||
| 	case status.Deleted: | ||||
| 		if d.Get("restore").(bool) { | ||||
| 			_, err := c.CloudBroker().Account().Restore(ctx, account.RestoreRequest{ | ||||
| 				AccountID: accountId, | ||||
| 			}) | ||||
| 
 | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 			if _, ok := d.GetOk("enable"); ok { | ||||
| 				if err := utilityAccountEnableUpdate(ctx, d, m, acc); err != nil { | ||||
| 					return diag.FromErr(err) | ||||
| 				} | ||||
| 			} | ||||
| 			hasChanged = true | ||||
| 		} | ||||
| 	case status.Disabled: | ||||
| 		log.Debugf("The account is in status: %s, troubles may occur with update. Please, enable account first.", acc.Status) | ||||
| 	case status.Confirmed: | ||||
| 	} | ||||
| 
 | ||||
| 	if hasChanged { | ||||
| 		acc, err = utilityAccountCheckPresence(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			d.SetId("") | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enable") { | ||||
| 		if err := utilityAccountEnableUpdate(ctx, d, m, acc); err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChanges("account_name", "send_access_emails", "uniq_pools", "resource_limits") { | ||||
| 		if err := utilityAccountUpdate(ctx, d, m); err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("cpu_allocation_parameter") { | ||||
| 		if err := utilityAccountCPUParameterUpdate(ctx, d, m); err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("cpu_allocation_ratio") { | ||||
| 		if err := utilityAccountCPURatioUpdate(ctx, d, m); err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("users") { | ||||
| 		if err := utilityAccountUsersUpdate(ctx, d, m, acc); err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return resourceAccountRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| func ResourceAccount() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceAccountCreate, | ||||
| 		ReadContext:   resourceAccountRead, | ||||
| 		UpdateContext: resourceAccountUpdate, | ||||
| 		DeleteContext: resourceAccountDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceAccountSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,442 +1,71 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package disks | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	diskList, err := utilityDiskListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenDiskList(diskList)) | ||||
| 	d.Set("entry_count", diskList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceDiskListSchemaMake() map[string]*schema.Schema { | ||||
| 	res := map[string]*schema.Schema{ | ||||
| 		"by_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by ID", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by name", | ||||
| 		}, | ||||
| 		"account_name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by account name", | ||||
| 		}, | ||||
| 		"disk_max_size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by max disk size", | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by status", | ||||
| 		}, | ||||
| 		"shared": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by shared field", | ||||
| 		}, | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "ID of the account the disks belong to", | ||||
| 		}, | ||||
| 		"type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "type of the disks", | ||||
| 		}, | ||||
| 		"sep_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by sep id", | ||||
| 		}, | ||||
| 		"pool": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "Find by pool name", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "Page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"account_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"account_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"acl": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"boot_partition": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"computes": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"compute_id": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"compute_name": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"created_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"deleted_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"desc": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"destruction_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"devicename": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"disk_path": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"gid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"disk_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"image_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"images": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeString, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"iotune": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"read_bytes_sec": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"read_bytes_sec_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"read_iops_sec": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"read_iops_sec_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"size_iops_sec": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"total_bytes_sec": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"total_bytes_sec_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"total_iops_sec": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"total_iops_sec_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"write_bytes_sec": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"write_bytes_sec_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"write_iops_sec": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"write_iops_sec_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"iqn": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"login": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"machine_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"machine_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"milestones": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"disk_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"order": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"params": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"parent_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"passwd": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"pci_slot": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"pool": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"present_to": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Schema{ | ||||
| 							Type: schema.TypeInt, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"purge_attempts": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"purge_time": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"reality_device_number": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"reference_id": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"res_id": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"res_name": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"role": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"sep_id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"sep_type": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"shareable": { | ||||
| 						Type: schema.TypeBool, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"size_max": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"size_used": { | ||||
| 						Type:     schema.TypeFloat, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"snapshots": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"guid": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"label": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"reference_id": { | ||||
| 									Type: schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"res_id": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"snap_set_guid": { | ||||
| 									Type:     schema.TypeString, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"snap_set_time": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"timestamp": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"tech_status": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"type": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"vmid": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| func DataSourceDiskList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceDiskListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceDiskListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package disks | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	diskList, err := utilityDiskListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenDiskList(diskList)) | ||||
| 	d.Set("entry_count", diskList.EntryCount) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceDiskList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceDiskListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceDiskListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,100 +1,68 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package grid | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceGridRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	grid, err := utilityGridCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	d.SetId(strconv.FormatUint(grid.ID, 10)) | ||||
| 	flattenGrid(d, grid) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceGetGridSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"grid_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Required: true, | ||||
| 		}, | ||||
| 		"flag": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"gid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"location_code": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func DataSourceGrid() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceGridRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceGetGridSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package grid | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceGridRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	grid, err := utilityGridCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	d.SetId(strconv.FormatUint(grid.ID, 10)) | ||||
| 	flattenGrid(d, grid) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceGrid() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceGridRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceGetGridSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,265 +1,69 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package grid | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	gridList, err := utilityGridListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenGridList(gridList)) | ||||
| 	d.Set("entry_count", gridList.EntryCount) | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceGridListSchemaMake() map[string]*schema.Schema { | ||||
| 	rets := map[string]*schema.Schema{ | ||||
| 		"by_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "by id", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "name", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "grid list", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: dataSourceGridSchemaMake(), | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "entry count", | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	return rets | ||||
| } | ||||
| 
 | ||||
| func dataSourceGridSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"resources": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"current": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"cpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disk_size": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disk_size_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ext_ips": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ext_traffic": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"gpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ram": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"seps": { | ||||
| 									Type:     schema.TypeList, | ||||
| 									Computed: true, | ||||
| 									Elem: &schema.Resource{ | ||||
| 										Schema: map[string]*schema.Schema{ | ||||
| 											"sep_id": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"data_name": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size_max": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 										}, | ||||
| 									}, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 					"reserved": { | ||||
| 						Type:     schema.TypeList, | ||||
| 						Computed: true, | ||||
| 						Elem: &schema.Resource{ | ||||
| 							Schema: map[string]*schema.Schema{ | ||||
| 								"cpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disk_size": { | ||||
| 									Type:     schema.TypeFloat, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"disk_size_max": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ext_ips": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ext_traffic": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"gpu": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"ram": { | ||||
| 									Type:     schema.TypeInt, | ||||
| 									Computed: true, | ||||
| 								}, | ||||
| 								"seps": { | ||||
| 									Type:     schema.TypeList, | ||||
| 									Computed: true, | ||||
| 									Elem: &schema.Resource{ | ||||
| 										Schema: map[string]*schema.Schema{ | ||||
| 											"sep_id": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"data_name": { | ||||
| 												Type:     schema.TypeString, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 											"disk_size_max": { | ||||
| 												Type:     schema.TypeFloat, | ||||
| 												Computed: true, | ||||
| 											}, | ||||
| 										}, | ||||
| 									}, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"flag": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"gid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"location_code": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func DataSourceGridList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceGridListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceGridListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package grid | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	gridList, err := utilityGridListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenGridList(gridList)) | ||||
| 	d.Set("entry_count", gridList.EntryCount) | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceGridList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceGridListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceGridListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,63 +1,63 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package grid | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| ) | ||||
| 
 | ||||
| func utilityGridCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.RecordGrid, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := grid.GetRequest{} | ||||
| 
 | ||||
| 	if d.Id() != "" { | ||||
| 		id, _ := strconv.ParseUint(d.Id(), 10, 64) | ||||
| 		req.GID = id | ||||
| 	} else { | ||||
| 		req.GID = uint64(d.Get("grid_id").(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("utilityGridCheckPresence: load grid") | ||||
| 	grid, err := c.CloudBroker().Grid().Get(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return grid, nil | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package grid | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| ) | ||||
| 
 | ||||
| func utilityGridCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.RecordGrid, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := grid.GetRequest{} | ||||
| 
 | ||||
| 	if d.Id() != "" { | ||||
| 		id, _ := strconv.ParseUint(d.Id(), 10, 64) | ||||
| 		req.GID = id | ||||
| 	} else { | ||||
| 		req.GID = uint64(d.Get("grid_id").(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("utilityGridCheckPresence: load grid") | ||||
| 	gridRec, err := c.CloudBroker().Grid().Get(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return gridRec, nil | ||||
| } | ||||
|  | ||||
| @ -1,98 +1,69 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	imageList, err := utilityImageListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenImageList(imageList)) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceImageListSchemaMake() map[string]*schema.Schema { | ||||
| 	rets := map[string]*schema.Schema{ | ||||
| 		"sep_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "filter images by storage endpoint provider ID", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "image list", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: dataSourceImageSchemaMake(), | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	return rets | ||||
| } | ||||
| 
 | ||||
| func DataSourceImageList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceImageListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceImageListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	imageList, err := utilityImageListCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenImageList(imageList)) | ||||
| 	d.Set("entry_count", imageList.EntryCount) | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceImageList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceImageListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceImageListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,167 +1,69 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	imageListStacks, err := utilityImageListStacksCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenImageListStacks(d, imageListStacks)) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourceImageListStackSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"api_url": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"api_key": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"app_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"desc": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"drivers": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"error": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"images": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeInt, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"login": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"passwd": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"reference_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"type": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func dataSourceImageListStacksSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"image_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "image id", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: dataSourceImageListStackSchemaMake(), | ||||
| 			}, | ||||
| 			Description: "items of stacks list", | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func DataSourceImageListStacks() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceImageListStacksRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceImageListStacksSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	imageListStacks, err := utilityImageListStacksCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 	d.Set("items", flattenImageListStacks(imageListStacks)) | ||||
| 	d.Set("entry_count", imageListStacks.EntryCount) | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourceImageListStacks() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourceImageListStacksRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourceImageListStacksSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,382 +1,257 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| ) | ||||
| 
 | ||||
| func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceCDROMImageCreate: called for image %s", d.Get("name").(string)) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.CreateCDROMImageRequest{ | ||||
| 		Name: d.Get("name").(string), | ||||
| 		URL:  d.Get("url").(string), | ||||
| 		GID:  uint64(d.Get("gid").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	drivers := []string{} | ||||
| 	for _, driver := range d.Get("drivers").([]interface{}) { | ||||
| 		drivers = append(drivers, driver.(string)) | ||||
| 	} | ||||
| 
 | ||||
| 	req.Drivers = drivers | ||||
| 
 | ||||
| 	if username, ok := d.GetOk("username_dl"); ok { | ||||
| 		req.UsernameDL = username.(string) | ||||
| 	} | ||||
| 	if password, ok := d.GetOk("password_dl"); ok { | ||||
| 		req.PasswordDl = password.(string) | ||||
| 	} | ||||
| 	if accountId, ok := d.GetOk("account_id"); ok { | ||||
| 		req.AccountID = uint64(accountId.(int)) | ||||
| 	} | ||||
| 	if sepId, ok := d.GetOk("sep_id"); ok { | ||||
| 		req.SEPID = uint64(sepId.(int)) | ||||
| 	} | ||||
| 	if poolName, ok := d.GetOk("pool_name"); ok { | ||||
| 		req.PoolName = poolName.(string) | ||||
| 	} | ||||
| 	if architecture, ok := d.GetOk("architecture"); ok { | ||||
| 		req.Architecture = architecture.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	imageId, err := c.CloudBroker().Image().CreateCDROMImage(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(imageId, 10)) | ||||
| 	d.Set("image_id", imageId) | ||||
| 
 | ||||
| 	image, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.Set("bootable", image.Bootable) | ||||
| 
 | ||||
| 	diagnostics := resourceImageRead(ctx, d, m) | ||||
| 	if diagnostics != nil { | ||||
| 		return diagnostics | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| 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()) | ||||
| 
 | ||||
| 	imageData, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.DeleteCDROMImageRequest{ | ||||
| 		ImageID: imageData.ID, | ||||
| 	} | ||||
| 
 | ||||
| 	if permanently, ok := d.GetOk("permanently"); ok { | ||||
| 		req.Permanently = permanently.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().Image().DeleteCDROMImage(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceCDROMImageSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "Name of the rescue disk", | ||||
| 		}, | ||||
| 		"url": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "URL where to download ISO from", | ||||
| 		}, | ||||
| 		"gid": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "grid (platform) ID where this template should be create in", | ||||
| 		}, | ||||
| 		"boot_type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "Boot type of image bios or uefi", | ||||
| 		}, | ||||
| 		"image_type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "Image type linux, windows or other", | ||||
| 		}, | ||||
| 		"drivers": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Required: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 			Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", | ||||
| 		}, | ||||
| 		"meta": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 			Description: "meta", | ||||
| 		}, | ||||
| 		"hot_resize": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Does this machine supports hot resize", | ||||
| 		}, | ||||
| 		// "username": {
 | ||||
| 		// 	Type:        schema.TypeString,
 | ||||
| 		// 	Optional:    true,
 | ||||
| 		// 	Computed:    true,
 | ||||
| 		// 	Description: "Optional username for the image",
 | ||||
| 		// },
 | ||||
| 		// "password": {
 | ||||
| 		// 	Type:        schema.TypeString,
 | ||||
| 		// 	Optional:    true,
 | ||||
| 		// 	Computed:    true,
 | ||||
| 		// 	Description: "Optional password for the image",
 | ||||
| 		// },
 | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "AccountId to make the image exclusive", | ||||
| 		}, | ||||
| 		"username_dl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "username for upload binary media", | ||||
| 		}, | ||||
| 		"password_dl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "password for upload binary media", | ||||
| 		}, | ||||
| 		"sep_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "storage endpoint provider ID", | ||||
| 		}, | ||||
| 		"pool_name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "pool for image create", | ||||
| 		}, | ||||
| 		"architecture": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "binary architecture of this image, one of X86_64 of PPC64_LE", | ||||
| 		}, | ||||
| 		"image_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "image id", | ||||
| 		}, | ||||
| 		"permanently": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Whether to completely delete the image", | ||||
| 		}, | ||||
| 		"bootable": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Does this image boot OS", | ||||
| 		}, | ||||
| 		"unc_path": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "unc path", | ||||
| 		}, | ||||
| 		"link_to": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "", | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "status", | ||||
| 		}, | ||||
| 		"tech_status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "tech atatus", | ||||
| 		}, | ||||
| 		"version": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "version", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "image size", | ||||
| 		}, | ||||
| 		"enabled": { | ||||
| 			Type:     schema.TypeBool, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"computeci_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"milestones": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"provider_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"purge_attempts": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"reference_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"res_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"res_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rescuecd": { | ||||
| 			Type:     schema.TypeBool, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"desc": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"shared_with": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeInt, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"enabled_stacks": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Optional: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"history": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"timestamp": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func ResourceCDROMImage() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceCDROMImageCreate, | ||||
| 		ReadContext:   resourceImageRead, | ||||
| 		UpdateContext: resourceImageUpdate, | ||||
| 		DeleteContext: resourceCDROMImageDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceCDROMImageSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" | ||||
| ) | ||||
| 
 | ||||
| func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceCDROMImageCreate: called for image %s", d.Get("name").(string)) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.CreateCDROMImageRequest{ | ||||
| 		Name: d.Get("name").(string), | ||||
| 		URL:  d.Get("url").(string), | ||||
| 	} | ||||
| 
 | ||||
| 	if err := ic.ExistGID(ctx, uint64(d.Get("gid").(int)), c); err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	req.GID = uint64(d.Get("gid").(int)) | ||||
| 
 | ||||
| 	drivers := []string{} | ||||
| 	for _, driver := range d.Get("drivers").([]interface{}) { | ||||
| 		drivers = append(drivers, driver.(string)) | ||||
| 	} | ||||
| 	req.Drivers = drivers | ||||
| 
 | ||||
| 	if username, ok := d.GetOk("username_dl"); ok { | ||||
| 		req.UsernameDL = username.(string) | ||||
| 	} | ||||
| 	if password, ok := d.GetOk("password_dl"); ok { | ||||
| 		req.PasswordDl = password.(string) | ||||
| 	} | ||||
| 	if accountId, ok := d.GetOk("account_id"); ok { | ||||
| 		req.AccountID = uint64(accountId.(int)) | ||||
| 	} | ||||
| 	if sepId, ok := d.GetOk("sep_id"); ok { | ||||
| 		req.SEPID = uint64(sepId.(int)) | ||||
| 	} | ||||
| 	if poolName, ok := d.GetOk("pool_name"); ok { | ||||
| 		req.PoolName = poolName.(string) | ||||
| 	} | ||||
| 	if architecture, ok := d.GetOk("architecture"); ok { | ||||
| 		req.Architecture = architecture.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	imageId, err := c.CloudBroker().Image().CreateCDROMImage(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(imageId, 10)) | ||||
| 
 | ||||
| 	return resourceImageRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| func resourceCDROMImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceCDROMImageRead: called for %s id: %s", d.Get("name").(string), d.Id()) | ||||
| 
 | ||||
| 	img, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	switch img.Status { | ||||
| 	case status.Modeled: | ||||
| 		return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status) | ||||
| 	case status.Destroyed, status.Purged: | ||||
| 		d.SetId("") | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	} | ||||
| 
 | ||||
| 	flattenImage(d, img) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| 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()) | ||||
| 
 | ||||
| 	imageData, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.DeleteCDROMImageRequest{ | ||||
| 		ImageID: imageData.ID, | ||||
| 	} | ||||
| 
 | ||||
| 	if permanently, ok := d.GetOk("permanently"); ok { | ||||
| 		req.Permanently = permanently.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().Image().DeleteCDROMImage(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceCDROMImageUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceCDROMImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 
 | ||||
| 	img, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	switch img.Status { | ||||
| 	case status.Modeled: | ||||
| 		return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status) | ||||
| 	case status.Destroyed, status.Purged: | ||||
| 		d.SetId("") | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enabled") { | ||||
| 		err := resourceImageChangeEnabled(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("shared_with") { | ||||
| 		err := resourceImageShare(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("computeci_id") { | ||||
| 		err := resourceImageChangeComputeci(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enabled_stacks") { | ||||
| 		err := resourceImageUpdateNodes(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChanges("name", "password_dl", "username_dl", "account_id", "bootable", "hot_resize") { | ||||
| 		err := resourceImageCDROMEdit(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageCDROMEdit(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.EditRequest{} | ||||
| 
 | ||||
| 	req.ImageID = uint64(d.Get("image_id").(int)) | ||||
| 	if d.HasChange("name") { | ||||
| 		req.Name = d.Get("name").(string) | ||||
| 	} | ||||
| 	if d.HasChange("username_dl") { | ||||
| 		req.Username = d.Get("username_dl").(string) | ||||
| 	} | ||||
| 	if d.HasChange("password_dl") { | ||||
| 		req.Password = d.Get("password_dl").(string) | ||||
| 	} | ||||
| 	if d.HasChange("account_id") { | ||||
| 		req.AccountID = uint64(d.Get("account_id").(int)) | ||||
| 	} | ||||
| 	if d.HasChange("bootable") { | ||||
| 		req.Bootable = d.Get("bootable").(bool) | ||||
| 	} | ||||
| 	if d.HasChange("hot_resize") { | ||||
| 		req.HotResize = d.Get("hot_resize").(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().Edit(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func ResourceCDROMImage() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceCDROMImageCreate, | ||||
| 		ReadContext:   resourceCDROMImageRead, | ||||
| 		UpdateContext: resourceCDROMImageUpdate, | ||||
| 		DeleteContext: resourceCDROMImageDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceCDROMImageSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,611 +1,341 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| ) | ||||
| 
 | ||||
| func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.CreateRequest{ | ||||
| 		Name:      d.Get("name").(string), | ||||
| 		URL:       d.Get("url").(string), | ||||
| 		GID:       uint64(d.Get("gid").(int)), | ||||
| 		BootType:  d.Get("boot_type").(string), | ||||
| 		ImageType: d.Get("image_type").(string), | ||||
| 	} | ||||
| 
 | ||||
| 	drivers := []string{} | ||||
| 	for _, driver := range d.Get("drivers").([]interface{}) { | ||||
| 		drivers = append(drivers, driver.(string)) | ||||
| 	} | ||||
| 
 | ||||
| 	req.Drivers = drivers | ||||
| 
 | ||||
| 	if hotresize, ok := d.GetOk("hot_resize"); ok { | ||||
| 		req.HotResize = hotresize.(bool) | ||||
| 	} | ||||
| 	if username, ok := d.GetOk("username"); ok { | ||||
| 		req.Username = username.(string) | ||||
| 	} | ||||
| 	if password, ok := d.GetOk("password"); ok { | ||||
| 		req.Password = password.(string) | ||||
| 	} | ||||
| 	if accountId, ok := d.GetOk("account_id"); ok { | ||||
| 		req.AccountID = uint64(accountId.(int)) | ||||
| 	} | ||||
| 	if usernameDL, ok := d.GetOk("username_dl"); ok { | ||||
| 		req.UsernameDL = usernameDL.(string) | ||||
| 	} | ||||
| 	if passwordDL, ok := d.GetOk("password_dl"); ok { | ||||
| 		req.PasswordDL = passwordDL.(string) | ||||
| 	} | ||||
| 	if sepId, ok := d.GetOk("sep_id"); ok { | ||||
| 		req.SEPID = uint64(sepId.(int)) | ||||
| 	} | ||||
| 	if poolName, ok := d.GetOk("pool_name"); ok { | ||||
| 		req.PoolName = poolName.(string) | ||||
| 	} | ||||
| 	if architecture, ok := d.GetOk("architecture"); ok { | ||||
| 		req.Architecture = architecture.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	imageId, err := c.CloudBroker().Image().CreateImage(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(imageId, 10)) | ||||
| 	d.Set("image_id", imageId) | ||||
| 
 | ||||
| 	return resourceImageRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| 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(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	flattenImage(d, image) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| 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()) | ||||
| 
 | ||||
| 	_, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.DeleteRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	if reason, ok := d.GetOk("reason"); ok { | ||||
| 		req.Reason = reason.(string) | ||||
| 	} | ||||
| 	if permanently, ok := d.GetOk("permanently"); ok { | ||||
| 		req.Permanently = permanently.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().Image().Delete(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageEditName(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.RenameRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 		Name:    d.Get("name").(string), | ||||
| 	} | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().Rename(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageUpdate(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.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	if d.HasChange("enabled") { | ||||
| 		err := resourceImageChangeEnabled(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("name") { | ||||
| 		err := resourceImageEditName(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("shared_with") { | ||||
| 		err := resourceImageShare(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("computeci_id") { | ||||
| 		err := resourceImageChangeComputeci(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enabled_stacks") { | ||||
| 		err := resourceImageUpdateNodes(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("link_to") { | ||||
| 		err := resourceImageLink(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize") { | ||||
| 		req := image.EditRequest{} | ||||
| 
 | ||||
| 		req.ImageID = uint64(d.Get("image_id").(int)) | ||||
| 		req.Name = d.Get("name").(string) | ||||
| 
 | ||||
| 		req.Username = d.Get("username").(string) | ||||
| 		req.Password = d.Get("password").(string) | ||||
| 		req.AccountID = uint64(d.Get("account_id").(int)) | ||||
| 		req.Bootable = d.Get("bootable").(bool) | ||||
| 		req.HotResize = d.Get("hot_resize").(bool) | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().Edit(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageChangeEnabled(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	imageId := uint64(d.Get("image_id").(int)) | ||||
| 
 | ||||
| 	if d.Get("enabled").(bool) { | ||||
| 		req := image.EnableRequest{ | ||||
| 			ImageID: imageId, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().Enable(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} else { | ||||
| 		req := image.DisableRequest{ | ||||
| 			ImageID: imageId, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().Disable(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageLink(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.LinkRequest{ | ||||
| 		ImageID:  uint64(d.Get("image_id").(int)), | ||||
| 		TargetID: uint64(d.Get("link_to").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().Link(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageShare(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceImageShare: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.ShareRequest{ | ||||
| 		ImageId: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 	accIds := []uint64{} | ||||
| 	for _, accId := range d.Get("shared_with").([]interface{}) { | ||||
| 		accIds = append(accIds, uint64(accId.(int))) | ||||
| 	} | ||||
| 	req.AccountIDs = accIds | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().Share(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageChangeComputeci(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	imageId := uint64(d.Get("image_id").(int)) | ||||
| 	computeci := uint64(d.Get("computeci_id").(int)) | ||||
| 
 | ||||
| 	if computeci == 0 { | ||||
| 		req := image.ComputeCIUnsetRequest{ | ||||
| 			ImageID: imageId, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().ComputeCIUnset(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} else { | ||||
| 		req := image.ComputeCISetRequest{ | ||||
| 			ImageID:     imageId, | ||||
| 			ComputeCIID: computeci, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().ComputeCISet(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageUpdateNodes(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.UpdateNodesRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 	enabledStacks := []uint64{} | ||||
| 	for _, stack := range d.Get("enabled_stacks").([]interface{}) { | ||||
| 		enabledStacks = append(enabledStacks, uint64(stack.(int))) | ||||
| 	} | ||||
| 
 | ||||
| 	req.EnabledStacks = enabledStacks | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().UpdateNodes(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "Name of the rescue disk", | ||||
| 		}, | ||||
| 		"url": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "URL where to download media from", | ||||
| 		}, | ||||
| 		"gid": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "grid (platform) ID where this template should be create in", | ||||
| 		}, | ||||
| 		"boot_type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "Boot type of image bios or uefi", | ||||
| 		}, | ||||
| 		"image_type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "Image type linux, windows or other", | ||||
| 		}, | ||||
| 		"drivers": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Required: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 			Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", | ||||
| 		}, | ||||
| 		"meta": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 			Description: "meta", | ||||
| 		}, | ||||
| 		"hot_resize": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Does this machine supports hot resize", | ||||
| 		}, | ||||
| 		"username": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Optional username for the image", | ||||
| 		}, | ||||
| 		"password": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Optional password for the image", | ||||
| 		}, | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "AccountId to make the image exclusive", | ||||
| 		}, | ||||
| 		"username_dl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "username for upload binary media", | ||||
| 		}, | ||||
| 		"password_dl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "password for upload binary media", | ||||
| 		}, | ||||
| 		"sep_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "storage endpoint provider ID", | ||||
| 		}, | ||||
| 		"pool_name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "pool for image create", | ||||
| 		}, | ||||
| 		"architecture": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "binary architecture of this image, one of X86_64 of PPC64_LE", | ||||
| 		}, | ||||
| 		"image_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "image id", | ||||
| 		}, | ||||
| 		"permanently": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Whether to completely delete the image", | ||||
| 		}, | ||||
| 		"bootable": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Does this image boot OS", | ||||
| 		}, | ||||
| 		"unc_path": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "unc path", | ||||
| 		}, | ||||
| 		"link_to": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "", | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "status", | ||||
| 		}, | ||||
| 		"tech_status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "tech atatus", | ||||
| 		}, | ||||
| 		"version": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "version", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "image size", | ||||
| 		}, | ||||
| 		"enabled": { | ||||
| 			Type:     schema.TypeBool, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"computeci_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"milestones": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"provider_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"purge_attempts": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"reference_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"res_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"res_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rescuecd": { | ||||
| 			Type:     schema.TypeBool, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"reason": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Optional: true, | ||||
| 		}, | ||||
| 		"last_modified": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"desc": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"shared_with": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeInt, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"sync": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Default:     false, | ||||
| 			Description: "Create image from a media identified by URL (in synchronous mode)", | ||||
| 		}, | ||||
| 		"enabled_stacks": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Optional: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"history": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"timestamp": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func ResourceImage() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceImageCreate, | ||||
| 		ReadContext:   resourceImageRead, | ||||
| 		UpdateContext: resourceImageUpdate, | ||||
| 		DeleteContext: resourceImageDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceImageSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" | ||||
| ) | ||||
| 
 | ||||
| func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	syncMode := d.Get("sync_mode").(bool) | ||||
| 	var imageId uint64 | ||||
| 
 | ||||
| 	if syncMode { | ||||
| 		req, err := SyncCreateRequest(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 		imageId, err = c.CloudBroker().Image().SyncCreate(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} else { | ||||
| 		req, err := CreateRequest(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 		imageId, err = c.CloudBroker().Image().CreateImage(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(imageId, 10)) | ||||
| 
 | ||||
| 	return resourceImageRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| 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()) | ||||
| 
 | ||||
| 	img, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	switch img.Status { | ||||
| 	case status.Modeled: | ||||
| 		return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status) | ||||
| 	case status.Destroyed, status.Purged: | ||||
| 		d.SetId("") | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	} | ||||
| 
 | ||||
| 	flattenImage(d, img) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| 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()) | ||||
| 
 | ||||
| 	_, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.DeleteRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	if reason, ok := d.GetOk("reason"); ok { | ||||
| 		req.Reason = reason.(string) | ||||
| 	} | ||||
| 	if permanently, ok := d.GetOk("permanently"); ok { | ||||
| 		req.Permanently = permanently.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().Image().Delete(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 
 | ||||
| 	img, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	switch img.Status { | ||||
| 	case status.Modeled: | ||||
| 		return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status) | ||||
| 	case status.Destroyed, status.Purged: | ||||
| 		d.SetId("") | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enabled") { | ||||
| 		err := resourceImageChangeEnabled(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("shared_with") { | ||||
| 		err := resourceImageShare(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("computeci_id") { | ||||
| 		err := resourceImageChangeComputeci(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enabled_stacks") { | ||||
| 		err := resourceImageUpdateNodes(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize") { | ||||
| 		err := resourceImageEdit(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageChangeEnabled(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	imageId := uint64(d.Get("image_id").(int)) | ||||
| 
 | ||||
| 	if d.Get("enabled").(bool) { | ||||
| 		req := image.EnableRequest{ | ||||
| 			ImageID: imageId, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().Enable(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} else { | ||||
| 		req := image.DisableRequest{ | ||||
| 			ImageID: imageId, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().Disable(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageShare(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceImageShare: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.ShareRequest{ | ||||
| 		ImageId: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 	accIds := []uint64{} | ||||
| 	for _, accId := range d.Get("shared_with").([]interface{}) { | ||||
| 		accIds = append(accIds, uint64(accId.(int))) | ||||
| 	} | ||||
| 	req.AccountIDs = accIds | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().Share(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageChangeComputeci(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	imageId := uint64(d.Get("image_id").(int)) | ||||
| 	computeci := uint64(d.Get("computeci_id").(int)) | ||||
| 
 | ||||
| 	if computeci == 0 { | ||||
| 		req := image.ComputeCIUnsetRequest{ | ||||
| 			ImageID: imageId, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().ComputeCIUnset(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} else { | ||||
| 		req := image.ComputeCISetRequest{ | ||||
| 			ImageID:     imageId, | ||||
| 			ComputeCIID: computeci, | ||||
| 		} | ||||
| 
 | ||||
| 		_, err := c.CloudBroker().Image().ComputeCISet(ctx, req) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageUpdateNodes(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.UpdateNodesRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 	enabledStacks := []uint64{} | ||||
| 	for _, stack := range d.Get("enabled_stacks").([]interface{}) { | ||||
| 		enabledStacks = append(enabledStacks, uint64(stack.(int))) | ||||
| 	} | ||||
| 
 | ||||
| 	req.EnabledStacks = enabledStacks | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().UpdateNodes(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.EditRequest{} | ||||
| 
 | ||||
| 	req.ImageID = uint64(d.Get("image_id").(int)) | ||||
| 	if d.HasChange("name") { | ||||
| 		req.Name = d.Get("name").(string) | ||||
| 	} | ||||
| 	if d.HasChange("username") { | ||||
| 		req.Username = d.Get("username").(string) | ||||
| 	} | ||||
| 	if d.HasChange("password") { | ||||
| 		req.Password = d.Get("password").(string) | ||||
| 	} | ||||
| 	if d.HasChange("account_id") { | ||||
| 		req.AccountID = uint64(d.Get("account_id").(int)) | ||||
| 	} | ||||
| 	if d.HasChange("bootable") { | ||||
| 		req.Bootable = d.Get("bootable").(bool) | ||||
| 	} | ||||
| 	if d.HasChange("hot_resize") { | ||||
| 		req.HotResize = d.Get("hot_resize").(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().Edit(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func ResourceImage() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceImageCreate, | ||||
| 		ReadContext:   resourceImageRead, | ||||
| 		UpdateContext: resourceImageUpdate, | ||||
| 		DeleteContext: resourceImageDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceImageSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,331 +1,220 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| ) | ||||
| 
 | ||||
| func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.CreateVirtualRequest{ | ||||
| 		Name:     d.Get("name").(string), | ||||
| 		TargetID: uint64(d.Get("target_id").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	imageId, err := c.CloudBroker().Image().CreateVirtual(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(imageId, 10)) | ||||
| 	d.Set("image_id", imageId) | ||||
| 
 | ||||
| 	return resourceImageRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| func resourceVirtualImageSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "name of the virtual image to create", | ||||
| 		}, | ||||
| 		"target_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "ID of real image to link this virtual image to upon creation", | ||||
| 		}, | ||||
| 		"history": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: map[string]*schema.Schema{ | ||||
| 					"guid": { | ||||
| 						Type:     schema.TypeString, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"id": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 					"timestamp": { | ||||
| 						Type:     schema.TypeInt, | ||||
| 						Computed: true, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"url": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "URL where to download media from", | ||||
| 		}, | ||||
| 		"gid": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "grid (platform) ID where this template should be create in", | ||||
| 		}, | ||||
| 		"boot_type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "Boot type of image bios or uefi", | ||||
| 		}, | ||||
| 		"image_type": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "Image type linux, windows or other", | ||||
| 		}, | ||||
| 		"drivers": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 			Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]", | ||||
| 		}, | ||||
| 		"meta": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 			Description: "meta", | ||||
| 		}, | ||||
| 		"hot_resize": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Does this machine supports hot resize", | ||||
| 		}, | ||||
| 		"username": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Optional username for the image", | ||||
| 		}, | ||||
| 		"password": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Optional password for the image", | ||||
| 		}, | ||||
| 		"account_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "AccountId to make the image exclusive", | ||||
| 		}, | ||||
| 		"username_dl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "username for upload binary media", | ||||
| 		}, | ||||
| 		"password_dl": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "password for upload binary media", | ||||
| 		}, | ||||
| 		"sep_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "storage endpoint provider ID", | ||||
| 		}, | ||||
| 		"pool_name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "pool for image create", | ||||
| 		}, | ||||
| 		"architecture": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "binary architecture of this image, one of X86_64 of PPC64_LE", | ||||
| 		}, | ||||
| 		"image_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "image id", | ||||
| 		}, | ||||
| 		"permanently": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Whether to completely delete the image", | ||||
| 		}, | ||||
| 		"bootable": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "Does this image boot OS", | ||||
| 		}, | ||||
| 		"unc_path": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "unc path", | ||||
| 		}, | ||||
| 		"link_to": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "", | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "status", | ||||
| 		}, | ||||
| 		"tech_status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "tech atatus", | ||||
| 		}, | ||||
| 		"version": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Computed:    true, | ||||
| 			Description: "version", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "image size", | ||||
| 		}, | ||||
| 		"enabled": { | ||||
| 			Type:     schema.TypeBool, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"computeci_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"milestones": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"provider_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"purge_attempts": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"reference_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"res_id": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"res_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rescuecd": { | ||||
| 			Type:     schema.TypeBool, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"reason": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Optional: true, | ||||
| 		}, | ||||
| 		"last_modified": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"desc": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"enabled_stacks": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Optional: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"shared_with": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeInt, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func ResourceVirtualImage() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceVirtualImageCreate, | ||||
| 		ReadContext:   resourceImageRead, | ||||
| 		UpdateContext: resourceImageUpdate, | ||||
| 		DeleteContext: resourceImageDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceVirtualImageSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" | ||||
| ) | ||||
| 
 | ||||
| func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.CreateVirtualRequest{ | ||||
| 		Name:     d.Get("name").(string), | ||||
| 		TargetID: uint64(d.Get("link_to").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	imageId, err := c.CloudBroker().Image().CreateVirtual(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(imageId, 10)) | ||||
| 
 | ||||
| 	return resourceImageRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| func resourceVirtualImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceVirtualImageRead: called for %s id: %s", d.Get("name").(string), d.Id()) | ||||
| 
 | ||||
| 	img, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	switch img.Status { | ||||
| 	case status.Modeled: | ||||
| 		return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status) | ||||
| 	case status.Destroyed, status.Purged: | ||||
| 		d.SetId("") | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	} | ||||
| 
 | ||||
| 	flattenImage(d, img) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceVirtualImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceVirtualImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 
 | ||||
| 	_, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.DeleteRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	if reason, ok := d.GetOk("reason"); ok { | ||||
| 		req.Reason = reason.(string) | ||||
| 	} | ||||
| 	if permanently, ok := d.GetOk("permanently"); ok { | ||||
| 		req.Permanently = permanently.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().Image().Delete(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceVirtualImageUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourceVirtualImageEdit: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 
 | ||||
| 	img, err := utilityImageCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	switch img.Status { | ||||
| 	case status.Modeled: | ||||
| 		return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status) | ||||
| 	case status.Destroyed, status.Purged: | ||||
| 		d.SetId("") | ||||
| 		return diag.Errorf("The resource cannot be updated because it has been destroyed") | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enabled") { | ||||
| 		err := resourceImageChangeEnabled(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("shared_with") { | ||||
| 		err := resourceImageShare(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("computeci_id") { | ||||
| 		err := resourceImageChangeComputeci(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enabled_stacks") { | ||||
| 		err := resourceImageUpdateNodes(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChanges("name", "username", "password", "account_id", "bootable", "hot_resize") { | ||||
| 		err := resourceImageEdit(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("link_to") { | ||||
| 		err := resourceImageLink(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourceImageLink(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id()) | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.LinkRequest{ | ||||
| 		ImageID:  uint64(d.Get("image_id").(int)), | ||||
| 		TargetID: uint64(d.Get("link_to").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	_, err := c.CloudBroker().Image().Link(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func ResourceVirtualImage() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourceVirtualImageCreate, | ||||
| 		ReadContext:   resourceVirtualImageRead, | ||||
| 		UpdateContext: resourceVirtualImageUpdate, | ||||
| 		DeleteContext: resourceVirtualImageDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourceVirtualImageSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,60 +1,60 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| ) | ||||
| 
 | ||||
| func utilityImageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.RecordImage, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.GetRequest{} | ||||
| 
 | ||||
| 	if (strconv.Itoa(d.Get("image_id").(int))) != "0" { | ||||
| 		req.ImageID = uint64(d.Get("image_id").(int)) | ||||
| 	} else { | ||||
| 		id, _ := strconv.ParseUint(d.Id(), 10, 64) | ||||
| 		req.ImageID = id | ||||
| 	} | ||||
| 
 | ||||
| 	image, err := c.CloudBroker().Image().Get(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return image, nil | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| ) | ||||
| 
 | ||||
| func utilityImageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.RecordImage, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.GetRequest{} | ||||
| 
 | ||||
| 	if d.Id() != "" { | ||||
| 		id, _ := strconv.ParseUint(d.Id(), 10, 64) | ||||
| 		req.ImageID = id | ||||
| 	} else { | ||||
| 		req.ImageID = uint64(d.Get("image_id").(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	image, err := c.CloudBroker().Image().Get(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return image, nil | ||||
| } | ||||
|  | ||||
| @ -1,66 +1,98 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| ) | ||||
| 
 | ||||
| func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.ListRequest{} | ||||
| 
 | ||||
| 	if sepId, ok := d.GetOk("sep_id"); ok { | ||||
| 		req.SepID = uint64(sepId.(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	if page, ok := d.GetOk("page"); ok { | ||||
| 		req.Page = uint64(page.(int)) | ||||
| 	} | ||||
| 	if size, ok := d.GetOk("size"); ok { | ||||
| 		req.Size = uint64(size.(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("utilityImageListCheckPresence: load image list") | ||||
| 	imageList, err := c.CloudBroker().Image().List(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return imageList, nil | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| ) | ||||
| 
 | ||||
| func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.ListRequest{} | ||||
| 
 | ||||
| 	if sepId, ok := d.GetOk("sep_id"); ok { | ||||
| 		req.SepID = uint64(sepId.(int)) | ||||
| 	} | ||||
| 	if byId, ok := d.GetOk("by_id"); ok { | ||||
| 		req.ByID = uint64(byId.(int)) | ||||
| 	} | ||||
| 	if name, ok := d.GetOk("name"); ok { | ||||
| 		req.Name = name.(string) | ||||
| 	} | ||||
| 	if status, ok := d.GetOk("status"); ok { | ||||
| 		req.Status = status.(string) | ||||
| 	} | ||||
| 	if architecture, ok := d.GetOk("architecture"); ok { | ||||
| 		req.Architecture = architecture.(string) | ||||
| 	} | ||||
| 	if typeImage, ok := d.GetOk("type_image"); ok { | ||||
| 		req.TypeImage = typeImage.(string) | ||||
| 	} | ||||
| 	if imageSize, ok := d.GetOk("image_size"); ok { | ||||
| 		req.ImageSize = uint64(imageSize.(int)) | ||||
| 	} | ||||
| 	if sepName, ok := d.GetOk("sep_name"); ok { | ||||
| 		req.SEPName = sepName.(string) | ||||
| 	} | ||||
| 	if pool, ok := d.GetOk("pool"); ok { | ||||
| 		req.Pool = pool.(string) | ||||
| 	} | ||||
| 	if public, ok := d.GetOk("public"); ok { | ||||
| 		req.Public = public.(bool) | ||||
| 	} | ||||
| 	if hotResize, ok := d.GetOk("hot_resize"); ok { | ||||
| 		req.HotResize = hotResize.(bool) | ||||
| 	} | ||||
| 	if bootable, ok := d.GetOk("bootable"); ok { | ||||
| 		req.Bootable = bootable.(bool) | ||||
| 	} | ||||
| 	if page, ok := d.GetOk("page"); ok { | ||||
| 		req.Page = uint64(page.(int)) | ||||
| 	} | ||||
| 	if size, ok := d.GetOk("size"); ok { | ||||
| 		req.Size = uint64(size.(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("utilityImageListCheckPresence: load image list") | ||||
| 	imageList, err := c.CloudBroker().Image().List(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return imageList, nil | ||||
| } | ||||
|  | ||||
| @ -1,57 +1,73 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| ) | ||||
| 
 | ||||
| func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListStacks, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.ListStacksRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("utilityImageListStacksCheckPresence: load image list") | ||||
| 	imageListStacks, err := c.CloudBroker().Image().ListStacks(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return imageListStacks, nil | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package image | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| ) | ||||
| 
 | ||||
| func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListStacks, error) { | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := image.ListStacksRequest{ | ||||
| 		ImageID: uint64(d.Get("image_id").(int)), | ||||
| 	} | ||||
| 
 | ||||
| 	if page, ok := d.GetOk("page"); ok { | ||||
| 		req.Page = uint64(page.(int)) | ||||
| 	} | ||||
| 	if size, ok := d.GetOk("size"); ok { | ||||
| 		req.Size = uint64(size.(int)) | ||||
| 	} | ||||
| 	if name, ok := d.GetOk("name"); ok { | ||||
| 		req.Name = name.(string) | ||||
| 	} | ||||
| 	if status, ok := d.GetOk("status"); ok { | ||||
| 		req.Status = status.(string) | ||||
| 	} | ||||
| 	if typeImage, ok := d.GetOk("type_image"); ok { | ||||
| 		req.Type = typeImage.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Debugf("utilityImageListStacksCheckPresence: load image list") | ||||
| 	imageListStacks, err := c.CloudBroker().Image().ListStacks(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return imageListStacks, nil | ||||
| } | ||||
|  | ||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -1,140 +1,69 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package pcidevice | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" | ||||
| ) | ||||
| 
 | ||||
| func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.Set("ckey", pcidevice.CKey) | ||||
| 	d.Set("meta", flattens.FlattenMeta(pcidevice.Meta)) | ||||
| 	d.Set("compute_id", pcidevice.ComputeID) | ||||
| 	d.Set("description", pcidevice.Description) | ||||
| 	d.Set("guid", pcidevice.GUID) | ||||
| 	d.Set("hw_path", pcidevice.HwPath) | ||||
| 	d.Set("device_id",pcidevice.ID) | ||||
| 	d.Set("name", pcidevice.Name) | ||||
| 	d.Set("rg_id", pcidevice.RGID) | ||||
| 	d.Set("stack_id", pcidevice.StackID) | ||||
| 	d.Set("status", pcidevice.Status) | ||||
| 	d.Set("system_name", pcidevice.SystemName) | ||||
| 
 | ||||
| 	d.SetId(strconv.Itoa(d.Get("device_id").(int))) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourcePcideviceSchemaMake() map[string]*schema.Schema { | ||||
| 	rets := map[string]*schema.Schema{ | ||||
| 		"device_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Required: true, | ||||
| 			ForceNew: true, | ||||
| 		}, | ||||
| 		"ckey": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"meta": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"compute_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"description": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"hw_path": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"stack_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"system_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	return rets | ||||
| } | ||||
| 
 | ||||
| func DataSourcePcidevice() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourcePcideviceRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourcePcideviceSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package pcidevice | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	flattenPcidevice(d, pcidevice) | ||||
| 	d.SetId(strconv.Itoa(d.Get("device_id").(int))) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourcePcidevice() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourcePcideviceRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourcePcideviceSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,149 +1,72 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package pcidevice | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" | ||||
| ) | ||||
| 
 | ||||
| func flattenPcideviceList(pl *pcidevice.ListPCIDevices) []map[string]interface{} { | ||||
| 	res := make([]map[string]interface{}, 0, len(pl.Data)) | ||||
| 	for _, item := range pl.Data { | ||||
| 		temp := map[string]interface{}{ | ||||
| 			"ckey":        item.CKey, | ||||
| 			"meta":        flattens.FlattenMeta(item.Meta), | ||||
| 			"compute_id":  item.ComputeID, | ||||
| 			"description": item.Description, | ||||
| 			"guid":        item.GUID, | ||||
| 			"hw_path":     item.HwPath, | ||||
| 			"device_id":   item.ID, | ||||
| 			"rg_id":       item.RGID, | ||||
| 			"name":        item.Name, | ||||
| 			"stack_id":    item.StackID, | ||||
| 			"status":      item.Status, | ||||
| 			"system_name": item.SystemName, | ||||
| 		} | ||||
| 		res = append(res, temp) | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	pcideviceList, err := utilityPcideviceListCheckPresence(ctx, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.Set("items", flattenPcideviceList(pcideviceList)) | ||||
| 	d.Set("entry_count", pcideviceList.EntryCount) | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func dataSourcePcideviceListSchemaMake() map[string]*schema.Schema { | ||||
| 	rets := map[string]*schema.Schema{ | ||||
| 		"by_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "by_id", | ||||
| 		}, | ||||
| 		"compute_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "compute_id", | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "name", | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "rg_id", | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Description: "status", | ||||
| 		}, | ||||
| 		"page": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page number", | ||||
| 		}, | ||||
| 		"size": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Optional:    true, | ||||
| 			Description: "page size", | ||||
| 		}, | ||||
| 		"items": { | ||||
| 			Type:        schema.TypeList, | ||||
| 			Computed:    true, | ||||
| 			Description: "pcidevice list", | ||||
| 			Elem: &schema.Resource{ | ||||
| 				Schema: dataSourcePcideviceSchemaMake(), | ||||
| 			}, | ||||
| 		}, | ||||
| 		"entry_count": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Computed:    true, | ||||
| 			Description: "entry count", | ||||
| 		}, | ||||
| 	} | ||||
| 	return rets | ||||
| } | ||||
| 
 | ||||
| func DataSourcePcideviceList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourcePcideviceListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourcePcideviceListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package pcidevice | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| ) | ||||
| 
 | ||||
| func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	pcideviceList, err := utilityPcideviceListCheckPresence(ctx, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.Set("items", flattenPcideviceList(pcideviceList)) | ||||
| 	d.Set("entry_count", pcideviceList.EntryCount) | ||||
| 
 | ||||
| 	id := uuid.New() | ||||
| 	d.SetId(id.String()) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func DataSourcePcideviceList() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		ReadContext: dataSourcePcideviceListRead, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: dataSourcePcideviceListSchemaMake(), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1,292 +1,229 @@ | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package pcidevice | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" | ||||
| 
 | ||||
| ) | ||||
| 
 | ||||
| func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	req := pcidevice.CreateRequest{} | ||||
| 
 | ||||
| 	haveRGID, err := existRGID(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	if !haveRGID { | ||||
| 		return diag.Errorf("resourcePcideviceCreate: can't create Pcidevice because RGID %d is not allowed or does not exist", d.Get("rg_id").(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	haveStackID, err := existStackID(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	if !haveStackID { | ||||
| 		return diag.Errorf("resourcePcideviceCreate: can't create Pcidevice because StackID %d is not allowed or does not exist", d.Get("stack_id").(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	req.StackID = uint64(d.Get("stack_id").(int)) | ||||
| 	req.RGID = uint64(d.Get("rg_id").(int)) | ||||
| 	req.Name = d.Get("name").(string) | ||||
| 	req.HWPath = d.Get("hw_path").(string) | ||||
| 
 | ||||
| 	if description, ok := d.GetOk("description"); ok { | ||||
| 		req.Description = description.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	pcideviceId, err := c.CloudBroker().PCIDevice().Create(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(pcideviceId, 10)) | ||||
| 	d.Set("device_id", pcideviceId) | ||||
| 
 | ||||
| 	return resourcePcideviceRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.Set("ckey", pcidevice.CKey) | ||||
| 	d.Set("meta", flattens.FlattenMeta(pcidevice.Meta)) | ||||
| 	d.Set("compute_id", pcidevice.ComputeID) | ||||
| 	d.Set("description", pcidevice.Description) | ||||
| 	d.Set("guid", pcidevice.GUID) | ||||
| 	d.Set("hw_path", pcidevice.HwPath) | ||||
| 	d.Set("device_id", pcidevice.ID) | ||||
| 	d.Set("rg_id", pcidevice.RGID) | ||||
| 	d.Set("name", pcidevice.Name) | ||||
| 	d.Set("stack_id", pcidevice.StackID) | ||||
| 	d.Set("status", pcidevice.Status) | ||||
| 	d.Set("system_name", pcidevice.SystemName) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourcePcideviceUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 
 | ||||
| 	haveRGID, err := existRGID(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	if !haveRGID { | ||||
| 		return diag.Errorf("resourcePcideviceCreate: can't update Pcidevice because RGID %d is not allowed or does not exist", d.Get("rg_id").(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	haveStackID, err := existStackID(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	if !haveStackID { | ||||
| 		return diag.Errorf("resourcePcideviceCreate: can't update Pcidevice because StackID %d is not allowed or does not exist", d.Get("stack_id").(int)) | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enable") { | ||||
| 		state := d.Get("enable").(bool) | ||||
| 		c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 		if state { | ||||
| 			req := pcidevice.EnableRequest{ | ||||
| 				DeviceID: uint64(d.Get("device_id").(int)), | ||||
| 			} | ||||
| 
 | ||||
| 			_, err := c.CloudBroker().PCIDevice().Enable(ctx, req) | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 		} else { | ||||
| 			req := pcidevice.DisableRequest{ | ||||
| 				DeviceID: uint64(d.Get("device_id").(int)), | ||||
| 			} | ||||
| 			if force, ok := d.GetOk("force"); ok { | ||||
| 				req.Force = force.(bool) | ||||
| 			} | ||||
| 
 | ||||
| 			_, err := c.CloudBroker().PCIDevice().Disable(ctx, req) | ||||
| 			if err != nil { | ||||
| 				return diag.FromErr(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return resourcePcideviceRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| 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()) | ||||
| 
 | ||||
| 	pciDevice, err := utilityPcideviceCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 	if pciDevice.Status == status.Destroyed || pciDevice.Status == status.Purged { | ||||
| 		return nil | ||||
| 	} | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	req := pcidevice.DeleteRequest{ | ||||
| 		DeviceID: pciDevice.ID, | ||||
| 	} | ||||
| 	 | ||||
| 	if force, ok := d.GetOk("force"); ok { | ||||
| 		req.Force = force.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	_, err = c.CloudBroker().PCIDevice().Delete(ctx, req) | ||||
| 	if err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourcePcideviceSchemaMake() map[string]*schema.Schema { | ||||
| 	return map[string]*schema.Schema{ | ||||
| 		"ckey": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"meta": { | ||||
| 			Type:     schema.TypeList, | ||||
| 			Computed: true, | ||||
| 			Elem: &schema.Schema{ | ||||
| 				Type: schema.TypeString, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"compute_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"description": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Optional:    true, | ||||
| 			Computed:    true, | ||||
| 			Description: "description, just for information", | ||||
| 		}, | ||||
| 		"guid": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"hw_path": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "PCI address of the device", | ||||
| 		}, | ||||
| 		"device_id": { | ||||
| 			Type:     schema.TypeInt, | ||||
| 			Optional: true, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"name": { | ||||
| 			Type:        schema.TypeString, | ||||
| 			Required:    true, | ||||
| 			Description: "Name of Device", | ||||
| 		}, | ||||
| 		"rg_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "Resource GROUP", | ||||
| 		}, | ||||
| 		"stack_id": { | ||||
| 			Type:        schema.TypeInt, | ||||
| 			Required:    true, | ||||
| 			Description: "stackId", | ||||
| 		}, | ||||
| 		"status": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"system_name": { | ||||
| 			Type:     schema.TypeString, | ||||
| 			Computed: true, | ||||
| 		}, | ||||
| 		"force": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Default:     false, | ||||
| 			Description: "Force delete", | ||||
| 		}, | ||||
| 		"enable": { | ||||
| 			Type:        schema.TypeBool, | ||||
| 			Optional:    true, | ||||
| 			Default:     false, | ||||
| 			Description: "Enable pci device", | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func ResourcePcidevice() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourcePcideviceCreate, | ||||
| 		ReadContext:   resourcePcideviceRead, | ||||
| 		UpdateContext: resourcePcideviceUpdate, | ||||
| 		DeleteContext: resourcePcideviceDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourcePcideviceSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| /* | ||||
| Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. | ||||
| Authors: | ||||
| Petr Krutov, <petr.krutov@digitalenergy.online> | ||||
| Stanislav Solovev, <spsolovev@digitalenergy.online> | ||||
| 
 | ||||
| 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://repository.basistech.ru/BASIS/terraform-provider-decort
 | ||||
| 
 | ||||
| Please see README.md to learn where to place source code so that it | ||||
| builds seamlessly. | ||||
| 
 | ||||
| Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
 | ||||
| */ | ||||
| 
 | ||||
| package pcidevice | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||||
| 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||
| 	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc" | ||||
| 	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" | ||||
| ) | ||||
| 
 | ||||
| func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 	createReq := pcidevice.CreateRequest{} | ||||
| 
 | ||||
| 	if diags := checkParamsExistence(ctx, d, c); diags != nil { | ||||
| 		return diags | ||||
| 	} | ||||
| 
 | ||||
| 	createReq.StackID = uint64(d.Get("stack_id").(int)) | ||||
| 	createReq.RGID = uint64(d.Get("rg_id").(int)) | ||||
| 	createReq.Name = d.Get("name").(string) | ||||
| 	createReq.HWPath = d.Get("hw_path").(string) | ||||
| 
 | ||||
| 	if description, ok := d.GetOk("description"); ok { | ||||
| 		createReq.Description = description.(string) | ||||
| 	} | ||||
| 
 | ||||
| 	pcideviceId, err := c.CloudBroker().PCIDevice().Create(ctx, createReq) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId(strconv.FormatUint(pcideviceId, 10)) | ||||
| 	d.Set("device_id", pcideviceId) | ||||
| 
 | ||||
| 	warnings := dc.Warnings{} | ||||
| 
 | ||||
| 	if enable, ok := d.GetOk("enable"); ok { | ||||
| 		log.Debugf("resourcePcideviceCreate: enable=%t device_id %d after completing its resource configuration", enable, pcideviceId) | ||||
| 
 | ||||
| 		if enable.(bool) { | ||||
| 			req := pcidevice.EnableRequest{DeviceID: pcideviceId} | ||||
| 			if _, err := c.CloudBroker().PCIDevice().Enable(ctx, req); err != nil { | ||||
| 				warnings.Add(err) | ||||
| 			} | ||||
| 
 | ||||
| 		} else { | ||||
| 			req := pcidevice.DisableRequest{ | ||||
| 				DeviceID: pcideviceId, | ||||
| 			} | ||||
| 			if force, ok := d.GetOk("force_disable"); ok { | ||||
| 				req.Force = force.(bool) | ||||
| 				log.Debugf("force_disable=%v", force) | ||||
| 			} | ||||
| 			if _, err := c.CloudBroker().PCIDevice().Disable(ctx, req); err != nil { | ||||
| 				warnings.Add(err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return append(resourcePcideviceRead(ctx, d, m), warnings.Get()...) | ||||
| } | ||||
| 
 | ||||
| func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourcePcideviceRead: called for pci_device id %d, name %s", | ||||
| 		d.Id(), d.Get("name").(string)) | ||||
| 
 | ||||
| 	pcideviceRec, err := utilityPcideviceCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	flattenPcidevice(d, pcideviceRec) | ||||
| 
 | ||||
| 	log.Debugf("resourcePcideviceRead: after flattenPcidevice: device_id %s, name %s", | ||||
| 		d.Id(), d.Get("name").(string)) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func resourcePcideviceUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||||
| 	log.Debugf("resourcePcideviceUpdate: called for pcidevice id %s, name %s", d.Id(), d.Get("name").(string)) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	if diags := checkParamsExistence(ctx, d, c); diags != nil { | ||||
| 		return diags | ||||
| 	} | ||||
| 
 | ||||
| 	if d.HasChange("enable") { | ||||
| 		err := resourcePcideviceChangeEnable(ctx, d, m) | ||||
| 		if err != nil { | ||||
| 			return diag.FromErr(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return resourcePcideviceRead(ctx, d, m) | ||||
| } | ||||
| 
 | ||||
| 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()) | ||||
| 
 | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	pciDevice, err := utilityPcideviceCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		d.SetId("") | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	if pciDevice.Status == status.Destroyed || pciDevice.Status == status.Purged { | ||||
| 		return nil | ||||
| 	} | ||||
| 
 | ||||
| 	req := pcidevice.DeleteRequest{ | ||||
| 		DeviceID: pciDevice.ID, | ||||
| 	} | ||||
| 	if force, ok := d.GetOk("force_delete"); ok { | ||||
| 		req.Force = force.(bool) | ||||
| 	} | ||||
| 
 | ||||
| 	if _, err = c.CloudBroker().PCIDevice().Delete(ctx, req); err != nil { | ||||
| 		return diag.FromErr(err) | ||||
| 	} | ||||
| 
 | ||||
| 	d.SetId("") | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func ResourcePcidevice() *schema.Resource { | ||||
| 	return &schema.Resource{ | ||||
| 		SchemaVersion: 1, | ||||
| 
 | ||||
| 		CreateContext: resourcePcideviceCreate, | ||||
| 		ReadContext:   resourcePcideviceRead, | ||||
| 		UpdateContext: resourcePcideviceUpdate, | ||||
| 		DeleteContext: resourcePcideviceDelete, | ||||
| 
 | ||||
| 		Importer: &schema.ResourceImporter{ | ||||
| 			StateContext: schema.ImportStatePassthroughContext, | ||||
| 		}, | ||||
| 
 | ||||
| 		Timeouts: &schema.ResourceTimeout{ | ||||
| 			Create:  &constants.Timeout60s, | ||||
| 			Read:    &constants.Timeout30s, | ||||
| 			Update:  &constants.Timeout60s, | ||||
| 			Delete:  &constants.Timeout60s, | ||||
| 			Default: &constants.Timeout60s, | ||||
| 		}, | ||||
| 
 | ||||
| 		Schema: resourcePcideviceSchemaMake(), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func resourcePcideviceChangeEnable(ctx context.Context, d *schema.ResourceData, m interface{}) error { | ||||
| 	enable := d.Get("enable").(bool) | ||||
| 	log.Debugf("resourcePcideviceChangeEnable: enable=%t device_id %s after completing its resource configuration", enable, d.Id()) | ||||
| 
 | ||||
| 	pcideviceRec, err := utilityPcideviceCheckPresence(ctx, d, m) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	c := m.(*controller.ControllerCfg) | ||||
| 
 | ||||
| 	if enable { | ||||
| 		req := pcidevice.EnableRequest{ | ||||
| 			DeviceID: pcideviceRec.ID, | ||||
| 		} | ||||
| 
 | ||||
| 		if _, err := c.CloudBroker().PCIDevice().Enable(ctx, req); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} else { | ||||
| 		req := pcidevice.DisableRequest{ | ||||
| 			DeviceID: pcideviceRec.ID, | ||||
| 		} | ||||
| 		if force, ok := d.GetOk("force_disable"); ok { | ||||
| 			req.Force = force.(bool) | ||||
| 		} | ||||
| 
 | ||||
| 		if _, err := c.CloudBroker().PCIDevice().Disable(ctx, req); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
Some files were not shown because too many files have changed in this diff Show More
					Loading…
					
					
				
		Reference in new issue