4.6.1
This commit is contained in:
@@ -1,169 +1,169 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/location"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
|
||||
)
|
||||
|
||||
func Provider() *schema.Provider {
|
||||
return &schema.Provider{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"authenticator": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: statefuncs.StateFuncToLower,
|
||||
ValidateFunc: validation.StringInSlice([]string{"decs3o", "legacy", "jwt", "bvs"}, true), // ignore case while validating
|
||||
Description: "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'decs3o', 'legacy', 'jwt' or 'bvs'.",
|
||||
},
|
||||
|
||||
"oauth2_url": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
StateFunc: statefuncs.StateFuncToLower,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil),
|
||||
Description: "OAuth2 application URL in 'decs3o' and 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"controller_url": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
StateFunc: statefuncs.StateFuncToLower,
|
||||
Description: "URL of DECORT Cloud controller to use. API calls will be directed to this URL.",
|
||||
},
|
||||
|
||||
"user": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_USER", nil),
|
||||
Description: "User name for DECORT cloud API operations in 'legacy' authentication mode.",
|
||||
},
|
||||
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_PASSWORD", nil),
|
||||
Description: "User password for DECORT cloud API operations in 'legacy' authentication mode.",
|
||||
},
|
||||
|
||||
"bvs_user": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_USER", nil),
|
||||
Description: "User name for DECORT cloud API operations in 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"bvs_password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_PASSWORD", nil),
|
||||
Description: "User password for DECORT cloud API operations in 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"domain": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_DOMAIN", nil),
|
||||
Description: "User password for DECORT cloud API operations in 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"app_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_ID", nil),
|
||||
Description: "Application ID to access DECORT cloud API in 'decs3o' and 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"app_secret": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_SECRET", nil),
|
||||
Description: "Application secret to access DECORT cloud API in 'decs3o' and 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"jwt": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_JWT", nil),
|
||||
Description: "JWT to access DECORT cloud API in 'jwt' authentication mode.",
|
||||
},
|
||||
|
||||
"allow_unverified_ssl": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "If true, DECORT API will not verify SSL certificates. Use this with caution and in trusted environments only!",
|
||||
},
|
||||
|
||||
"path_cfg": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "The path of the configuration file entry",
|
||||
},
|
||||
|
||||
"path_token": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "The path of the token file entry",
|
||||
},
|
||||
|
||||
"time_to_refresh": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "The number of minutes before the expiration of the token, a refresh will be made",
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
ResourcesMap: newResourcesMap(),
|
||||
|
||||
DataSourcesMap: newDataSourcesMap(),
|
||||
|
||||
ConfigureContextFunc: providerConfigure,
|
||||
}
|
||||
}
|
||||
|
||||
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
|
||||
decsController, err := controller.ControllerConfigure(d)
|
||||
if err != nil {
|
||||
return nil, diag.FromErr(err)
|
||||
}
|
||||
|
||||
gridId, err := location.UtilityLocationGetDefaultGridID(ctx, decsController)
|
||||
if err != nil {
|
||||
return nil, diag.FromErr(err)
|
||||
}
|
||||
if gridId == 0 {
|
||||
return nil, diag.FromErr(fmt.Errorf("providerConfigure: invalid default Grid ID = 0"))
|
||||
}
|
||||
|
||||
return decsController, nil
|
||||
}
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/location"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
|
||||
)
|
||||
|
||||
func Provider() *schema.Provider {
|
||||
return &schema.Provider{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"authenticator": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: statefuncs.StateFuncToLower,
|
||||
ValidateFunc: validation.StringInSlice([]string{"decs3o", "legacy", "jwt", "bvs"}, true), // ignore case while validating
|
||||
Description: "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'decs3o', 'legacy', 'jwt' or 'bvs'.",
|
||||
},
|
||||
|
||||
"oauth2_url": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
StateFunc: statefuncs.StateFuncToLower,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil),
|
||||
Description: "OAuth2 application URL in 'decs3o' and 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"controller_url": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
StateFunc: statefuncs.StateFuncToLower,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_CONTROLLER_URL", nil),
|
||||
Description: "URL of DECORT Cloud controller to use. API calls will be directed to this URL.",
|
||||
},
|
||||
|
||||
"user": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_USER", nil),
|
||||
Description: "User name for DECORT cloud API operations in 'legacy' authentication mode.",
|
||||
},
|
||||
|
||||
"password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_PASSWORD", nil),
|
||||
Description: "User password for DECORT cloud API operations in 'legacy' authentication mode.",
|
||||
},
|
||||
|
||||
"bvs_user": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_USER", nil),
|
||||
Description: "User name for DECORT cloud API operations in 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"bvs_password": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_BVS_PASSWORD", nil),
|
||||
Description: "User password for DECORT cloud API operations in 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"domain": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_DOMAIN", nil),
|
||||
Description: "User password for DECORT cloud API operations in 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"app_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_ID", nil),
|
||||
Description: "Application ID to access DECORT cloud API in 'decs3o' and 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"app_secret": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_SECRET", nil),
|
||||
Description: "Application secret to access DECORT cloud API in 'decs3o' and 'bvs' authentication mode.",
|
||||
},
|
||||
|
||||
"jwt": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DECORT_JWT", nil),
|
||||
Description: "JWT to access DECORT cloud API in 'jwt' authentication mode.",
|
||||
},
|
||||
|
||||
"allow_unverified_ssl": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "If true, DECORT API will not verify SSL certificates. Use this with caution and in trusted environments only!",
|
||||
},
|
||||
|
||||
"path_cfg": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "The path of the configuration file entry",
|
||||
},
|
||||
|
||||
"path_token": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "The path of the token file entry",
|
||||
},
|
||||
|
||||
"time_to_refresh": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "The number of minutes before the expiration of the token, a refresh will be made",
|
||||
},
|
||||
},
|
||||
|
||||
ResourcesMap: newResourcesMap(),
|
||||
|
||||
DataSourcesMap: newDataSourcesMap(),
|
||||
|
||||
ConfigureContextFunc: providerConfigure,
|
||||
}
|
||||
}
|
||||
|
||||
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
|
||||
decsController, err := controller.ControllerConfigure(d)
|
||||
if err != nil {
|
||||
return nil, diag.FromErr(err)
|
||||
}
|
||||
|
||||
gridId, err := location.UtilityLocationGetDefaultGridID(ctx, decsController)
|
||||
if err != nil {
|
||||
return nil, diag.FromErr(err)
|
||||
}
|
||||
if gridId == 0 {
|
||||
return nil, diag.FromErr(fmt.Errorf("providerConfigure: invalid default Grid ID = 0"))
|
||||
}
|
||||
|
||||
return decsController, nil
|
||||
}
|
||||
|
||||
@@ -183,16 +183,16 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
}
|
||||
|
||||
if lbSysctlParams, ok := d.GetOk("lb_sysctl_params"); ok {
|
||||
syscrlSliceMaps := lbSysctlParams.([]map[string]string)
|
||||
syscrlSliceMaps := lbSysctlParams.([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
for _, syscrlMap := range syscrlSliceMaps {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
@@ -534,27 +534,28 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
}
|
||||
|
||||
if d.HasChange("lb_sysctl_params") && d.Get("with_lb").(bool) {
|
||||
lbSysctlParams := d.Get("lb_sysctl_params").([]map[string]string)
|
||||
lbSysctlParams := d.Get("lb_sysctl_params").([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(lbSysctlParams))
|
||||
for _, syscrlMap := range lbSysctlParams {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: cluster.LBID,
|
||||
SysctlParams: res,
|
||||
}
|
||||
_, err := c.CloudAPI().LB().UpdateSysctlParams(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
if len(res) > 0 {
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: cluster.LBID,
|
||||
SysctlParams: res,
|
||||
}
|
||||
_, err := c.CloudAPI().LB().UpdateSysctlParams(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,16 +168,16 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
}
|
||||
|
||||
if lbSysctlParams, ok := d.GetOk("lb_sysctl_params"); ok {
|
||||
syscrlSliceMaps := lbSysctlParams.([]map[string]string)
|
||||
syscrlSliceMaps := lbSysctlParams.([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
for _, syscrlMap := range syscrlSliceMaps {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
@@ -552,27 +552,28 @@ func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
}
|
||||
|
||||
if d.HasChange("lb_sysctl_params") && d.Get("with_lb").(bool) {
|
||||
lbSysctlParams := d.Get("lb_sysctl_params").([]map[string]string)
|
||||
lbSysctlParams := d.Get("lb_sysctl_params").([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(lbSysctlParams))
|
||||
for _, syscrlMap := range lbSysctlParams {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: cluster.LBID,
|
||||
SysctlParams: res,
|
||||
}
|
||||
_, err := c.CloudAPI().LB().UpdateSysctlParams(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
if len(res) > 0 {
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: cluster.LBID,
|
||||
SysctlParams: res,
|
||||
}
|
||||
_, err := c.CloudAPI().LB().UpdateSysctlParams(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func utilityDataComputeCheckPresence(ctx context.Context, d *schema.ResourceData
|
||||
|
||||
computeRecord, err := c.CloudAPI().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return *computeRecord, err
|
||||
return compute.RecordCompute{}, err
|
||||
}
|
||||
|
||||
return *computeRecord, nil
|
||||
|
||||
@@ -92,16 +92,16 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
req.HighlyAvailable = haMode.(bool)
|
||||
}
|
||||
if sysctlParams, ok := d.GetOk("sysctl_params"); ok {
|
||||
syscrlSliceMaps := sysctlParams.([]map[string]string)
|
||||
syscrlSliceMaps := sysctlParams.([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
for _, syscrlMap := range syscrlSliceMaps {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
@@ -364,27 +364,28 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
}
|
||||
|
||||
if d.HasChange("sysctl_params") {
|
||||
syscrlSliceMaps := d.Get("sysctl_params").([]map[string]string)
|
||||
syscrlSliceMaps := d.Get("sysctl_params").([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
for _, syscrlMap := range syscrlSliceMaps {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
SysctlParams: res,
|
||||
}
|
||||
_, err := c.CloudAPI().LB().UpdateSysctlParams(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
if len(res) > 0 {
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
SysctlParams: res,
|
||||
}
|
||||
_, err := c.CloudAPI().LB().UpdateSysctlParams(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,379 +1,379 @@
|
||||
/*
|
||||
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 lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"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"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceLBBackendCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendCreate")
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendCreate: can't create LB backend because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendCreateRequest{}
|
||||
|
||||
req.BackendName = d.Get("name").(string)
|
||||
req.LBID = uint64(d.Get("lb_id").(int))
|
||||
|
||||
if algorithm, ok := d.GetOk("algorithm"); ok {
|
||||
req.Algorithm = algorithm.(string)
|
||||
}
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendCreate(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("name").(string))
|
||||
|
||||
_, err = utilityLBBackendCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return resourceLBBackendRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceLBBackendRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendRead")
|
||||
|
||||
b, err := utilityLBBackendCheckPresence(ctx, d, m)
|
||||
if b == nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
|
||||
|
||||
flattenResourceLBBackend(d, b, lbId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendDelete")
|
||||
|
||||
_, err := utilityLBBackendCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendDeleteRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
BackendName: d.Get("name").(string),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendDelete(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendEdit")
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendUpdate: can't update LB backend because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
req := lb.BackendUpdateRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
BackendName: d.Get("name").(string),
|
||||
}
|
||||
|
||||
if d.HasChange("algorithm") {
|
||||
req.Algorithm = d.Get("algorithm").(string)
|
||||
}
|
||||
if d.HasChange("inter") {
|
||||
req.Inter = uint64(d.Get("inter").(int))
|
||||
}
|
||||
if d.HasChange("downinter") {
|
||||
req.DownInter = uint64(d.Get("downinter").(int))
|
||||
}
|
||||
if d.HasChange("rise") {
|
||||
req.Rise = uint64(d.Get("rise").(int))
|
||||
}
|
||||
if d.HasChange("fall") {
|
||||
req.Fall = uint64(d.Get("fall").(int))
|
||||
}
|
||||
if d.HasChange("slowstart") {
|
||||
req.SlowStart = uint64(d.Get("slowstart").(int))
|
||||
}
|
||||
if d.HasChange("maxconn") {
|
||||
req.MaxConn = uint64(d.Get("maxconn").(int))
|
||||
}
|
||||
if d.HasChange("maxqueue") {
|
||||
req.MaxQueue = uint64(d.Get("maxqueue").(int))
|
||||
}
|
||||
if d.HasChange("weight") {
|
||||
req.Weight = uint64(d.Get("weight").(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendUpdate(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return resourceLBBackendRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func ResourceLBBackend() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceLBBackendCreate,
|
||||
ReadContext: resourceLBBackendRead,
|
||||
UpdateContext: resourceLBBackendUpdate,
|
||||
DeleteContext: resourceLBBackendDelete,
|
||||
|
||||
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: map[string]*schema.Schema{
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of the LB instance to backendCreate",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Must be unique among all backends of this LB - name of the new backend to create",
|
||||
},
|
||||
"algorithm": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"roundrobin", "static-rr", "leastconn"}, false),
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"servers": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"check": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
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>
|
||||
|
||||
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"
|
||||
"strings"
|
||||
|
||||
"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"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceLBBackendCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendCreate")
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendCreate: can't create LB backend because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendCreateRequest{}
|
||||
|
||||
req.BackendName = d.Get("name").(string)
|
||||
req.LBID = uint64(d.Get("lb_id").(int))
|
||||
|
||||
if algorithm, ok := d.GetOk("algorithm"); ok {
|
||||
req.Algorithm = algorithm.(string)
|
||||
}
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendCreate(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("name").(string))
|
||||
|
||||
_, err = utilityLBBackendCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return resourceLBBackendRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceLBBackendRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendRead")
|
||||
|
||||
b, err := utilityLBBackendCheckPresence(ctx, d, m)
|
||||
if b == nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
|
||||
|
||||
flattenResourceLBBackend(d, b, lbId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendDelete")
|
||||
|
||||
_, err := utilityLBBackendCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendDeleteRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
BackendName: d.Get("name").(string),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendDelete(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendEdit")
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendUpdate: can't update LB backend because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
req := lb.BackendUpdateRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
BackendName: d.Get("name").(string),
|
||||
}
|
||||
|
||||
if algorithm, ok := d.GetOk("algorithm"); ok {
|
||||
req.Algorithm = algorithm.(string)
|
||||
}
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendUpdate(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return resourceLBBackendRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func ResourceLBBackend() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceLBBackendCreate,
|
||||
ReadContext: resourceLBBackendRead,
|
||||
UpdateContext: resourceLBBackendUpdate,
|
||||
DeleteContext: resourceLBBackendDelete,
|
||||
|
||||
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: map[string]*schema.Schema{
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of the LB instance to backendCreate",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Must be unique among all backends of this LB - name of the new backend to create",
|
||||
},
|
||||
"algorithm": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"roundrobin", "static-rr", "leastconn"}, false),
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"servers": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"check": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"server_settings": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,320 +1,320 @@
|
||||
/*
|
||||
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 lb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"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"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceLBBackendServerCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerCreate")
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendServerCreate: can't create LB backend server because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendServerAddRequest{
|
||||
BackendName: d.Get("backend_name").(string),
|
||||
ServerName: d.Get("name").(string),
|
||||
Address: d.Get("address").(string),
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
Port: uint64(d.Get("port").(int)),
|
||||
}
|
||||
|
||||
if check, ok := d.GetOk("check"); ok {
|
||||
req.Check = check.(string)
|
||||
}
|
||||
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendServerAdd(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("backend_name").(string) + "#" + d.Get("name").(string))
|
||||
|
||||
_, err = utilityLBBackendServerCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return resourceLBBackendServerRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceLBBackendServerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerRead")
|
||||
|
||||
s, err := utilityLBBackendServerCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
|
||||
backendName := strings.Split(d.Id(), "#")[1]
|
||||
|
||||
flattenResourceLBBackendServer(d, s, lbId, backendName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendServerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerDelete")
|
||||
|
||||
_, err := utilityLBBackendServerCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendServerDeleteRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
BackendName: d.Get("backend_name").(string),
|
||||
ServerName: d.Get("name").(string),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendServerDelete(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendServerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerEdit")
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendServerUpdate: can't update LB backend server because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
req := lb.BackendServerUpdateRequest{
|
||||
BackendName: d.Get("backend_name").(string),
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
ServerName: d.Get("name").(string),
|
||||
Address: d.Get("address").(string),
|
||||
Port: uint64(d.Get("port").(int)),
|
||||
}
|
||||
|
||||
if d.HasChange("check") {
|
||||
req.Check = d.Get("check").(string)
|
||||
}
|
||||
if d.HasChange("inter") {
|
||||
req.Inter = uint64(d.Get("inter").(int))
|
||||
}
|
||||
if d.HasChange("downinter") {
|
||||
req.DownInter = uint64(d.Get("downinter").(int))
|
||||
}
|
||||
if d.HasChange("rise") {
|
||||
req.Rise = uint64(d.Get("rise").(int))
|
||||
}
|
||||
if d.HasChange("fall") {
|
||||
req.Fall = uint64(d.Get("fall").(int))
|
||||
}
|
||||
if d.HasChange("slowstart") {
|
||||
req.SlowStart = uint64(d.Get("slowstart").(int))
|
||||
}
|
||||
if d.HasChange("maxconn") {
|
||||
req.MaxConn = uint64(d.Get("maxconn").(int))
|
||||
}
|
||||
if d.HasChange("maxqueue") {
|
||||
req.MaxQueue = uint64(d.Get("maxqueue").(int))
|
||||
}
|
||||
if d.HasChange("weight") {
|
||||
req.Weight = uint64(d.Get("weight").(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendServerUpdate(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
//TODO: перенести servers сюда
|
||||
|
||||
return resourceLBBackendServerRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func ResourceLBBackendServer() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceLBBackendServerCreate,
|
||||
ReadContext: resourceLBBackendServerRead,
|
||||
UpdateContext: resourceLBBackendServerUpdate,
|
||||
DeleteContext: resourceLBBackendServerDelete,
|
||||
|
||||
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: map[string]*schema.Schema{
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of the LB instance to backendCreate",
|
||||
},
|
||||
"backend_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Must be unique among all backends of this LB - name of the new backend to create",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Must be unique among all servers defined for this backend - name of the server definition to add.",
|
||||
},
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "IP address of the server.",
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Port number on the server",
|
||||
},
|
||||
"check": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"disabled", "enabled"}, false),
|
||||
Description: "set to disabled if this server should be used regardless of its state.",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
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>
|
||||
|
||||
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"
|
||||
"strings"
|
||||
|
||||
"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"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceLBBackendServerCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerCreate")
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendServerCreate: can't create LB backend server because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendServerAddRequest{
|
||||
BackendName: d.Get("backend_name").(string),
|
||||
ServerName: d.Get("name").(string),
|
||||
Address: d.Get("address").(string),
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
Port: uint64(d.Get("port").(int)),
|
||||
}
|
||||
|
||||
if check, ok := d.GetOk("check"); ok {
|
||||
req.Check = check.(string)
|
||||
}
|
||||
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendServerAdd(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.Itoa(d.Get("lb_id").(int)) + "#" + d.Get("backend_name").(string) + "#" + d.Get("name").(string))
|
||||
|
||||
_, err = utilityLBBackendServerCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return resourceLBBackendServerRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceLBBackendServerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerRead")
|
||||
|
||||
s, err := utilityLBBackendServerCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
lbId, _ := strconv.ParseInt(strings.Split(d.Id(), "#")[0], 10, 32)
|
||||
backendName := strings.Split(d.Id(), "#")[1]
|
||||
|
||||
flattenResourceLBBackendServer(d, s, lbId, backendName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendServerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerDelete")
|
||||
|
||||
_, err := utilityLBBackendServerCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := lb.BackendServerDeleteRequest{
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
BackendName: d.Get("backend_name").(string),
|
||||
ServerName: d.Get("name").(string),
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendServerDelete(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLBBackendServerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLBBackendServerEdit")
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
haveLBID, err := existLBID(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveLBID {
|
||||
return diag.Errorf("resourceLBBackendServerUpdate: can't update LB backend server because LBID %d is not allowed or does not exist", d.Get("lb_id").(int))
|
||||
}
|
||||
|
||||
req := lb.BackendServerUpdateRequest{
|
||||
BackendName: d.Get("backend_name").(string),
|
||||
LBID: uint64(d.Get("lb_id").(int)),
|
||||
ServerName: d.Get("name").(string),
|
||||
Address: d.Get("address").(string),
|
||||
Port: uint64(d.Get("port").(int)),
|
||||
}
|
||||
|
||||
if check, ok := d.GetOk("check"); ok {
|
||||
req.Check = check.(string)
|
||||
}
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err = c.CloudAPI().LB().BackendServerUpdate(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
//TODO: перенести servers сюда
|
||||
|
||||
return resourceLBBackendServerRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func ResourceLBBackendServer() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceLBBackendServerCreate,
|
||||
ReadContext: resourceLBBackendServerRead,
|
||||
UpdateContext: resourceLBBackendServerUpdate,
|
||||
DeleteContext: resourceLBBackendServerDelete,
|
||||
|
||||
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: map[string]*schema.Schema{
|
||||
"lb_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of the LB instance to backendCreate",
|
||||
},
|
||||
"backend_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Must be unique among all backends of this LB - name of the new backend to create",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "Must be unique among all servers defined for this backend - name of the server definition to add.",
|
||||
},
|
||||
"address": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "IP address of the server.",
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Port number on the server",
|
||||
},
|
||||
"check": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"disabled", "enabled"}, false),
|
||||
Description: "set to disabled if this server should be used regardless of its state.",
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"downinter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"fall": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"inter": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxconn": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"maxqueue": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"rise": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"slowstart": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"weight": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -718,7 +718,7 @@ func ipSchemaMake() map[string]*schema.Schema {
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"DHCP", "VIP", "EXCLUDE"}, false),
|
||||
ValidateFunc: validation.StringInSlice([]string{"DHCP", "VIP", "EXCLUDED"}, false),
|
||||
},
|
||||
"ip_addr": {
|
||||
Type: schema.TypeString,
|
||||
|
||||
@@ -186,6 +186,10 @@ func ExistVins(ctx context.Context, vinsId uint64, c *controller.ControllerCfg)
|
||||
func ExistVinses(ctx context.Context, vinsIds []uint64, c *controller.ControllerCfg) []error {
|
||||
var errs []error
|
||||
|
||||
if len(vinsIds) == 0 {
|
||||
return errs
|
||||
}
|
||||
|
||||
req := cb_vins.ListRequest{
|
||||
IncludeDeleted: false,
|
||||
}
|
||||
@@ -217,6 +221,10 @@ func ExistVinses(ctx context.Context, vinsIds []uint64, c *controller.Controller
|
||||
func ExistExtNets(ctx context.Context, extNetIds []uint64, c *controller.ControllerCfg) []error {
|
||||
var errs []error
|
||||
|
||||
if len(extNetIds) == 0 {
|
||||
return errs
|
||||
}
|
||||
|
||||
req := cb_extnet.ListRequest{}
|
||||
|
||||
extNetList, err := c.CloudBroker().ExtNet().List(ctx, req)
|
||||
@@ -246,6 +254,10 @@ func ExistExtNets(ctx context.Context, extNetIds []uint64, c *controller.Control
|
||||
func ExistVFPools(ctx context.Context, vfpoolIds []uint64, c *controller.ControllerCfg) []error {
|
||||
var errs []error
|
||||
|
||||
if len(vfpoolIds) == 0 {
|
||||
return errs
|
||||
}
|
||||
|
||||
req := cb_vfpool.ListRequest{}
|
||||
|
||||
vfpoolList, err := c.CloudBroker().VFPool().List(ctx, req)
|
||||
|
||||
@@ -167,16 +167,16 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
}
|
||||
|
||||
if lbSysctlParams, ok := d.GetOk("lb_sysctl_params"); ok {
|
||||
syscrlSliceMaps := lbSysctlParams.([]map[string]string)
|
||||
syscrlSliceMaps := lbSysctlParams.([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
for _, syscrlMap := range syscrlSliceMaps {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
@@ -428,7 +428,7 @@ func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := k8s.DeleteRequest{
|
||||
K8SID: k8sData.ID,
|
||||
K8SID: k8sData.ID,
|
||||
}
|
||||
|
||||
if val, ok := d.GetOk("permanently"); ok {
|
||||
@@ -586,25 +586,28 @@ func handleStart(ctx context.Context, c *controller.ControllerCfg, start bool, k
|
||||
|
||||
func handleUpdateLbSysctlParams(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, k8sData *k8s.RecordK8S) error {
|
||||
|
||||
lbSysctlParams := d.Get("lb_sysctl_params").([]map[string]string)
|
||||
lbSysctlParams := d.Get("lb_sysctl_params").([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(lbSysctlParams))
|
||||
for _, syscrlMap := range lbSysctlParams {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: k8sData.LBID,
|
||||
SysctlParams: res,
|
||||
}
|
||||
if len(res) > 0 {
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: k8sData.LBID,
|
||||
SysctlParams: res,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().LB().UpdateSysctlParams(ctx, req)
|
||||
return err
|
||||
_, err := c.CloudBroker().LB().UpdateSysctlParams(ctx, req)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -193,12 +193,6 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"depresent": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "whether to depresent compute disks from node or not",
|
||||
},
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -2849,6 +2843,12 @@ func resourceComputeSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "Optional text description of this compute instance.",
|
||||
},
|
||||
"depresent": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "whether to depresent compute disks from node or not",
|
||||
},
|
||||
"started": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
|
||||
@@ -71,16 +71,16 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
|
||||
req.HighlyAvailable = haMode.(bool)
|
||||
}
|
||||
if sysctlParams, ok := d.GetOk("sysctl_params"); ok {
|
||||
syscrlSliceMaps := sysctlParams.([]map[string]string)
|
||||
syscrlSliceMaps := sysctlParams.([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
for _, syscrlMap := range syscrlSliceMaps {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
@@ -349,26 +349,28 @@ func resourceLbEnable(ctx context.Context, lbId uint64, m interface{}) error {
|
||||
func resourceLbChangeSysctlParams(ctx context.Context, d *schema.ResourceData, lbId uint64, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
syscrlSliceMaps := d.Get("sysctl_params").([]map[string]string)
|
||||
syscrlSliceMaps := d.Get("sysctl_params").([]interface{})
|
||||
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||
for _, syscrlMap := range syscrlSliceMaps {
|
||||
tempMap := make(map[string]interface{})
|
||||
for k, v := range syscrlMap {
|
||||
if intVal, err := strconv.Atoi(v); err == nil {
|
||||
for k, v := range syscrlMap.(map[string]interface{}) {
|
||||
if intVal, err := strconv.Atoi(v.(string)); err == nil {
|
||||
tempMap[k] = intVal
|
||||
continue
|
||||
}
|
||||
tempMap[k] = v
|
||||
tempMap[k] = v.(string)
|
||||
}
|
||||
res = append(res, tempMap)
|
||||
}
|
||||
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: lbId,
|
||||
SysctlParams: res,
|
||||
if len(res) > 0 {
|
||||
req := lb.UpdateSysctParamsRequest{
|
||||
LBID: lbId,
|
||||
SysctlParams: res,
|
||||
}
|
||||
_, err := c.CloudBroker().LB().UpdateSysctlParams(ctx, req)
|
||||
return err
|
||||
}
|
||||
_, err := c.CloudBroker().LB().UpdateSysctlParams(ctx, req)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLbDisable(ctx context.Context, lbId uint64, m interface{}) error {
|
||||
|
||||
@@ -150,32 +150,32 @@ func resourceLBBackendUpdate(ctx context.Context, d *schema.ResourceData, m inte
|
||||
BackendName: d.Get("name").(string),
|
||||
}
|
||||
|
||||
if d.HasChange("algorithm") {
|
||||
req.Algorithm = d.Get("algorithm").(string)
|
||||
if algorithm, ok := d.GetOk("algorithm"); ok {
|
||||
req.Algorithm = algorithm.(string)
|
||||
}
|
||||
if d.HasChange("inter") {
|
||||
req.Inter = uint64(d.Get("inter").(int))
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if d.HasChange("downinter") {
|
||||
req.DownInter = uint64(d.Get("downinter").(int))
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if d.HasChange("rise") {
|
||||
req.Rise = uint64(d.Get("rise").(int))
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if d.HasChange("fall") {
|
||||
req.Fall = uint64(d.Get("fall").(int))
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if d.HasChange("slowstart") {
|
||||
req.SlowStart = uint64(d.Get("slowstart").(int))
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if d.HasChange("maxconn") {
|
||||
req.MaxConn = uint64(d.Get("maxconn").(int))
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if d.HasChange("maxqueue") {
|
||||
req.MaxQueue = uint64(d.Get("maxqueue").(int))
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if d.HasChange("weight") {
|
||||
req.Weight = uint64(d.Get("weight").(int))
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().LB().BackendUpdate(ctx, req)
|
||||
|
||||
@@ -161,32 +161,32 @@ func resourceLBBackendServerUpdate(ctx context.Context, d *schema.ResourceData,
|
||||
Port: uint64(d.Get("port").(int)),
|
||||
}
|
||||
|
||||
if d.HasChange("check") {
|
||||
req.Check = d.Get("check").(string)
|
||||
if check, ok := d.GetOk("check"); ok {
|
||||
req.Check = check.(string)
|
||||
}
|
||||
if d.HasChange("inter") {
|
||||
req.Inter = uint64(d.Get("inter").(int))
|
||||
if inter, ok := d.GetOk("inter"); ok {
|
||||
req.Inter = uint64(inter.(int))
|
||||
}
|
||||
if d.HasChange("downinter") {
|
||||
req.DownInter = uint64(d.Get("downinter").(int))
|
||||
if downinter, ok := d.GetOk("downinter"); ok {
|
||||
req.DownInter = uint64(downinter.(int))
|
||||
}
|
||||
if d.HasChange("rise") {
|
||||
req.Rise = uint64(d.Get("rise").(int))
|
||||
if rise, ok := d.GetOk("rise"); ok {
|
||||
req.Rise = uint64(rise.(int))
|
||||
}
|
||||
if d.HasChange("fall") {
|
||||
req.Fall = uint64(d.Get("fall").(int))
|
||||
if fall, ok := d.GetOk("fall"); ok {
|
||||
req.Fall = uint64(fall.(int))
|
||||
}
|
||||
if d.HasChange("slowstart") {
|
||||
req.SlowStart = uint64(d.Get("slowstart").(int))
|
||||
if slowstart, ok := d.GetOk("slowstart"); ok {
|
||||
req.SlowStart = uint64(slowstart.(int))
|
||||
}
|
||||
if d.HasChange("maxconn") {
|
||||
req.MaxConn = uint64(d.Get("maxconn").(int))
|
||||
if maxconn, ok := d.GetOk("maxconn"); ok {
|
||||
req.MaxConn = uint64(maxconn.(int))
|
||||
}
|
||||
if d.HasChange("maxqueue") {
|
||||
req.MaxQueue = uint64(d.Get("maxqueue").(int))
|
||||
if maxqueue, ok := d.GetOk("maxqueue"); ok {
|
||||
req.MaxQueue = uint64(maxqueue.(int))
|
||||
}
|
||||
if d.HasChange("weight") {
|
||||
req.Weight = uint64(d.Get("weight").(int))
|
||||
if weight, ok := d.GetOk("weight"); ok {
|
||||
req.Weight = uint64(weight.(int))
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().LB().BackendServerUpdate(ctx, req)
|
||||
|
||||
@@ -185,7 +185,20 @@ func flattenNicInfo(infos node.ListNicInfo) []map[string]interface{} {
|
||||
"num_vfs": item.NumVFS,
|
||||
"os_name": item.OSName,
|
||||
"pci_slot": item.PCISlot,
|
||||
"vf_list": flattenNodeItem(item.VFList),
|
||||
"vf_list": flattenVFList(item.VFList),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVFList(vfList []interface{}) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(vfList))
|
||||
for _, v := range vfList {
|
||||
vConv := v.(map[string]interface{})
|
||||
temp := map[string]interface{}{
|
||||
"fn_id": vConv["fnId"],
|
||||
"pci_slot": vConv["pciSlot"],
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
@@ -164,8 +164,17 @@ func dataSourceNodeSchemaMake() map[string]*schema.Schema {
|
||||
"vf_list": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"fn_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"pci_slot": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -477,8 +486,17 @@ func dataSourceNodeListSchemaMake() map[string]*schema.Schema {
|
||||
"vf_list": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"fn_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"pci_slot": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -34,6 +34,7 @@ package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
@@ -69,7 +70,7 @@ func resourceSepCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
}
|
||||
|
||||
var consumedNIDs []uint64
|
||||
for _, item := range d.Get("consumed_by").([]interface{}) {
|
||||
for _, item := range d.Get("consumed_by").(*schema.Set).List() {
|
||||
consumedNIDs = append(consumedNIDs, uint64(item.(int)))
|
||||
}
|
||||
|
||||
@@ -172,84 +173,9 @@ func resourceSepDelete(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
}
|
||||
|
||||
func resourceSepUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceSepUpdate: called for %s, id: %d", d.Get("name").(string), d.Get("sep_id").(int))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
return diag.Errorf(
|
||||
"SEP upgrade is not possible via terraform")
|
||||
|
||||
if diags := checkParamsExistence(ctx, d, c); diags != nil {
|
||||
return diags
|
||||
}
|
||||
|
||||
if d.HasChange("account_ids") {
|
||||
err := resourceSepChangeAccess(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("access_to_pool") {
|
||||
err := resourceSepChangeAccessToPool(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("decommission") {
|
||||
err := resourceSepDecommission(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("upd_capacity_limit") {
|
||||
err := resourceSepUpdateCapacityLimit(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("config") {
|
||||
err := resourceSepUpdateConfig(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("field_edit") {
|
||||
err := resourceSepFieldEdit(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("enable") {
|
||||
err := resourceSepChangeEnabled(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("consumed_by") {
|
||||
err := resourceSepUpdateNodes(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("provided_by") {
|
||||
err := resourceSepUpdateProviders(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("pools") {
|
||||
err := resourceSepChangePools(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceSepRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceSepChangeAccess(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
@@ -371,10 +297,47 @@ func resourceSepChangePools(ctx context.Context, d *schema.ResourceData, m inter
|
||||
|
||||
newPoolsList := newPoolsInterface.(*schema.Set).Difference(oldPoolsInterface.(*schema.Set)).List()
|
||||
for _, pool := range newPoolsList {
|
||||
poolItem := pool.(map[string]interface{})
|
||||
|
||||
accessAccountIDs := []uint64{}
|
||||
|
||||
for _, v := range poolItem["access_account_ids"].([]interface{}) {
|
||||
accessAccountIDs = append(accessAccountIDs, uint64(v.(int)))
|
||||
}
|
||||
accessResGroupIDs := []uint64{}
|
||||
for _, v := range poolItem["access_res_group_ids"].([]interface{}) {
|
||||
accessResGroupIDs = append(accessResGroupIDs, uint64(v.(int)))
|
||||
}
|
||||
|
||||
types := []string{}
|
||||
for _, v := range poolItem["types"].([]interface{}) {
|
||||
types = append(types, v.(string))
|
||||
}
|
||||
|
||||
uris := []UrisModel{}
|
||||
list := poolItem["uris"].(*schema.Set).List()
|
||||
for _, v := range list {
|
||||
if m, ok := v.(map[string]interface{}); ok {
|
||||
uris = append(uris, UrisModel{IP: m["ip"].(string),
|
||||
Port: uint64(m["port"].(int)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
poolValue := PoolModel{
|
||||
AccessAccountIDs: accessAccountIDs,
|
||||
AccessResGroupIDs: accessResGroupIDs,
|
||||
Name: poolItem["name"].(string),
|
||||
Types: types,
|
||||
Uris: uris,
|
||||
UsageLimit: uint64(poolItem["usage_limit"].(int)),
|
||||
}
|
||||
marshalPool, _ := json.Marshal(poolValue)
|
||||
log.Debugf(string(marshalPool))
|
||||
addPoolReq := sep.AddPoolRequest{
|
||||
SEPID: uint64(d.Get("sep_id").(int)),
|
||||
Sync: true,
|
||||
Pool: pool.(string),
|
||||
Pool: string(marshalPool),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().SEP().AddPool(ctx, addPoolReq)
|
||||
@@ -386,43 +349,6 @@ func resourceSepChangePools(ctx context.Context, d *schema.ResourceData, m inter
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepDecommission(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
decommission := d.Get("decommission").(bool)
|
||||
if decommission {
|
||||
req := sep.DecommissionRequest{
|
||||
SEPID: uint64(d.Get("sep_id").(int)),
|
||||
ClearPhisically: d.Get("clear_physically").(bool),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().SEP().Decommission(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepUpdateCapacityLimit(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
updCapacityLimit := d.Get("upd_capacity_limit").(bool)
|
||||
if updCapacityLimit {
|
||||
req := sep.UpdateCapacityLimitRequest{
|
||||
SEPID: uint64(d.Get("sep_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().SEP().UpdateCapacityLimit(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSepUpdateConfig(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
@@ -581,3 +507,18 @@ func ResourceSep() *schema.Resource {
|
||||
Schema: resourceSepSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
type PoolModel struct {
|
||||
AccessAccountIDs []uint64 `json:"accessAccountIds"`
|
||||
AccessResGroupIDs []uint64 `json:"accessResGroupIds"`
|
||||
Name string `json:"name"`
|
||||
Types []string `json:"types"`
|
||||
Uris []UrisModel `json:"uris"`
|
||||
UsageLimit uint64 `json:"usage_limit"`
|
||||
}
|
||||
|
||||
type UrisModel struct {
|
||||
IP string `json:"ip"`
|
||||
|
||||
Port uint64 `json:"port"`
|
||||
}
|
||||
|
||||
@@ -533,67 +533,78 @@ func resourceSepSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"clear_physically": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: true,
|
||||
Description: "clear disks and images physically",
|
||||
},
|
||||
"decommission": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "unlink everything that exists from SEP",
|
||||
},
|
||||
"enable": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "enable SEP after creation",
|
||||
},
|
||||
"field_edit": {
|
||||
Type: schema.TypeList,
|
||||
MaxItems: 1,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"field_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "field name",
|
||||
},
|
||||
"field_value": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "field value",
|
||||
},
|
||||
"field_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "field type",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"sep_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "sep type des id",
|
||||
},
|
||||
"upd_capacity_limit": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Update SEP capacity limit",
|
||||
},
|
||||
"pools": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Description: "add/delete pools to/from sep",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_account_ids": {
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
Description: "access account ids",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"access_res_group_ids": {
|
||||
Type: schema.TypeList,
|
||||
Required: true,
|
||||
Description: "access res group ids",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "name",
|
||||
},
|
||||
"types": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Description: "types",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"uris": {
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
Description: "uris",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "ip",
|
||||
},
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "port",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"usage_limit": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "usage limit",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"ckey": {
|
||||
@@ -610,9 +621,10 @@ func resourceSepSchemaMake() map[string]*schema.Schema {
|
||||
},
|
||||
},
|
||||
"config": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "sep config string",
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "sep config string",
|
||||
DiffSuppressFunc: resourceSepDiffSupperss,
|
||||
},
|
||||
"consumed_by": {
|
||||
Type: schema.TypeSet,
|
||||
|
||||
@@ -34,6 +34,8 @@ package sep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -67,3 +69,15 @@ func utilitySepCheckPresence(ctx context.Context, d *schema.ResourceData, m inte
|
||||
|
||||
return sep, nil
|
||||
}
|
||||
|
||||
func resourceSepDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool {
|
||||
var v1, v2 interface{}
|
||||
json.Unmarshal([]byte(newVal), &v1)
|
||||
json.Unmarshal([]byte(oldVal), &v2)
|
||||
if reflect.DeepEqual(v1, v2) {
|
||||
log.Debugf("resourceSepDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=TRUE", key, oldVal, newVal)
|
||||
return true
|
||||
}
|
||||
log.Debugf("resourceSepDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=FALSE", key, oldVal, newVal)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ func flattenUserList(users *user.ListUsers) []map[string]interface{} {
|
||||
temp := map[string]interface{}{
|
||||
"ckey": item.CKey,
|
||||
"meta": flattens.FlattenMeta(item.Meta),
|
||||
"api_access": item.APIAccess,
|
||||
"apiaccess": item.APIAccess,
|
||||
"active": item.Active,
|
||||
"authkey": item.AuthKey,
|
||||
"authkeys": flattenItemUser(item.AuthKeys),
|
||||
|
||||
@@ -2018,7 +2018,7 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"DHCP", "VIP", "EXCLUDE"}, false),
|
||||
ValidateFunc: validation.StringInSlice([]string{"DHCP", "VIP", "EXCLUDED"}, false),
|
||||
},
|
||||
"ip_addr": {
|
||||
Type: schema.TypeString,
|
||||
|
||||
Reference in New Issue
Block a user