4.5.0-alpha
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dataSourceAccountComputeSchemaMake() map[string]*schema.Schema {
|
||||
return 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dataSourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"dc_location": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"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,
|
||||
},
|
||||
"disksize": {
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"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,
|
||||
},
|
||||
"extips": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
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,
|
||||
},
|
||||
"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_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_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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"send_access_emails": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
// "service_account": {
|
||||
// Type: schema.TypeBool,
|
||||
// Computed: true,
|
||||
// },
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dataSourceAccountFlipGroupSchemaMake() map[string]*schema.Schema {
|
||||
return 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dataSourceAccountItemSchemaMake() map[string]*schema.Schema {
|
||||
return 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,
|
||||
},
|
||||
"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_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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"send_access_emails": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"service_account": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,14 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Default: true,
|
||||
Description: "if true send emails when a user is granted access to resources",
|
||||
},
|
||||
"uniq_pools": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"users": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
@@ -77,6 +85,18 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"cpu_allocation_parameter": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "set cpu allocation parameter",
|
||||
},
|
||||
"cpu_allocation_ratio": {
|
||||
Type: schema.TypeFloat,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "set cpu allocation ratio",
|
||||
},
|
||||
"restore": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
@@ -91,6 +111,7 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
"enable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "enable/disable account",
|
||||
},
|
||||
"resource_limits": {
|
||||
@@ -106,6 +127,10 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
},
|
||||
"cu_d": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
},
|
||||
"cu_dm": {
|
||||
Type: schema.TypeFloat,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
@@ -142,78 +167,6 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"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,
|
||||
},
|
||||
"disksize": {
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"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,
|
||||
},
|
||||
"extips": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -293,10 +246,13 @@ func resourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
// "service_account": {
|
||||
// Type: schema.TypeBool,
|
||||
// Computed: true,
|
||||
// },
|
||||
"resource_types": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dataSourceAccountVinsSchema() map[string]*schema.Schema {
|
||||
return 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
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
|
||||
|
||||
const accountAddUserAPI = "/restmachine/cloudbroker/account/addUser"
|
||||
const accountAuditsAPI = "/restmachine/cloudbroker/account/audits"
|
||||
const accountCreateAPI = "/restmachine/cloudbroker/account/create"
|
||||
const accountDeleteAPI = "/restmachine/cloudbroker/account/delete"
|
||||
const accountDeleteUserAPI = "/restmachine/cloudbroker/account/deleteUser"
|
||||
const accountDisableAPI = "/restmachine/cloudbroker/account/disable"
|
||||
const accountEnableAPI = "/restmachine/cloudbroker/account/enable"
|
||||
const accountGetAPI = "/restmachine/cloudbroker/account/get"
|
||||
const accountListAPI = "/restmachine/cloudbroker/account/list"
|
||||
const accountListComputesAPI = "/restmachine/cloudbroker/account/listComputes"
|
||||
const accountListDeletedAPI = "/restmachine/cloudbroker/account/listDeleted"
|
||||
const accountListDisksAPI = "/restmachine/cloudbroker/account/listDisks"
|
||||
const accountListFlipGroupsAPI = "/restmachine/cloudbroker/account/listFlipGroups"
|
||||
const accountListRGAPI = "/restmachine/cloudbroker/account/listRG"
|
||||
const accountListVinsAPI = "/restmachine/cloudbroker/account/listVins"
|
||||
const accountRestoreAPI = "/restmachine/cloudbroker/account/restore"
|
||||
const accountUpdateAPI = "/restmachine/cloudbroker/account/update"
|
||||
const accountUpdateUserAPI = "/restmachine/cloudbroker/account/updateUser"
|
||||
|
||||
//currently unused
|
||||
//const accountsEnableAPI = "/restmachine/cloudbroker/account/enableAccounts"
|
||||
//const accountsDisableAPI = "/restmachine/cloudbroker/account/disableAccounts"
|
||||
//const accountsDeleteAPI = "/restmachine/cloudbroker/account/deleteAccounts"
|
||||
@@ -1,8 +1,9 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 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.
|
||||
@@ -66,3 +67,174 @@ func DataSourceAccount() *schema.Resource {
|
||||
Schema: dataSourceAccountSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceAccountSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"dc_location": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"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.TypeInt,
|
||||
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_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,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -65,7 +65,28 @@ func dataSourceAccountAuditsListSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Search Result",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceAccountAuditSchemaMake(),
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -85,4 +106,4 @@ func DataSourceAccountAuditsList() *schema.Resource {
|
||||
|
||||
Schema: dataSourceAccountAuditsListSchemaMake(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -49,6 +49,7 @@ func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceDa
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccountComputesList(accountComputesList))
|
||||
d.Set("entry_count", accountComputesList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -60,18 +61,154 @@ func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema {
|
||||
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: dataSourceAccountComputeSchemaMake(),
|
||||
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,
|
||||
@@ -85,4 +222,4 @@ func DataSourceAccountComputesList() *schema.Resource {
|
||||
|
||||
Schema: dataSourceAccountComputesListSchemaMake(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -40,19 +40,6 @@ import (
|
||||
"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 {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenListDeleted(accountDeletedList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceAccountDeletedList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
@@ -64,6 +51,234 @@ func DataSourceAccountDeletedList() *schema.Resource {
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceAccountListSchemaMake(),
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -48,6 +48,7 @@ func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData,
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccountDisksList(accountDisksList))
|
||||
d.Set("entry_count", accountDisksList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -59,14 +60,77 @@ func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema {
|
||||
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: dataSourceAccountDiskSchemaMake(),
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -49,6 +49,7 @@ func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.Resource
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList))
|
||||
d.Set("entry_count", accountFlipGroupsList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -60,14 +61,143 @@ func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema {
|
||||
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: dataSourceAccountFlipGroupSchemaMake(),
|
||||
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
|
||||
}
|
||||
@@ -85,4 +215,4 @@ func DataSourceAccountFlipGroupsList() *schema.Resource {
|
||||
|
||||
Schema: dataSourceAccountFlipGroupsListSchemaMake(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 dataSourceAccountResourceConsumptionGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
accountResourceConsumptionRec, err := utilityAccountResourceConsumptionGetCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
flattenResourceConsumption(d, accountResourceConsumptionRec)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceAccountResourceConsumptionGetSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"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.TypeFloat,
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reserved": {
|
||||
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.TypeFloat,
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceAccountResourceConsumptionGet() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceAccountResourceConsumptionGetRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceAccountResourceConsumptionGetSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ 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.
|
||||
@@ -40,42 +41,6 @@ import (
|
||||
"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 {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccountList(accountList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"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: dataSourceAccountItemSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceAccountList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
@@ -90,3 +55,238 @@ func DataSourceAccountList() *schema.Resource {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -1,205 +1,212 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
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.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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"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,
|
||||
},
|
||||
"extips": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
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,
|
||||
},
|
||||
"extips": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"exttraffic": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"gpu": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ram": {
|
||||
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,
|
||||
},
|
||||
"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>
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 dataSourceAccountResourceConsumptionListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
accountResourceConsumptionList, err := utilityAccountResourceConsumptionListCheckPresence(ctx, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccResourceConsumption(accountResourceConsumptionList))
|
||||
d.Set("entry_count", accountResourceConsumptionList.EntryCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceAccountResourceConsumptionListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"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.TypeFloat,
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reserved": {
|
||||
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.TypeFloat,
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceAccountResourceConsumptionList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceAccountResourceConsumptionListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceAccountResourceConsumptionListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -40,38 +40,6 @@ import (
|
||||
"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 {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccountRGList(accountRGList))
|
||||
|
||||
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",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Search Result",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceAccountRGSchemaMake(),
|
||||
},
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceAccountRGList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
@@ -86,3 +54,309 @@ func DataSourceAccountRGList() *schema.Resource {
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -49,6 +49,7 @@ func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData,
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccountVinsList(accountVinsList))
|
||||
d.Set("entry_count", accountVinsList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -60,14 +61,117 @@ func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema {
|
||||
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: dataSourceAccountVinsSchema(),
|
||||
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
|
||||
}
|
||||
@@ -85,4 +189,4 @@ func DataSourceAccountVinsList() *schema.Resource {
|
||||
|
||||
Schema: dataSourceAccountVinsListSchemaMake(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,12 @@ import (
|
||||
|
||||
func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) {
|
||||
d.Set("dc_location", acc.DCLocation)
|
||||
// d.Set("resources", flattenAccResources(acc.Resources))
|
||||
d.Set("ckey", acc.CKey)
|
||||
d.Set("acl", flattenAccAcl(acc.ACL))
|
||||
d.Set("company", acc.Company)
|
||||
d.Set("companyurl", acc.CompanyURL)
|
||||
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
|
||||
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
|
||||
d.Set("created_by", acc.CreatedBy)
|
||||
d.Set("created_time", acc.CreatedTime)
|
||||
d.Set("deactivation_time", acc.DeactivationTime)
|
||||
@@ -23,8 +24,10 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
|
||||
d.Set("account_id", acc.ID)
|
||||
d.Set("account_name", acc.Name)
|
||||
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
|
||||
d.Set("resource_types", acc.ResTypes)
|
||||
d.Set("send_access_emails", acc.SendAccessEmails)
|
||||
d.Set("status", acc.Status)
|
||||
d.Set("uniq_pools", acc.UniqPools)
|
||||
d.Set("updated_time", acc.UpdatedTime)
|
||||
d.Set("version", acc.Version)
|
||||
d.Set("vins", acc.VINS)
|
||||
@@ -32,12 +35,12 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
|
||||
|
||||
func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
|
||||
d.Set("dc_location", acc.DCLocation)
|
||||
// d.Set("resources", flattenAccResources(acc.Resources))
|
||||
d.Set("ckey", acc.CKey)
|
||||
// d.Set("meta", flattens.FlattenMeta(acc.))
|
||||
d.Set("acl", flattenAccAcl(acc.ACL))
|
||||
d.Set("company", acc.Company)
|
||||
d.Set("companyurl", acc.CompanyURL)
|
||||
d.Set("cpu_allocation_parameter", acc.CPUAllocationParameter)
|
||||
d.Set("cpu_allocation_ratio", acc.CPUAllocationRatio)
|
||||
d.Set("created_by", acc.CreatedBy)
|
||||
d.Set("created_time", acc.CreatedTime)
|
||||
d.Set("deactivation_time", acc.DeactivationTime)
|
||||
@@ -48,9 +51,10 @@ func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
|
||||
d.Set("account_id", acc.ID)
|
||||
d.Set("account_name", acc.Name)
|
||||
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
|
||||
d.Set("resource_types", acc.ResTypes)
|
||||
d.Set("send_access_emails", acc.SendAccessEmails)
|
||||
// d.Set("service_account", acc.ServiceAccount)
|
||||
d.Set("status", acc.Status)
|
||||
d.Set("uniq_pools", acc.UniqPools)
|
||||
d.Set("updated_time", acc.UpdatedTime)
|
||||
d.Set("version", acc.Version)
|
||||
d.Set("vins", acc.VINS)
|
||||
@@ -94,7 +98,7 @@ func flattenAccRGComputes(argc account.Computes) []map[string]interface{} {
|
||||
func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"consumed": flattenAccConsumed(argr.Consumed),
|
||||
"consumed": flattenAccResource(argr.Consumed),
|
||||
"limits": flattenAccLimits(argr.Limits),
|
||||
"reserved": flattenAccResource(argr.Reserved),
|
||||
}
|
||||
@@ -102,39 +106,17 @@ func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccResources(r account.RecordResourceConsumption) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"current": flattenAccResource(r.Current),
|
||||
"reserved": flattenAccResource(r.Reserved),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccConsumed(c account.Consumed) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": c.CPU,
|
||||
"disksize": c.DiskSize,
|
||||
"extips": c.ExtIPs,
|
||||
"exttraffic": c.ExtTraffic,
|
||||
"gpu": c.GPU,
|
||||
"ram": c.RAM,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccLimits(l account.Limits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": l.CPU,
|
||||
"disksize": l.DiskSize,
|
||||
"extips": l.ExtIPs,
|
||||
"exttraffic": l.ExtTraffic,
|
||||
"gpu": l.GPU,
|
||||
"ram": l.RAM,
|
||||
"cpu": l.CPU,
|
||||
"disksize": l.DiskSize,
|
||||
"disksizemax": l.DiskSizeMax,
|
||||
"extips": l.ExtIPs,
|
||||
"exttraffic": l.ExtTraffic,
|
||||
"gpu": l.GPU,
|
||||
"ram": l.RAM,
|
||||
"seps": l.SEPs,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
@@ -143,12 +125,14 @@ func flattenAccLimits(l account.Limits) []map[string]interface{} {
|
||||
func flattenAccResource(r account.Resource) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": r.CPU,
|
||||
"disksize": r.DiskSize,
|
||||
"extips": r.ExtIPs,
|
||||
"exttraffic": r.ExtTraffic,
|
||||
"gpu": r.GPU,
|
||||
"ram": r.RAM,
|
||||
"cpu": r.CPU,
|
||||
"disksize": r.DiskSize,
|
||||
"disksizemax": r.DiskSizeMax,
|
||||
"extips": r.ExtIPs,
|
||||
"exttraffic": r.ExtTraffic,
|
||||
"gpu": r.GPU,
|
||||
"ram": r.RAM,
|
||||
"seps": flattenAccountSeps(r.SEPs),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
@@ -175,6 +159,7 @@ func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{}
|
||||
temp := map[string]interface{}{
|
||||
"cu_c": rl.CuC,
|
||||
"cu_d": rl.CuD,
|
||||
"cu_dm": rl.CuDM,
|
||||
"cu_i": rl.CuI,
|
||||
"cu_m": rl.CuM,
|
||||
"cu_np": rl.CuNP,
|
||||
@@ -186,7 +171,7 @@ func flattenRgResourceLimits(rl account.ResourceLimits) []map[string]interface{}
|
||||
}
|
||||
|
||||
func flattenRgAcl(rgAcls []account.ACL) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, len(rgAcls))
|
||||
for _, rgAcl := range rgAcls {
|
||||
temp := map[string]interface{}{
|
||||
"explicit": rgAcl.Explicit,
|
||||
@@ -205,38 +190,31 @@ func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acc := range al.Data {
|
||||
temp := map[string]interface{}{
|
||||
"dc_location": acc.DCLocation,
|
||||
"ckey": acc.CKey,
|
||||
"meta": flattens.FlattenMeta(acc.Meta),
|
||||
|
||||
"acl": flattenRgAcl(acc.ACL),
|
||||
|
||||
"company": acc.Company,
|
||||
"companyurl": acc.CompanyURL,
|
||||
"created_by": acc.CreatedBy,
|
||||
|
||||
"created_time": acc.CreatedTime,
|
||||
|
||||
"deactivation_time": acc.DeactivationTime,
|
||||
"deleted_by": acc.DeletedBy,
|
||||
|
||||
"deleted_time": acc.DeletedTime,
|
||||
|
||||
"displayname": acc.DisplayName,
|
||||
"guid": acc.GUID,
|
||||
|
||||
"account_id": acc.ID,
|
||||
"account_name": acc.Name,
|
||||
|
||||
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
|
||||
"send_access_emails": acc.SendAccessEmails,
|
||||
// "service_account": acc.ServiceAccount,
|
||||
|
||||
"status": acc.Status,
|
||||
"updated_time": acc.UpdatedTime,
|
||||
|
||||
"version": acc.Version,
|
||||
"vins": acc.VINS,
|
||||
"dc_location": acc.DCLocation,
|
||||
"ckey": acc.CKey,
|
||||
"meta": flattens.FlattenMeta(acc.Meta),
|
||||
"acl": flattenRgAcl(acc.ACL),
|
||||
"company": acc.Company,
|
||||
"companyurl": acc.CompanyURL,
|
||||
"cpu_allocation_parameter": acc.CPUAllocationParameter,
|
||||
"cpu_allocation_ratio": acc.CPUAllocationRatio,
|
||||
"created_by": acc.CreatedBy,
|
||||
"created_time": acc.CreatedTime,
|
||||
"deactivation_time": acc.DeactivationTime,
|
||||
"deleted_by": acc.DeletedBy,
|
||||
"deleted_time": acc.DeletedTime,
|
||||
"displayname": acc.DisplayName,
|
||||
"guid": acc.GUID,
|
||||
"account_id": acc.ID,
|
||||
"account_name": acc.Name,
|
||||
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
|
||||
"resource_types": acc.ResTypes,
|
||||
"send_access_emails": acc.SendAccessEmails,
|
||||
"status": acc.Status,
|
||||
"uniq_pools": acc.UniqPools,
|
||||
"updated_time": acc.UpdatedTime,
|
||||
"version": acc.Version,
|
||||
"vins": acc.VINS,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -247,38 +225,31 @@ func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, acc := range al.Data {
|
||||
temp := map[string]interface{}{
|
||||
"dc_location": acc.DCLocation,
|
||||
"ckey": acc.CKey,
|
||||
"meta": flattens.FlattenMeta(acc.Meta),
|
||||
|
||||
"acl": flattenRgAcl(acc.ACL),
|
||||
|
||||
"company": acc.Company,
|
||||
"companyurl": acc.CompanyURL,
|
||||
"created_by": acc.CreatedBy,
|
||||
|
||||
"created_time": acc.CreatedTime,
|
||||
|
||||
"deactivation_time": acc.DeactivationTime,
|
||||
"deleted_by": acc.DeletedBy,
|
||||
|
||||
"deleted_time": acc.DeletedTime,
|
||||
|
||||
"displayname": acc.DisplayName,
|
||||
"guid": acc.GUID,
|
||||
|
||||
"account_id": acc.ID,
|
||||
"account_name": acc.Name,
|
||||
|
||||
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
|
||||
"send_access_emails": acc.SendAccessEmails,
|
||||
// "service_account": acc.ServiceAccount,
|
||||
|
||||
"status": acc.Status,
|
||||
"updated_time": acc.UpdatedTime,
|
||||
|
||||
"version": acc.Version,
|
||||
"vins": acc.VINS,
|
||||
"dc_location": acc.DCLocation,
|
||||
"ckey": acc.CKey,
|
||||
"meta": flattens.FlattenMeta(acc.Meta),
|
||||
"acl": flattenRgAcl(acc.ACL),
|
||||
"company": acc.Company,
|
||||
"companyurl": acc.CompanyURL,
|
||||
"cpu_allocation_parameter": acc.CPUAllocationParameter,
|
||||
"cpu_allocation_ratio": acc.CPUAllocationRatio,
|
||||
"created_by": acc.CreatedBy,
|
||||
"created_time": acc.CreatedTime,
|
||||
"deactivation_time": acc.DeactivationTime,
|
||||
"deleted_by": acc.DeletedBy,
|
||||
"deleted_time": acc.DeletedTime,
|
||||
"displayname": acc.DisplayName,
|
||||
"guid": acc.GUID,
|
||||
"account_id": acc.ID,
|
||||
"account_name": acc.Name,
|
||||
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
|
||||
"resource_types": acc.ResTypes,
|
||||
"send_access_emails": acc.SendAccessEmails,
|
||||
"status": acc.Status,
|
||||
"uniq_pools": acc.UniqPools,
|
||||
"updated_time": acc.UpdatedTime,
|
||||
"version": acc.Version,
|
||||
"vins": acc.VINS,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -338,6 +309,7 @@ func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} {
|
||||
"disk_name": ad.Name,
|
||||
"pool_name": ad.Pool,
|
||||
"sep_id": ad.SepID,
|
||||
"shareable": ad.Shareable,
|
||||
"size_max": ad.SizeMax,
|
||||
"type": ad.Type,
|
||||
}
|
||||
@@ -403,3 +375,39 @@ func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenResourceConsumption(d *schema.ResourceData, acc *account.RecordResourceConsumption) {
|
||||
d.Set("account_id", acc.AccountID)
|
||||
d.Set("consumed", flattenAccResource(acc.Consumed))
|
||||
d.Set("reserved", flattenAccResource(acc.Reserved))
|
||||
d.Set("resource_limits", flattenRgResourceLimits(acc.ResourceLimits))
|
||||
}
|
||||
|
||||
func flattenAccountSeps(seps map[string]map[string]account.DiskUsage) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for sepKey, sepVal := range seps {
|
||||
for dataKey, dataVal := range sepVal {
|
||||
temp := map[string]interface{}{
|
||||
"sep_id": sepKey,
|
||||
"data_name": dataKey,
|
||||
"disk_size": dataVal.DiskSize,
|
||||
"disk_size_max": dataVal.DiskSizeMax,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccResourceConsumption(lrc *account.ListResources) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(lrc.Data))
|
||||
for _, rc := range lrc.Data {
|
||||
temp := map[string]interface{}{
|
||||
"consumed": flattenAccResource(rc.Consumed),
|
||||
"reserved": flattenAccResource(rc.Reserved),
|
||||
"account_id": rc.AccountID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
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
|
||||
|
||||
type AccountAclRecord struct {
|
||||
IsExplicit bool `json:"explicit"`
|
||||
Guid string `json:"guid"`
|
||||
Rights string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UgroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
type ResourceLimits struct {
|
||||
CUC float64 `json:"CU_C"`
|
||||
CUD float64 `json:"CU_D"`
|
||||
CUI float64 `json:"CU_I"`
|
||||
CUM float64 `json:"CU_M"`
|
||||
CUNP float64 `json:"CU_NP"`
|
||||
GpuUnits float64 `json:"gpu_units"`
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
DCLocation string `json:"DCLocation"`
|
||||
CKey string `jspn:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Acl []AccountAclRecord `json:"acl"`
|
||||
Company string `json:"company"`
|
||||
CompanyUrl string `json:"companyurl"`
|
||||
CreatedBy string `jspn:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeactiovationTime float64 `json:"deactivationTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
DisplayName string `json:"displayname"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||
ServiceAccount bool `json:"serviceAccount"`
|
||||
Status string `json:"status"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Version int `json:"version"`
|
||||
Vins []int `json:"vins"`
|
||||
}
|
||||
|
||||
type AccountList []Account
|
||||
|
||||
type Resource struct {
|
||||
CPU int `json:"cpu"`
|
||||
Disksize int `json:"disksize"`
|
||||
Extips int `json:"extips"`
|
||||
Exttraffic int `json:"exttraffic"`
|
||||
GPU int `json:"gpu"`
|
||||
RAM int `json:"ram"`
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
Current Resource `json:"Current"`
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
type AccountWithResources struct {
|
||||
Account
|
||||
Resources Resources `json:"Resources"`
|
||||
}
|
||||
|
||||
type AccountCompute struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
CPUs int `json:"cpus"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ComputeId int `json:"id"`
|
||||
ComputeName string `json:"name"`
|
||||
RAM int `json:"ram"`
|
||||
Registered bool `json:"registered"`
|
||||
RgId int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
TotalDisksSize int `json:"totalDisksSize"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
VinsConnected int `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
type AccountComputesList []AccountCompute
|
||||
|
||||
type AccountDisk struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Pool string `json:"pool"`
|
||||
SepId int `json:"sepId"`
|
||||
SizeMax int `json:"sizeMax"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type AccountDisksList []AccountDisk
|
||||
|
||||
type AccountVin struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Computes int `json:"computes"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
ExternalIP string `json:"externalIP"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
PriVnfDevId int `json:"priVnfDevId"`
|
||||
RgId int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountVinsList []AccountVin
|
||||
|
||||
type AccountAudit struct {
|
||||
Call string `json:"call"`
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
StatusCode int `json:"statuscode"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
type AccountAuditsList []AccountAudit
|
||||
|
||||
type AccountRGComputes struct {
|
||||
Started int `json:"Started"`
|
||||
Stopped int `json:"Stopped"`
|
||||
}
|
||||
|
||||
type AccountRGResources struct {
|
||||
Consumed Resource `json:"Consumed"`
|
||||
Limits Resource `json:"Limits"`
|
||||
Reserved Resource `json:"Reserved"`
|
||||
}
|
||||
|
||||
type AccountRG struct {
|
||||
Computes AccountRGComputes `json:"Computes"`
|
||||
Resources AccountRGResources `json:"Resources"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
RGID int `json:"id"`
|
||||
Milestones int `json:"milestones"`
|
||||
RGName string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
Vinses int `json:"vinses"`
|
||||
}
|
||||
|
||||
type AccountRGList []AccountRG
|
||||
|
||||
type AccountFlipGroup struct {
|
||||
AccountId int `json:"accountId"`
|
||||
ClientType string `json:"clientType"`
|
||||
ConnType string `json:"connType"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime int `json:"createdTime"`
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime int `json:"deletedTime"`
|
||||
Desc string `json:"desc"`
|
||||
GID int `json:"gid"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
IP string `json:"ip"`
|
||||
Milestones int `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
NetID int `json:"netId"`
|
||||
NetType string `json:"netType"`
|
||||
NetMask int `json:"netmask"`
|
||||
Status string `json:"status"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime int `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type AccountFlipGroupsList []AccountFlipGroup
|
||||
@@ -42,12 +42,15 @@ import (
|
||||
"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("resourceAccountCreate")
|
||||
log.Debugf("resourseAccountCreate")
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := account.CreateRequest{}
|
||||
|
||||
req.Name = d.Get("account_name").(string)
|
||||
@@ -56,57 +59,63 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
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 {
|
||||
resLimit := resLimits.([]interface{})[0]
|
||||
resLimitConv := resLimit.(map[string]interface{})
|
||||
if resLimitConv["cu_m"] != nil {
|
||||
maxMemCap := int64(resLimitConv["cu_m"].(float64))
|
||||
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 resLimitConv["cu_d"] != nil {
|
||||
maxDiskCap := int64(resLimitConv["cu_d"].(float64))
|
||||
if resLimitsConv["cu_dm"] != nil {
|
||||
maxDiskCap := int64(resLimitsConv["cu_dm"].(float64))
|
||||
if maxDiskCap == 0 {
|
||||
req.MaxVDiskCapacity = -1
|
||||
} else {
|
||||
req.MaxVDiskCapacity = maxDiskCap
|
||||
}
|
||||
}
|
||||
if resLimitConv["cu_c"] != nil {
|
||||
maxCPUCap := int64(resLimitConv["cu_c"].(float64))
|
||||
if resLimitsConv["cu_c"] != nil {
|
||||
maxCPUCap := int64(resLimitsConv["cu_c"].(float64))
|
||||
if maxCPUCap == 0 {
|
||||
req.MaxCPUCapacity = -1
|
||||
} else {
|
||||
req.MaxCPUCapacity = maxCPUCap
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["cu_i"] != nil {
|
||||
maxNumPublicIP := int64(resLimitConv["cu_i"].(float64))
|
||||
if resLimitsConv["cu_i"] != nil {
|
||||
maxNumPublicIP := int64(resLimitsConv["cu_i"].(float64))
|
||||
if maxNumPublicIP == 0 {
|
||||
req.MaxNumPublicIP = -1
|
||||
} else {
|
||||
req.MaxNumPublicIP = maxNumPublicIP
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["cu_np"] != nil {
|
||||
maxNP := int64(resLimitConv["cu_np"].(float64))
|
||||
if resLimitsConv["cu_np"] != nil {
|
||||
maxNP := int64(resLimitsConv["cu_np"].(float64))
|
||||
if maxNP == 0 {
|
||||
req.MaxNetworkPeerTransfer = -1
|
||||
} else {
|
||||
req.MaxNetworkPeerTransfer = maxNP
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["gpu_units"] != nil {
|
||||
gpuUnits := int64(resLimitConv["gpu_units"].(float64))
|
||||
if resLimitsConv["gpu_units"] != nil {
|
||||
gpuUnits := int64(resLimitsConv["gpu_units"].(float64))
|
||||
if gpuUnits == 0 {
|
||||
req.GPUUnits = -1
|
||||
} else {
|
||||
@@ -121,55 +130,72 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(accountId, 10))
|
||||
d.Set("account_id", accountId)
|
||||
|
||||
diagnostics := resourceAccountRead(ctx, d, m)
|
||||
if diagnostics != nil {
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
if enable, ok := d.GetOk("enable"); ok {
|
||||
enable := enable.(bool)
|
||||
if enable {
|
||||
req := account.EnableRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
_, err := c.CloudBroker().Account().Enable(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
req := account.DisableRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
_, err := c.CloudBroker().Account().Disable(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
var w dc.Warnings
|
||||
|
||||
if users, ok := d.GetOk("users"); ok {
|
||||
addedUsers := users.([]interface{})
|
||||
|
||||
if len(addedUsers) > 0 {
|
||||
for _, user := range addedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
req := account.AddUserRequest{
|
||||
AccountID: accountId,
|
||||
Username: userConv["user_id"].(string),
|
||||
AccessType: userConv["access_type"].(string),
|
||||
}
|
||||
for _, user := range addedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
|
||||
_, err := c.CloudBroker().Account().AddUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
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 {
|
||||
@@ -220,35 +246,88 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
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 {
|
||||
req := account.EnableRequest{
|
||||
AccountID: acc.ID,
|
||||
}
|
||||
_, err := c.CloudBroker().Account().Enable(ctx, req)
|
||||
|
||||
if enable && acc.Status == status.Disabled {
|
||||
_, err := c.CloudBroker().Account().Enable(ctx, account.EnableRequest{
|
||||
AccountID: accountId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else {
|
||||
req := account.DisableRequest{
|
||||
AccountID: acc.ID,
|
||||
}
|
||||
_, err := c.CloudBroker().Account().Disable(ctx, req)
|
||||
} else if !enable && acc.Status == status.Enabled {
|
||||
_, err := c.CloudBroker().Account().Disable(ctx, account.DisableRequest{
|
||||
AccountID: accountId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateReq := account.UpdateRequest{AccountID: acc.ID}
|
||||
hasChange := false
|
||||
req := account.UpdateRequest{
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
updated := false
|
||||
|
||||
if d.HasChange("account_name") {
|
||||
updateReq.Name = d.Get("account_name").(string)
|
||||
|
||||
hasChange = true
|
||||
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{})
|
||||
@@ -256,81 +335,84 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
if resLimitConv["cu_m"] != nil {
|
||||
maxMemCap := int(resLimitConv["cu_m"].(float64))
|
||||
if maxMemCap == 0 {
|
||||
updateReq.MaxMemoryCapacity = -1
|
||||
req.MaxMemoryCapacity = -1
|
||||
} else {
|
||||
updateReq.MaxMemoryCapacity = int64(maxMemCap)
|
||||
req.MaxMemoryCapacity = int64(maxMemCap)
|
||||
}
|
||||
}
|
||||
if resLimitConv["cu_d"] != nil {
|
||||
maxDiskCap := int(resLimitConv["cu_d"].(float64))
|
||||
if resLimitConv["cu_dm"] != nil {
|
||||
maxDiskCap := int(resLimitConv["cu_dm"].(float64))
|
||||
if maxDiskCap == 0 {
|
||||
updateReq.MaxVDiskCapacity = -1
|
||||
req.MaxVDiskCapacity = -1
|
||||
} else {
|
||||
updateReq.MaxVDiskCapacity = int64(maxDiskCap)
|
||||
req.MaxVDiskCapacity = int64(maxDiskCap)
|
||||
}
|
||||
}
|
||||
if resLimitConv["cu_c"] != nil {
|
||||
maxCPUCap := int(resLimitConv["cu_c"].(float64))
|
||||
if maxCPUCap == 0 {
|
||||
updateReq.MaxCPUCapacity = -1
|
||||
req.MaxCPUCapacity = -1
|
||||
} else {
|
||||
updateReq.MaxCPUCapacity = int64(maxCPUCap)
|
||||
req.MaxCPUCapacity = int64(maxCPUCap)
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["cu_i"] != nil {
|
||||
maxNumPublicIP := int(resLimitConv["cu_i"].(float64))
|
||||
if maxNumPublicIP == 0 {
|
||||
updateReq.MaxNumPublicIP = -1
|
||||
req.MaxNumPublicIP = -1
|
||||
} else {
|
||||
updateReq.MaxNumPublicIP = int64(maxNumPublicIP)
|
||||
req.MaxNumPublicIP = int64(maxNumPublicIP)
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["cu_np"] != nil {
|
||||
maxNP := int(resLimitConv["cu_np"].(float64))
|
||||
if maxNP == 0 {
|
||||
updateReq.MaxNetworkPeerTransfer = -1
|
||||
req.MaxNetworkPeerTransfer = -1
|
||||
} else {
|
||||
updateReq.MaxNetworkPeerTransfer = int64(maxNP)
|
||||
req.MaxNetworkPeerTransfer = int64(maxNP)
|
||||
}
|
||||
|
||||
}
|
||||
if resLimitConv["gpu_units"] != nil {
|
||||
gpuUnits := int(resLimitConv["gpu_units"].(float64))
|
||||
if gpuUnits == 0 {
|
||||
updateReq.GPUUnits = -1
|
||||
req.GPUUnits = -1
|
||||
} else {
|
||||
updateReq.GPUUnits = int64(gpuUnits)
|
||||
req.GPUUnits = int64(gpuUnits)
|
||||
}
|
||||
}
|
||||
|
||||
hasChange = true
|
||||
updated = true
|
||||
}
|
||||
|
||||
if d.HasChange("send_access_emails") {
|
||||
updateReq.SendAccessEmails = d.Get("send_access_emails").(bool)
|
||||
hasChange = true
|
||||
}
|
||||
|
||||
if hasChange {
|
||||
_, err := c.CloudBroker().Account().Update(ctx, updateReq)
|
||||
if updated {
|
||||
_, err := c.CloudBroker().Account().Update(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("restore") {
|
||||
restore := d.Get("restore").(bool)
|
||||
if restore {
|
||||
req := account.RestoreRequest{
|
||||
AccountID: acc.ID,
|
||||
}
|
||||
if d.HasChange("cpu_allocation_parameter") {
|
||||
cpuAllocationParameter := d.Get("cpu_allocation_parameter").(string)
|
||||
|
||||
_, err := c.CloudBroker().Account().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,67 +429,66 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
||||
deletedUsers = append(deletedUsers, el)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newConv {
|
||||
if !isContainsUser(oldConv, el) {
|
||||
addedUsers = append(addedUsers, el)
|
||||
} else {
|
||||
if isChangedUser(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{})
|
||||
|
||||
if len(deletedUsers) > 0 {
|
||||
for _, user := range deletedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
req := account.DeleteUserRequest{
|
||||
AccountID: acc.ID,
|
||||
UserName: userConv["user_id"].(string),
|
||||
RecursiveDelete: userConv["recursive_delete"].(bool),
|
||||
}
|
||||
_, err := c.CloudBroker().Account().DeleteUser(ctx, account.DeleteUserRequest{
|
||||
AccountID: accountId,
|
||||
UserName: userConv["user_id"].(string),
|
||||
RecursiveDelete: userConv["recursive_delete"].(bool),
|
||||
})
|
||||
|
||||
_, err := c.CloudBroker().Account().DeleteUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedUsers) > 0 {
|
||||
for _, user := range addedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
req := account.AddUserRequest{
|
||||
AccountID: acc.ID,
|
||||
Username: userConv["user_id"].(string),
|
||||
AccessType: strings.ToUpper(userConv["access_type"].(string)),
|
||||
}
|
||||
for _, user := range addedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
|
||||
_, err := c.CloudBroker().Account().AddUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, 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)
|
||||
}
|
||||
}
|
||||
|
||||
if len(updatedUsers) > 0 {
|
||||
for _, user := range updatedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
req := account.UpdateUserRequest{
|
||||
AccountID: acc.ID,
|
||||
UserID: userConv["user_id"].(string),
|
||||
AccessType: strings.ToUpper(userConv["access_type"].(string)),
|
||||
}
|
||||
for _, user := range updatedUsers {
|
||||
userConv := user.(map[string]interface{})
|
||||
|
||||
_, err := c.CloudBroker().Account().UpdateUser(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
_, 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 nil
|
||||
return resourceAccountRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func isContainsUser(els []interface{}, el interface{}) bool {
|
||||
|
||||
@@ -44,13 +44,15 @@ import (
|
||||
|
||||
func utilityAccountCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.RecordAccount, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
accountID := d.Get("account_id").(int)
|
||||
|
||||
req := account.GetRequest{}
|
||||
|
||||
if (strconv.Itoa(d.Get("account_id").(int))) != "0" {
|
||||
req.AccountID = uint64(d.Get("account_id").(int))
|
||||
if d.Id() == "" {
|
||||
req.AccountID = uint64(accountID)
|
||||
} else {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.AccountID = id
|
||||
req.AccountID, _ = strconv.ParseUint(d.Id(), 10, 64)
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountCheckPresence: load account")
|
||||
|
||||
@@ -47,6 +47,46 @@ func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.Reso
|
||||
AccountID: uint64(d.Get("account_id").(int)),
|
||||
}
|
||||
|
||||
if compute_id, ok := d.GetOk("compute_id"); ok {
|
||||
req.ComputeID = uint64(compute_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if rg_name, ok := d.GetOk("rg_name"); ok {
|
||||
req.RGName = rg_name.(string)
|
||||
}
|
||||
|
||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||
req.RGID = uint64(rg_id.(int))
|
||||
}
|
||||
|
||||
if tech_status, ok := d.GetOk("tech_status"); ok {
|
||||
req.TechStatus = tech_status.(string)
|
||||
}
|
||||
|
||||
if ip_address, ok := d.GetOk("ip_address"); ok {
|
||||
req.IPAddress = ip_address.(string)
|
||||
}
|
||||
|
||||
if extnet_name, ok := d.GetOk("extnet_name"); ok {
|
||||
req.ExtNetName = extnet_name.(string)
|
||||
}
|
||||
|
||||
if extnet_id, ok := d.GetOk("extnet_id"); ok {
|
||||
req.ExtNetID = uint64(extnet_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))
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
|
||||
accountComputesList, err := c.CloudBroker().Account().ListComputes(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -48,10 +48,23 @@ func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.Resou
|
||||
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 by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
|
||||
if acl, ok := d.GetOk("acl"); ok {
|
||||
req.ACL = acl.(string)
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountDeletedListCheckPresence: load")
|
||||
accountDeletedList, err := c.CloudBroker().Account().ListDeleted(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,30 @@ func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.Resourc
|
||||
AccountID: uint64(d.Get("account_id").(int)),
|
||||
}
|
||||
|
||||
if disk_id, ok := d.GetOk("disk_id"); ok {
|
||||
req.DiskID = uint64(disk_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
||||
req.DiskMaxSize = uint64(disk_max_size.(int))
|
||||
}
|
||||
|
||||
if typeVal, ok := d.GetOk("type"); ok {
|
||||
req.Type = typeVal.(string)
|
||||
}
|
||||
|
||||
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("utilityAccountDisksListCheckPresence: load account list")
|
||||
accountDisksList, err := c.CloudBroker().Account().ListDisks(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,38 @@ func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.Re
|
||||
AccountID: uint64(d.Get("account_id").(int)),
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if vins_id, ok := d.GetOk("vins_id"); ok {
|
||||
req.VINSID = uint64(vins_id.(int))
|
||||
}
|
||||
|
||||
if vins_name, ok := d.GetOk("vins_name"); ok {
|
||||
req.VINSName = vins_name.(string)
|
||||
}
|
||||
|
||||
if extnet_id, ok := d.GetOk("extnet_id"); ok {
|
||||
req.ExtNetID = uint64(extnet_id.(int))
|
||||
}
|
||||
|
||||
if by_ip, ok := d.GetOk("by_ip"); ok {
|
||||
req.ByIP = by_ip.(string)
|
||||
}
|
||||
|
||||
if flipgroup_id, ok := d.GetOk("flipgroup_id"); ok {
|
||||
req.FLIPGroupID = uint64(flipgroup_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))
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountFlipGroupsListCheckPresence")
|
||||
accountFlipGroupsList, err := c.CloudBroker().Account().ListFLIPGroups(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityAccountResourceConsumptionGetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.RecordResourceConsumption, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
id := uint64(d.Get("account_id").(int))
|
||||
|
||||
req:= account.GetResourceConsumptionRequest {
|
||||
AccountID: id,
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountResourceConsumptionGetCheckPresence: load")
|
||||
accountResourceConsumptionRec, err := c.CloudBroker().Account().GetResourceConsumption(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountResourceConsumptionRec, nil
|
||||
}
|
||||
@@ -52,6 +52,22 @@ func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if acl, ok := d.GetOk("acl"); ok {
|
||||
req.ACL = acl.(string)
|
||||
}
|
||||
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountListCheckPresence: load account list")
|
||||
accountList, err := c.CloudBroker().Account().List(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,35 +1,53 @@
|
||||
/*
|
||||
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 grid
|
||||
|
||||
const GridListGetAPI = "/restmachine/cloudbroker/grid/list"
|
||||
const GridGetAPI = "/restmachine/cloudbroker/grid/get"
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityAccountResourceConsumptionListCheckPresence(ctx context.Context, m interface{}) (*account.ListResources, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debugf("utilityAccountResourceConsumptionListCheckPresence: load")
|
||||
accountResourceConsumptionList, err := c.CloudBroker().Account().ListResourceConsumption(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accountResourceConsumptionList, nil
|
||||
}
|
||||
@@ -47,6 +47,34 @@ func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceDa
|
||||
AccountID: uint64(d.Get("account_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 rg_id, ok := d.GetOk("rg_id"); ok {
|
||||
req.RGID = uint64(rg_id.(int))
|
||||
}
|
||||
|
||||
if vins_id, ok := d.GetOk("vins_id"); ok {
|
||||
req.VINSID = uint64(vins_id.(int))
|
||||
}
|
||||
|
||||
if vm_id, ok := d.GetOk("vm_id"); ok {
|
||||
req.VMID = uint64(vm_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountRGListCheckPresence: load account list")
|
||||
accountRGList, err := c.CloudBroker().Account().ListRG(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,30 @@ func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.Resource
|
||||
AccountID: uint64(d.Get("account_id").(int)),
|
||||
}
|
||||
|
||||
if vins_id, ok := d.GetOk("vins_id"); ok {
|
||||
req.VINSID = uint64(vins_id.(int))
|
||||
}
|
||||
|
||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||
req.RGID = uint64(rg_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 ext_ip, ok := d.GetOk("ext_ip"); ok {
|
||||
req.ExtIP = ext_ip.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
||||
accountVinsList, err := c.CloudBroker().Account().ListVINS(ctx, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -79,6 +79,22 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
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,
|
||||
@@ -222,6 +238,13 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
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,
|
||||
@@ -258,6 +281,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"shareable": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -279,6 +306,10 @@ func dataSourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -49,12 +49,43 @@ func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m inter
|
||||
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,
|
||||
@@ -65,6 +96,16 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
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,
|
||||
@@ -96,6 +137,22 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
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,
|
||||
@@ -251,6 +308,13 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
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,
|
||||
@@ -287,6 +351,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"shareable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -308,6 +376,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -346,6 +418,10 @@ func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
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 dataSourceDiskListTypesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
listTypes, err := utilityDiskListTypesCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", listTypes.Data)
|
||||
d.Set("entry_count", listTypes.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceDiskListTypesSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceDiskListTypes() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
ReadContext: dataSourceDiskListTypesRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceDiskListTypesSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
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 dataSourceDiskListTypesDetailedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
listTypesDetailed, err := utilityDiskListTypesDetailedCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenDiskListTypesDetailed(listTypesDetailed))
|
||||
d.Set("entry_count", listTypesDetailed.EntryCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceDiskListTypesDetailed() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
ReadContext: dataSourceDiskListTypesDetailedRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"pools": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Pool name",
|
||||
},
|
||||
"system": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"types": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "The types of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Storage endpoint provider ID to create disk",
|
||||
},
|
||||
"sep_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
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>
|
||||
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 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 dataSourceDiskListUnattachedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
diskListUnattached, err := utilityDiskListUnattachedCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenDiskListUnattached(diskListUnattached))
|
||||
d.Set("entry_count", diskListUnattached.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceDiskListUnattached() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceDiskListUnattachedRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceDiskListUnattachedSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"by_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Find by ID",
|
||||
},
|
||||
"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",
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "type of the disks",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "ID of the account the disks belong to",
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "ID of SEP",
|
||||
},
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"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{
|
||||
"_ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "CKey",
|
||||
},
|
||||
"_meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "Meta parameters",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of the account the disks belong to",
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The name of the subscriber '(account') to whom this disk belongs",
|
||||
},
|
||||
"acl": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"boot_partition": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Number of disk partitions",
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Created time",
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Deleted time",
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Description of disk",
|
||||
},
|
||||
"destruction_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Time of final deletion",
|
||||
},
|
||||
"disk_path": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Disk path",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of the grid (platform)",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Disk ID on the storage side",
|
||||
},
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "The unique ID of the subscriber-owner of the disk",
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Image ID",
|
||||
},
|
||||
"images": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "IDs of images using the disk",
|
||||
},
|
||||
"iotune": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"read_bytes_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Number of bytes to read per second",
|
||||
},
|
||||
"read_bytes_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Maximum number of bytes to read",
|
||||
},
|
||||
"read_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Number of io read operations per second",
|
||||
},
|
||||
"read_iops_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Maximum number of io read operations",
|
||||
},
|
||||
"size_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Size of io operations",
|
||||
},
|
||||
"total_bytes_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Total size bytes per second",
|
||||
},
|
||||
"total_bytes_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Maximum total size of bytes per second",
|
||||
},
|
||||
"total_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Total number of io operations per second",
|
||||
},
|
||||
"total_iops_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Maximum total number of io operations per second",
|
||||
},
|
||||
"write_bytes_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Number of bytes to write per second",
|
||||
},
|
||||
"write_bytes_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Maximum number of bytes to write per second",
|
||||
},
|
||||
"write_iops_sec": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Number of write operations per second",
|
||||
},
|
||||
"write_iops_sec_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Maximum number of write operations per second",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"iqn": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Disk IQN",
|
||||
},
|
||||
"login": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Login to access the disk",
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Milestones",
|
||||
},
|
||||
"disk_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of disk",
|
||||
},
|
||||
"order": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Disk order",
|
||||
},
|
||||
"params": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Disk params",
|
||||
},
|
||||
"parent_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of the parent disk",
|
||||
},
|
||||
"passwd": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Password to access the disk",
|
||||
},
|
||||
"pci_slot": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "ID of the pci slot to which the disk is connected",
|
||||
},
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Pool for disk location",
|
||||
},
|
||||
"present_to": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Number of deletion attempts",
|
||||
},
|
||||
"purge_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Time of the last deletion attempt",
|
||||
},
|
||||
"reality_device_number": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Reality device number",
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ID of the reference to the disk",
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Resource ID",
|
||||
},
|
||||
"res_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the resource",
|
||||
},
|
||||
"role": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Disk role",
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Storage endpoint provider ID to create disk",
|
||||
},
|
||||
"shareable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Size in GB",
|
||||
},
|
||||
"size_used": {
|
||||
Type: schema.TypeFloat,
|
||||
Computed: true,
|
||||
Description: "Number of used space, in GB",
|
||||
},
|
||||
"snapshots": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ID of the snapshot",
|
||||
},
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the snapshot",
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Reference to the snapshot",
|
||||
},
|
||||
"snap_set_guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The set snapshot ID",
|
||||
},
|
||||
"snap_set_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "The set time of the snapshot",
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Snapshot time",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Disk status",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Technical status of the disk",
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
|
||||
},
|
||||
"vmid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Virtual Machine ID (Deprecated)",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
129
internal/service/cloudbroker/disks/data_source_disk_snapshot.go
Normal file
129
internal/service/cloudbroker/disks/data_source_disk_snapshot.go
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
var snapshot disks.ItemSnapshot
|
||||
label := d.Get("label").(string)
|
||||
for _, sn := range disk.Snapshots {
|
||||
if label == sn.Label {
|
||||
snapshot = sn
|
||||
break
|
||||
}
|
||||
}
|
||||
if label != snapshot.Label {
|
||||
return diag.Errorf("Snapshot with label \"%v\" not found", label)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
flattenDiskSnapshot(d, snapshot)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceDiskSnapshot() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceDiskSnapshotRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceDiskSnapshotSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceDiskSnapshotSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "The unique ID of the subscriber-owner of the disk",
|
||||
},
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Name of the snapshot",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ID of the snapshot",
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Snapshot time",
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Reference to the snapshot",
|
||||
},
|
||||
"snap_set_guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The set snapshot ID",
|
||||
},
|
||||
"snap_set_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "The set time of the snapshot",
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 dataSourceDiskSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenDiskSnapshotList(disk.Snapshots))
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceDiskSnapshotList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceDiskSnapshotListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceDiskSnapshotListSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceDiskSnapshotListSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "The unique ID of the subscriber-owner of the disk",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name of the snapshot",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ID of the snapshot",
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Snapshot time",
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Reference to the snapshot",
|
||||
},
|
||||
"snap_set_guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The set snapshot ID",
|
||||
},
|
||||
"snap_set_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "The set time of the snapshot",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
|
||||
@@ -14,6 +15,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
|
||||
d.Set("account_name", disk.AccountName)
|
||||
d.Set("acl", string(diskAcl))
|
||||
d.Set("boot_partition", disk.BootPartition)
|
||||
d.Set("computes", flattenDiskComputes(disk.Computes))
|
||||
d.Set("created_time", disk.CreatedTime)
|
||||
d.Set("deleted_time", disk.DeletedTime)
|
||||
d.Set("desc", disk.Description)
|
||||
@@ -37,6 +39,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
|
||||
d.Set("pci_slot", disk.PCISlot)
|
||||
d.Set("pool", disk.Pool)
|
||||
d.Set("purge_attempts", disk.PurgeAttempts)
|
||||
d.Set("present_to", disk.PresentTo)
|
||||
d.Set("purge_time", disk.PurgeTime)
|
||||
d.Set("reality_device_number", disk.RealityDeviceNumber)
|
||||
d.Set("reference_id", disk.ReferenceID)
|
||||
@@ -45,6 +48,7 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
|
||||
d.Set("role", disk.Role)
|
||||
d.Set("sep_id", disk.SEPID)
|
||||
d.Set("sep_type", disk.SEPType)
|
||||
d.Set("shareable", disk.Shareable)
|
||||
d.Set("size_max", disk.SizeMax)
|
||||
d.Set("size_used", disk.SizeUsed)
|
||||
d.Set("snapshots", flattendDiskSnapshotList(disk.Snapshots))
|
||||
@@ -54,6 +58,27 @@ func flattenDisk(d *schema.ResourceData, disk *disks.RecordDisk) {
|
||||
d.Set("vmid", disk.VMID)
|
||||
}
|
||||
|
||||
func flattenDiskSnapshot(d *schema.ResourceData, snapshot disks.ItemSnapshot) {
|
||||
d.Set("timestamp", snapshot.Timestamp)
|
||||
d.Set("guid", snapshot.GUID)
|
||||
d.Set("reference_id", snapshot.ReferenceID)
|
||||
d.Set("res_id", snapshot.ResID)
|
||||
d.Set("snap_set_guid", snapshot.SnapSetGUID)
|
||||
d.Set("snap_set_time", snapshot.SnapSetTime)
|
||||
}
|
||||
|
||||
func flattenDiskComputes(computes map[string]string) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(computes))
|
||||
for key, val := range computes {
|
||||
tmp := map[string]interface{}{
|
||||
"compute_id": key,
|
||||
"compute_name": val,
|
||||
}
|
||||
res = append(res, tmp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenIOTune(iot disks.IOTune) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
@@ -140,6 +165,7 @@ func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
|
||||
temp := map[string]interface{}{
|
||||
"guid": snapshot.GUID,
|
||||
"label": snapshot.Label,
|
||||
"reference_id": snapshot.ReferenceID,
|
||||
"res_id": snapshot.ResID,
|
||||
"snap_set_guid": snapshot.SnapSetGUID,
|
||||
"snap_set_time": snapshot.SnapSetTime,
|
||||
@@ -151,3 +177,105 @@ func flattendDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
|
||||
return res
|
||||
|
||||
}
|
||||
|
||||
func flattenDiskListTypesDetailed(tld *disks.ListTypes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, typeListDetailed := range tld.Data {
|
||||
toMap := typeListDetailed.(map[string]interface{})
|
||||
temp := map[string]interface{}{
|
||||
"pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})),
|
||||
"sep_id": toMap["sepId"].(float64),
|
||||
"sep_name": toMap["sepName"].(string),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenListTypesDetailedPools(pools []interface{}) []interface{} {
|
||||
res := make([]interface{}, 0)
|
||||
for _, pool := range pools {
|
||||
toMap := pool.(map[string]interface{})
|
||||
temp := map[string]interface{}{
|
||||
"name": toMap["name"].(string),
|
||||
"system": toMap["system"].(string),
|
||||
"types": toMap["types"].([]interface{}),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDiskListUnattached(ul *disks.ListUnattachedDisks) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, unattachedDisk := range ul.Data {
|
||||
unattachedDiskAcl, _ := json.Marshal(unattachedDisk.ACL)
|
||||
tmp := map[string]interface{}{
|
||||
"_ckey": unattachedDisk.CKey,
|
||||
"_meta": flattens.FlattenMeta(unattachedDisk.Meta),
|
||||
"account_id": unattachedDisk.AccountID,
|
||||
"account_name": unattachedDisk.AccountName,
|
||||
"acl": string(unattachedDiskAcl),
|
||||
"boot_partition": unattachedDisk.BootPartition,
|
||||
"created_time": unattachedDisk.CreatedTime,
|
||||
"deleted_time": unattachedDisk.DeletedTime,
|
||||
"desc": unattachedDisk.Description,
|
||||
"destruction_time": unattachedDisk.DestructionTime,
|
||||
"disk_path": unattachedDisk.DiskPath,
|
||||
"gid": unattachedDisk.GID,
|
||||
"guid": unattachedDisk.GUID,
|
||||
"disk_id": unattachedDisk.ID,
|
||||
"image_id": unattachedDisk.ImageID,
|
||||
"images": unattachedDisk.Images,
|
||||
"iotune": flattenIOTune(unattachedDisk.IOTune),
|
||||
"iqn": unattachedDisk.IQN,
|
||||
"login": unattachedDisk.Login,
|
||||
"milestones": unattachedDisk.Milestones,
|
||||
"disk_name": unattachedDisk.Name,
|
||||
"order": unattachedDisk.Order,
|
||||
"params": unattachedDisk.Params,
|
||||
"parent_id": unattachedDisk.ParentID,
|
||||
"passwd": unattachedDisk.Password,
|
||||
"pci_slot": unattachedDisk.PCISlot,
|
||||
"pool": unattachedDisk.Pool,
|
||||
"present_to": unattachedDisk.PresentTo,
|
||||
"purge_attempts": unattachedDisk.PurgeAttempts,
|
||||
"purge_time": unattachedDisk.PurgeTime,
|
||||
"reality_device_number": unattachedDisk.RealityDeviceNumber,
|
||||
"reference_id": unattachedDisk.ReferenceID,
|
||||
"res_id": unattachedDisk.ResID,
|
||||
"res_name": unattachedDisk.ResName,
|
||||
"role": unattachedDisk.Role,
|
||||
"sep_id": unattachedDisk.SEPID,
|
||||
"shareable": unattachedDisk.Shareable,
|
||||
"size_max": unattachedDisk.SizeMax,
|
||||
"size_used": unattachedDisk.SizeUsed,
|
||||
"snapshots": flattenDiskSnapshotList(unattachedDisk.Snapshots),
|
||||
"status": unattachedDisk.Status,
|
||||
"tech_status": unattachedDisk.TechStatus,
|
||||
"type": unattachedDisk.Type,
|
||||
"vmid": unattachedDisk.VMID,
|
||||
}
|
||||
res = append(res, tmp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDiskSnapshotList(sl disks.ListSnapshots) []interface{} {
|
||||
res := make([]interface{}, 0)
|
||||
for _, snapshot := range sl {
|
||||
temp := map[string]interface{}{
|
||||
"guid": snapshot.GUID,
|
||||
"label": snapshot.Label,
|
||||
"reference_id": snapshot.ReferenceID,
|
||||
"res_id": snapshot.ResID,
|
||||
"snap_set_guid": snapshot.SnapSetGUID,
|
||||
"snap_set_time": snapshot.SnapSetTime,
|
||||
"timestamp": snapshot.Timestamp,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
accountID := uint64(d.Get("account_id").(int))
|
||||
|
||||
accountList, err := c.CloudBroker().Account().List(ctx, account.ListRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(accountList.FilterByID(accountID).Data) == 0 {
|
||||
return fmt.Errorf("resourceDiskCreate: can't create/update Disk because AccountID %d is not allowed or does not exist", accountID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
gid := uint64(d.Get("gid").(int))
|
||||
|
||||
gidList, err := c.CloudBroker().Grid().List(ctx, grid.ListRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, elem := range gidList.Data {
|
||||
if elem.GID == gid {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("resourceDiskCreate: can't create/update Disk because GID %d is not allowed or does not exist", gid)
|
||||
}
|
||||
|
||||
func checkParamsExists(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
err := existAccountID(ctx, d, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return existGID(ctx, d, m)
|
||||
}
|
||||
@@ -35,129 +35,233 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
"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"
|
||||
|
||||
"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"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := disks.CreateRequest{}
|
||||
|
||||
req.AccountID = uint64(d.Get("account_id").(int))
|
||||
req.GID = uint64(d.Get("gid").(int))
|
||||
req.Name = d.Get("disk_name").(string)
|
||||
req.Size = uint64(d.Get("size_max").(int))
|
||||
|
||||
if typeRaw, ok := d.GetOk("type"); ok {
|
||||
req.Type = strings.ToUpper(typeRaw.(string))
|
||||
} else {
|
||||
req.Type = "D"
|
||||
}
|
||||
|
||||
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||
req.SEPID = uint64(sepId.(int))
|
||||
}
|
||||
|
||||
if poolName, ok := d.GetOk("pool"); ok {
|
||||
req.Pool = poolName.(string)
|
||||
}
|
||||
|
||||
argVal, argSet := d.GetOk("desc")
|
||||
if argSet {
|
||||
req.Description = argVal.(string)
|
||||
}
|
||||
|
||||
diskId, err := c.CloudBroker().Disks().Create(ctx, req)
|
||||
err := checkParamsExists(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(diskId, 10))
|
||||
req := disks.CreateRequest{
|
||||
AccountID: uint64(d.Get("account_id").(int)),
|
||||
GID: uint64(d.Get("gid").(int)),
|
||||
Name: d.Get("disk_name").(string),
|
||||
Size: uint64(d.Get("size_max").(int)),
|
||||
Type: d.Get("type").(string),
|
||||
}
|
||||
|
||||
if desc, ok := d.GetOk("desc"); ok {
|
||||
req.Description = desc.(string)
|
||||
}
|
||||
|
||||
if ssdSize, ok := d.GetOk("ssd_size"); ok {
|
||||
req.SSDSize = uint64(ssdSize.(int))
|
||||
}
|
||||
|
||||
if sepID, ok := d.GetOk("sep_id"); ok {
|
||||
req.SEPID = uint64(sepID.(int))
|
||||
}
|
||||
|
||||
if pool, ok := d.GetOk("pool"); ok {
|
||||
req.Pool = pool.(string)
|
||||
}
|
||||
|
||||
diskID, err := c.CloudBroker().Disks().Create(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(diskID, 10))
|
||||
|
||||
w := dc.Warnings{}
|
||||
|
||||
if iotuneRaw, ok := d.GetOk("iotune"); ok {
|
||||
iot := iotuneRaw.([]interface{})[0]
|
||||
iotune := iot.(map[string]interface{})
|
||||
req := disks.LimitIORequest{
|
||||
DiskID: diskId,
|
||||
DiskID: diskID,
|
||||
IOPS: uint64(iotune["total_iops_sec"].(int)),
|
||||
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
|
||||
ReadBytesSec: uint64(iotune["read_bytes_sec"].(int)),
|
||||
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)),
|
||||
TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
|
||||
ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)),
|
||||
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)),
|
||||
TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)),
|
||||
ReadBytesSecMax: uint64(iotune["read_bytes_sec_max"].(int)),
|
||||
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
|
||||
TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)),
|
||||
ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)),
|
||||
ReadIOPSSecMax: uint64(iotune["read_iops_sec_max"].(int)),
|
||||
WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)),
|
||||
SizeIOPSSec: uint64(iotune["size_iops_sec"].(int)),
|
||||
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
|
||||
TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)),
|
||||
TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)),
|
||||
TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
|
||||
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)),
|
||||
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
|
||||
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)),
|
||||
WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Disks().LimitIO(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
w.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceDiskRead(ctx, d, m)
|
||||
if shareable := d.Get("shareable"); shareable.(bool) {
|
||||
_, err := c.CloudBroker().Disks().Share(ctx, disks.ShareRequest{
|
||||
DiskID: diskID,
|
||||
})
|
||||
if err != nil {
|
||||
w.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
return append(w.Get(), resourceDiskRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
w := dc.Warnings{}
|
||||
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
hasChangeState := false
|
||||
|
||||
switch disk.Status {
|
||||
case status.Destroyed, status.Purged:
|
||||
d.Set("disk_id", 0)
|
||||
d.SetId("")
|
||||
return resourceDiskCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
req := disks.RestoreRequest{
|
||||
DiskID: disk.ID,
|
||||
}
|
||||
|
||||
if reason, ok := d.GetOk("reason"); ok {
|
||||
req.Reason = reason.(string)
|
||||
} else {
|
||||
req.Reason = "Terraform automatic restore"
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Disks().Restore(ctx, req)
|
||||
if err != nil {
|
||||
w.Add(err)
|
||||
}
|
||||
case status.Assigned:
|
||||
case status.Modeled:
|
||||
return diag.Errorf("The disk is in status: %s, please, contact support for more information", disk.Status)
|
||||
case status.Creating:
|
||||
case status.Created:
|
||||
case status.Allocated:
|
||||
case status.Unallocated:
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
disk, err = utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
flattenDisk(d, disk)
|
||||
|
||||
return nil
|
||||
return w.Get()
|
||||
}
|
||||
|
||||
func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
diskID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
w := dc.Warnings{}
|
||||
|
||||
err := checkParamsExists(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
hasChangeState := false
|
||||
|
||||
switch disk.Status {
|
||||
case status.Destroyed, status.Purged:
|
||||
d.Set("disk_id", 0)
|
||||
d.SetId("")
|
||||
return resourceDiskCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
req := disks.RestoreRequest{
|
||||
DiskID: disk.ID,
|
||||
}
|
||||
|
||||
if reason, ok := d.GetOk("reason"); ok {
|
||||
req.Reason = reason.(string)
|
||||
} else {
|
||||
req.Reason = "Terraform automatic restore"
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Disks().Restore(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
case status.Assigned:
|
||||
case status.Modeled:
|
||||
return diag.Errorf("The disk is in status: %s, please, contact support for more information", disk.Status)
|
||||
case status.Creating:
|
||||
case status.Created:
|
||||
case status.Allocated:
|
||||
case status.Unallocated:
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
disk, err = utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("size_max") {
|
||||
oldSize, newSize := d.GetChange("size_max")
|
||||
if oldSize.(int) < newSize.(int) {
|
||||
log.Debugf("resourceDiskUpdate: resizing disk ID %s - %d GB -> %d GB",
|
||||
d.Id(), oldSize.(int), newSize.(int))
|
||||
req := disks.ResizeRequest{
|
||||
DiskID: diskID,
|
||||
|
||||
_, err := c.CloudBroker().Disks().Resize(ctx, disks.ResizeRequest{
|
||||
DiskID: disk.ID,
|
||||
Size: uint64(newSize.(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Disks().Resize(ctx, req)
|
||||
})
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
w.Add(err)
|
||||
}
|
||||
|
||||
d.Set("size_max", newSize)
|
||||
} else if oldSize.(int) > newSize.(int) {
|
||||
return diag.FromErr(fmt.Errorf("resourceDiskUpdate: Disk ID %s - reducing disk size is not allowed", d.Id()))
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("disk_name") {
|
||||
req := disks.RenameRequest{
|
||||
DiskID: diskID,
|
||||
_, err := c.CloudBroker().Disks().Rename(ctx, disks.RenameRequest{
|
||||
DiskID: disk.ID,
|
||||
Name: d.Get("disk_name").(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Disks().Rename(ctx, req)
|
||||
})
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
w.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,44 +269,49 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
iot := d.Get("iotune").([]interface{})[0]
|
||||
iotune := iot.(map[string]interface{})
|
||||
req := disks.LimitIORequest{
|
||||
DiskID: diskID,
|
||||
IOPS: uint64(iotune["total_iops_sec"].(int)),
|
||||
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
|
||||
ReadBytesSec: uint64(iotune["read_bytes_sec"].(int)),
|
||||
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)),
|
||||
TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
|
||||
ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)),
|
||||
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)),
|
||||
TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)),
|
||||
ReadBytesSecMax: uint64(iotune["read_bytes_sec_max"].(int)),
|
||||
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
|
||||
TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)),
|
||||
ReadIOPSSec: uint64(iotune["read_iops_sec"].(int)),
|
||||
ReadIOPSSecMax: uint64(iotune["read_iops_sec_max"].(int)),
|
||||
WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)),
|
||||
SizeIOPSSec: uint64(iotune["size_iops_sec"].(int)),
|
||||
TotalBytesSec: uint64(iotune["total_bytes_sec"].(int)),
|
||||
TotalBytesSecMax: uint64(iotune["total_bytes_sec_max"].(int)),
|
||||
TotalIOPSSecMax: uint64(iotune["total_iops_sec_max"].(int)),
|
||||
TotalIOPSSec: uint64(iotune["total_iops_sec"].(int)),
|
||||
WriteBytesSec: uint64(iotune["write_bytes_sec"].(int)),
|
||||
WriteBytesSecMax: uint64(iotune["write_bytes_sec_max"].(int)),
|
||||
WriteIOPSSec: uint64(iotune["write_iops_sec"].(int)),
|
||||
WriteIOPSSecMax: uint64(iotune["write_iops_sec_max"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Disks().LimitIO(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
w.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("restore") {
|
||||
if d.Get("restore").(bool) {
|
||||
req := disks.RestoreRequest{
|
||||
DiskID: diskID,
|
||||
Reason: d.Get("reason").(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Disks().Restore(ctx, req)
|
||||
if d.HasChange("shareable") {
|
||||
old, new := d.GetChange("shareable")
|
||||
if !old.(bool) && new.(bool) && !disk.Shareable {
|
||||
_, err := c.CloudBroker().Disks().Share(ctx, disks.ShareRequest{
|
||||
DiskID: disk.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
w.Add(err)
|
||||
}
|
||||
}
|
||||
if old.(bool) && !new.(bool) && disk.Shareable {
|
||||
_, err := c.CloudBroker().Disks().Unshare(ctx, disks.UnshareRequest{
|
||||
DiskID: disk.ID,
|
||||
})
|
||||
if err != nil {
|
||||
w.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resourceDiskRead(ctx, d, m)
|
||||
return append(w.Get(), resourceDiskRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
@@ -210,6 +319,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
||||
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -225,6 +335,8 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -233,41 +345,46 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
"disk_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"D", "B", "T"}, false),
|
||||
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"D", "B", "T"}, false),
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"ssd_size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"pool": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"detach": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
@@ -286,17 +403,17 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Default: "",
|
||||
Description: "reason for an action",
|
||||
},
|
||||
"shareable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"restore": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "restore deleting disk",
|
||||
},
|
||||
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -309,6 +426,22 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
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,
|
||||
@@ -333,6 +466,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -452,7 +589,13 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"present_to": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"purge_attempts": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -481,7 +624,6 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"sep_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -503,6 +645,10 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
215
internal/service/cloudbroker/disks/resource_disk_snapshot.go
Normal file
215
internal/service/cloudbroker/disks/resource_disk_snapshot.go
Normal file
@@ -0,0 +1,215 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceDiskSnapshotCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
snapshots := disk.Snapshots
|
||||
snapshot := disks.ItemSnapshot{}
|
||||
label := d.Get("label").(string)
|
||||
for _, sn := range snapshots {
|
||||
if label == sn.Label {
|
||||
snapshot = sn
|
||||
break
|
||||
}
|
||||
}
|
||||
if label != snapshot.Label {
|
||||
return diag.Errorf("Snapshot with label \"%v\" not found", label)
|
||||
}
|
||||
|
||||
if rollback := d.Get("rollback").(bool); rollback {
|
||||
req := disks.SnapshotRollbackRequest{
|
||||
DiskID: disk.ID,
|
||||
Label: label,
|
||||
TimeStamp: uint64(d.Get("timestamp").(int)),
|
||||
}
|
||||
|
||||
log.Debugf("resourceDiskCreate: Snapshot rollback with label", label)
|
||||
_, err := c.CloudBroker().Disks().SnapshotRollback(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
return resourceDiskSnapshotRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
snapshots := disk.Snapshots
|
||||
snapshot := disks.ItemSnapshot{}
|
||||
label := d.Get("label").(string)
|
||||
for _, sn := range snapshots {
|
||||
if label == sn.Label {
|
||||
snapshot = sn
|
||||
break
|
||||
}
|
||||
}
|
||||
if label != snapshot.Label {
|
||||
return diag.Errorf("Snapshot with label \"%v\" not found", label)
|
||||
}
|
||||
|
||||
flattenDiskSnapshot(d, snapshot)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceDiskSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
snapshots := disk.Snapshots
|
||||
snapshot := disks.ItemSnapshot{}
|
||||
label := d.Get("label").(string)
|
||||
for _, sn := range snapshots {
|
||||
if label == sn.Label {
|
||||
snapshot = sn
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if label != snapshot.Label {
|
||||
return diag.Errorf("Snapshot with label \"%v\" not found", label)
|
||||
}
|
||||
|
||||
if d.HasChange("rollback") && d.Get("rollback").(bool) == true {
|
||||
req := disks.SnapshotRollbackRequest{
|
||||
DiskID: disk.ID,
|
||||
Label: label,
|
||||
TimeStamp: uint64(d.Get("timestamp").(int)),
|
||||
}
|
||||
|
||||
log.Debugf("resourceDiskUpdtae: Snapshot rollback with label", label)
|
||||
_, err := c.CloudBroker().Disks().SnapshotRollback(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceDiskSnapshotRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceDiskSnapshotDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
disk, err := utilityDiskCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := disks.SnapshotDeleteRequest{
|
||||
DiskID: disk.ID,
|
||||
Label: d.Get("label").(string),
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().Disks().SnapshotDelete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResourceDiskSnapshot() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceDiskSnapshotCreate,
|
||||
ReadContext: resourceDiskSnapshotRead,
|
||||
UpdateContext: resourceDiskSnapshotUpdate,
|
||||
DeleteContext: resourceDiskSnapshotDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout300s,
|
||||
Delete: &constants.Timeout300s,
|
||||
Default: &constants.Timeout300s,
|
||||
},
|
||||
|
||||
Schema: resourceDiskSnapshotSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func resourceDiskSnapshotSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"disk_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "The unique ID of the subscriber-owner of the disk",
|
||||
},
|
||||
"label": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
Description: "Name of the snapshot",
|
||||
},
|
||||
"rollback": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Needed in order to make a snapshot rollback",
|
||||
},
|
||||
"timestamp": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Snapshot time",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ID of the snapshot",
|
||||
},
|
||||
"reference_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"res_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Reference to the snapshot",
|
||||
},
|
||||
"snap_set_guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The set snapshot ID",
|
||||
},
|
||||
"snap_set_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "The set time of the snapshot",
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,9 @@ func utilityDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m int
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := disks.GetRequest{}
|
||||
|
||||
if d.Get("disk_id").(int) == 0 {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.DiskID = id
|
||||
if d.Id() != "" {
|
||||
diskID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.DiskID = diskID
|
||||
} else {
|
||||
req.DiskID = uint64(d.Get("disk_id").(int))
|
||||
}
|
||||
|
||||
@@ -46,18 +46,42 @@ func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := disks.ListRequest{}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
if account_name, ok := d.GetOk("account_name"); ok {
|
||||
req.AccountName = account_name.(string)
|
||||
}
|
||||
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
||||
req.DiskMaxSize = int64(disk_max_size.(int))
|
||||
}
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
if shared, ok := d.GetOk("shared"); ok {
|
||||
req.Shared = shared.(bool)
|
||||
}
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
if diskType, ok := d.GetOk("type"); ok {
|
||||
req.Type = strings.ToUpper(diskType.(string))
|
||||
}
|
||||
if pool, ok := d.GetOk("pool"); ok {
|
||||
req.Pool = pool.(string)
|
||||
}
|
||||
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))
|
||||
}
|
||||
if diskType, ok := d.GetOk("type"); ok {
|
||||
req.Type = strings.ToUpper(diskType.(string))
|
||||
}
|
||||
if accountId, ok := d.GetOk("accountId"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityDiskListCheckPresence: load disk list")
|
||||
diskList, err := c.CloudBroker().Disks().List(ctx, req)
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
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 disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDiskListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := disks.ListDeletedRequest{}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
if account_name, ok := d.GetOk("account_name"); ok {
|
||||
req.AccountName = account_name.(string)
|
||||
}
|
||||
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
||||
req.DiskMaxSize = int64(disk_max_size.(int))
|
||||
}
|
||||
if shared, ok := d.GetOk("shared"); ok {
|
||||
req.Shared = shared.(bool)
|
||||
}
|
||||
if account_id, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(account_id.(int))
|
||||
}
|
||||
if typev, ok := d.GetOk("type"); ok {
|
||||
req.Type = typev.(string)
|
||||
}
|
||||
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("utilityDiskListDeletedCheckPresence: load disk list")
|
||||
diskList, err := c.CloudBroker().Disks().ListDeleted(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return diskList, nil
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDiskListTypesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := disks.ListTypesRequest{
|
||||
Detailed: false,
|
||||
}
|
||||
|
||||
log.Debugf("utilityDiskListTypesCheckPresence: load disk list Types Detailed")
|
||||
typesList, err := c.CloudBroker().Disks().ListTypes(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return typesList, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDiskListTypesDetailedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListTypes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debugf("utilityDiskListTypesDetailedCheckPresence: load disk list Types Detailed")
|
||||
listTypesDetailed, err := c.CloudBroker().Disks().ListTypes(ctx, disks.ListTypesRequest{
|
||||
Detailed: true,
|
||||
})
|
||||
|
||||
log.Debugf("%+v", listTypesDetailed.Data[0].(map[string]interface{}))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return listTypesDetailed, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDiskListUnattachedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListUnattachedDisks, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := disks.ListUnattachedRequest{}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
if account_name, ok := d.GetOk("account_name"); ok {
|
||||
req.AccountName = account_name.(string)
|
||||
}
|
||||
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
||||
req.DiskMaxSize = int64(disk_max_size.(int))
|
||||
}
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
if diskType, ok := d.GetOk("type"); ok {
|
||||
req.Type = diskType.(string)
|
||||
}
|
||||
if accountId, ok := d.GetOk("accountId"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||
req.SEPID = uint64(sepId.(int))
|
||||
}
|
||||
if pool, ok := d.GetOk("pool"); ok {
|
||||
req.Pool = pool.(string)
|
||||
}
|
||||
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("utilityDiskListUnattachedCheckPresence: load disk Unattached list")
|
||||
unattachedList, err := c.CloudBroker().Disks().ListUnattached(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return unattachedList, nil
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
|
||||
func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"net_id": {
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
@@ -116,10 +116,6 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ipcidr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -198,6 +194,10 @@ func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"domain_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -50,14 +50,14 @@ func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
|
||||
d.Set("net_id", extnetId)
|
||||
d.Set("extnet_id", extnetId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"net_id": {
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 extnet
|
||||
|
||||
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 dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(staticRoute.ID, 10))
|
||||
flattenStaticRouteData(d, staticRoute)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the ExtNet",
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the static route",
|
||||
},
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
func DataSourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 extnet
|
||||
|
||||
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 dataSourceStaticRouteListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRouteList, err := utilityStaticRouteListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenStaticRouteList(staticRouteList))
|
||||
d.Set("entry_count", staticRouteList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaticRouteListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of ExtNet",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceStaticRouteList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -46,6 +46,7 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
|
||||
"ckey": item.CKey,
|
||||
"meta": flattens.FlattenMeta(item.Meta),
|
||||
"default": item.Default,
|
||||
"default_qos": flattenExtnetDefaultQos(item.DefaultQOS),
|
||||
"desc": item.Description,
|
||||
"free_ips": item.FreeIPs,
|
||||
"gid": item.GID,
|
||||
@@ -62,6 +63,7 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
|
||||
"status": item.Status,
|
||||
"vlan_id": item.VLANID,
|
||||
"check_ips": item.CheckIPs,
|
||||
"vnfs": flattenExtnetVNFS(item.VNFs),
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
@@ -73,7 +75,6 @@ func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
|
||||
func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) {
|
||||
d.Set("ckey", recNet.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(recNet.Meta))
|
||||
|
||||
d.Set("default", recNet.Default)
|
||||
d.Set("desc", recNet.Description)
|
||||
d.Set("free_ips", recNet.FreeIPs)
|
||||
@@ -96,17 +97,49 @@ func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) {
|
||||
d.Set("gateway", recNet.Gateway)
|
||||
d.Set("network", recNet.Network)
|
||||
d.Set("prefix", recNet.Prefix)
|
||||
|
||||
d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS))
|
||||
d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs))
|
||||
d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
|
||||
}
|
||||
|
||||
func flattenRecordExtnetResource(d *schema.ResourceData, recNet *extnet.RecordExtNet, staticRouteList *extnet.ListStaticRoutes) {
|
||||
d.Set("ckey", recNet.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(recNet.Meta))
|
||||
d.Set("default", recNet.Default)
|
||||
d.Set("desc", recNet.Description)
|
||||
d.Set("free_ips", recNet.FreeIPs)
|
||||
d.Set("gid", recNet.GID)
|
||||
d.Set("guid", recNet.GUID)
|
||||
d.Set("extnet_id", recNet.ID)
|
||||
d.Set("ipcidr", recNet.IPCIDR)
|
||||
d.Set("milestones", recNet.Milestones)
|
||||
d.Set("name", recNet.Name)
|
||||
d.Set("network_id", recNet.NetworkID)
|
||||
d.Set("ovs_bridge", recNet.OVSBridge)
|
||||
d.Set("pre_reservations_num", recNet.PreReservationsNum)
|
||||
d.Set("pri_vnfdev_id", recNet.PriVNFDevID)
|
||||
d.Set("shared_with", recNet.SharedWith)
|
||||
d.Set("status", recNet.Status)
|
||||
d.Set("vlan_id", recNet.VLANID)
|
||||
d.Set("check_ips", recNet.CheckIPs)
|
||||
d.Set("dns", recNet.DNS)
|
||||
d.Set("excluded", flattenExtnetExcluded(recNet.Excluded))
|
||||
d.Set("gateway", recNet.Gateway)
|
||||
d.Set("network", recNet.Network)
|
||||
d.Set("prefix", recNet.Prefix)
|
||||
d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS))
|
||||
d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs))
|
||||
d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
|
||||
d.Set("routes", flattenStaticRouteList(staticRouteList))
|
||||
}
|
||||
|
||||
|
||||
func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for _, er := range ers {
|
||||
temp := map[string]interface{}{
|
||||
"client_type": er.ClientType,
|
||||
"desc": er.Description,
|
||||
"domain_name": er.DomainName,
|
||||
"hostname": er.Hostname,
|
||||
"ip": er.IP,
|
||||
@@ -159,3 +192,29 @@ func flattenExtnetDefaultQos(edqos extnet.QOS) []map[string]interface{} {
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStaticRouteList(sr *extnet.ListStaticRoutes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(sr.Data))
|
||||
for _, staticRoute := range sr.Data {
|
||||
temp := map[string]interface{}{
|
||||
"route_id": staticRoute.ID,
|
||||
"destination": staticRoute.Destination,
|
||||
"gateway": staticRoute.Gateway,
|
||||
"guid": staticRoute.GUID,
|
||||
"netmask": staticRoute.Netmask,
|
||||
"compute_ids": staticRoute.ComputeIds,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStaticRouteData(d *schema.ResourceData, route *extnet.ItemRoutes) {
|
||||
d.Set("destination", route.Destination)
|
||||
d.Set("gateway", route.Gateway)
|
||||
d.Set("guid", route.GUID)
|
||||
d.Set("netmask", route.Netmask)
|
||||
d.Set("compute_ids", route.ComputeIds)
|
||||
d.Set("route_id", route.ID)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -43,12 +43,17 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"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"
|
||||
)
|
||||
|
||||
func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("cloudbroker: resourceExtnetCreate called with name '%s'", d.Get("name").(string))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if err := ic.ExistGID(ctx, uint64(d.Get("gid").(int)), c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := extnet.CreateRequest{
|
||||
Name: d.Get("name").(string),
|
||||
GID: uint64(d.Get("gid").(int)),
|
||||
@@ -122,6 +127,7 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(netID, 10))
|
||||
d.Set("extnet_id", netID)
|
||||
log.Debugf("cloudbroker: Extnet with id %d successfully created on platform", netID)
|
||||
|
||||
if d.Get("excluded_ips").(*schema.Set).Len() > 0 {
|
||||
@@ -163,8 +169,12 @@ func resourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
staticRouteList, err := utilityStaticRouteListInResourceCheckPresence(ctx, m, recNet.ID)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenRecordExtnet(d, recNet)
|
||||
flattenRecordExtnetResource(d, recNet, staticRouteList)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -219,6 +229,35 @@ func resourceExtnetUpdate(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("excluded_ips_range") {
|
||||
if err := handleExcludedIPsRangeUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("shared_with") {
|
||||
if err := handleSharedWithUpdate(ctx, d, c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("virtual") {
|
||||
if err := handleVirtualUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("restart") {
|
||||
if err := handleRestartUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
if d.HasChange("migrate") {
|
||||
if err := handleMigrateUpdate(ctx, d, c, recNet); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceExtnetRead(ctx, d, m)
|
||||
}
|
||||
|
||||
@@ -253,13 +292,13 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
"ipcidr": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
// ForceNew: true,
|
||||
Description: "IP network CIDR",
|
||||
},
|
||||
"vlan_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
// ForceNew: true,
|
||||
Description: "VLAN ID",
|
||||
},
|
||||
"gateway": {
|
||||
@@ -352,6 +391,23 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
Description: "IPs to exclude in current extnet pool",
|
||||
},
|
||||
"excluded_ips_range": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"ip_start": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"ip_end": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Description: "Range of IPs to exclude in current extnet pool",
|
||||
},
|
||||
"default_qos": {
|
||||
Type: schema.TypeList,
|
||||
MaxItems: 1,
|
||||
@@ -381,6 +437,15 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
},
|
||||
"restart":{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "restart extnet vnf device",
|
||||
},
|
||||
"migrate":{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -488,6 +553,41 @@ func resourceExtnetSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"reservations": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
@@ -540,6 +640,10 @@ func ResourceExtnetCB() *schema.Resource {
|
||||
UpdateContext: resourceExtnetUpdate,
|
||||
DeleteContext: resourceExtnetDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout300s,
|
||||
Create: &constants.Timeout300s,
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"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/service/cloudbroker/ic"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if err := ic.ExistExtNet(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := extnet.StaticRouteAddRequest{
|
||||
ExtNetId: uint64(d.Get("extnet_id").(int)),
|
||||
Destination: d.Get("destination").(string),
|
||||
Netmask: d.Get("netmask").(string),
|
||||
Gateway: d.Get("gateway").(string),
|
||||
}
|
||||
|
||||
if computesIDS, ok := d.GetOk("compute_ids"); ok {
|
||||
ids := computesIDS.([]interface{})
|
||||
|
||||
res := make([]uint64, 0, len (ids))
|
||||
|
||||
for _, id := range ids {
|
||||
computeId := uint64(id.(int))
|
||||
res = append(res, computeId)
|
||||
}
|
||||
|
||||
req.ComputeIds = res
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteAdd(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
staticRouteData, err := getStaticRouteData(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(fmt.Sprintf("%d#%d", req.ExtNetId, staticRouteData.ID))
|
||||
|
||||
return resourceStaticRouteRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenStaticRouteData(d, staticRouteData)
|
||||
|
||||
return warnings.Get()
|
||||
}
|
||||
|
||||
func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
if err := ic.ExistExtNet(ctx, uint64(d.Get("extnet_id").(int)), c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if d.HasChange("compute_ids") {
|
||||
deletedIds := make([]uint64, 0)
|
||||
addedIds := make([]uint64, 0)
|
||||
|
||||
oldComputeIds, newComputeIds := d.GetChange("compute_ids")
|
||||
oldComputeIdsSlice := oldComputeIds.([]interface{})
|
||||
newComputeIdsSlice := newComputeIds.([]interface{})
|
||||
|
||||
for _, el := range oldComputeIdsSlice {
|
||||
if !isContainsIds(newComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
deletedIds = append(deletedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newComputeIdsSlice {
|
||||
if !isContainsIds(oldComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
addedIds = append(addedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedIds) > 0 {
|
||||
req := extnet.StaticRouteAccessRevokeRequest{
|
||||
ExtNetID: uint64(d.Get("extnet_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: deletedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteAccessRevoke(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedIds) > 0 {
|
||||
req := extnet.StaticRouteAccessGrantRequest{
|
||||
ExtNetID: uint64(d.Get("extnet_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: addedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteAccessGrant(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceStaticRouteRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteDelRequest{}
|
||||
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return diag.Errorf("broken state id - %s", d.Id())
|
||||
}
|
||||
|
||||
req.ExtNetID, _ = strconv.ParseUint(arr[0], 10, 64)
|
||||
req.RouteId, _ = strconv.ParseUint(arr[1], 10, 64)
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().StaticRouteDel(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := dataSourceStaticRouteSchemaMake()
|
||||
rets["route_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
}
|
||||
rets["compute_ids"] = &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
}
|
||||
rets["destination"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
rets["gateway"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
rets["netmask"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func isContainsIds(els []interface{}, el interface{}) bool {
|
||||
convEl := el.(int)
|
||||
for _, elOld := range els {
|
||||
if convEl == elOld.(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ResourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceStaticRouteCreate,
|
||||
ReadContext: resourceStaticRouteRead,
|
||||
UpdateContext: resourceStaticRouteUpdate,
|
||||
DeleteContext: resourceStaticRouteDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout20m,
|
||||
Read: &constants.Timeout600s,
|
||||
Update: &constants.Timeout20m,
|
||||
Delete: &constants.Timeout600s,
|
||||
Default: &constants.Timeout600s,
|
||||
},
|
||||
|
||||
Schema: resourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -38,245 +38,20 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
)
|
||||
|
||||
func handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
old_set, new_set := d.GetChange("excluded_ips")
|
||||
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
if detach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, detach_ip := range detach_set.List() {
|
||||
ips = append(ips, detach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len())
|
||||
req := extnet.IPsIncludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
if attach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, attach_ip := range attach_set.List() {
|
||||
ips = append(ips, attach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID)
|
||||
req := extnet.IPsExcludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
set_default := d.Get("set_default").(bool)
|
||||
if set_default && recNet.Default == false {
|
||||
req := extnet.SetDefaultRequest{
|
||||
NetID: recNet.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().SetDefault(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
doBasicUpdate := false
|
||||
basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID}
|
||||
|
||||
if d.HasChange("name") {
|
||||
basiUpdateReq.Name = d.Get("name").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
if d.HasChange("desc") {
|
||||
basiUpdateReq.Description = d.Get("desc").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
|
||||
if doBasicUpdate {
|
||||
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
enable := d.Get("enable").(bool)
|
||||
if enable {
|
||||
if recNet.Status == status.Disabled {
|
||||
req := extnet.EnableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Enable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if recNet.Status == status.Enabled {
|
||||
req := extnet.DisableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Disable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{})
|
||||
|
||||
req := extnet.DefaultQOSUpdateRequest{
|
||||
NetID: recNet.ID,
|
||||
IngressRate: uint64(qos["in_rate"].(int)),
|
||||
IngressBurst: uint64(qos["in_burst"].(int)),
|
||||
EgressRate: uint64(qos["e_rate"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("ntp").([]interface{})
|
||||
|
||||
ntp_list := make([]string, 0)
|
||||
for _, ntp_address := range changed_list {
|
||||
ntp_list = append(ntp_list, ntp_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.NTPApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
NTPList: ntp_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().NTPApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("dns").([]interface{})
|
||||
|
||||
dns_list := make([]string, 0)
|
||||
for _, dns_address := range changed_list {
|
||||
dns_list = append(dns_list, dns_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.DNSApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
DNSList: dns_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DNSApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
return c.CloudBroker().ExtNet().GetDefault(ctx)
|
||||
}
|
||||
|
||||
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNet, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := extnet.ListRequest{}
|
||||
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if network, ok := d.GetOk("network"); ok {
|
||||
req.Network = network.(string)
|
||||
}
|
||||
|
||||
if vlan_id, ok := d.GetOk("vlan_id"); ok {
|
||||
req.VLANID = uint64(vlan_id.(int))
|
||||
}
|
||||
|
||||
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
|
||||
req.VNFDevID = uint64(vnfdev_id.(int))
|
||||
}
|
||||
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
|
||||
res, err := c.CloudBroker().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.RecordExtNet, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
var netId uint64
|
||||
|
||||
if id, ok := d.GetOk("net_id"); ok {
|
||||
netId = uint64(id.(int))
|
||||
req := extnet.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
netId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.NetID = netId
|
||||
} else {
|
||||
parsed, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
netId = parsed
|
||||
}
|
||||
|
||||
req := extnet.GetRequest{
|
||||
NetID: netId,
|
||||
req.NetID = uint64(d.Get("extnet_id").(int))
|
||||
}
|
||||
|
||||
res, err := c.CloudBroker().ExtNet().Get(ctx, req)
|
||||
|
||||
@@ -1,63 +1,54 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dataSourceAccountDiskSchemaMake() map[string]*schema.Schema {
|
||||
return 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,
|
||||
},
|
||||
"size_max": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
/*
|
||||
<<<<<<<< HEAD:internal/dc/utils.go
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
========
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
>>>>>>>> dev:internal/service/cloudbroker/extnet/utility_extnet_default.go
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
<<<<<<<< HEAD:internal/dc/utils.go
|
||||
Nikita Sorokin, <nesorokin@basistech.ru>
|
||||
========
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
>>>>>>>> dev:internal/service/cloudbroker/extnet/utility_extnet_default.go
|
||||
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
return c.CloudBroker().ExtNet().GetDefault(ctx)
|
||||
}
|
||||
91
internal/service/cloudbroker/extnet/utility_extnet_list.go
Normal file
91
internal/service/cloudbroker/extnet/utility_extnet_list.go
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNet, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := extnet.ListRequest{}
|
||||
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
|
||||
if by_id, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(by_id.(int))
|
||||
}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
|
||||
if network, ok := d.GetOk("network"); ok {
|
||||
req.Network = network.(string)
|
||||
}
|
||||
|
||||
if vlan_id, ok := d.GetOk("vlan_id"); ok {
|
||||
req.VLANID = uint64(vlan_id.(int))
|
||||
}
|
||||
|
||||
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
|
||||
req.VNFDevID = uint64(vnfdev_id.(int))
|
||||
}
|
||||
|
||||
if status, ok := d.GetOk("status"); ok {
|
||||
req.Status = status.(string)
|
||||
}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
|
||||
if size, ok := d.GetOk("size"); ok {
|
||||
req.Size = uint64(size.(int))
|
||||
}
|
||||
|
||||
res, err := c.CloudBroker().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
360
internal/service/cloudbroker/extnet/utility_extnet_resource.go
Normal file
360
internal/service/cloudbroker/extnet/utility_extnet_resource.go
Normal file
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"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 handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
old_set, new_set := d.GetChange("excluded_ips")
|
||||
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
if detach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, detach_ip := range detach_set.List() {
|
||||
ips = append(ips, detach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len())
|
||||
req := extnet.IPsIncludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
if attach_set.Len() > 0 {
|
||||
ips := make([]string, 0)
|
||||
for _, attach_ip := range attach_set.List() {
|
||||
ips = append(ips, attach_ip.(string))
|
||||
}
|
||||
|
||||
log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID)
|
||||
req := extnet.IPsExcludeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPs: ips,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
set_default := d.Get("set_default").(bool)
|
||||
if set_default && !recNet.Default {
|
||||
req := extnet.SetDefaultRequest{
|
||||
NetID: recNet.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().SetDefault(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
doBasicUpdate := false
|
||||
basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID}
|
||||
|
||||
if d.HasChange("name") {
|
||||
basiUpdateReq.Name = d.Get("name").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
if d.HasChange("desc") {
|
||||
basiUpdateReq.Description = d.Get("desc").(string)
|
||||
doBasicUpdate = true
|
||||
}
|
||||
|
||||
if doBasicUpdate {
|
||||
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
enable := d.Get("enable").(bool)
|
||||
if enable {
|
||||
if recNet.Status == status.Disabled {
|
||||
req := extnet.EnableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Enable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if recNet.Status == status.Enabled {
|
||||
req := extnet.DisableRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().Disable(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{})
|
||||
|
||||
req := extnet.DefaultQOSUpdateRequest{
|
||||
NetID: recNet.ID,
|
||||
IngressRate: uint64(qos["in_rate"].(int)),
|
||||
IngressBurst: uint64(qos["in_burst"].(int)),
|
||||
EgressRate: uint64(qos["e_rate"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("ntp").([]interface{})
|
||||
|
||||
ntp_list := make([]string, 0)
|
||||
for _, ntp_address := range changed_list {
|
||||
ntp_list = append(ntp_list, ntp_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.NTPApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
NTPList: ntp_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().NTPApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
changed_list := d.Get("dns").([]interface{})
|
||||
|
||||
dns_list := make([]string, 0)
|
||||
for _, dns_address := range changed_list {
|
||||
dns_list = append(dns_list, dns_address.(string))
|
||||
}
|
||||
|
||||
req := extnet.DNSApplyRequest{
|
||||
NetID: recNet.ID,
|
||||
DNSList: dns_list,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DNSApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleExcludedIPsRangeUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
old_set, new_set := d.GetChange("excluded_ips_range")
|
||||
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
if detach_set.Len() > 0 {
|
||||
for _, detach_ip_range := range detach_set.List() {
|
||||
|
||||
log.Debugf("cloudbroker: removing range of IP addreses from excluded range list")
|
||||
|
||||
req := extnet.IPsIncludeRangeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPStart: detach_ip_range.(map[string]interface{})["ip_start"].(string),
|
||||
IPEnd: detach_ip_range.(map[string]interface{})["ip_end"].(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsIncludeRange(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
if attach_set.Len() > 0 {
|
||||
for _, attach_ip_range := range attach_set.List() {
|
||||
|
||||
log.Debugf("cloudbroker: excluding range of IP addreses from excluded range list")
|
||||
|
||||
req := extnet.IPsExcludeRangeRequest{
|
||||
NetID: recNet.ID,
|
||||
IPStart: attach_ip_range.(map[string]interface{})["ip_start"].(string),
|
||||
IPEnd: attach_ip_range.(map[string]interface{})["ip_end"].(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().IPsExcludeRange(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSharedWithUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) error {
|
||||
deletedIds := make([]uint64, 0)
|
||||
addedIds := make([]uint64, 0)
|
||||
|
||||
oldAccountIds, newAccountIds := d.GetChange("shared_with")
|
||||
oldAccountIdsSlice := oldAccountIds.([]interface{})
|
||||
newAccountIdsSlice := newAccountIds.([]interface{})
|
||||
|
||||
for _, el := range oldAccountIdsSlice {
|
||||
if !isContainsIds(newAccountIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
deletedIds = append(deletedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newAccountIdsSlice {
|
||||
if !isContainsIds(oldAccountIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
addedIds = append(addedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedIds) > 0 {
|
||||
for _, accountId := range deletedIds {
|
||||
req := extnet.AccessRemoveRequest{
|
||||
NetID: uint64(d.Get("extnet_id").(int)),
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().AccessRemove(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedIds) > 0 {
|
||||
for _, accountId := range addedIds {
|
||||
req := extnet.AccessAddRequest{
|
||||
NetID: uint64(d.Get("extnet_id").(int)),
|
||||
AccountID: accountId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().AccessAdd(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleVirtualUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
virtualOld, virtualNew := d.GetChange("virtual")
|
||||
|
||||
if virtualOld == false && virtualNew == true {
|
||||
req := extnet.DeviceRemoveRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().DeviceRemove(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else if virtualOld == true && virtualNew == false {
|
||||
req := extnet.DeviceDeployRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().DeviceDeploy(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleRestartUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
restartOld, restartNew := d.GetChange("restart")
|
||||
|
||||
if restartOld == false && restartNew == true {
|
||||
req := extnet.DeviceRestartRequest{NetID: recNet.ID}
|
||||
_, err := c.CloudBroker().ExtNet().DeviceRestart(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleMigrateUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
|
||||
stackId := uint64(d.Get("migrate").(int))
|
||||
|
||||
if err := ic.ExistStack(ctx, stackId, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := extnet.DeviceMigrateRequest{
|
||||
NetID: recNet.ID,
|
||||
StackID: stackId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().ExtNet().DeviceMigrate(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityDataStaticRouteCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ItemRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{}
|
||||
var routeId uint64
|
||||
|
||||
if d.Id() != "" {
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return nil, fmt.Errorf("broken state id")
|
||||
}
|
||||
|
||||
req.ExtNetID, _ = strconv.ParseUint(arr[0], 10, 64)
|
||||
routeId, _ = strconv.ParseUint(arr[1], 10, 64)
|
||||
} else {
|
||||
req.ExtNetID = uint64(d.Get("extnet_id").(int))
|
||||
routeId = uint64(d.Get("route_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteCheckPresence, extnet id: %v", req.ExtNetID)
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteCheckPresence: ROUTE ID %v", routeId)
|
||||
|
||||
staticRoute := extnet.ItemRoutes{}
|
||||
for _, route := range staticRouteList.Data {
|
||||
if routeId == route.ID {
|
||||
staticRoute = route
|
||||
return &staticRoute, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("static route not found")
|
||||
}
|
||||
|
||||
func getStaticRouteData(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ItemRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{}
|
||||
req.ExtNetID = uint64(d.Get("extnet_id").(int))
|
||||
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
destination := d.Get("destination").(string)
|
||||
gateway := d.Get("gateway").(string)
|
||||
|
||||
staticRoute := extnet.ItemRoutes{}
|
||||
for _, route := range staticRouteList.Data {
|
||||
if destination == route.Destination && gateway == route.Gateway {
|
||||
staticRoute = route
|
||||
return &staticRoute, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("static route not found")
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityStaticRouteListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListStaticRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{}
|
||||
|
||||
req.ExtNetID = uint64(d.Get("extnet_id").(int))
|
||||
|
||||
log.Debugf("utilityStaticRouteListCheckPresence")
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return staticRouteList, nil
|
||||
}
|
||||
|
||||
func utilityStaticRouteListInResourceCheckPresence(ctx context.Context, m interface{}, extnetId uint64) (*extnet.ListStaticRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := extnet.StaticRouteListRequest{
|
||||
ExtNetID: extnetId,
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteListInResourceCheckPresence")
|
||||
staticRouteList, err := c.CloudBroker().ExtNet().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return staticRouteList, nil
|
||||
}
|
||||
219
internal/service/cloudbroker/flipgroup/data_source_flipgroup.go
Normal file
219
internal/service/cloudbroker/flipgroup/data_source_flipgroup.go
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
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 dataSourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
flipgroup, err := utilityFlipgroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenFlipgroup(d, flipgroup)
|
||||
d.SetId(strconv.Itoa(d.Get("flipgroup_id").(int)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"flipgroup_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "flipgroup_id",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "account_id",
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "account_name",
|
||||
},
|
||||
"client_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "client_ids",
|
||||
},
|
||||
"client_names": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "client_names",
|
||||
},
|
||||
"client_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "client_type",
|
||||
},
|
||||
"conn_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "conn_id",
|
||||
},
|
||||
"conn_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "conn_type",
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "created_by",
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "created_time",
|
||||
},
|
||||
"default_gw": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "default_gw",
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "deleted_by",
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "deleted_time",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "description",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "gid",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "guid",
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ip",
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "milestones",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "name",
|
||||
},
|
||||
"net_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "net_id",
|
||||
},
|
||||
"net_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "net_type",
|
||||
},
|
||||
"network": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "network",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "rg_id",
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "rg_name",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "updated_by",
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "updated_time",
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
func DataSourceFlipgroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceFlipgroupRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceFlipgroupSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
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 dataSourceFlipgroupListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
flipgroupsList, err := utilityFlipgroupListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenFlipgroupsList(flipgroupsList))
|
||||
d.Set("entry_count", flipgroupsList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceFlipgroupItemSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ckey",
|
||||
},
|
||||
"meta": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "account_id",
|
||||
},
|
||||
"client_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "client_ids",
|
||||
},
|
||||
"client_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "client_type",
|
||||
},
|
||||
"conn_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "conn_id",
|
||||
},
|
||||
"conn_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "conn_type",
|
||||
},
|
||||
"default_gw": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "default_gw",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "description",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "gid",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "guid",
|
||||
},
|
||||
"flipgroup_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "flipgroup_id",
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "ip",
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "milestones",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "name",
|
||||
},
|
||||
"net_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "net_id",
|
||||
},
|
||||
"net_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "net_type",
|
||||
},
|
||||
"net_mask": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "net_mask",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "status",
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourceFlipgroupsListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "name",
|
||||
},
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "vins_id",
|
||||
},
|
||||
"vins_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "vins_name",
|
||||
},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "extnet_id",
|
||||
},
|
||||
"by_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "by_ip",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "rg_id",
|
||||
},
|
||||
"by_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "by_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: dataSourceFlipgroupItemSchemaMake(),
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry_count",
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceFlipgroupList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceFlipgroupListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceFlipgroupsListSchemaMake(),
|
||||
}
|
||||
}
|
||||
100
internal/service/cloudbroker/flipgroup/flattens.go
Normal file
100
internal/service/cloudbroker/flipgroup/flattens.go
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenFlipgroup(d *schema.ResourceData, flip *flipgroup.RecordFLIPGroup) {
|
||||
d.Set("flipgroup_id", flip.ID)
|
||||
d.Set("account_id", flip.AccountID)
|
||||
d.Set("account_name", flip.AccountName)
|
||||
d.Set("client_ids", flip.ClientIDs)
|
||||
d.Set("client_names", flip.ClientNames)
|
||||
d.Set("client_type", flip.ClientType)
|
||||
d.Set("conn_id", flip.ConnID)
|
||||
d.Set("conn_type", flip.ConnType)
|
||||
d.Set("created_by", flip.CreatedBy)
|
||||
d.Set("created_time", flip.CreatedTime)
|
||||
d.Set("default_gw", flip.DefaultGW)
|
||||
d.Set("deleted_by", flip.DeletedBy)
|
||||
d.Set("deleted_time", flip.DeletedTime)
|
||||
d.Set("description", flip.Description)
|
||||
d.Set("gid", flip.GID)
|
||||
d.Set("guid", flip.GUID)
|
||||
d.Set("ip", flip.IP)
|
||||
d.Set("milestones", flip.Milestones)
|
||||
d.Set("name", flip.Name)
|
||||
d.Set("net_id", flip.NetID)
|
||||
d.Set("net_type", flip.NetType)
|
||||
d.Set("network", flip.Network)
|
||||
d.Set("rg_id", flip.RGID)
|
||||
d.Set("rg_name", flip.RGName)
|
||||
d.Set("status", flip.Status)
|
||||
d.Set("updated_by", flip.UpdatedBy)
|
||||
d.Set("updated_time", flip.UpdatedTime)
|
||||
}
|
||||
|
||||
func flattenFlipgroupsList(fg *flipgroup.ListFLIPGroups) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(fg.Data))
|
||||
for _, flip := range fg.Data {
|
||||
temp := map[string]interface{}{
|
||||
"ckey": flip.CKey,
|
||||
"meta": flattens.FlattenMeta(flip.Meta),
|
||||
"flipgroup_id": flip.ID,
|
||||
"account_id": flip.AccountID,
|
||||
"client_ids": flip.ClientIDs,
|
||||
"client_type": flip.ClientType,
|
||||
"conn_id": flip.ConnID,
|
||||
"conn_type": flip.ConnType,
|
||||
"default_gw": flip.DefaultGW,
|
||||
"description": flip.Description,
|
||||
"gid": flip.GID,
|
||||
"guid": flip.GUID,
|
||||
"ip": flip.IP,
|
||||
"milestones": flip.Milestones,
|
||||
"name": flip.Name,
|
||||
"net_id": flip.NetID,
|
||||
"net_type": flip.NetType,
|
||||
"net_mask": flip.NetMask,
|
||||
"status": flip.Status,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +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>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
)
|
||||
|
||||
func existAccountID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
accountId := uint64(d.Get("account_id").(int))
|
||||
req := account.ListRequest{}
|
||||
|
||||
accountList, err := c.CloudBroker().Account().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return len(accountList.FilterByID(accountId).Data) != 0, nil
|
||||
}
|
||||
|
||||
func existNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
netID := uint64(d.Get("net_id").(int))
|
||||
req := vins.ListRequest {}
|
||||
|
||||
vinsList, err := c.CloudBroker().VINS().List(ctx, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return len(vinsList.FilterByID(netID).Data) != 0, nil
|
||||
}
|
||||
364
internal/service/cloudbroker/flipgroup/resource_flipgroup.go
Normal file
364
internal/service/cloudbroker/flipgroup/resource_flipgroup.go
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
|
||||
"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"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func resourceFlipgroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceFlipgroupCreate called with name: %s, accountID %v", d.Get("name").(string), d.Get("account_id").(int))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := flipgroup.CreateRequest{
|
||||
Name: d.Get("name").(string),
|
||||
NetType: d.Get("net_type").(string),
|
||||
ClientType: d.Get("client_type").(string),
|
||||
}
|
||||
|
||||
haveAccount, err := existAccountID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveAccount {
|
||||
return diag.Errorf("resourceFlipgroupCreate: can't create Flipgroup because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
|
||||
}
|
||||
req.AccountID = uint64(d.Get("account_id").(int))
|
||||
|
||||
haveVINS, err := existNetID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveVINS {
|
||||
return diag.Errorf("resourceFlipgroupCreate: can't create Flipgroup because VinsID %d is not allowed or does not exist", d.Get("net_id").(int))
|
||||
}
|
||||
req.NetID = uint64(d.Get("net_id").(int))
|
||||
|
||||
if IP, ok := d.GetOk("ip"); ok {
|
||||
req.IP = IP.(string)
|
||||
}
|
||||
if description, ok := d.GetOk("desc"); ok {
|
||||
req.Description = description.(string)
|
||||
}
|
||||
|
||||
resp, err := c.CloudBroker().FLIPGroup().Create(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(fmt.Sprint(resp.ID))
|
||||
|
||||
var warnings dc.Warnings
|
||||
|
||||
if client_ids, ok := d.GetOk("client_ids"); ok {
|
||||
casted := client_ids.([]interface{})
|
||||
addComputesAfterCreation(ctx, &warnings, c, casted, resp.ID)
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceFlipgroupRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceFlipgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenFlipgroup(d, fg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceFlipgroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceFlipgroupUpdate called with id: %v", d.Get("flipgroup_id").(int))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
haveAccount, err := existAccountID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveAccount {
|
||||
return diag.Errorf("resourceFlipgroupUpdate: can't update Flipgroup because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
|
||||
}
|
||||
haveVINS, err := existNetID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
if !haveVINS {
|
||||
return diag.Errorf("resourceFlipgroupUpdate: can't update Flipgroup because VinsID %d is not allowed or does not exist", d.Get("net_id").(int))
|
||||
}
|
||||
|
||||
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
var warnings dc.Warnings
|
||||
basicUpdate := false
|
||||
req := flipgroup.EditRequest{FLIPGroupID: fg.ID}
|
||||
|
||||
if d.HasChange("desc") {
|
||||
req.Description = d.Get("desc").(string)
|
||||
basicUpdate = true
|
||||
}
|
||||
|
||||
if d.HasChange("name") {
|
||||
req.Name = d.Get("name").(string)
|
||||
basicUpdate = true
|
||||
}
|
||||
|
||||
if basicUpdate {
|
||||
_, err := c.CloudBroker().FLIPGroup().Edit(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("client_ids") {
|
||||
handleClientIDsUpdate(ctx, d, c, fg, &warnings)
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceFlipgroupRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceFlipgroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceFlipgroupDelete called with id: %v", d.Get("flipgroup_id").(int))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := flipgroup.DeleteRequest{
|
||||
FLIPGroupID: fg.ID,
|
||||
}
|
||||
|
||||
_, err = c.CloudBroker().FLIPGroup().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Account ID",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Flipgroup name",
|
||||
},
|
||||
"net_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "EXTNET or ViNS ID",
|
||||
},
|
||||
"net_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, true),
|
||||
Description: "Network type, EXTNET or VINS",
|
||||
},
|
||||
"client_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Type of client, 'compute' ('vins' will be later)",
|
||||
ValidateFunc: validation.StringInSlice([]string{"compute"}, true),
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "IP address to associate with this group. If empty, the platform will autoselect IP address",
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Text description of this Flipgroup instance",
|
||||
},
|
||||
"client_ids": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
Description: "List of clients attached to this Flipgroup instance",
|
||||
},
|
||||
"client_names": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
Description: "client_names",
|
||||
},
|
||||
"account_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "account_name",
|
||||
},
|
||||
"flipgroup_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"conn_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"conn_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "created_by",
|
||||
},
|
||||
"created_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "created_time",
|
||||
},
|
||||
"default_gw": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "deleted_by",
|
||||
},
|
||||
"deleted_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "deleted_time",
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"network": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "network",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "rg_id",
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "rg_name",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "updated_by",
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "updated_time",
|
||||
},
|
||||
"net_mask": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"ckey": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func ResourceFlipgroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
CreateContext: resourceFlipgroupCreate,
|
||||
ReadContext: resourceFlipgroupRead,
|
||||
UpdateContext: resourceFlipgroupUpdate,
|
||||
DeleteContext: resourceFlipgroupDelete,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout300s,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout300s,
|
||||
Delete: &constants.Timeout300s,
|
||||
Default: &constants.Timeout300s,
|
||||
},
|
||||
|
||||
Schema: resourceFlipgroupSchemaMake(),
|
||||
}
|
||||
}
|
||||
66
internal/service/cloudbroker/flipgroup/utility_flipgroup.go
Normal file
66
internal/service/cloudbroker/flipgroup/utility_flipgroup.go
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityFlipgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.RecordFLIPGroup, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := flipgroup.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.FLIPGroupID = id
|
||||
} else {
|
||||
req.FLIPGroupID = uint64(d.Get("flipgroup_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityDiskCheckPresence: load disk")
|
||||
flipgroup, err := c.CloudBroker().FLIPGroup().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return flipgroup, nil
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityFlipgroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*flipgroup.ListFLIPGroups, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := flipgroup.ListRequest{}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
if vinsId, ok := d.GetOk("vins_id"); ok {
|
||||
req.VINSID = uint64(vinsId.(int))
|
||||
}
|
||||
if vinsName, ok := d.GetOk("vins_name"); ok {
|
||||
req.VINSName = vinsName.(string)
|
||||
}
|
||||
if extnetId, ok := d.GetOk("extnet_id"); ok {
|
||||
req.ExtNetID = uint64(extnetId.(int))
|
||||
}
|
||||
if byIp, ok := d.GetOk("by_ip"); ok {
|
||||
req.ByIP = byIp.(string)
|
||||
}
|
||||
if rgId, ok := d.GetOk("rg_id"); ok {
|
||||
req.RGID = uint64(rgId.(int))
|
||||
}
|
||||
if byID, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(byID.(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("utilityFlipgroupListCheckPresence: load flipgroup list")
|
||||
flipgroupList, err := c.CloudBroker().FLIPGroup().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return flipgroupList, nil
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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>
|
||||
Tim Tkachev, <tvtkachev@basistech.ru>
|
||||
Sergey Kisil, <svkisil@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 flipgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
)
|
||||
|
||||
func addComputesAfterCreation(ctx context.Context, warnings *dc.Warnings, c *controller.ControllerCfg, compute_ids []interface{}, flipgroupID uint64) {
|
||||
if len(compute_ids) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
log.Debugf("Adding %v computes to flipgroup [id=%v]...", len(compute_ids), flipgroupID)
|
||||
|
||||
for _, elem := range compute_ids {
|
||||
compute_id := uint64(elem.(int))
|
||||
req := flipgroup.ComputeAddRequest{
|
||||
FLIPGroupID: flipgroupID,
|
||||
ComputeID: compute_id,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().FLIPGroup().ComputeAdd(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleClientIDsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, fg *flipgroup.RecordFLIPGroup, warn *dc.Warnings) {
|
||||
addedClients := make([]interface{}, 0)
|
||||
removedClients := make([]interface{}, 0)
|
||||
|
||||
old_set, new_set := d.GetChange("client_ids")
|
||||
oldSlice := old_set.([]interface{})
|
||||
newSlice := new_set.([]interface{})
|
||||
|
||||
for _, oldElem := range oldSlice {
|
||||
if !containsClient(newSlice, oldElem) {
|
||||
removedClients = append(removedClients, oldElem)
|
||||
}
|
||||
}
|
||||
|
||||
for _, newElem := range newSlice {
|
||||
if !containsClient(oldSlice, newElem) {
|
||||
addedClients = append(addedClients, newElem)
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("Found client_ids change with %v deletion(s) and %v addition(s) [flipgroupID=%v]", len(removedClients), len(addedClients), fg.ID)
|
||||
|
||||
if len(addedClients) > 0 {
|
||||
for _, id := range addedClients {
|
||||
req := flipgroup.ComputeAddRequest{
|
||||
FLIPGroupID: fg.ID,
|
||||
ComputeID: uint64(id.(int)),
|
||||
}
|
||||
|
||||
if _, err := c.CloudBroker().FLIPGroup().ComputeAdd(ctx, req); err != nil {
|
||||
warn.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(removedClients) > 0 {
|
||||
for _, id := range removedClients {
|
||||
req := flipgroup.ComputeRemoveRequest{
|
||||
FLIPGroupID: fg.ID,
|
||||
ComputeID: uint64(id.(int)),
|
||||
}
|
||||
|
||||
if _, err := c.CloudBroker().FLIPGroup().ComputeRemove(ctx, req); err != nil {
|
||||
warn.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func containsClient(set []interface{}, check interface{}) bool {
|
||||
for _, elem := range set {
|
||||
elemConv := elem.(int)
|
||||
checkConv := check.(int)
|
||||
if elemConv == checkConv {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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/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 dataSourceGridGetDiagnosisRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
diagnosis, err := utilityGridGetDiagnosisCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(d.Id())
|
||||
d.Set("diagnosis", diagnosis)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridGetDiagnosisSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"diagnosis": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceGridGetDiagnosis() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceGridGetDiagnosisRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridGetDiagnosisSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceGridPostDiagnosisRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
diagnosis, err := utilityGridPostDiagnosisCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(d.Id())
|
||||
d.Set("diagnosis", diagnosis)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridPostDiagnosisSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"diagnosis": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceGridPostDiagnosis() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceGridPostDiagnosisRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridPostDiagnosisSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 dataSourceGridGetStatusRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
grid, err := utilityGridGetStatusCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("status", grid)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridGetStatusSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"status": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceGridGetStatus() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceGridGetStatusRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridGetStatusSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceGridPostStatusRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
grid, err := utilityGridPostStatusCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("status", grid)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridPostStatusSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"status": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceGridPostStatus() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceGridPostStatusRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridPostStatusSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -48,12 +48,22 @@ func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m inter
|
||||
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,
|
||||
@@ -72,6 +82,11 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
|
||||
Schema: dataSourceGridSchemaMake(),
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry count",
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
@@ -79,6 +94,134 @@ func dataSourceGridListSchemaMake() map[string]*schema.Schema {
|
||||
|
||||
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,
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 dataSourceGridListEmailsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
gridListEmails, err := utilityGridListEmailsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", gridListEmails.Data)
|
||||
d.Set("entry_count", gridListEmails.EntryCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridListEmailsSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"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 emails",
|
||||
Elem: &schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry count",
|
||||
},
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func DataSourceGridListEmails() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceGridListEmailsRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridListEmailsSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 dataSourceGridGetConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
gridGetConsumption, err := utilityGridGetConsumptionCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId(strconv.FormatUint(gridGetConsumption.GID, 10))
|
||||
d.Set("consumed", flattenGridRecordResource(gridGetConsumption.Consumed))
|
||||
d.Set("reserved", flattenGridRecordResource(gridGetConsumption.Reserved))
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridGetConsumptionSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"grid_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
"consumed": {
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceGridGetConsumption() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceGridGetConsumptionRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridGetConsumptionSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 dataSourceGridListConsumptionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
gridListConsumption, err := utilityGridListConsumptionCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenGridListConsumption(gridListConsumption))
|
||||
d.Set("entry_count", gridListConsumption.EntryCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceGridListConsumptionSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "grid list consumption",
|
||||
Elem: &schema.Resource{
|
||||
Schema: dataSourceGridConsumptionSchemaMake(),
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry count",
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
func dataSourceGridConsumptionSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"consumed": {
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceGridListConsumption() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceGridListConsumptionRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceGridListConsumptionSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,10 @@ func flattenGrid(d *schema.ResourceData, grid *grid.RecordGrid) {
|
||||
}
|
||||
|
||||
func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(gl.Data))
|
||||
for _, item := range gl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"resources": flattenGridResources(item.Resources),
|
||||
"name": item.Name,
|
||||
"flag": item.Flag,
|
||||
"gid": item.GID,
|
||||
@@ -25,8 +26,62 @@ func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
|
||||
"location_code": item.LocationCode,
|
||||
"id": item.ID,
|
||||
}
|
||||
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenGridListConsumption(gl *grid.ListResourceConsumption) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(gl.Data))
|
||||
for _, item := range gl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"consumed": flattenGridRecordResource(item.Consumed),
|
||||
"reserved": flattenGridRecordResource(item.Reserved),
|
||||
"id": item.GID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenGridResources(r grid.Resources) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"current": flattenGridRecordResource(r.Current),
|
||||
"reserved": flattenGridRecordResource(r.Reserved),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenGridRecordResource(rr grid.RecordResource) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": rr.CPU,
|
||||
"disk_size": rr.DiskSize,
|
||||
"disk_size_max": rr.DiskSizeMax,
|
||||
"ext_ips": rr.ExtIPs,
|
||||
"ext_traffic": rr.ExtTraffic,
|
||||
"gpu": rr.GPU,
|
||||
"ram": rr.RAM,
|
||||
"seps": flattenGridSeps(rr.SEPs),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenGridSeps(seps map[string]map[string]grid.DiskUsage) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
for sepKey, sepVal := range seps {
|
||||
for dataKey, dataVal := range sepVal {
|
||||
temp := map[string]interface{}{
|
||||
"sep_id": sepKey,
|
||||
"data_name": dataKey,
|
||||
"disk_size": dataVal.DiskSize,
|
||||
"disk_size_max": dataVal.DiskSizeMax,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -33,7 +33,7 @@ package grid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
|
||||
@@ -46,10 +46,11 @@ func utilityGridCheckPresence(ctx context.Context, d *schema.ResourceData, m int
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := grid.GetRequest{}
|
||||
|
||||
if gridId, ok := d.GetOk("grid_id"); ok {
|
||||
req.GID = uint64(gridId.(int))
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.GID = id
|
||||
} else {
|
||||
return nil, errors.New("grid_id is required")
|
||||
req.GID = uint64(d.Get("grid_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityGridCheckPresence: load grid")
|
||||
|
||||
@@ -1,46 +1,64 @@
|
||||
/*
|
||||
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 kvmvm
|
||||
|
||||
const KvmX86CreateAPI = "/restmachine/cloudbroker/kvmx86/create"
|
||||
const KvmPPCCreateAPI = "/restmachine/cloudbroker/kvmppc/create"
|
||||
const ComputeGetAPI = "/restmachine/cloudbroker/compute/get"
|
||||
const RgListComputesAPI = "/restmachine/cloudbroker/rg/listComputes"
|
||||
const ComputeNetAttachAPI = "/restmachine/cloudbroker/compute/netAttach"
|
||||
const ComputeNetDetachAPI = "/restmachine/cloudbroker/compute/netDetach"
|
||||
const ComputeDiskAttachAPI = "/restmachine/cloudbroker/compute/diskAttach"
|
||||
const ComputeDiskDetachAPI = "/restmachine/cloudbroker/compute/diskDetach"
|
||||
const ComputeStartAPI = "/restmachine/cloudbroker/compute/start"
|
||||
const ComputeStopAPI = "/restmachine/cloudbroker/compute/stop"
|
||||
const ComputeResizeAPI = "/restmachine/cloudbroker/compute/resize"
|
||||
const DisksResizeAPI = "/restmachine/cloudbroker/disks/resize2"
|
||||
const ComputeDeleteAPI = "/restmachine/cloudbroker/compute/delete"
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 utilityGridGetConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.RecordResourcesConsumption, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := grid.GetResourceConsumptionRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.GridID = id
|
||||
} else {
|
||||
req.GridID = uint64(d.Get("grid_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityGridGetConsumptionCheckPresence: load specific grid")
|
||||
gridGetConsumption, err := c.CloudBroker().Grid().GetResourceConsumption(ctx,req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return gridGetConsumption, nil
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 utilityGridGetDiagnosisCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := grid.GetDiagnosisRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.GID = id
|
||||
} else {
|
||||
req.GID = uint64(d.Get("gid").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
|
||||
gridGetDiagnosis, err := c.CloudBroker().Grid().GetDiagnosisGET(ctx, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return gridGetDiagnosis, nil
|
||||
}
|
||||
|
||||
func utilityGridPostDiagnosisCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := grid.GetDiagnosisRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.GID = id
|
||||
} else {
|
||||
req.GID = uint64(d.Get("gid").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
|
||||
gridPostDiagnosis, err := c.CloudBroker().Grid().GetDiagnosis(ctx, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return gridPostDiagnosis, nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityGridGetStatusCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
|
||||
gridGetStatus, err := c.CloudBroker().Grid().StatusGET(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return gridGetStatus, nil
|
||||
}
|
||||
|
||||
func utilityGridPostStatusCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
|
||||
gridGetStatus, err := c.CloudBroker().Grid().Status(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return gridGetStatus, nil
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
@@ -45,6 +45,12 @@ func utilityGridListCheckPresence(ctx context.Context, d *schema.ResourceData, m
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := grid.ListRequest{}
|
||||
|
||||
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 page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
|
||||
@@ -0,0 +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>
|
||||
Sergey Kisil, <svkisil@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"
|
||||
|
||||
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 utilityGridListEmailsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.ListEmails, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := grid.ListEmailsRequest{}
|
||||
|
||||
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("utilityGridListEmailsCheckPresence: load grid list of emails")
|
||||
gridListEmails, err := c.CloudBroker().Grid().ListEmails(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return gridListEmails, nil
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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"
|
||||
|
||||
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 utilityGridListConsumptionCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.ListResourceConsumption, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debugf("utilityGridListConsumptionCheckPresence: load grid list consumption")
|
||||
gridListConsumption, err := c.CloudBroker().Grid().ListResourceConsumption(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return gridListConsumption, nil
|
||||
}
|
||||
162
internal/service/cloudbroker/ic/input_checks.go
Normal file
162
internal/service/cloudbroker/ic/input_checks.go
Normal file
@@ -0,0 +1,162 @@
|
||||
// Input checks
|
||||
package ic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
cb_extnet "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
cb_gid "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
|
||||
cb_image "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
|
||||
cb_rg "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
|
||||
cb_stack "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
|
||||
cb_vins "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func ExistRG(ctx context.Context, rgId uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_rg.ListRequest{
|
||||
ByID: rgId,
|
||||
IncludeDeleted: false,
|
||||
}
|
||||
|
||||
rgList, err := c.CloudBroker().RG().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(rgList.Data) == 0 {
|
||||
return fmt.Errorf("RG with id %v not found", rgId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistImage(ctx context.Context, imageId uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_image.ListRequest{
|
||||
ByID: imageId,
|
||||
}
|
||||
|
||||
listImages, err := c.CloudBroker().Image().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(listImages.Data) == 0 {
|
||||
return fmt.Errorf("image with id %v not found", imageId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistVinses(ctx context.Context, vinsIds []uint64, c *controller.ControllerCfg) []error {
|
||||
var errs []error
|
||||
|
||||
req := cb_vins.ListRequest{
|
||||
IncludeDeleted: false,
|
||||
}
|
||||
|
||||
vinsList, err := c.CloudBroker().VINS().List(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return errs
|
||||
}
|
||||
|
||||
for _, vinsId := range vinsIds {
|
||||
found := false
|
||||
|
||||
for _, vins := range vinsList.Data {
|
||||
if vinsId == vins.ID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
errs = append(errs, fmt.Errorf("VINS with ID %v not found", vinsId))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func ExistExtNets(ctx context.Context, extNetIds []uint64, c *controller.ControllerCfg) []error {
|
||||
var errs []error
|
||||
|
||||
req := cb_extnet.ListRequest{}
|
||||
|
||||
extNetList, err := c.CloudBroker().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return errs
|
||||
}
|
||||
|
||||
for _, extNetId := range extNetIds {
|
||||
found := false
|
||||
|
||||
for _, extNet := range extNetList.Data {
|
||||
if extNetId == extNet.ID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
errs = append(errs, fmt.Errorf("EXTNET with ID %v not found", extNetId))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func ExistExtNet(ctx context.Context, extNetId uint64, c *controller.ControllerCfg) error {
|
||||
|
||||
req := cb_extnet.ListRequest{
|
||||
ByID: extNetId,
|
||||
}
|
||||
|
||||
extNetList, err := c.CloudBroker().ExtNet().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(extNetList.Data) == 0 {
|
||||
return fmt.Errorf("EXTNET with ID %v not found", extNetId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistGID(ctx context.Context, gid uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_gid.ListRequest{}
|
||||
|
||||
gridList, err := c.CloudBroker().Grid().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, grid := range gridList.Data {
|
||||
if grid.GID == gid {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("GID with id %v not found", gid)
|
||||
}
|
||||
|
||||
func ExistStack(ctx context.Context, stackId uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_stack.ListRequest{
|
||||
ByID: stackId,
|
||||
}
|
||||
|
||||
stackList, err := c.CloudBroker().Stack().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(stackList.Data) == 0 {
|
||||
return fmt.Errorf("stack with id %v not found", stackList)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -76,17 +76,6 @@ func parseComputeDisksToExtraDisks(disks compute.ListDisks) []interface{} {
|
||||
return result
|
||||
}
|
||||
|
||||
func findBootDisk(disks compute.ListDisks) *compute.ItemDisk {
|
||||
for _, d := range disks {
|
||||
if d.Type == "B" {
|
||||
return &d
|
||||
}
|
||||
}
|
||||
|
||||
// some computes don't have a boot disk, so...
|
||||
return &compute.ItemDisk{}
|
||||
}
|
||||
|
||||
// Parse the list of interfaces from compute/get response into a list of networks
|
||||
// attached to this compute
|
||||
func parseComputeInterfacesToNetworks(ifaces compute.ListInterfaces) []interface{} {
|
||||
@@ -113,7 +102,7 @@ func parseComputeInterfacesToNetworks(ifaces compute.ListInterfaces) []interface
|
||||
return result
|
||||
}
|
||||
|
||||
func flattenCompute(d *schema.ResourceData, compFacts *compute.RecordCompute) error {
|
||||
func flattenDataCompute(d *schema.ResourceData, compFacts *compute.RecordCompute) error {
|
||||
// This function expects that compFacts string contains response from API compute/get,
|
||||
// i.e. detailed information about compute instance.
|
||||
//
|
||||
@@ -179,7 +168,7 @@ func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interf
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if err = flattenCompute(d, compFacts); err != nil {
|
||||
if err = flattenDataCompute(d, compFacts); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -297,15 +286,15 @@ func DataSourceCompute() *schema.Resource {
|
||||
},
|
||||
*/
|
||||
|
||||
"network": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
MaxItems: constants.MaxNetworksPerCompute,
|
||||
Elem: &schema.Resource{
|
||||
Schema: networkSubresourceSchemaMake(),
|
||||
},
|
||||
Description: "Network connection(s) for this compute.",
|
||||
},
|
||||
// "network": {
|
||||
// Type: schema.TypeSet,
|
||||
// Optional: true,
|
||||
// MaxItems: constants.MaxNetworksPerCompute,
|
||||
// Elem: &schema.Resource{
|
||||
// Schema: networkSubresourceSchemaMake(),
|
||||
// },
|
||||
// Description: "Network connection(s) for this compute.",
|
||||
// },
|
||||
|
||||
"os_users": {
|
||||
Type: schema.TypeList,
|
||||
|
||||
219
internal/service/cloudbroker/kvmvm/flattens.go
Normal file
219
internal/service/cloudbroker/kvmvm/flattens.go
Normal file
@@ -0,0 +1,219 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
|
||||
)
|
||||
|
||||
func flattenCompute(d *schema.ResourceData, computeRec *compute.RecordCompute) error {
|
||||
log.Debugf("flattenCompute: ID %d, RG ID %d", computeRec.ID, computeRec.RGID)
|
||||
|
||||
customFields, _ := json.Marshal(computeRec.CustomFields)
|
||||
devices, _ := json.Marshal(computeRec.Devices)
|
||||
|
||||
bootDisk := findBootDisk(computeRec.Disks)
|
||||
|
||||
d.Set("account_id", computeRec.AccountID)
|
||||
d.Set("account_name", computeRec.AccountName)
|
||||
d.Set("affinity_label", computeRec.AffinityLabel)
|
||||
d.Set("affinity_weight", computeRec.AffinityWeight)
|
||||
d.Set("affinity_rules", flattenAffinityRules(computeRec.AffinityRules))
|
||||
d.Set("anti_affinity_rules", flattenAffinityRules(computeRec.AntiAffinityRules))
|
||||
d.Set("arch", computeRec.Arch)
|
||||
d.Set("boot_order", computeRec.BootOrder)
|
||||
d.Set("boot_disk_size", computeRec.BootDiskSize)
|
||||
d.Set("clone_reference", computeRec.CloneReference)
|
||||
d.Set("clones", computeRec.Clones)
|
||||
d.Set("computeci_id", computeRec.ComputeCIID)
|
||||
d.Set("created_by", computeRec.CreatedBy)
|
||||
d.Set("created_time", computeRec.CreatedTime)
|
||||
d.Set("custom_fields", string(customFields))
|
||||
d.Set("deleted_by", computeRec.DeletedBy)
|
||||
d.Set("deleted_time", computeRec.DeletedTime)
|
||||
d.Set("description", computeRec.Description)
|
||||
d.Set("devices", string(devices))
|
||||
d.Set("disks",
|
||||
flattenComputeDisks(
|
||||
computeRec.Disks,
|
||||
d.Get("extra_disks").(*schema.Set).List(),
|
||||
bootDisk.ID,
|
||||
),
|
||||
)
|
||||
d.Set("gid", computeRec.GID)
|
||||
d.Set("guid", computeRec.GUID)
|
||||
d.Set("compute_id", computeRec.ID)
|
||||
d.Set("image_id", computeRec.ImageID)
|
||||
d.Set("interfaces", flattenInterfaces(computeRec.Interfaces))
|
||||
d.Set("lock_status", computeRec.LockStatus)
|
||||
d.Set("manager_id", computeRec.ManagerID)
|
||||
d.Set("manager_type", computeRec.ManagerType)
|
||||
d.Set("migrationjob", computeRec.MigrationJob)
|
||||
d.Set("milestones", computeRec.Milestones)
|
||||
d.Set("os_users", flattenOSUsers(computeRec.OSUsers))
|
||||
d.Set("pinned", computeRec.Pinned)
|
||||
d.Set("reference_id", computeRec.ReferenceID)
|
||||
d.Set("registered", computeRec.Registered)
|
||||
d.Set("res_name", computeRec.ResName)
|
||||
d.Set("rg_name", computeRec.RGName)
|
||||
d.Set("snap_sets", flattenSnapSets(computeRec.SnapSets))
|
||||
d.Set("stack_id", computeRec.StackID)
|
||||
d.Set("stack_name", computeRec.StackName)
|
||||
d.Set("stateless_sep_id", computeRec.StatelessSEPID)
|
||||
d.Set("stateless_sep_type", computeRec.StatelessSEPType)
|
||||
d.Set("status", computeRec.Status)
|
||||
d.Set("tags", flattenTags(computeRec.Tags))
|
||||
d.Set("tech_status", computeRec.TechStatus)
|
||||
d.Set("updated_by", computeRec.UpdatedBy)
|
||||
d.Set("updated_time", computeRec.UpdatedTime)
|
||||
d.Set("user_managed", computeRec.UserManaged)
|
||||
d.Set("vgpus", computeRec.VGPUs)
|
||||
d.Set("virtual_image_id", computeRec.VirtualImageID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenTags(tags map[string]interface{}) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(tags))
|
||||
|
||||
for k, v := range tags {
|
||||
res = append(res, map[string]interface{}{
|
||||
"key": k,
|
||||
"val": v,
|
||||
})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSnapSets(snaps compute.ListSnapshots) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(snaps))
|
||||
|
||||
for _, snap := range snaps {
|
||||
res = append(res, map[string]interface{}{
|
||||
"disks": snap.Disks,
|
||||
"guid": snap.GUID,
|
||||
"label": snap.Label,
|
||||
"timestamp": snap.Timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenOSUsers(users compute.ListOSUsers) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(users))
|
||||
|
||||
for _, user := range users {
|
||||
res = append(res, map[string]interface{}{
|
||||
"guid": user.GUID,
|
||||
"login": user.Login,
|
||||
"password": user.Password,
|
||||
"public_key": user.PubKey,
|
||||
})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenInterfaces(ifaces compute.ListInterfaces) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(ifaces))
|
||||
|
||||
for _, iface := range ifaces {
|
||||
res = append(res, map[string]interface{}{
|
||||
"conn_id": iface.ConnID,
|
||||
"conn_type": iface.ConnType,
|
||||
"def_gw": iface.DefGW,
|
||||
"flip_group_id": iface.FLIPGroupID,
|
||||
"guid": iface.GUID,
|
||||
"ip_address": iface.IPAddress,
|
||||
"listen_ssh": iface.ListenSSH,
|
||||
"mac": iface.MAC,
|
||||
"name": iface.Name,
|
||||
"net_id": iface.NetID,
|
||||
"netmask": iface.NetMask,
|
||||
"net_type": iface.NetType,
|
||||
"pci_slot": iface.PCISlot,
|
||||
"qos": flattenQOS(iface.QOS),
|
||||
"target": iface.Target,
|
||||
"type": iface.Type,
|
||||
"vnfs": iface.VNFs,
|
||||
})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenQOS(qos compute.QOS) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"e_rate": qos.ERate,
|
||||
"guid": qos.GUID,
|
||||
"in_brust": qos.InBurst,
|
||||
"in_rate": qos.InRate,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenComputeDisks(disksList compute.ListDisks, extraDisks []interface{}, bootDiskId uint64) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(disksList))
|
||||
for _, disk := range disksList {
|
||||
if disk.ID == bootDiskId || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
|
||||
continue
|
||||
}
|
||||
temp := map[string]interface{}{
|
||||
"disk_name": disk.Name,
|
||||
"size": disk.SizeMax,
|
||||
"sep_id": disk.SEPID,
|
||||
"disk_type": disk.Type,
|
||||
"pool": disk.Pool,
|
||||
"desc": disk.Description,
|
||||
"image_id": disk.ImageID,
|
||||
"disk_id": disk.ID,
|
||||
"shareable": disk.Shareable,
|
||||
"size_used": disk.SizeUsed,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
func findInExtraDisks(diskId uint, extraDisks []interface{}) bool {
|
||||
for _, ExtraDisk := range extraDisks {
|
||||
if diskId == uint(ExtraDisk.(int)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func findBootDisk(disks compute.ListDisks) *compute.ItemDisk {
|
||||
for _, disk := range disks {
|
||||
if disk.Type == "B" {
|
||||
return &disk
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func flattenAffinityRules(rules compute.ListRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(rules))
|
||||
|
||||
for _, rule := range rules {
|
||||
res = append(res, map[string]interface{}{
|
||||
"topology": rule.Topology,
|
||||
"policy": rule.Policy,
|
||||
"mode": rule.Mode,
|
||||
"key": rule.Key,
|
||||
"value": rule.Value,
|
||||
})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
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 kvmvm
|
||||
|
||||
type DiskRecord struct {
|
||||
Acl map[string]interface{} `json:"acl"`
|
||||
AccountID int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BootPartition int `json:"bootPartition"`
|
||||
CreatedTime uint64 `json:"creationTime"`
|
||||
ComputeID int `json:"computeId"`
|
||||
ComputeName string `json:"computeName"`
|
||||
DeletedTime uint64 `json:"deletionTime"`
|
||||
DeviceName string `json:"devicename"`
|
||||
Desc string `json:"desc"`
|
||||
DestructionTime uint64 `json:"destructionTime"`
|
||||
DiskPath string `json:"diskPath"`
|
||||
GridID int `json:"gid"`
|
||||
GUID int `json:"guid"`
|
||||
ID uint `json:"id"`
|
||||
ImageID int `json:"imageId"`
|
||||
Images []int `json:"images"`
|
||||
IOTune map[string]interface{} `json:"iotune"`
|
||||
IQN string `json:"iqn"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
MachineId int `json:"machineId"`
|
||||
MachineName string `json:"machineName"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Order int `json:"order"`
|
||||
Params string `json:"params"`
|
||||
Passwd string `json:"passwd"`
|
||||
ParentId int `json:"parentId"`
|
||||
PciSlot int `json:"pciSlot"`
|
||||
Pool string `json:"pool"`
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
RealityDeviceNumber int `json:"realityDeviceNumber"`
|
||||
ReferenceId string `json:"referenceId"`
|
||||
ResID string `json:"resId"`
|
||||
ResName string `json:"resName"`
|
||||
Role string `json:"role"`
|
||||
SepType string `json:"sepType"`
|
||||
SepID int `json:"sepId"` // NOTE: absent from compute/get output
|
||||
SizeMax int `json:"sizeMax"`
|
||||
SizeUsed float64 `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space
|
||||
Snapshots []SnapshotRecord `json:"snapshots"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
UpdateBy uint64 `json:"updateBy"`
|
||||
VMID int `json:"vmid"`
|
||||
}
|
||||
|
||||
type InterfaceRecord struct {
|
||||
ConnID int `json:"connId"` // This is VLAN ID or VxLAN ID, depending on ConnType
|
||||
ConnType string `json:"connType"` // Either "VLAN" or "VXLAN" tag
|
||||
DefaultGW string `json:"defGw"`
|
||||
Guid string `json:"guid"`
|
||||
IPAddress string `json:"ipAddress"` // without trailing network mask, i.e. "192.168.1.3"
|
||||
MAC string `json:"mac"`
|
||||
Name string `json:"name"`
|
||||
NetID int `json:"netId"` // This is either ExtNet ID or ViNS ID, depending on NetType
|
||||
NetMask int `json:"netMask"`
|
||||
NetType string `json:"netType"` // Either "EXTNET" or "VINS" tag
|
||||
PciSlot int `json:"pciSlot"`
|
||||
Target string `json:"target"`
|
||||
Type string `json:"type"`
|
||||
VNFs []int `json:"vnfs"`
|
||||
QOS InterfaceQosRecord `json:"qos"`
|
||||
}
|
||||
|
||||
type InterfaceQosRecord struct {
|
||||
ERate int `json:"eRate"`
|
||||
Guid string `json:"guid"`
|
||||
InBurst int `json:"inBurst"`
|
||||
InRate int `json:"inRate"`
|
||||
}
|
||||
|
||||
type SnapshotRecord struct {
|
||||
Guid string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
ResId string `json:"resId"`
|
||||
SnapSetGuid string `json:"snapSetGuid"`
|
||||
SnapSetTime uint64 `json:"snapSetTime"`
|
||||
TimeStamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type SnapshotRecordList []SnapshotRecord
|
||||
|
||||
type ComputeGetResp struct {
|
||||
// ACLs `json:"ACL"` - it is a dictionary, special parsing required
|
||||
AccountID int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Arch string `json:"arch"`
|
||||
BootDiskSize int `json:"bootdiskSize"`
|
||||
CloneReference int `json:"cloneReference"`
|
||||
Clones []int `json:"clones"`
|
||||
Cpu int `json:"cpus"`
|
||||
Desc string `json:"desc"`
|
||||
Disks []DiskRecord `json:"disks"`
|
||||
Driver string `json:"driver"`
|
||||
GridID int `json:"gid"`
|
||||
ID uint `json:"id"`
|
||||
ImageID int `json:"imageId"`
|
||||
ImageName string `json:"imageName"`
|
||||
Interfaces []InterfaceRecord `json:"interfaces"`
|
||||
LockStatus string `json:"lockStatus"`
|
||||
ManagerID int `json:"managerId"`
|
||||
ManagerType string `json:"manageType"`
|
||||
Name string `json:"name"`
|
||||
NatableVinsID int `json:"natableVinsId"`
|
||||
NatableVinsIP string `json:"natableVinsIp"`
|
||||
NatableVinsName string `json:"natableVinsName"`
|
||||
NatableVinsNet string `json:"natableVinsNetwork"`
|
||||
NatableVinsNetName string `json:"natableVinsNetworkName"`
|
||||
OsUsers []OsUserRecord `json:"osUsers"`
|
||||
Ram int `json:"ram"`
|
||||
RgID int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
SnapSets []SnapSetRecord `json:"snapSets"`
|
||||
Status string `json:"status"`
|
||||
// Tags []string `json:"tags"` // Tags were reworked since DECORT 3.7.1
|
||||
TechStatus string `json:"techStatus"`
|
||||
TotalDiskSize int `json:"totalDiskSize"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdateTime uint64 `json:"updateTime"`
|
||||
UserManaged bool `json:"userManaged"`
|
||||
Vgpus []int `json:"vgpus"`
|
||||
VinsConnected int `json:"vinsConnected"`
|
||||
VirtualImageID int `json:"virtualImageId"`
|
||||
}
|
||||
|
||||
type OsUserRecord struct {
|
||||
Guid string `json:"guid"`
|
||||
Login string `json:"login"`
|
||||
Password string `json:"password"`
|
||||
PubKey string `json:"pubkey"`
|
||||
}
|
||||
|
||||
type SnapSetRecord struct {
|
||||
Disks []int `json:"disks"`
|
||||
Guid string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
TimeStamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type ComputeBriefRecord struct { // this is a brief compute specifiaction as returned by API rg/listComputes
|
||||
// we do not even include here all fields as returned by this API, but only the most important that
|
||||
// are really necessary to identify and distinguish computes
|
||||
AccountID int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Name string `json:"name"`
|
||||
ID uint `json:"id"`
|
||||
RgID int `json:"rgId"`
|
||||
RgName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
}
|
||||
|
||||
type RgListComputesResp []ComputeBriefRecord
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
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 kvmvm
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"hash/fnv"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"sort"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
)
|
||||
|
||||
// This is subresource of compute resource used when creating/managing compute network connections
|
||||
|
||||
func networkSubresIPAddreDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool {
|
||||
if newVal != "" && newVal != oldVal {
|
||||
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=FALSE", key, oldVal, newVal)
|
||||
return false
|
||||
}
|
||||
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=TRUE", key, oldVal, newVal)
|
||||
return true // suppress difference
|
||||
}
|
||||
|
||||
// This function is based on the original Terraform SerializeResourceForHash found
|
||||
// in helper/schema/serialize.go
|
||||
// It skips network subresource attributes, which are irrelevant for identification
|
||||
// of unique network blocks
|
||||
func networkSubresourceSerialize(output *bytes.Buffer, val interface{}, resource *schema.Resource) {
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
|
||||
rs := resource.Schema
|
||||
m := val.(map[string]interface{})
|
||||
|
||||
keys := make([]string, 0, len(rs))
|
||||
allComputed := true
|
||||
|
||||
for k, val := range rs {
|
||||
if val.Optional || val.Required {
|
||||
allComputed = false
|
||||
}
|
||||
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
// explicitly ignore "ip_address" when hashing
|
||||
if k == "ip_address" {
|
||||
continue
|
||||
}
|
||||
|
||||
subSchema := rs[k]
|
||||
// Skip attributes that are not user-provided. Computed attributes
|
||||
// do not contribute to the hash since their ultimate value cannot
|
||||
// be known at plan/diff time.
|
||||
if !allComputed && !(subSchema.Required || subSchema.Optional) {
|
||||
continue
|
||||
}
|
||||
|
||||
output.WriteString(k)
|
||||
output.WriteRune(':')
|
||||
value := m[k]
|
||||
schema.SerializeValueForHash(output, value, subSchema)
|
||||
}
|
||||
}
|
||||
|
||||
// HashNetworkSubresource hashes network subresource of compute resource. It uses
|
||||
// specially designed networkSubresourceSerialize (see above) to make sure hashing
|
||||
// does not involve attributes that we deem irrelevant to the uniqueness of network
|
||||
// subresource definitions.
|
||||
// It is this function that should be specified as SchemaSetFunc when creating Set
|
||||
// from network subresource (e.g. in flattenCompute)
|
||||
//
|
||||
// This function is based on the original Terraform function HashResource from
|
||||
// helper/schema/set.go
|
||||
func HashNetworkSubresource(resource *schema.Resource) schema.SchemaSetFunc {
|
||||
return func(v interface{}) int {
|
||||
var serialized bytes.Buffer
|
||||
networkSubresourceSerialize(&serialized, v, resource)
|
||||
|
||||
hs := fnv.New32a()
|
||||
hs.Write(serialized.Bytes())
|
||||
return int(hs.Sum32())
|
||||
}
|
||||
}
|
||||
|
||||
func networkSubresourceSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"net_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: statefuncs.StateFuncToUpper,
|
||||
ValidateFunc: validation.StringInSlice([]string{"EXTNET", "VINS"}, false), // observe case while validating
|
||||
Description: "Type of the network for this connection, either EXTNET or VINS.",
|
||||
},
|
||||
|
||||
"net_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of the network for this connection.",
|
||||
},
|
||||
|
||||
"ip_address": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
|
||||
Description: "Optional IP address to assign to this connection. This IP should belong to the selected network and free for use.",
|
||||
},
|
||||
|
||||
"mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "MAC address associated with this connection. MAC address is assigned automatically.",
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
|
||||
)
|
||||
|
||||
func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
|
||||
errs := []error{}
|
||||
|
||||
if err := ic.ExistRG(ctx, uint64(d.Get("rg_id").(int)), c); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
if err := ic.ExistImage(ctx, uint64(d.Get("image_id").(int)), c); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
if netErrs := existNetworks(ctx, d, c); errs != nil {
|
||||
errs = append(errs, netErrs...)
|
||||
}
|
||||
|
||||
return dc.ErrorsToDiagnostics(errs)
|
||||
}
|
||||
|
||||
func existNetworks(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) []error {
|
||||
var errs []error
|
||||
var vinsIds, extNetIds []uint64
|
||||
|
||||
networksIface, ok := d.GetOk("network")
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
networkList := networksIface.(*schema.Set).List()
|
||||
for _, elem := range networkList {
|
||||
network := elem.(map[string]interface{})
|
||||
|
||||
switch network["net_type"].(string) {
|
||||
case "VINS":
|
||||
vinsIds = append(vinsIds, uint64(network["net_id"].(int)))
|
||||
case "EXTNET":
|
||||
extNetIds = append(extNetIds, uint64(network["net_id"].(int)))
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if vinsErrs := ic.ExistVinses(ctx, vinsIds, c); vinsErrs != nil {
|
||||
errs = append(errs, vinsErrs...)
|
||||
}
|
||||
|
||||
if extNetErrs := ic.ExistExtNets(ctx, extNetIds, c); extNetErrs != nil {
|
||||
errs = append(errs, extNetErrs...)
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -33,12 +33,10 @@ package kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
@@ -46,7 +44,6 @@ import (
|
||||
|
||||
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
computeID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta)
|
||||
|
||||
@@ -61,8 +58,9 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
}
|
||||
|
||||
for _, disk := range new_set.(*schema.Set).List() {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.DiskAttachRequest{
|
||||
ComputeID: computeID,
|
||||
ComputeID: computeId,
|
||||
DiskID: uint64(disk.(int)),
|
||||
}
|
||||
|
||||
@@ -84,32 +82,52 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
|
||||
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
|
||||
log.Debugf("utilityComputeExtraDisksConfigure: detach set has %d items for Compute ID %s", detach_set.Len(), d.Id())
|
||||
for _, diskId := range detach_set.List() {
|
||||
req := compute.DiskDetachRequest{
|
||||
ComputeID: computeID,
|
||||
DiskID: uint64(diskId.(int)),
|
||||
|
||||
if detach_set.Len() > 0 {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
stopReq := compute.StopRequest{
|
||||
ComputeID: computeId,
|
||||
Force: false,
|
||||
}
|
||||
_, err := c.CloudBroker().Compute().Stop(ctx, stopReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Compute().DiskDetach(ctx, req)
|
||||
for _, diskId := range detach_set.List() {
|
||||
req := compute.DiskDetachRequest{
|
||||
ComputeID: computeId,
|
||||
DiskID: uint64(diskId.(int)),
|
||||
}
|
||||
_, err := c.CloudBroker().Compute().DiskDetach(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to detach disk ID %d from Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
}
|
||||
}
|
||||
|
||||
req := compute.StartRequest{
|
||||
ComputeID: computeId,
|
||||
AltBootID: 0,
|
||||
}
|
||||
_, err = c.CloudBroker().Compute().Start(ctx, req)
|
||||
if err != nil {
|
||||
// failed to detach disk - there will be partial resource update
|
||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to detach disk ID %d from Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
|
||||
log.Debugf("utilityComputeExtraDisksConfigure: attach set has %d items for Compute ID %s", attach_set.Len(), d.Id())
|
||||
for _, diskId := range attach_set.List() {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.DiskAttachRequest{
|
||||
ComputeID: computeID,
|
||||
ComputeID: computeId,
|
||||
DiskID: uint64(diskId.(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Compute().DiskAttach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to attach disk - there will be partial resource update
|
||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
@@ -125,12 +143,50 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.RecordCompute, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := compute.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.ComputeID = computeId
|
||||
} else {
|
||||
req.ComputeID = uint64(d.Get("compute_id").(int))
|
||||
}
|
||||
|
||||
res, err := c.CloudBroker().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func networkSubresIPAddreDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool {
|
||||
if newVal != "" && newVal != oldVal {
|
||||
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=FALSE", key, oldVal, newVal)
|
||||
return false
|
||||
}
|
||||
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=TRUE", key, oldVal, newVal)
|
||||
return true // suppress difference
|
||||
}
|
||||
|
||||
func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool, skip_zero bool, computeID uint64) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
computeID, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
|
||||
old_set, new_set := d.GetChange("network")
|
||||
|
||||
req := compute.StopRequest{
|
||||
ComputeID: computeID,
|
||||
Force: true,
|
||||
}
|
||||
|
||||
log.Debugf("utilityComputeNetworksConfigure: stopping compute %d", computeID)
|
||||
_, err := c.CloudBroker().Compute().Stop(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
apiErrCount := 0
|
||||
var lastSavedError error
|
||||
|
||||
@@ -139,10 +195,14 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, runner := range new_set.(*schema.Set).List() {
|
||||
for i, runner := range new_set.(*schema.Set).List() {
|
||||
if i == 0 && skip_zero {
|
||||
continue
|
||||
}
|
||||
net_data := runner.(map[string]interface{})
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.NetAttachRequest{
|
||||
ComputeID: computeID,
|
||||
ComputeID: computeId,
|
||||
NetType: net_data["net_type"].(string),
|
||||
NetID: uint64(net_data["net_id"].(int)),
|
||||
}
|
||||
@@ -170,15 +230,15 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
log.Debugf("utilityComputeNetworksConfigure: detach set has %d items for Compute ID %s", detach_set.Len(), d.Id())
|
||||
for _, runner := range detach_set.List() {
|
||||
net_data := runner.(map[string]interface{})
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.NetDetachRequest{
|
||||
ComputeID: computeID,
|
||||
ComputeID: computeId,
|
||||
IPAddr: net_data["ip_address"].(string),
|
||||
MAC: net_data["mac"].(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().Compute().NetDetach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to detach this network - there will be partial resource update
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to detach net ID %d of type %s from Compute ID %s: %s",
|
||||
net_data["net_id"].(int), net_data["net_type"].(string), d.Id(), err)
|
||||
apiErrCount++
|
||||
@@ -190,10 +250,11 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", attach_set.Len(), d.Id())
|
||||
for _, runner := range attach_set.List() {
|
||||
net_data := runner.(map[string]interface{})
|
||||
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req := compute.NetAttachRequest{
|
||||
ComputeID: computeID,
|
||||
NetID: uint64(net_data["net_id"].(int)),
|
||||
ComputeID: computeId,
|
||||
NetType: net_data["net_type"].(string),
|
||||
NetID: uint64(net_data["net_id"].(int)),
|
||||
}
|
||||
|
||||
if net_data["ip_address"].(string) != "" {
|
||||
@@ -202,7 +263,6 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
|
||||
_, err := c.CloudBroker().Compute().NetAttach(ctx, req)
|
||||
if err != nil {
|
||||
// failed to attach this network - there will be partial resource update
|
||||
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
|
||||
net_data["net_id"].(int), net_data["net_type"].(string), d.Id(), err)
|
||||
apiErrCount++
|
||||
@@ -210,6 +270,15 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
}
|
||||
}
|
||||
|
||||
startReq := compute.StartRequest{ComputeID: computeID}
|
||||
|
||||
log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID)
|
||||
_, err = c.CloudBroker().Compute().Start(ctx, startReq)
|
||||
if err != nil {
|
||||
apiErrCount++
|
||||
lastSavedError = err
|
||||
}
|
||||
|
||||
if apiErrCount > 0 {
|
||||
log.Errorf("utilityComputeNetworksConfigure: there were %d error(s) when managing networks of Compute ID %s. Last error was: %s",
|
||||
apiErrCount, d.Id(), lastSavedError)
|
||||
@@ -219,73 +288,40 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
|
||||
return nil
|
||||
}
|
||||
|
||||
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.RecordCompute, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
idSet := false
|
||||
computeID, err := strconv.ParseUint(d.Id(), 10, 64)
|
||||
if err != nil || computeID <= 0 {
|
||||
computeId, argSet := d.GetOk("compute_id") // NB: compute_id is NOT present in computeResource schema!
|
||||
if argSet {
|
||||
computeID = uint64(computeId.(int))
|
||||
idSet = true
|
||||
}
|
||||
} else {
|
||||
idSet = true
|
||||
}
|
||||
|
||||
if idSet {
|
||||
// compute ID is specified, try to get compute instance straight by this ID
|
||||
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", computeID)
|
||||
req := compute.GetRequest{
|
||||
ComputeID: computeID,
|
||||
}
|
||||
|
||||
computeFacts, err := c.CloudBroker().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return computeFacts, nil
|
||||
}
|
||||
|
||||
// ID was not set in the schema upon entering this function - work through Compute name
|
||||
// and RG ID
|
||||
computeName, argSet := d.GetOk("name")
|
||||
if !argSet {
|
||||
return nil, fmt.Errorf("Cannot locate compute instance if name is empty and no compute ID specified")
|
||||
}
|
||||
|
||||
rgId, argSet := d.GetOk("rg_id")
|
||||
if !argSet {
|
||||
return nil, fmt.Errorf("Cannot locate compute by name %s if no resource group ID is set", computeName.(string))
|
||||
}
|
||||
|
||||
rgListComputesReq := rg.ListComputesRequest{
|
||||
RGID: uint64(rgId.(int)),
|
||||
}
|
||||
|
||||
computeList, err := c.CloudBroker().RG().ListComputes(ctx, rgListComputesReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("utilityComputeCheckPresence: traversing decoded JSON of length %d", len(computeList.Data))
|
||||
for index, item := range computeList.Data {
|
||||
// need to match Compute by name, skip Computes with the same name in DESTROYED satus
|
||||
if item.Name == computeName.(string) && item.Status != "DESTROYED" {
|
||||
log.Debugf("utilityComputeCheckPresence: index %d, matched name %s", index, item.Name)
|
||||
// we found the Compute we need - now get detailed information via compute/get API
|
||||
req := compute.GetRequest{
|
||||
ComputeID: item.ID,
|
||||
}
|
||||
|
||||
apiResp, err := c.CloudBroker().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return apiResp, nil
|
||||
func isChangeDisk(els []interface{}, el interface{}) bool {
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
elConv := el.(map[string]interface{})
|
||||
if elOldConv["disk_id"].(int) == elConv["disk_id"].(int) &&
|
||||
elOldConv["size"].(int) != elConv["size"].(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return false
|
||||
}
|
||||
|
||||
func isContainsDisk(els []interface{}, el interface{}) bool {
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
elConv := el.(map[string]interface{})
|
||||
if elOldConv["disk_name"].(string) == elConv["disk_name"].(string) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isContainsAR(els []interface{}, el interface{}) bool {
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
elConv := el.(map[string]interface{})
|
||||
if elOldConv["key"].(string) == elConv["key"].(string) &&
|
||||
elOldConv["value"].(string) == elConv["value"].(string) &&
|
||||
elOldConv["mode"].(string) == elConv["mode"].(string) &&
|
||||
elOldConv["topology"].(string) == elConv["topology"].(string) &&
|
||||
elOldConv["policy"].(string) == elConv["policy"].(string) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,59 +1,57 @@
|
||||
/*
|
||||
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 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dataSourceAccountAuditSchemaMake() map[string]*schema.Schema {
|
||||
return 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
/*
|
||||
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>
|
||||
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 kvmvm
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
|
||||
)
|
||||
|
||||
func utilityComputeBootDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*compute.ItemDisk, error) {
|
||||
computeRecord, err := utilityComputeCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bootDisk := &compute.ItemDisk{}
|
||||
for _, disk := range computeRecord.Disks {
|
||||
if disk.Name == "bootdisk" {
|
||||
*bootDisk = disk
|
||||
break
|
||||
}
|
||||
}
|
||||
return bootDisk, nil
|
||||
}
|
||||
70
internal/service/cloudbroker/lb/data_source_lb.go
Normal file
70
internal/service/cloudbroker/lb/data_source_lb.go
Normal file
@@ -0,0 +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>
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 lb
|
||||
|
||||
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 dataSourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
lb, err := utilityLBCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(lb.ID, 10))
|
||||
|
||||
flattenLB(d, lb)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceLB() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceLBRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dsLBSchemaMake(),
|
||||
}
|
||||
}
|
||||
70
internal/service/cloudbroker/lb/data_source_lb_list.go
Normal file
70
internal/service/cloudbroker/lb/data_source_lb_list.go
Normal file
@@ -0,0 +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>
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 lb
|
||||
|
||||
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 dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
lbList, err := utilityLBListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenLBList(lbList))
|
||||
d.Set("entry_count", lbList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceLBList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceLBListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dsLBListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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>
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 lb
|
||||
|
||||
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 dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
lbList, err := utilityLBListDeletedCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenLBList(lbList))
|
||||
d.Set("entry_count", lbList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceLBListDeleted() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceLBListDeletedRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dsLBListDeletedSchemaMake(),
|
||||
}
|
||||
}
|
||||
262
internal/service/cloudbroker/lb/flattens.go
Normal file
262
internal/service/cloudbroker/lb/flattens.go
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 lb
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenLBFrontendBind(d *schema.ResourceData, b *lb.ItemBinding, lbId int64, frontendName string) {
|
||||
d.Set("lb_id", lbId)
|
||||
d.Set("frontend_name", frontendName)
|
||||
d.Set("name", b.Name)
|
||||
d.Set("address", b.Address)
|
||||
d.Set("guid", b.GUID)
|
||||
d.Set("port", b.Port)
|
||||
}
|
||||
|
||||
func flattenLBFrontend(d *schema.ResourceData, f *lb.ItemFrontend, lbId int64) {
|
||||
d.Set("lb_id", lbId)
|
||||
d.Set("backend_name", f.Backend)
|
||||
d.Set("name", f.Name)
|
||||
d.Set("guid", f.GUID)
|
||||
d.Set("bindings", flattendBindings(f.Bindings))
|
||||
}
|
||||
|
||||
func flattenResourceLBBackendServer(d *schema.ResourceData, s *lb.ItemServer, lbId int64, backendName string) {
|
||||
d.Set("lb_id", lbId)
|
||||
d.Set("backend_name", backendName)
|
||||
d.Set("name", s.Name)
|
||||
d.Set("port", s.Port)
|
||||
d.Set("address", s.Address)
|
||||
d.Set("check", s.Check)
|
||||
d.Set("guid", s.GUID)
|
||||
d.Set("downinter", s.ServerSettings.DownInter)
|
||||
d.Set("fall", s.ServerSettings.Fall)
|
||||
d.Set("inter", s.ServerSettings.Inter)
|
||||
d.Set("maxconn", s.ServerSettings.MaxConn)
|
||||
d.Set("maxqueue", s.ServerSettings.MaxQueue)
|
||||
d.Set("rise", s.ServerSettings.Rise)
|
||||
d.Set("slowstart", s.ServerSettings.SlowStart)
|
||||
d.Set("weight", s.ServerSettings.Weight)
|
||||
|
||||
}
|
||||
|
||||
func flattenResourceLBBackend(d *schema.ResourceData, b *lb.ItemBackend, lbId int64) {
|
||||
d.Set("lb_id", lbId)
|
||||
d.Set("name", b.Name)
|
||||
d.Set("algorithm", b.Algorithm)
|
||||
d.Set("guid", b.GUID)
|
||||
d.Set("downinter", b.ServerDefaultSettings.DownInter)
|
||||
d.Set("fall", b.ServerDefaultSettings.Fall)
|
||||
d.Set("inter", b.ServerDefaultSettings.Inter)
|
||||
d.Set("maxconn", b.ServerDefaultSettings.MaxConn)
|
||||
d.Set("maxqueue", b.ServerDefaultSettings.MaxQueue)
|
||||
d.Set("rise", b.ServerDefaultSettings.Rise)
|
||||
d.Set("slowstart", b.ServerDefaultSettings.SlowStart)
|
||||
d.Set("weight", b.ServerDefaultSettings.Weight)
|
||||
d.Set("servers", flattenServers(b.Servers))
|
||||
}
|
||||
|
||||
func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) {
|
||||
d.Set("ha_mode", lb.HAMode)
|
||||
d.Set("ckey", lb.CKey)
|
||||
d.Set("meta", flattens.FlattenMeta(lb.Meta))
|
||||
d.Set("backends", flattenLBBackends(lb.Backends))
|
||||
d.Set("desc", lb.Description)
|
||||
d.Set("dp_api_user", lb.DPAPIUser)
|
||||
d.Set("dp_api_password", lb.DPAPIPassword)
|
||||
d.Set("extnet_id", lb.ExtNetID)
|
||||
d.Set("frontends", flattenFrontends(lb.Frontends))
|
||||
d.Set("gid", lb.GID)
|
||||
d.Set("guid", lb.GUID)
|
||||
d.Set("lb_id", lb.ID)
|
||||
d.Set("image_id", lb.ImageID)
|
||||
d.Set("milestones", lb.Milestones)
|
||||
d.Set("name", lb.Name)
|
||||
d.Set("primary_node", flattenNode(lb.PrimaryNode))
|
||||
d.Set("rg_id", lb.RGID)
|
||||
d.Set("secondary_node", flattenNode(lb.SecondaryNode))
|
||||
d.Set("status", lb.Status)
|
||||
d.Set("tech_status", lb.TechStatus)
|
||||
d.Set("vins_id", lb.VINSID)
|
||||
}
|
||||
|
||||
func flattenNode(node lb.Node) []map[string]interface{} {
|
||||
temp := make([]map[string]interface{}, 0)
|
||||
n := map[string]interface{}{
|
||||
"backend_ip": node.BackendIP,
|
||||
"compute_id": node.ComputeID,
|
||||
"frontend_ip": node.FrontendIP,
|
||||
"guid": node.GUID,
|
||||
"mgmt_ip": node.MGMTIP,
|
||||
"network_id": node.NetworkID,
|
||||
}
|
||||
|
||||
temp = append(temp, n)
|
||||
|
||||
return temp
|
||||
}
|
||||
|
||||
func flattendBindings(bs []lb.ItemBinding) []map[string]interface{} {
|
||||
temp := make([]map[string]interface{}, 0, len(bs))
|
||||
for _, b := range bs {
|
||||
t := map[string]interface{}{
|
||||
"address": b.Address,
|
||||
"guid": b.GUID,
|
||||
"name": b.Name,
|
||||
"port": b.Port,
|
||||
}
|
||||
temp = append(temp, t)
|
||||
}
|
||||
return temp
|
||||
}
|
||||
|
||||
func flattenFrontends(fs []lb.ItemFrontend) []map[string]interface{} {
|
||||
temp := make([]map[string]interface{}, 0, len(fs))
|
||||
for _, f := range fs {
|
||||
t := map[string]interface{}{
|
||||
"backend": f.Backend,
|
||||
"bindings": flattendBindings(f.Bindings),
|
||||
"guid": f.GUID,
|
||||
"name": f.Name,
|
||||
}
|
||||
temp = append(temp, t)
|
||||
}
|
||||
|
||||
return temp
|
||||
}
|
||||
|
||||
func flattenServers(servers []lb.ItemServer) []map[string]interface{} {
|
||||
temp := make([]map[string]interface{}, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
t := map[string]interface{}{
|
||||
"address": server.Address,
|
||||
"check": server.Check,
|
||||
"guid": server.GUID,
|
||||
"name": server.Name,
|
||||
"port": server.Port,
|
||||
"server_settings": flattenServerSettings(server.ServerSettings),
|
||||
}
|
||||
|
||||
temp = append(temp, t)
|
||||
}
|
||||
return temp
|
||||
}
|
||||
|
||||
func flattenServerSettings(defSet lb.ServerSettings) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"downinter": defSet.DownInter,
|
||||
"fall": defSet.Fall,
|
||||
"guid": defSet.GUID,
|
||||
"inter": defSet.Inter,
|
||||
"maxconn": defSet.MaxConn,
|
||||
"maxqueue": defSet.MaxQueue,
|
||||
"rise": defSet.Rise,
|
||||
"slowstart": defSet.SlowStart,
|
||||
"weight": defSet.Weight,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenLBBackends(backends []lb.ItemBackend) []map[string]interface{} {
|
||||
temp := make([]map[string]interface{}, 0, len(backends))
|
||||
for _, item := range backends {
|
||||
t := map[string]interface{}{
|
||||
"algorithm": item.Algorithm,
|
||||
"guid": item.GUID,
|
||||
"name": item.Name,
|
||||
"server_default_settings": flattenServerSettings(item.ServerDefaultSettings),
|
||||
"servers": flattenServers(item.Servers),
|
||||
}
|
||||
temp = append(temp, t)
|
||||
}
|
||||
return temp
|
||||
}
|
||||
|
||||
func flattenLBList(lbl *lb.ListLB) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(lbl.Data))
|
||||
for _, lb := range lbl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"ha_mode": lb.HAMode,
|
||||
"acl": flattenACl(lb.ACL),
|
||||
"backends": flattenLBBackends(lb.Backends),
|
||||
"created_by": lb.CreatedBy,
|
||||
"created_time": lb.CreatedTime,
|
||||
"deleted_by": lb.DeletedBy,
|
||||
"deleted_time": lb.DeletedTime,
|
||||
"desc": lb.Description,
|
||||
"dp_api_user": lb.DPAPIUser,
|
||||
"dp_api_password": lb.DPAPIPassword,
|
||||
"extnet_id": lb.ExtNetID,
|
||||
"frontends": flattenFrontends(lb.Frontends),
|
||||
"gid": lb.GID,
|
||||
"guid": lb.GUID,
|
||||
"lb_id": lb.ID,
|
||||
"milestones": lb.Milestones,
|
||||
"name": lb.Name,
|
||||
"primary_node": flattenNode(lb.PrimaryNode),
|
||||
"rg_id": lb.RGID,
|
||||
"rg_name": lb.RGName,
|
||||
"secondary_node": flattenNode(lb.SecondaryNode),
|
||||
"status": lb.Status,
|
||||
"tech_status": lb.TechStatus,
|
||||
"updated_by": lb.UpdatedBy,
|
||||
"updated_time": lb.UpdatedTime,
|
||||
"vins_id": lb.VINSID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenACl(m interface{}) string {
|
||||
switch d := m.(type) {
|
||||
case string:
|
||||
return d
|
||||
case int:
|
||||
return strconv.Itoa(d)
|
||||
case int64:
|
||||
return strconv.FormatInt(d, 10)
|
||||
case float64:
|
||||
return strconv.FormatInt(int64(d), 10)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
177
internal/service/cloudbroker/lb/lb_data_subresource.go
Normal file
177
internal/service/cloudbroker/lb/lb_data_subresource.go
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 lb
|
||||
|
||||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func dsLBSchemaMake() map[string]*schema.Schema {
|
||||
sch := createLBSchema()
|
||||
sch["lb_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
}
|
||||
return sch
|
||||
}
|
||||
|
||||
|
||||
func dsLBListDeletedSchemaMake() 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",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Filter by Account ID",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Filter by RG ID",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Filter by TechStatus",
|
||||
},
|
||||
"front_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Filter by FrontIP",
|
||||
},
|
||||
"back_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Filter by BackIP",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 0,
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 0,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: createLBListSchema(),
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dsLBListSchemaMake() 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",
|
||||
},
|
||||
"account_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Filter by Account ID",
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Filter by RG ID",
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Filter by TechStatus",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Filter by Status",
|
||||
},
|
||||
"front_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Filter by FrontIP",
|
||||
},
|
||||
"back_ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "Filter by BackIP",
|
||||
},
|
||||
"includedeleted": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 0,
|
||||
},
|
||||
"size": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 0,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: createLBListSchema(),
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
95
internal/service/cloudbroker/lb/lb_resource_subresource.go
Normal file
95
internal/service/cloudbroker/lb/lb_resource_subresource.go
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 lb
|
||||
|
||||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func lbResourceSchemaMake() map[string]*schema.Schema {
|
||||
sch := createLBSchema()
|
||||
sch["rg_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
sch["name"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
sch["extnet_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
sch["vins_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
sch["start"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
}
|
||||
|
||||
sch["desc"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
}
|
||||
|
||||
sch["enable"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
}
|
||||
|
||||
sch["restart"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
}
|
||||
|
||||
sch["restore"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
}
|
||||
|
||||
sch["config_reset"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
}
|
||||
|
||||
sch["permanently"] = &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
}
|
||||
return sch
|
||||
}
|
||||
702
internal/service/cloudbroker/lb/lb_schema.go
Normal file
702
internal/service/cloudbroker/lb/lb_schema.go
Normal file
@@ -0,0 +1,702 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
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 lb
|
||||
|
||||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
func createLBSchema() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ha_mode": {
|
||||
Type: schema.TypeBool,
|
||||
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.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"backends": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"algorithm": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"server_default_settings": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"servers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"check": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_user": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_password": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"frontends": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"backend": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"bindings": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"image_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"primary_node": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"backend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"secondary_node": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"backend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func createLBListSchema() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"ha_mode": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"backends": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"algorithm": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"server_default_settings": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"servers": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"check": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
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,
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_user": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dp_api_password": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"frontends": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"backend": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"bindings": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"gid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"milestones": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"primary_node": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"backend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"rg_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"secondary_node": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"backend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"compute_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"frontend_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"mgmt_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"network_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"tech_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user