Compare commits

..

2 Commits

Author SHA1 Message Date
3a5825ade0 4.4.4 2024-03-25 12:00:45 +03:00
ce4b847596 4.4.3 2023-12-14 18:32:46 +03:00
1196 changed files with 22034 additions and 113414 deletions

View File

@@ -1,31 +1,20 @@
## Version 4.5.3 ## Version 4.4.4
### Bugfix ### Bugfix
- Change field Value in schema resource kvmvm in blocks affinity_rules and anti_affinity_rules from required to optional in cloudapi and cloudbroker - Changed field Value in schema resource kvmvm in blocks affinity_rules and anti_affinity_rules from required to optional in cloudapi
- Change the format ID in resource k8s_wg from wg_id to k8s_id#wg_id - Changed the format ID in resource k8s_wg from wg_id to k8s_id#wg_id
- Fix scripts intall.bat and intall.sh - Fixed scripts intall.bat and intall.sh
- Increased timeouts for resources account, disk, cdrom_image, image, virtual_image, k8s_wg, vins, rg in cloudbroker so that they match the same from cloudapi - Change logic from disk delete and disk add to disk rename when disk.disk_name field is changed in resource cloudapi/kvmvm
- Increased timeouts for resources pcidevice, sep, sep_config in cloudbroker
- Fix bug in affinity_rules in cloudbroker/kvmvm
- Add field NeedReboot in cloudapi/kvmvm in data_source, data_source_list and resource schemas
- Fix bug with field ExtNetID in CreateInRGRequest in cloudapi/vins and cloudbroker/vins
- Add boolean field Safe in Restart func in resource cloudapi/lb
- Add field force_resize in Resize func in resource cloudapi/kvmvm and cloudbroker/kvmvm
- Fix bug in cloudBroker/kvmvm with disk and extra_disks
- Change logic from disk delete and disk add to disk rename when disk.disk_name field is changed in resource cloudapi/kvmvm and cloudbroker/kvmvm
- Fix allowed network plugin value from "weawenet" to "weavenet" for k8ci, k8s resources in cloudbroker and for k8s resource in cloudapi - Fix allowed network plugin value from "weawenet" to "weavenet" for k8ci, k8s resources in cloudbroker and for k8s resource in cloudapi
- Fix bug with deleting decort_bservice resource when setting enable=false in cloudapi/bservice - Fix bug with deleting decort_bservice resource when setting enable=false in cloudapi/bservice
- Fix panic in data source decort_bservice_snapshot_list in cloudapi/bservice - Fix panic in data source decort_bservice_snapshot_list in cloudapi/bservice
- Fix panic in data source decort_rg_affinity_groups_list in cloudapi/rg - Fix panic in data source decort_rg_affinity_groups_list in cloudapi/rg
- Fix change description in resource decort_cb_kvmvm in cloudbroker - Fix duplicate enabling of bservice after create in cloudapi/bservice
- Computed field bootdisk_size has been renamed to boot_disk_size in data sources decort_kvmvm, decort_kvmvm_list, decort_cb_kvmvm_list in cloudapi and cloudbroker - Fix start of bservice after create in cloudapi/b
- Change request logic for delete resource decort_cb_k8s_cp in cloudbroker - Fix permanently field for disks delete, change default value from true to false in decort_kvmvm in cloudapi/kvmvm
- Fix schema in datasource decort_cb_kvmvm in cloudbroker, fields boot_disk_id, sep_id, pool, extra_disks, network, net_id, net_type, ip_address, mac have been removes
- Fix panic with RG in cloudapi
- Fix permanently field for disks delete in decort_kvmvm in cloudapi/kvmvm and decort_cb_kvmvm in cloudbroker/kvmvm
- Fix bug with enable request duplication
### Feature ### Feature
- Add "permanently" flag in k8s, k8s_cp in cloudapi
- Add RAM divisibility validation in compute, k8s, k8s_cp and k8s_wg resources in cloudapi and cloudbroker - Add RAM validation in cloudapi/[k8s, k8s_cp, k8s_wg, kvmvm, bservice]
- Add "permanently" flag in k8s, k8s_cp in cloudapi - Add RAM validation in cloudbroker/[k8s, k8s_wg, kvmvm]
- Add field restore in cloudapi/disk resource

View File

@@ -7,7 +7,7 @@ ZIPDIR = ./zip
BINARY=${NAME} BINARY=${NAME}
WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH} WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH}
MAINPATH = ./cmd/decort/ MAINPATH = ./cmd/decort/
VERSION=4.5.3 VERSION=4.4.4
OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH) OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)
FILES = ${BINARY}_${VERSION}_darwin_amd64\ FILES = ${BINARY}_${VERSION}_darwin_amd64\

View File

@@ -6,7 +6,6 @@ Terraform provider для платформы Digital Energy Cloud Orchestration
| Версия DECORT API | Версия провайдера Terraform | | Версия DECORT API | Версия провайдера Terraform |
| ------ | ------ | | ------ | ------ |
| 3.8.9 | 4.5.x |
| 3.8.8 | 4.4.x | | 3.8.8 | 4.4.x |
| 3.8.7 | 4.3.x | | 3.8.7 | 4.3.x |
| 3.8.6 | 4.0.x, 4.1.x, 4.2.x | | 3.8.6 | 4.0.x, 4.1.x, 4.2.x |
@@ -27,42 +26,23 @@ Terraform provider для платформы Digital Energy Cloud Orchestration
## Возможности провайдера ## Возможности провайдера
- Режим пользователя: - Работа с Compute instances,
- Работа с accounts, - Работа с disks,
- Работа с bservice, - Работа с k8s,
- Работа с disks, - Работа с image,
- Работа с extnets, - Работа с flipgroups,
- Работа с flipgroups, - Работа с stacks,
- Работа с image, - Работа с reource groups,
- Работа с k8s, - Работа с VINS,
- Работа с Compute instances, - Работа с pfw,
- Работа с load balancer, - Работа с accounts,
- Работа с locations, - Работа с snapshots,
- Работа с pfw, - Работа с bservice,
- Работа с resource groups, - Работа с extnets,
- Работа с snapshots, - Работа с locations,
- Работа с stacks, - Работа с load balancer.
- Работа с VINS.
- Режим администратора: Вики проекта: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
- Работа с accounts,
- Работа с audits,
- Работа с disks,
- Работа с extnets,
- Работа с flipgroups,
- Работа с grids,
- Работа с images,
- Работа с k8ci,
- Работа с k8s,
- Работа с Compute instances,
- Работа с load balancer,
- Работа с pci device,
- Работа с resource groups,
- Работа с seps,
- Работа с stacks,
- Работа с VINS.
Со списком и описанием функционала всех групп можно ознамоиться на Вики проекта: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
## Установка ## Установка
Начиная с версии провайдера `4.3.0` в релизном архиве находятся скрипты-инсталляторы. Начиная с версии провайдера `4.3.0` в релизном архиве находятся скрипты-инсталляторы.
@@ -109,7 +89,7 @@ terraform {
9. Добавьте в файл блок с инициализацией провайдера. 9. Добавьте в файл блок с инициализацией провайдера.
```terraform ```terraform
provider "decort" { provider "decort" {
authenticator = "decs3o" authenticator = "oauth2"
controller_url = "https://mr4.digitalenergy.online" controller_url = "https://mr4.digitalenergy.online"
oauth2_url = "https://sso.digitalenergy.online" oauth2_url = "https://sso.digitalenergy.online"
allow_unverified_ssl = true allow_unverified_ssl = true
@@ -195,7 +175,7 @@ ${host_name}/${namespace}/${type}
8. Добавьте в файл блок с инициализацией провайдера. 8. Добавьте в файл блок с инициализацией провайдера.
```terraform ```terraform
provider "decort" { provider "decort" {
authenticator = "decs3o" authenticator = "oauth2"
controller_url = "https://mr4.digitalenergy.online" controller_url = "https://mr4.digitalenergy.online"
oauth2_url = "https://sso.digitalenergy.online" oauth2_url = "https://sso.digitalenergy.online"
allow_unverified_ssl = true allow_unverified_ssl = true

View File

@@ -58,7 +58,7 @@ Two ways for starting:
```terraform ```terraform
provider "decort" { provider "decort" {
authenticator = "decs3o" authenticator = "oauth2"
#controller_url = <DECORT_CONTROLLER_URL> #controller_url = <DECORT_CONTROLLER_URL>
controller_url = "https://ds1.digitalenergy.online" controller_url = "https://ds1.digitalenergy.online"
#oauth2_url = <DECORT_SSO_URL> #oauth2_url = <DECORT_SSO_URL>

2
go.mod
View File

@@ -8,7 +8,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.0
golang.org/x/net v0.17.0 golang.org/x/net v0.17.0
repository.basistech.ru/BASIS/decort-golang-sdk v1.7.7 repository.basistech.ru/BASIS/decort-golang-sdk v1.6.14
) )
require ( require (

4
go.sum
View File

@@ -285,5 +285,5 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
repository.basistech.ru/BASIS/decort-golang-sdk v1.7.7 h1:VIF+NXXfYec8DtlTcPae+CjB0fhH8ovBQxKMwEnLgE8= repository.basistech.ru/BASIS/decort-golang-sdk v1.6.14 h1:FSu4kPKHsrmZpYIUKlX0s4v53CGmmT2Ne2uWuiRh6pM=
repository.basistech.ru/BASIS/decort-golang-sdk v1.7.7/go.mod h1:7fj8sgGZFiiExewQeqckCS4WxwOmU0oP6BO6mi1Lpkw= repository.basistech.ru/BASIS/decort-golang-sdk v1.6.14/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE=

View File

@@ -1,33 +1,32 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package constants package constants
import "time" import "time"
// timeouts for API calls from CRUD functions of Terraform plugin // timeouts for API calls from CRUD functions of Terraform plugin
var Timeout30s = time.Second * 30 var Timeout30s = time.Second * 30
var Timeout60s = time.Second * 60 var Timeout60s = time.Second * 60
var Timeout180s = time.Second * 180 var Timeout180s = time.Second * 180
var Timeout300s = time.Second * 300 var Timeout300s = time.Second * 300
var Timeout600s = time.Second * 600 var Timeout600s = time.Second * 600
var Timeout900s = time.Second * 900 var Timeout20m = time.Minute * 20
var Timeout20m = time.Minute * 20 var Timeout30m = time.Minute * 30
var Timeout30m = time.Minute * 30

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -23,13 +23,14 @@ package controller
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
// "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
decort "repository.basistech.ru/BASIS/decort-golang-sdk" decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/config" "repository.basistech.ru/BASIS/decort-golang-sdk/config"
@@ -42,32 +43,24 @@ import (
// enumerated constants that define authentication modes // enumerated constants that define authentication modes
const ( const (
MODE_UNDEF = iota // this is the invalid mode - it should never be seen MODE_UNDEF = iota // this is the invalid mode - it should never be seen
MODE_LEGACY MODE_LEGACY = iota
MODE_DECS3O MODE_OAUTH2 = iota
MODE_JWT MODE_JWT = iota
MODE_BVS
) )
type ControllerCfg struct { type ControllerCfg struct {
controller_url string // always required controller_url string // always required
auth_mode_code int // always required auth_mode_code int // always required
auth_mode_txt string // always required, it is a text representation of auth mode auth_mode_txt string // always required, it is a text representation of auth mode
bvs_user string // required for bvs mode
bvs_password string // required for bvs mode
domain string // required for bvs mode
token config.Token // obtained from BVS provider on successful login in bvs mode
path_cfg string // the path of the configuration file entry
path_token string // the path of the token file entry
time_to_refresh int64 // the number of minutes before the expiration of the token, a refresh will be made
legacy_user string // required for legacy mode legacy_user string // required for legacy mode
legacy_password string // required for legacy mode legacy_password string // required for legacy mode
legacy_sid string // obtained from DECORT controller on successful login in legacy mode legacy_sid string // obtained from DECORT controller on successful login in legacy mode
jwt string // obtained from Outh2 provider on successful login in decs3o mode, required in jwt mode jwt string // obtained from Outh2 provider on successful login in oauth2 mode, required in jwt mode
app_id string // required for decs3o and bvs mode app_id string // required for oauth2 mode
app_secret string // required for decs3o and bvs mode app_secret string // required for oauth2 mode
oauth2_url string // required for decs3o and bvs mode oauth2_url string // always required
decort_username string // assigned to either legacy_user (legacy mode) or Oauth2 user (decs3o mode) upon successful verification decort_username string // assigned to either legacy_user (legacy mode) or Oauth2 user (oauth2 mode) upon successful verification
cc_client *http.Client // assigned when all initial checks successfully passed cc_client *http.Client // assigned when all initial checks successfully passed
caller interfaces.Caller caller interfaces.Caller
} }
@@ -90,24 +83,17 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
legacy_user: d.Get("user").(string), legacy_user: d.Get("user").(string),
legacy_password: d.Get("password").(string), legacy_password: d.Get("password").(string),
legacy_sid: "", legacy_sid: "",
bvs_user: d.Get("bvs_user").(string),
bvs_password: d.Get("bvs_password").(string),
domain: d.Get("domain").(string),
jwt: d.Get("jwt").(string), jwt: d.Get("jwt").(string),
app_id: d.Get("app_id").(string), app_id: d.Get("app_id").(string),
app_secret: d.Get("app_secret").(string), app_secret: d.Get("app_secret").(string),
oauth2_url: d.Get("oauth2_url").(string), oauth2_url: d.Get("oauth2_url").(string),
decort_username: "", decort_username: "",
token: config.Token{},
path_cfg: d.Get("path_cfg").(string),
path_token: d.Get("path_token").(string),
time_to_refresh: int64(d.Get("time_to_refresh").(int)),
} }
allow_unverified_ssl := d.Get("allow_unverified_ssl").(bool) allow_unverified_ssl := d.Get("allow_unverified_ssl").(bool)
if ret_config.controller_url == "" { if ret_config.controller_url == "" {
return nil, fmt.Errorf("empty DECORT cloud controller URL provided") return nil, fmt.Errorf("Empty DECORT cloud controller URL provided.")
} }
// this should have already been done by StateFunc defined in Schema, but we want to be sure // this should have already been done by StateFunc defined in Schema, but we want to be sure
@@ -116,53 +102,33 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
switch ret_config.auth_mode_txt { switch ret_config.auth_mode_txt {
case "jwt": case "jwt":
if ret_config.jwt == "" { if ret_config.jwt == "" {
return nil, fmt.Errorf("authenticator mode 'jwt' specified but no JWT provided") return nil, fmt.Errorf("Authenticator mode 'jwt' specified but no JWT provided.")
} }
ret_config.auth_mode_code = MODE_JWT ret_config.auth_mode_code = MODE_JWT
case "decs3o": case "oauth2":
if ret_config.oauth2_url == "" { if ret_config.oauth2_url == "" {
return nil, fmt.Errorf("authenticator mode 'decs3o' specified but no OAuth2 URL provided") return nil, fmt.Errorf("Authenticator mode 'oauth2' specified but no OAuth2 URL provided.")
} }
if ret_config.app_id == "" { if ret_config.app_id == "" {
return nil, fmt.Errorf("authenticator mode 'decs3o' specified but no Application ID provided") return nil, fmt.Errorf("Authenticator mode 'oauth2' specified but no Application ID provided.")
} }
if ret_config.app_secret == "" { if ret_config.app_secret == "" {
return nil, fmt.Errorf("authenticator mode 'decs3o' specified but no Secret ID provided") return nil, fmt.Errorf("Authenticator mode 'oauth2' specified but no Secret ID provided.")
} }
ret_config.auth_mode_code = MODE_DECS3O ret_config.auth_mode_code = MODE_OAUTH2
case "legacy": case "legacy":
// //
ret_config.legacy_user = d.Get("user").(string) ret_config.legacy_user = d.Get("user").(string)
if ret_config.legacy_user == "" { if ret_config.legacy_user == "" {
return nil, fmt.Errorf("authenticator mode 'legacy' specified but no user provided") return nil, fmt.Errorf("Authenticator mode 'legacy' specified but no user provided.")
} }
ret_config.legacy_password = d.Get("password").(string) ret_config.legacy_password = d.Get("password").(string)
if ret_config.legacy_password == "" { if ret_config.legacy_password == "" {
return nil, fmt.Errorf("authenticator mode 'legacy' specified but no password provided") return nil, fmt.Errorf("Authenticator mode 'legacy' specified but no password provided.")
} }
ret_config.auth_mode_code = MODE_LEGACY ret_config.auth_mode_code = MODE_LEGACY
case "bvs":
if ret_config.bvs_user == "" {
return nil, fmt.Errorf("authenticator mode 'bvs' specified but no user provided")
}
if ret_config.bvs_password == "" {
return nil, fmt.Errorf("authenticator mode 'bvs' specified but no password provided")
}
if ret_config.oauth2_url == "" {
return nil, fmt.Errorf("authenticator mode 'bvs' specified but no bvs URL provided")
}
if ret_config.app_id == "" {
return nil, fmt.Errorf("authenticator mode 'bvs' specified but no Application ID provided")
}
if ret_config.app_secret == "" {
return nil, fmt.Errorf("authenticator mode 'bvs' specified but no Secret ID provided")
}
if ret_config.domain == "" {
return nil, fmt.Errorf("authenticator mode 'bvs' specified but no Domain provided")
}
ret_config.auth_mode_code = MODE_BVS
default: default:
return nil, fmt.Errorf("unknown authenticator mode %q provided", ret_config.auth_mode_txt) return nil, fmt.Errorf("Unknown authenticator mode %q provided.", ret_config.auth_mode_txt)
} }
if allow_unverified_ssl { if allow_unverified_ssl {
@@ -198,16 +164,16 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
if !ok { if !ok {
return nil, err return nil, err
} }
case MODE_DECS3O: case MODE_OAUTH2:
// on success getDECS3OJWT will set config.jwt to the obtained JWT, so there is no // on success getOAuth2JWT will set config.jwt to the obtained JWT, so there is no
// need to set it once again here // need to set it once again here
// _, err := ret_config.getDECS3OJWT() // _, err := ret_config.getOAuth2JWT()
// if err != nil { // if err != nil {
// return nil, err // return nil, err
// } // }
// we are not verifying the JWT when parsing because actual verification is done on the // // we are not verifying the JWT when parsing because actual verification is done on the
// OVC controller side. Here we do parsing solely to extract Oauth2 user name (claim "user") // // OVC controller side. Here we do parsing solely to extract Oauth2 user name (claim "user")
// and JWT issuer name (claim "iss") // // and JWT issuer name (claim "iss")
// parser := jwt.Parser{} // parser := jwt.Parser{}
// token, _, err := parser.ParseUnverified(ret_config.jwt, jwt.MapClaims{}) // token, _, err := parser.ParseUnverified(ret_config.jwt, jwt.MapClaims{})
// if err != nil { // if err != nil {
@@ -220,7 +186,7 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
// tbuf.WriteString(claims["iss"].(string)) // tbuf.WriteString(claims["iss"].(string))
// ret_config.decort_username = tbuf.String() // ret_config.decort_username = tbuf.String()
// } else { // } else {
// return nil, fmt.Errorf("failed to extract user and iss fields from JWT token in oauth2 mode") // return nil, fmt.Errorf("Failed to extract user and iss fields from JWT token in oauth2 mode.")
// } // }
sdkConf := config.Config{ sdkConf := config.Config{
@@ -232,27 +198,10 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
} }
ret_config.caller = decort.New(sdkConf) ret_config.caller = decort.New(sdkConf)
case MODE_BVS:
sdkConf := config.BVSConfig{
AppID: ret_config.app_id,
AppSecret: ret_config.app_secret,
SSOURL: ret_config.oauth2_url,
DecortURL: ret_config.controller_url,
SSLSkipVerify: allow_unverified_ssl,
Username: ret_config.bvs_user,
Password: ret_config.bvs_password,
Domain: ret_config.domain,
Token: ret_config.token,
PathCfg: ret_config.path_cfg,
PathToken: ret_config.path_token,
TimeToRefresh: ret_config.time_to_refresh,
}
ret_config.caller = decort.NewBVS(sdkConf)
default: default:
// FYI, this should never happen due to all above checks, but we want to be fool proof // FYI, this should never happen due to all above checks, but we want to be fool proof
return nil, fmt.Errorf("unknown authenticator mode code %d provided", ret_config.auth_mode_code) return nil, fmt.Errorf("Unknown authenticator mode code %d provided.", ret_config.auth_mode_code)
} }
// All checks passed successfully, credentials corresponding to the selected authenticator mode // All checks passed successfully, credentials corresponding to the selected authenticator mode
@@ -264,13 +213,13 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
// return config.decort_username // return config.decort_username
// } // }
// func (config *ControllerCfg) getDECS3OJWT() (string, error) { // func (config *ControllerCfg) getOAuth2JWT() (string, error) {
// // Obtain JWT from the Oauth2 provider using application ID and application secret provided in config. // // Obtain JWT from the Oauth2 provider using application ID and application secret provided in config.
// if config.auth_mode_code == MODE_UNDEF { // if config.auth_mode_code == MODE_UNDEF {
// return "", fmt.Errorf("getOAuth2JWT method called for undefined authorization mode") // return "", fmt.Errorf("getOAuth2JWT method called for undefined authorization mode.")
// } // }
// if config.auth_mode_code != MODE_DECS3O { // if config.auth_mode_code != MODE_OAUTH2 {
// return "", fmt.Errorf("getOAuth2JWT method called for incompatible authorization mode %q", config.auth_mode_txt) // return "", fmt.Errorf("getOAuth2JWT method called for incompatible authorization mode %q.", config.auth_mode_txt)
// } // }
// params := url.Values{} // params := url.Values{}
@@ -301,7 +250,7 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
// } // }
// defer resp.Body.Close() // defer resp.Body.Close()
// responseData, err := io.ReadAll(resp.Body) // responseData, err := ioutil.ReadAll(resp.Body)
// if err != nil { // if err != nil {
// return "", err // return "", err
// } // }
@@ -321,13 +270,13 @@ func (config *ControllerCfg) validateJWT(jwt string) (bool, error) {
*/ */
if jwt == "" { if jwt == "" {
if config.jwt == "" { if config.jwt == "" {
return false, fmt.Errorf("validateJWT method called, but no meaningful JWT provided") return false, fmt.Errorf("validateJWT method called, but no meaningful JWT provided.")
} }
jwt = config.jwt jwt = config.jwt
} }
if config.oauth2_url == "" { if config.oauth2_url == "" {
return false, fmt.Errorf("validateJWT method called, but no OAuth2 URL provided") return false, fmt.Errorf("validateJWT method called, but no OAuth2 URL provided.")
} }
req, err := http.NewRequest("POST", config.controller_url+"/restmachine/cloudapi/account/list", nil) req, err := http.NewRequest("POST", config.controller_url+"/restmachine/cloudapi/account/list", nil)
@@ -344,7 +293,7 @@ func (config *ControllerCfg) validateJWT(jwt string) (bool, error) {
return false, err return false, err
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("validateJWT: unexpected status code %d when validating JWT against %q", return false, fmt.Errorf("validateJWT: unexpected status code %d when validating JWT against %q.",
resp.StatusCode, req.URL) resp.StatusCode, req.URL)
} }
defer resp.Body.Close() defer resp.Body.Close()
@@ -360,10 +309,10 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) {
reason, the method will return false and error. reason, the method will return false and error.
*/ */
if config.auth_mode_code == MODE_UNDEF { if config.auth_mode_code == MODE_UNDEF {
return false, fmt.Errorf("validateLegacyUser method called for undefined authorization mode") return false, fmt.Errorf("validateLegacyUser method called for undefined authorization mode.")
} }
if config.auth_mode_code != MODE_LEGACY { if config.auth_mode_code != MODE_LEGACY {
return false, fmt.Errorf("validateLegacyUser method called for incompatible authorization mode %q", config.auth_mode_txt) return false, fmt.Errorf("validateLegacyUser method called for incompatible authorization mode %q.", config.auth_mode_txt)
} }
params := url.Values{} params := url.Values{}
@@ -384,12 +333,12 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) {
return false, err return false, err
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("validateLegacyUser: unexpected status code %d when validating legacy user %q against %q", return false, fmt.Errorf("validateLegacyUser: unexpected status code %d when validating legacy user %q against %q.",
resp.StatusCode, config.legacy_user, config.controller_url) resp.StatusCode, config.legacy_user, config.controller_url)
} }
defer resp.Body.Close() defer resp.Body.Close()
responseData, err := io.ReadAll(req.Body) responseData, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -401,32 +350,21 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) {
} }
func (config *ControllerCfg) CloudAPI() *cloudapi.CloudAPI { func (config *ControllerCfg) CloudAPI() *cloudapi.CloudAPI {
switch config.auth_mode_code { if config.auth_mode_code == MODE_LEGACY {
case MODE_LEGACY:
client, _ := config.caller.(*decort.LegacyDecortClient) client, _ := config.caller.(*decort.LegacyDecortClient)
return client.CloudAPI() return client.CloudAPI()
case MODE_DECS3O:
client, _ := config.caller.(*decort.DecortClient)
return client.CloudAPI()
case MODE_BVS:
client, _ := config.caller.(*decort.BVSDecortClient)
return client.CloudAPI()
default:
return &cloudapi.CloudAPI{}
} }
client, _ := config.caller.(*decort.DecortClient)
return client.CloudAPI()
} }
func (config *ControllerCfg) CloudBroker() *cloudbroker.CloudBroker { func (config *ControllerCfg) CloudBroker() *cloudbroker.CloudBroker {
switch config.auth_mode_code { if config.auth_mode_code == MODE_LEGACY {
case MODE_LEGACY:
client, _ := config.caller.(*decort.LegacyDecortClient) client, _ := config.caller.(*decort.LegacyDecortClient)
return client.CloudBroker() return client.CloudBroker()
case MODE_DECS3O:
client, _ := config.caller.(*decort.DecortClient)
return client.CloudBroker()
case MODE_BVS:
client, _ := config.caller.(*decort.BVSDecortClient)
return client.CloudBroker()
default:
return &cloudbroker.CloudBroker{}
} }
client, _ := config.caller.(*decort.DecortClient)
return client.CloudBroker()
} }

View File

@@ -1,254 +1,172 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package provider package provider
import ( import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/extnet" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/locations" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/locations"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/stack" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/stack"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins"
cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account"
cb_audit "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/audit" cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet"
cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid"
cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup" cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
cb_grid "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/grid" cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg"
cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm" cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep"
cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb" cb_vgpu "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vgpu"
cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice" )
cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg"
cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep" func newDataSourcesMap() map[string]*schema.Resource {
cb_stack "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/stack" return map[string]*schema.Resource{
cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins" "decort_account": account.DataSourceAccount(),
"decort_account_resource_consumption_list": account.DataSourceAccountResourceConsumptionList(),
// cb_vgpu "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vgpu" "decort_account_resource_consumption_get": account.DataSourceAccountResourceConsumptionGet(),
cb_k8ci "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8ci" "decort_resgroup": rg.DataSourceResgroup(),
cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s" "decort_kvmvm": kvmvm.DataSourceCompute(),
) "decort_kvmvm_list": kvmvm.DataSourceComputeList(),
"decort_kvmvm_list_deleted": kvmvm.DataSourceComputeListDeleted(),
func newDataSourcesMap() map[string]*schema.Resource { "decort_kvmvm_audits": kvmvm.DataSourceComputeAudits(),
return map[string]*schema.Resource{ "decort_kvmvm_get_audits": kvmvm.DataSourceComputeGetAudits(),
"decort_account": account.DataSourceAccount(), "decort_kvmvm_get_console_url": kvmvm.DataSourceComputeGetConsoleUrl(),
"decort_resgroup": rg.DataSourceResgroup(), "decort_kvmvm_get_log": kvmvm.DataSourceComputeGetLog(),
"decort_kvmvm": kvmvm.DataSourceCompute(), "decort_kvmvm_pfw_list": kvmvm.DataSourceComputePfwList(),
"decort_kvmvm_list": kvmvm.DataSourceComputeList(), "decort_kvmvm_user_list": kvmvm.DataSourceComputeUserList(),
"decort_kvmvm_audits": kvmvm.DataSourceComputeAudits(), "decort_kvmvm_snapshot_usage": kvmvm.DataSourceComputeSnapshotUsage(),
"decort_kvmvm_get_audits": kvmvm.DataSourceComputeGetAudits(), "decort_kvmvm_vgpu_list": kvmvm.DataSourceComputeVGPUList(),
"decort_kvmvm_get_console_url": kvmvm.DataSourceComputeGetConsoleUrl(), "decort_kvmvm_pci_device_list": kvmvm.DataSourceComputePCIDeviceList(),
"decort_kvmvm_get_log": kvmvm.DataSourceComputeGetLog(), "decort_k8s": k8s.DataSourceK8s(),
"decort_kvmvm_pfw_list": kvmvm.DataSourceComputePfwList(), "decort_k8s_list": k8s.DataSourceK8sList(),
"decort_kvmvm_user_list": kvmvm.DataSourceComputeUserList(), "decort_k8s_list_deleted": k8s.DataSourceK8sListDeleted(),
"decort_kvmvm_snapshot_usage": kvmvm.DataSourceComputeSnapshotUsage(), "decort_k8s_wg": k8s.DataSourceK8sWg(),
"decort_k8s": k8s.DataSourceK8s(), "decort_k8s_wg_list": k8s.DataSourceK8sWgList(),
"decort_k8s_list": k8s.DataSourceK8sList(), "decort_k8s_computes": k8s.DataSourceK8sComputes(),
"decort_k8s_list_deleted": k8s.DataSourceK8sListDeleted(), "decort_k8s_wg_cloud_init": k8s.DataSourceK8sWgCloudInit(),
"decort_k8s_wg": k8s.DataSourceK8sWg(), "decort_k8ci_list": k8s.DataSourceK8CIList(),
"decort_k8s_wg_list": k8s.DataSourceK8sWgList(), "decort_vins": vins.DataSourceVins(),
"decort_k8s_computes": k8s.DataSourceK8sComputes(), "decort_vins_list": vins.DataSourceVinsList(),
"decort_k8ci_list": k8s.DataSourceK8CIList(), "decort_vins_audits": vins.DataSourceVinsAudits(),
"decort_vins": vins.DataSourceVins(), "decort_vins_ip_list": vins.DataSourceVinsIpList(),
"decort_vins_list": vins.DataSourceVinsList(), "decort_vins_list_deleted": vins.DataSourceVinsListDeleted(),
"decort_vins_audits": vins.DataSourceVinsAudits(), "decort_vins_ext_net_list": vins.DataSourceVinsExtNetList(),
"decort_vins_ip_list": vins.DataSourceVinsIpList(), "decort_vins_nat_rule_list": vins.DataSourceVinsNatRuleList(),
"decort_vins_list_deleted": vins.DataSourceVinsListDeleted(), "decort_vins_static_route_list": vins.DataSourceStaticRouteList(),
"decort_vins_ext_net_list": vins.DataSourceVinsExtNetList(), "decort_vins_static_route": vins.DataSourceStaticRoute(),
"decort_vins_nat_rule_list": vins.DataSourceVinsNatRuleList(), "decort_snapshot_list": snapshot.DataSourceSnapshotList(),
"decort_vins_static_route_list": vins.DataSourceStaticRouteList(), "decort_disk": disks.DataSourceDisk(),
"decort_vins_static_route": vins.DataSourceStaticRoute(), "decort_disk_list": disks.DataSourceDiskList(),
"decort_snapshot_list": snapshot.DataSourceSnapshotList(), "decort_rg_list": rg.DataSourceRgList(),
"decort_disk": disks.DataSourceDisk(), "decort_rg_affinity_group_computes": rg.DataSourceRgAffinityGroupComputes(),
"decort_disk_list": disks.DataSourceDiskList(), "decort_rg_affinity_groups_list": rg.DataSourceRgAffinityGroupsList(),
"decort_rg_list": rg.DataSourceRgList(), "decort_rg_affinity_groups_get": rg.DataSourceRgAffinityGroupsGet(),
"decort_rg_affinity_group_computes": rg.DataSourceRgAffinityGroupComputes(), "decort_rg_audits": rg.DataSourceRgAudits(),
"decort_rg_affinity_groups_list": rg.DataSourceRgAffinityGroupsList(), "decort_rg_list_computes": rg.DataSourceRgListComputes(),
"decort_rg_affinity_groups_get": rg.DataSourceRgAffinityGroupsGet(), "decort_rg_list_deleted": rg.DataSourceRgListDeleted(),
"decort_rg_audits": rg.DataSourceRgAudits(), "decort_rg_list_lb": rg.DataSourceRgListLb(),
"decort_rg_list_computes": rg.DataSourceRgListComputes(), "decort_rg_list_pfw": rg.DataSourceRgListPfw(),
"decort_rg_list_deleted": rg.DataSourceRgListDeleted(), "decort_rg_list_vins": rg.DataSourceRgListVins(),
"decort_rg_list_lb": rg.DataSourceRgListLb(), "decort_rg_resource_consumption_list": rg.DataSourceRGResourceConsumptionList(),
"decort_rg_list_pfw": rg.DataSourceRgListPfw(), "decort_rg_resource_consumption_get": rg.DataSourceRGResourceConsumptionGet(),
"decort_rg_list_vins": rg.DataSourceRgListVins(), "decort_rg_usage": rg.DataSourceRgUsage(),
"decort_rg_usage": rg.DataSourceRgUsage(), "decort_disk_list_types_detailed": disks.DataSourceDiskListTypesDetailed(),
"decort_disk_list_types_detailed": disks.DataSourceDiskListTypesDetailed(), "decort_disk_list_types": disks.DataSourceDiskListTypes(),
"decort_disk_list_types": disks.DataSourceDiskListTypes(), "decort_disk_list_deleted": disks.DataSourceDiskListDeleted(),
"decort_disk_list_deleted": disks.DataSourceDiskListDeleted(), "decort_disk_list_unattached": disks.DataSourceDiskListUnattached(),
"decort_disk_list_unattached": disks.DataSourceDiskListUnattached(), "decort_disk_snapshot": disks.DataSourceDiskSnapshot(),
"decort_disk_snapshot": disks.DataSourceDiskSnapshot(), "decort_disk_snapshot_list": disks.DataSourceDiskSnapshotList(),
"decort_disk_snapshot_list": disks.DataSourceDiskSnapshotList(), "decort_account_list": account.DataSourceAccountList(),
"decort_account_list": account.DataSourceAccountList(), "decort_account_computes_list": account.DataSourceAccountComputesList(),
"decort_account_computes_list": account.DataSourceAccountComputesList(), "decort_account_disks_list": account.DataSourceAccountDisksList(),
"decort_account_disks_list": account.DataSourceAccountDisksList(), "decort_account_vins_list": account.DataSourceAccountVinsList(),
"decort_account_vins_list": account.DataSourceAccountVinsList(), "decort_account_audits_list": account.DataSourceAccountAuditsList(),
"decort_account_audits_list": account.DataSourceAccountAuditsList(), "decort_account_rg_list": account.DataSourceAccountRGList(),
"decort_account_rg_list": account.DataSourceAccountRGList(), "decort_account_consumed_units": account.DataSourceAccountConsumedUnits(),
"decort_account_consumed_units": account.DataSourceAccountConsumedUnits(), "decort_account_consumed_units_by_type": account.DataSourceAccountConsumedUnitsByType(),
"decort_account_consumed_units_by_type": account.DataSourceAccountConsumedUnitsByType(), "decort_account_reserved_units": account.DataSourceAccountReservedUnits(),
"decort_account_reserved_units": account.DataSourceAccountReservedUnits(), "decort_account_templates_list": account.DataSourceAccountTemplatessList(),
"decort_account_templates_list": account.DataSourceAccountTemplatessList(), "decort_account_deleted_list": account.DataSourceAccountDeletedList(),
"decort_account_deleted_list": account.DataSourceAccountDeletedList(), "decort_account_flipgroups_list": account.DataSourceAccountFlipGroupsList(),
"decort_account_flipgroups_list": account.DataSourceAccountFlipGroupsList(), "decort_bservice_list": bservice.DataSourceBasicServiceList(),
"decort_bservice_list": bservice.DataSourceBasicServiceList(), "decort_bservice": bservice.DataSourceBasicService(),
"decort_bservice": bservice.DataSourceBasicService(), "decort_bservice_snapshot_list": bservice.DataSourceBasicServiceSnapshotList(),
"decort_bservice_snapshot_list": bservice.DataSourceBasicServiceSnapshotList(), "decort_bservice_group": bservice.DataSourceBasicServiceGroup(),
"decort_bservice_group": bservice.DataSourceBasicServiceGroup(), "decort_bservice_deleted_list": bservice.DataSourceBasicServiceDeletedList(),
"decort_bservice_deleted_list": bservice.DataSourceBasicServiceDeletedList(), "decort_extnet_list": extnet.DataSourceExtnetList(),
"decort_extnet_list": extnet.DataSourceExtnetList(), "decort_extnet_computes_list": extnet.DataSourceExtnetComputesList(),
"decort_extnet_computes_list": extnet.DataSourceExtnetComputesList(), "decort_extnet": extnet.DataSourceExtnet(),
"decort_extnet": extnet.DataSourceExtnet(), "decort_extnet_default": extnet.DataSourceExtnetDefault(),
"decort_extnet_default": extnet.DataSourceExtnetDefault(), "decort_locations_list": locations.DataSourceLocationsList(),
"decort_locations_list": locations.DataSourceLocationsList(), "decort_location_url": locations.DataSourceLocationUrl(),
"decort_location_url": locations.DataSourceLocationUrl(), "decort_image_list": image.DataSourceImageList(),
"decort_image_list": image.DataSourceImageList(), "decort_image": image.DataSourceImage(),
"decort_image": image.DataSourceImage(), "decort_lb": lb.DataSourceLB(),
"decort_lb": lb.DataSourceLB(), "decort_lb_list": lb.DataSourceLBList(),
"decort_lb_list": lb.DataSourceLBList(), "decort_lb_list_deleted": lb.DataSourceLBListDeleted(),
"decort_lb_list_deleted": lb.DataSourceLBListDeleted(), "decort_flipgroup": flipgroup.DataSourceFlipgroup(),
"decort_flipgroup": flipgroup.DataSourceFlipgroup(), "decort_flipgroup_list": flipgroup.DataSourceFlipGroupList(),
"decort_flipgroup_list": flipgroup.DataSourceFlipGroupList(), "decort_stack": stack.DataSourceStack(),
"decort_stack": stack.DataSourceStack(), "decort_stack_list": stack.DataSourceStackList(),
"decort_stack_list": stack.DataSourceStackList(),
"decort_account_resource_consumption_list": account.DataSourceAccountResourceConsumptionList(), "decort_cb_account": cb_account.DataSourceAccount(),
"decort_account_resource_consumption_get": account.DataSourceAccountResourceConsumptionGet(), "decort_cb_account_list": cb_account.DataSourceAccountList(),
"decort_kvmvm_list_deleted": kvmvm.DataSourceComputeListDeleted(), "decort_cb_account_computes_list": cb_account.DataSourceAccountComputesList(),
"decort_kvmvm_vgpu_list": kvmvm.DataSourceComputeVGPUList(), "decort_cb_account_deleted_list": cb_account.DataSourceAccountDeletedList(),
"decort_kvmvm_pci_device_list": kvmvm.DataSourceComputePCIDeviceList(), "decort_cb_account_disks_list": cb_account.DataSourceAccountDisksList(),
"decort_k8s_wg_cloud_init": k8s.DataSourceK8sWgCloudInit(), "decort_cb_account_flipgroups_list": cb_account.DataSourceAccountFlipGroupsList(),
"decort_rg_resource_consumption_list": rg.DataSourceRGResourceConsumptionList(), "decort_cb_account_rg_list": cb_account.DataSourceAccountRGList(),
"decort_rg_resource_consumption_get": rg.DataSourceRGResourceConsumptionGet(), "decort_cb_account_vins_list": cb_account.DataSourceAccountVinsList(),
"decort_cb_account_audits_list": cb_account.DataSourceAccountAuditsList(),
"decort_cb_account": cb_account.DataSourceAccount(), "decort_cb_extnet": cb_extnet.DataSourceExtnetCB(),
"decort_cb_account_list": cb_account.DataSourceAccountList(), "decort_cb_extnet_list": cb_extnet.DataSourceExtnetListCB(),
"decort_cb_account_computes_list": cb_account.DataSourceAccountComputesList(), "decort_cb_extnet_default": cb_extnet.DataSourceExtnetDefaultCB(),
"decort_cb_account_list_deleted": cb_account.DataSourceAccountDeletedList(), "decort_cb_disk": cb_disks.DataSourceDisk(),
"decort_cb_account_disks_list": cb_account.DataSourceAccountDisksList(), "decort_cb_disk_list": cb_disks.DataSourceDiskList(),
"decort_cb_account_flipgroups_list": cb_account.DataSourceAccountFlipGroupsList(), "decort_cb_image": cb_image.DataSourceImage(),
"decort_cb_account_rg_list": cb_account.DataSourceAccountRGList(), "decort_cb_grid": cb_grid.DataSourceGrid(),
"decort_cb_account_vins_list": cb_account.DataSourceAccountVinsList(), "decort_cb_grid_list": cb_grid.DataSourceGridList(),
"decort_cb_account_resource_consumption_get": cb_account.DataSourceAccountResourceConsumptionGet(), "decort_cb_image_list": cb_image.DataSourceImageList(),
"decort_cb_account_resource_consumption_list": cb_account.DataSourceAccountResourceConsumptionList(), "decort_cb_image_list_stacks": cb_image.DataSourceImageListStacks(),
"decort_cb_account_audits_list": cb_account.DataSourceAccountAuditsList(), "decort_cb_pcidevice": cb_pcidevice.DataSourcePcidevice(),
"decort_cb_audit": cb_audit.DataSourceAudit(), "decort_cb_pcidevice_list": cb_pcidevice.DataSourcePcideviceList(),
"decort_cb_audit_list": cb_audit.DataSourceAuditList(), "decort_cb_sep_list": cb_sep.DataSourceSepList(),
"decort_cb_audit_linked_jobs": cb_audit.DataSourceAuditLinkedJobs(), "decort_cb_sep": cb_sep.DataSourceSep(),
"decort_cb_extnet": cb_extnet.DataSourceExtnetCB(), "decort_cb_sep_consumption": cb_sep.DataSourceSepConsumption(),
"decort_cb_extnet_list": cb_extnet.DataSourceExtnetListCB(), "decort_cb_sep_disk_list": cb_sep.DataSourceSepDiskList(),
"decort_cb_extnet_default": cb_extnet.DataSourceExtnetDefaultCB(), "decort_cb_sep_config": cb_sep.DataSourceSepConfig(),
"decort_cb_extnet_static_route_list": cb_extnet.DataSourceStaticRouteList(), "decort_cb_sep_pool": cb_sep.DataSourceSepPool(),
"decort_cb_extnet_static_route": cb_extnet.DataSourceStaticRoute(), "decort_cb_vgpu": cb_vgpu.DataSourceVGPU(),
"decort_cb_image": cb_image.DataSourceImage(), "decort_cb_rg_list": cb_rg.DataSourceRgList(),
"decort_cb_grid": cb_grid.DataSourceGrid(), }
"decort_cb_grid_get_status": cb_grid.DataSourceGridGetStatus(),
"decort_cb_grid_post_status": cb_grid.DataSourceGridPostStatus(), }
"decort_cb_grid_get_diagnosis": cb_grid.DataSourceGridGetDiagnosis(),
"decort_cb_grid_post_diagnosis": cb_grid.DataSourceGridPostDiagnosis(),
"decort_cb_grid_list": cb_grid.DataSourceGridList(),
"decort_cb_grid_list_emails": cb_grid.DataSourceGridListEmails(),
"decort_cb_grid_list_consumption": cb_grid.DataSourceGridListConsumption(),
"decort_cb_grid_get_consumption": cb_grid.DataSourceGridGetConsumption(),
"decort_cb_image_list": cb_image.DataSourceImageList(),
"decort_cb_image_list_stacks": cb_image.DataSourceImageListStacks(),
"decort_cb_kvmvm": cb_kvmvm.DataSourceCompute(),
"decort_cb_kvmvm_affinity_relations": cb_kvmvm.DataSourceComputeAffinityRelations(),
"decort_cb_kvmvm_audits": cb_kvmvm.DataSourceComputeAudits(),
"decort_cb_kvmvm_boot_order_get": cb_kvmvm.DataSourceComputeBootOrderGet(),
"decort_cb_kvmvm_get_audits": cb_kvmvm.DataSourceComputeGetAudits(),
"decort_cb_kvmvm_get_console_url": cb_kvmvm.DataSourceComputeGetConsoleUrl(),
"decort_cb_kvmvm_get_log": cb_kvmvm.DataSourceComputeGetLog(),
"decort_cb_kvmvm_list": cb_kvmvm.DataSourceComputeList(),
"decort_cb_kvmvm_list_deleted": cb_kvmvm.DataSourceComputeListDeleted(),
"decort_cb_kvmvm_migrate_storage_info": cb_kvmvm.DataSourceComputeMigrateStorageInfo(),
"decort_cb_kvmvm_pci_device_list": cb_kvmvm.DataSourceComputePCIDeviceList(),
"decort_cb_kvmvm_pfw_list": cb_kvmvm.DataSourceComputePfwList(),
"decort_cb_kvmvm_snapshot_list": cb_kvmvm.DataSourceComputeSnapshotList(),
"decort_cb_kvmvm_snapshot_usage": cb_kvmvm.DataSourceComputeSnapshotUsage(),
"decort_cb_kvmvm_user_list": cb_kvmvm.DataSourceComputeUserList(),
"decort_cb_kvmvm_vgpu_list": cb_kvmvm.DataSourceComputeVGPUList(),
"decort_cb_disk": cb_disks.DataSourceDisk(),
"decort_cb_disk_list": cb_disks.DataSourceDiskList(),
"decort_cb_disk_list_deleted": cb_disks.DataSourceDiskListDeleted(),
"decort_cb_disk_list_types": cb_disks.DataSourceDiskListTypes(),
"decort_cb_disk_list_types_detailed": cb_disks.DataSourceDiskListTypesDetailed(),
"decort_cb_disk_list_unattached": cb_disks.DataSourceDiskListUnattached(),
"decort_cb_disk_snapshot": cb_disks.DataSourceDiskSnapshot(),
"decort_cb_disk_snapshot_list": cb_disks.DataSourceDiskSnapshotList(),
"decort_cb_pcidevice": cb_pcidevice.DataSourcePcidevice(),
"decort_cb_pcidevice_list": cb_pcidevice.DataSourcePcideviceList(),
"decort_cb_rg": cb_rg.DataSourceResgroup(),
"decort_cb_rg_affinity_group_computes": cb_rg.DataSourceRgAffinityGroupComputes(),
"decort_cb_rg_affinity_groups_get": cb_rg.DataSourceRgAffinityGroupsGet(),
"decort_cb_rg_affinity_groups_list": cb_rg.DataSourceRgAffinityGroupsList(),
"decort_cb_rg_resource_consumption_get": cb_rg.DataSourceRGResourceConsumptionGet(),
"decort_cb_rg_resource_consumption_list": cb_rg.DataSourceRGResourceConsumptionList(),
"decort_cb_rg_audits": cb_rg.DataSourceRgAudits(),
"decort_cb_rg_list": cb_rg.DataSourceRgList(),
"decort_cb_rg_list_deleted": cb_rg.DataSourceRgListDeleted(),
"decort_cb_rg_list_computes": cb_rg.DataSourceRgListComputes(),
"decort_cb_rg_list_lb": cb_rg.DataSourceRgListLb(),
"decort_cb_rg_list_pfw": cb_rg.DataSourceRgListPfw(),
"decort_cb_rg_list_vins": cb_rg.DataSourceRgListVins(),
"decort_cb_rg_usage": cb_rg.DataSourceRgUsage(),
"decort_cb_sep_list": cb_sep.DataSourceSepList(),
"decort_cb_sep": cb_sep.DataSourceSep(),
"decort_cb_sep_consumption": cb_sep.DataSourceSepConsumption(),
"decort_cb_sep_disk_list": cb_sep.DataSourceSepDiskList(),
"decort_cb_sep_config": cb_sep.DataSourceSepConfig(),
"decort_cb_sep_pool": cb_sep.DataSourceSepPool(),
"decort_cb_lb": cb_lb.DataSourceLB(),
"decort_cb_lb_list": cb_lb.DataSourceLBList(),
"decort_cb_lb_list_deleted": cb_lb.DataSourceLBListDeleted(),
"decort_cb_flipgroup_list": cb_flipgroup.DataSourceFlipgroupList(),
"decort_cb_flipgroup": cb_flipgroup.DataSourceFlipgroup(),
"decort_cb_stack_list": cb_stack.DataSourceStacksList(),
"decort_cb_stack": cb_stack.DataSourceStack(),
"decort_cb_vins": cb_vins.DataSourceVins(),
"decort_cb_vins_list": cb_vins.DataSourceVinsList(),
"decort_cb_vins_audits": cb_vins.DataSourceVinsAudits(),
"decort_cb_vins_ip_list": cb_vins.DataSourceVinsIpList(),
"decort_cb_vins_list_deleted": cb_vins.DataSourceVinsListDeleted(),
"decort_cb_vins_ext_net_list": cb_vins.DataSourceVinsExtNetList(),
"decort_cb_vins_nat_rule_list": cb_vins.DataSourceVinsNatRuleList(),
"decort_cb_vins_static_route": cb_vins.DataSourceStaticRoute(),
"decort_cb_vins_static_route_list": cb_vins.DataSourceStaticRouteList(),
"decort_cb_k8ci": cb_k8ci.DataSourceK8CI(),
"decort_cb_k8ci_list": cb_k8ci.DataSourceK8CIList(),
"decort_cb_k8ci_list_deleted": cb_k8ci.DataSourceK8CIListDeleted(),
"decort_cb_k8s": cb_k8s.DataSourceK8s(),
"decort_cb_k8s_list": cb_k8s.DataSourceK8sList(),
"decort_cb_k8s_list_deleted": cb_k8s.DataSourceK8sListDeleted(),
"decort_cb_k8s_wg": cb_k8s.DataSourceK8sWg(),
"decort_cb_k8s_wg_cloud_init": cb_k8s.DataSourceK8sWgCloudInit(),
"decort_cb_k8s_wg_list": cb_k8s.DataSourceK8sWgList(),
"decort_cb_k8s_computes": cb_k8s.DataSourceK8sComputes(),
}
}

View File

@@ -40,8 +40,8 @@ func Provider() *schema.Provider {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
StateFunc: statefuncs.StateFuncToLower, StateFunc: statefuncs.StateFuncToLower,
ValidateFunc: validation.StringInSlice([]string{"decs3o", "legacy", "jwt", "bvs"}, true), // ignore case while validating ValidateFunc: validation.StringInSlice([]string{"oauth2", "legacy", "jwt"}, true), // ignore case while validating
Description: "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'decs3o', 'legacy', 'jwt' or 'bvs'.", Description: "Authentication mode to use when connecting to DECORT cloud API. Should be one of 'oauth2', 'legacy' or 'jwt'.",
}, },
"oauth2_url": { "oauth2_url": {
@@ -49,7 +49,7 @@ func Provider() *schema.Provider {
Optional: true, Optional: true,
StateFunc: statefuncs.StateFuncToLower, StateFunc: statefuncs.StateFuncToLower,
DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil), DefaultFunc: schema.EnvDefaultFunc("DECORT_OAUTH2_URL", nil),
Description: "OAuth2 application URL in 'decs3o' and 'bvs' authentication mode.", Description: "OAuth2 application URL in 'oauth2' authentication mode.",
}, },
"controller_url": { "controller_url": {
@@ -74,39 +74,18 @@ func Provider() *schema.Provider {
Description: "User password for DECORT cloud API operations in 'legacy' authentication mode.", 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": { "app_id": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_ID", nil), DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_ID", nil),
Description: "Application ID to access DECORT cloud API in 'decs3o' and 'bvs' authentication mode.", Description: "Application ID to access DECORT cloud API in 'oauth2' authentication mode.",
}, },
"app_secret": { "app_secret": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_SECRET", nil), DefaultFunc: schema.EnvDefaultFunc("DECORT_APP_SECRET", nil),
Description: "Application secret to access DECORT cloud API in 'decs3o' and 'bvs' authentication mode.", Description: "Application secret to access DECORT cloud API in 'oauth2' authentication mode.",
}, },
"jwt": { "jwt": {
@@ -122,25 +101,6 @@ func Provider() *schema.Provider {
Default: false, Default: false,
Description: "If true, DECORT API will not verify SSL certificates. Use this with caution and in trusted environments only!", 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(), ResourcesMap: newResourcesMap(),

View File

@@ -1,103 +1,95 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package provider package provider
import ( import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/disks"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/k8s"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/kvmvm"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/lb"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/pfw" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/pfw"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins"
cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account" cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account"
cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks" cb_disks "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/disks"
cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet" cb_extnet "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/extnet"
cb_flipgroup "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/flipgroup" cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image"
cb_image "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/image" cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s"
cb_k8s "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8s" cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm"
cb_kvmvm "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/kvmvm" cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice"
cb_lb "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/lb" cb_pfw "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pfw"
cb_pcidevice "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/pcidevice" cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg"
cb_rg "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/rg" cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep"
cb_sep "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/sep" cb_snapshot "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/snapshot"
cb_k8ci "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/k8ci" cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins"
cb_vins "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/vins" )
)
func newResourcesMap() map[string]*schema.Resource {
func newResourcesMap() map[string]*schema.Resource { return map[string]*schema.Resource{
return map[string]*schema.Resource{ "decort_resgroup": rg.ResourceResgroup(),
"decort_resgroup": rg.ResourceResgroup(), "decort_kvmvm": kvmvm.ResourceCompute(),
"decort_kvmvm": kvmvm.ResourceCompute(), "decort_disk": disks.ResourceDisk(),
"decort_disk": disks.ResourceDisk(), "decort_disk_snapshot": disks.ResourceDiskSnapshot(),
"decort_disk_snapshot": disks.ResourceDiskSnapshot(), "decort_vins": vins.ResourceVins(),
"decort_vins": vins.ResourceVins(), "decort_pfw": pfw.ResourcePfw(),
"decort_pfw": pfw.ResourcePfw(), "decort_k8s": k8s.ResourceK8s(),
"decort_k8s": k8s.ResourceK8s(), "decort_k8s_wg": k8s.ResourceK8sWg(),
"decort_k8s_wg": k8s.ResourceK8sWg(), "decort_k8s_cp": k8s.ResourceK8sCP(),
"decort_k8s_cp": k8s.ResourceK8sCP(), "decort_snapshot": snapshot.ResourceSnapshot(),
"decort_snapshot": snapshot.ResourceSnapshot(), "decort_account": account.ResourceAccount(),
"decort_account": account.ResourceAccount(), "decort_bservice": bservice.ResourceBasicService(),
"decort_bservice": bservice.ResourceBasicService(), "decort_bservice_group": bservice.ResourceBasicServiceGroup(),
"decort_bservice_group": bservice.ResourceBasicServiceGroup(), "decort_image": image.ResourceImage(),
"decort_image": image.ResourceImage(), "decort_image_virtual": image.ResourceImageVirtual(),
"decort_image_virtual": image.ResourceImageVirtual(), "decort_lb": lb.ResourceLB(),
"decort_lb": lb.ResourceLB(), "decort_lb_backend": lb.ResourceLBBackend(),
"decort_lb_backend": lb.ResourceLBBackend(), "decort_lb_backend_server": lb.ResourceLBBackendServer(),
"decort_lb_backend_server": lb.ResourceLBBackendServer(), "decort_lb_frontend": lb.ResourceLBFrontend(),
"decort_lb_frontend": lb.ResourceLBFrontend(), "decort_lb_frontend_bind": lb.ResourceLBFrontendBind(),
"decort_lb_frontend_bind": lb.ResourceLBFrontendBind(), "decort_flipgroup": flipgroup.ResourceFlipgroup(),
"decort_flipgroup": flipgroup.ResourceFlipgroup(), "decort_vins_static_route": vins.ResourceStaticRoute(),
"decort_vins_static_route": vins.ResourceStaticRoute(),
"decort_cb_account": cb_account.ResourceAccount(),
"decort_cb_account": cb_account.ResourceAccount(), "decort_cb_extnet": cb_extnet.ResourceExtnetCB(),
"decort_cb_extnet": cb_extnet.ResourceExtnetCB(), "decort_cb_disk": cb_disks.ResourceDisk(),
"decort_cb_extnet_static_route": cb_extnet.ResourceStaticRoute(), "decort_cb_image": cb_image.ResourceImage(),
"decort_cb_disk": cb_disks.ResourceDisk(), "decort_cb_virtual_image": cb_image.ResourceVirtualImage(),
"decort_cb_disk_snapshot": cb_disks.ResourceDiskSnapshot(), "decort_cb_cdrom_image": cb_image.ResourceCDROMImage(),
"decort_cb_image": cb_image.ResourceImage(), "decort_cb_delete_images": cb_image.ResourceDeleteImages(),
"decort_cb_virtual_image": cb_image.ResourceVirtualImage(), "decort_cb_pcidevice": cb_pcidevice.ResourcePcidevice(),
"decort_cb_cdrom_image": cb_image.ResourceCDROMImage(), "decort_cb_sep": cb_sep.ResourceSep(),
"decort_cb_pcidevice": cb_pcidevice.ResourcePcidevice(), "decort_cb_sep_config": cb_sep.ResourceSepConfig(),
"decort_cb_sep": cb_sep.ResourceSep(), "decort_cb_resgroup": cb_rg.ResourceResgroup(),
"decort_cb_sep_config": cb_sep.ResourceSepConfig(), "decort_cb_kvmvm": cb_kvmvm.ResourceCompute(),
"decort_cb_kvmvm": cb_kvmvm.ResourceCompute(), "decort_cb_vins": cb_vins.ResourceVins(),
"decort_cb_vins": cb_vins.ResourceVins(), "decort_cb_pfw": cb_pfw.ResourcePfw(),
"decort_cb_k8ci": cb_k8ci.ResourceK8CI(), "decort_cb_k8s": cb_k8s.ResourceK8s(),
"decort_cb_k8s_cp": cb_k8s.ResourceK8sCP(), "decort_cb_k8s_wg": cb_k8s.ResourceK8sWg(),
"decort_cb_k8s_wg": cb_k8s.ResourceK8sWg(), "decort_cb_snapshot": cb_snapshot.ResourceSnapshot(),
"decort_cb_vins_static_route": cb_vins.ResourceStaticRoute(), }
"decort_cb_flipgroup": cb_flipgroup.ResourceFlipgroup(), }
"decort_cb_lb": cb_lb.ResourceLB(),
"decort_cb_lb_backend": cb_lb.ResourceLBBackend(),
"decort_cb_lb_backend_server": cb_lb.ResourceLBBackendServer(),
"decort_cb_lb_frontend": cb_lb.ResourceLBFrontend(),
"decort_cb_lb_frontend_bind": cb_lb.ResourceLBFrontendBind(),
"decort_cb_rg": cb_rg.ResourceResgroup(),
}
}

View File

@@ -45,7 +45,6 @@ import (
func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
acc, err := utilityAccountCheckPresence(ctx, d, m) acc, err := utilityAccountCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -100,10 +99,6 @@ func resourceLimitsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeFloat, Type: schema.TypeFloat,
Computed: true, Computed: true,
}, },
"cu_dm": {
Type: schema.TypeFloat,
Computed: true,
},
"cu_i": { "cu_i": {
Type: schema.TypeFloat, Type: schema.TypeFloat,
Computed: true, Computed: true,

View File

@@ -1,128 +1,127 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountAuditsList(aal account.ListAudits) []map[string]interface{} { func flattenAccountAuditsList(aal account.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, aa := range aal { for _, aa := range aal {
temp := map[string]interface{}{ temp := map[string]interface{}{
"call": aa.Call, "call": aa.Call,
"responsetime": aa.ResponseTime, "responsetime": aa.ResponseTime,
"statuscode": aa.StatusCode, "statuscode": aa.StatusCode,
"timestamp": aa.Timestamp, "timestamp": aa.Timestamp,
"user": aa.User, "user": aa.User,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountAuditsList, err := utilityAccountAuditsListCheckPresence(ctx, d, m) accountAuditsList, err := utilityAccountAuditsListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountAuditsList(accountAuditsList))
d.Set("items", flattenAccountAuditsList(accountAuditsList))
return nil
return nil }
}
func dataSourceAccountAuditsListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountAuditsListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "Search Result",
Description: "Search Result", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "call": {
"call": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "responsetime": {
"responsetime": { Type: schema.TypeFloat,
Type: schema.TypeFloat, Computed: true,
Computed: true, },
}, "statuscode": {
"statuscode": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "timestamp": {
"timestamp": { Type: schema.TypeFloat,
Type: schema.TypeFloat, Computed: true,
Computed: true, },
}, "user": {
"user": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, }
} return res
return res }
}
func DataSourceAccountAuditsList() *schema.Resource {
func DataSourceAccountAuditsList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountAuditsListRead,
ReadContext: dataSourceAccountAuditsListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountAuditsListSchemaMake(),
Schema: dataSourceAccountAuditsListSchemaMake(), }
} }
}

View File

@@ -1,258 +1,257 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountComputesList(acl *account.ListComputes) []map[string]interface{} { func flattenAccountComputesList(acl *account.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, acc := range acl.Data { for _, acc := range acl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"account_id": acc.AccountID, "account_id": acc.AccountID,
"account_name": acc.AccountName, "account_name": acc.AccountName,
"cpus": acc.CPUs, "cpus": acc.CPUs,
"created_by": acc.CreatedBy, "created_by": acc.CreatedBy,
"created_time": acc.CreatedTime, "created_time": acc.CreatedTime,
"deleted_by": acc.DeletedBy, "deleted_by": acc.DeletedBy,
"deleted_time": acc.DeletedTime, "deleted_time": acc.DeletedTime,
"compute_id": acc.ComputeID, "compute_id": acc.ComputeID,
"compute_name": acc.ComputeName, "compute_name": acc.ComputeName,
"ram": acc.RAM, "ram": acc.RAM,
"registered": acc.Registered, "registered": acc.Registered,
"rg_id": acc.RGID, "rg_id": acc.RGID,
"rg_name": acc.RGName, "rg_name": acc.RGName,
"status": acc.Status, "status": acc.Status,
"tech_status": acc.TechStatus, "tech_status": acc.TechStatus,
"total_disks_size": acc.TotalDisksSize, "total_disks_size": acc.TotalDisksSize,
"updated_by": acc.UpdatedBy, "updated_by": acc.UpdatedBy,
"updated_time": acc.UpdatedTime, "updated_time": acc.UpdatedTime,
"user_managed": acc.UserManaged, "user_managed": acc.UserManaged,
"vins_connected": acc.VINSConnected, "vins_connected": acc.VINSConnected,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountComputesList, err := utilityAccountComputesListCheckPresence(ctx, d, m) accountComputesList, err := utilityAccountComputesListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountComputesList(accountComputesList))
d.Set("items", flattenAccountComputesList(accountComputesList)) d.Set("entry_count", accountComputesList.EntryCount)
d.Set("entry_count", accountComputesList.EntryCount)
return nil
return nil }
}
func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountComputesListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "compute_id": {
"compute_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by compute ID",
Description: "Filter by compute ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by compute name",
Description: "Filter by compute name", },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by RG name",
Description: "Filter by RG name", },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by RG ID",
Description: "Filter by RG ID", },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by tech. status",
Description: "Filter by tech. status", },
}, "ip_address": {
"ip_address": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by IP address",
Description: "Filter by IP address", },
}, "extnet_name": {
"extnet_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by extnet name",
Description: "Filter by extnet name", },
}, "extnet_id": {
"extnet_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by extnet ID",
Description: "Filter by extnet ID", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "Search Result",
Description: "Search Result", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "cpus": {
"cpus": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "created_by": {
"created_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "deleted_by": {
"deleted_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "compute_id": {
"compute_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "compute_name": {
"compute_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "ram": {
"ram": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "registered": {
"registered": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "total_disks_size": {
"total_disks_size": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "updated_by": {
"updated_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "user_managed": {
"user_managed": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "vins_connected": {
"vins_connected": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountComputesList() *schema.Resource {
func DataSourceAccountComputesList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountComputesListRead,
ReadContext: dataSourceAccountComputesListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountComputesListSchemaMake(),
Schema: dataSourceAccountComputesListSchemaMake(), }
} }
}

View File

@@ -1,116 +1,110 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(ctx, d, m) accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("cu_c", accountConsumedUnits.CUC)
d.Set("cu_c", accountConsumedUnits.CUC) d.Set("cu_d", accountConsumedUnits.CUD)
d.Set("cu_d", accountConsumedUnits.CUD) d.Set("cu_i", accountConsumedUnits.CUI)
d.Set("cu_dm", accountConsumedUnits.CUDM) d.Set("cu_m", accountConsumedUnits.CUM)
d.Set("cu_i", accountConsumedUnits.CUI) d.Set("cu_np", accountConsumedUnits.CUNP)
d.Set("cu_m", accountConsumedUnits.CUM) d.Set("gpu_units", accountConsumedUnits.GPUUnits)
d.Set("cu_np", accountConsumedUnits.CUNP)
d.Set("gpu_units", accountConsumedUnits.GPUUnits) return nil
}
return nil
} func dataSourceAccountConsumedUnitsSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
func dataSourceAccountConsumedUnitsSchemaMake() map[string]*schema.Schema { "account_id": {
res := map[string]*schema.Schema{ Type: schema.TypeInt,
"account_id": { Required: true,
Type: schema.TypeInt, Description: "ID of the account",
Required: true, },
Description: "ID of the account", "cu_c": {
}, Type: schema.TypeFloat,
"cu_c": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_d": {
}, Type: schema.TypeFloat,
"cu_d": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_i": {
}, Type: schema.TypeFloat,
"cu_dm": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_m": {
}, Type: schema.TypeFloat,
"cu_i": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_np": {
}, Type: schema.TypeFloat,
"cu_m": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "gpu_units": {
}, Type: schema.TypeFloat,
"cu_np": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, }
}, return res
"gpu_units": { }
Type: schema.TypeFloat,
Computed: true, func DataSourceAccountConsumedUnits() *schema.Resource {
}, return &schema.Resource{
} SchemaVersion: 1,
return res
} ReadContext: dataSourceAccountConsumedUnitsRead,
func DataSourceAccountConsumedUnits() *schema.Resource { Timeouts: &schema.ResourceTimeout{
return &schema.Resource{ Read: &constants.Timeout30s,
SchemaVersion: 1, Default: &constants.Timeout60s,
},
ReadContext: dataSourceAccountConsumedUnitsRead,
Schema: dataSourceAccountConsumedUnitsSchemaMake(),
Timeouts: &schema.ResourceTimeout{ }
Read: &constants.Timeout30s, }
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountConsumedUnitsSchemaMake(),
}
}

View File

@@ -1,91 +1,90 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceAccountConsumedUnitsByTypeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountConsumedUnitsByTypeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
result, err := utilityAccountConsumedUnitsByTypeCheckPresence(ctx, d, m) result, err := utilityAccountConsumedUnitsByTypeCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("cu_result", result)
d.Set("cu_result", result)
return nil
return nil }
}
func dataSourceAccountConsumedUnitsByTypeSchemaMake() map[string]*schema.Schema {
func dataSourceAccountConsumedUnitsByTypeSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "cu_type": {
"cu_type": { Type: schema.TypeString,
Type: schema.TypeString, Required: true,
Required: true, Description: "cloud unit resource type",
Description: "cloud unit resource type", },
}, "cu_result": {
"cu_result": { Type: schema.TypeFloat,
Type: schema.TypeFloat, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountConsumedUnitsByType() *schema.Resource {
func DataSourceAccountConsumedUnitsByType() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountConsumedUnitsByTypeRead,
ReadContext: dataSourceAccountConsumedUnitsByTypeRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountConsumedUnitsByTypeSchemaMake(),
Schema: dataSourceAccountConsumedUnitsByTypeSchemaMake(), }
} }
}

View File

@@ -1,78 +1,77 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountDeletedList, err := utilityAccountDeletedListCheckPresence(ctx, d, m) accountDeletedList, err := utilityAccountDeletedListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountList(accountDeletedList))
d.Set("items", flattenAccountList(accountDeletedList)) d.Set("entry_count", accountDeletedList.EntryCount)
d.Set("entry_count", accountDeletedList.EntryCount)
return nil
return nil }
}
func dataSourceAccountDeletedListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountDeletedListSchemaMake() map[string]*schema.Schema { temp := dataSourceAccountListSchemaMake()
temp := dataSourceAccountListSchemaMake() delete(temp, "status")
delete(temp, "status") return temp
return temp }
}
func DataSourceAccountDeletedList() *schema.Resource {
func DataSourceAccountDeletedList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountDeletedListRead,
ReadContext: dataSourceAccountDeletedListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountDeletedListSchemaMake(),
Schema: dataSourceAccountDeletedListSchemaMake(), }
} }
}

View File

@@ -1,172 +1,171 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} { func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, ad := range adl.Data { for _, ad := range adl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"disk_id": ad.ID, "disk_id": ad.ID,
"disk_name": ad.Name, "disk_name": ad.Name,
"pool": ad.Pool, "pool": ad.Pool,
"sep_id": ad.SEPID, "sep_id": ad.SEPID,
"shareable": ad.Shareable, "shareable": ad.Shareable,
"size_max": ad.SizeMax, "size_max": ad.SizeMax,
"type": ad.Type, "type": ad.Type,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountDisksList, err := utilityAccountDisksListCheckPresence(ctx, d, m) accountDisksList, err := utilityAccountDisksListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountDisksList(accountDisksList))
d.Set("items", flattenAccountDisksList(accountDisksList)) d.Set("entry_count", accountDisksList.EntryCount)
d.Set("entry_count", accountDisksList.EntryCount)
return nil
return nil }
}
func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountDisksListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "disk_id": {
"disk_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by disk ID",
Description: "Filter by disk ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by disk name",
Description: "Filter by disk name", },
}, "disk_max_size": {
"disk_max_size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by disk max size",
Description: "Filter by disk max size", },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by disk type",
Description: "Filter by disk type", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "Search Result",
Description: "Search Result", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "disk_id": {
"disk_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "disk_name": {
"disk_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "pool": {
"pool": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "sep_id": {
"sep_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "shareable": {
"shareable": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "size_max": {
"size_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountDisksList() *schema.Resource {
func DataSourceAccountDisksList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountDisksListRead,
ReadContext: dataSourceAccountDisksListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountDisksListSchemaMake(),
Schema: dataSourceAccountDisksListSchemaMake(), }
} }
}

View File

@@ -1,253 +1,252 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountFlipGroupsList(afgl *account.ListFLIPGroups) []map[string]interface{} { func flattenAccountFlipGroupsList(afgl *account.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, afg := range afgl.Data { for _, afg := range afgl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"account_id": afg.AccountID, "account_id": afg.AccountID,
"client_type": afg.ClientType, "client_type": afg.ClientType,
"conn_type": afg.ConnType, "conn_type": afg.ConnType,
"created_by": afg.CreatedBy, "created_by": afg.CreatedBy,
"created_time": afg.CreatedTime, "created_time": afg.CreatedTime,
"default_gw": afg.DefaultGW, "default_gw": afg.DefaultGW,
"deleted_by": afg.DeletedBy, "deleted_by": afg.DeletedBy,
"deleted_time": afg.DeletedTime, "deleted_time": afg.DeletedTime,
"desc": afg.Description, "desc": afg.Description,
"gid": afg.GID, "gid": afg.GID,
"guid": afg.GUID, "guid": afg.GUID,
"fg_id": afg.ID, "fg_id": afg.ID,
"ip": afg.IP, "ip": afg.IP,
"milestones": afg.Milestones, "milestones": afg.Milestones,
"fg_name": afg.Name, "fg_name": afg.Name,
"net_id": afg.NetID, "net_id": afg.NetID,
"net_type": afg.NetType, "net_type": afg.NetType,
"netmask": afg.NetMask, "netmask": afg.NetMask,
"status": afg.Status, "status": afg.Status,
"updated_by": afg.UpdatedBy, "updated_by": afg.UpdatedBy,
"updated_time": afg.UpdatedTime, "updated_time": afg.UpdatedTime,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(ctx, d, m) accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList))
d.Set("items", flattenAccountFlipGroupsList(accountFlipGroupsList)) d.Set("entry_count", accountFlipGroupsList.EntryCount)
d.Set("entry_count", accountFlipGroupsList.EntryCount)
return nil
return nil }
}
func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountFlipGroupsListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by name",
Description: "Filter by name", },
}, "vins_id": {
"vins_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by ViNS ID",
Description: "Filter by ViNS ID", },
}, "vins_name": {
"vins_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by ViNS name",
Description: "Filter by ViNS name", },
}, "extnet_id": {
"extnet_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by extnet ID",
Description: "Filter by extnet ID", },
}, "by_ip": {
"by_ip": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by IP",
Description: "Filter by IP", },
}, "flipgroup_id": {
"flipgroup_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by flipgroup ID",
Description: "Filter by flipgroup ID", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "Search Result",
Description: "Search Result", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "client_type": {
"client_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "conn_type": {
"conn_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_by": {
"created_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "default_gw": {
"default_gw": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_by": {
"deleted_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "desc": {
"desc": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "gid": {
"gid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "guid": {
"guid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "fg_id": {
"fg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ip": {
"ip": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "milestones": {
"milestones": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "fg_name": {
"fg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "net_id": {
"net_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "net_type": {
"net_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "netmask": {
"netmask": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_by": {
"updated_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountFlipGroupsList() *schema.Resource {
func DataSourceAccountFlipGroupsList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountFlipGroupsListRead,
ReadContext: dataSourceAccountFlipGroupsListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountFlipGroupsListSchemaMake(),
Schema: dataSourceAccountFlipGroupsListSchemaMake(), }
} }
}

View File

@@ -44,7 +44,6 @@ import (
func dataSourceAccountResourceConsumptionGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountResourceConsumptionGetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountResourceConsumptionRec, err := utilityAccountResourceConsumptionGetCheckPresence(ctx, d, m) accountResourceConsumptionRec, err := utilityAccountResourceConsumptionGetCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -1,210 +1,209 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountList(al *account.ListAccounts) []map[string]interface{} { func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, acc := range al.Data { for _, acc := range al.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"acl": flattenRgAcl(acc.ACL), "acl": flattenRgAcl(acc.ACL),
"created_time": acc.CreatedTime, "created_time": acc.CreatedTime,
"deleted_time": acc.DeletedTime, "deleted_time": acc.DeletedTime,
"account_id": acc.ID, "account_id": acc.ID,
"account_name": acc.Name, "account_name": acc.Name,
"status": acc.Status, "status": acc.Status,
"updated_time": acc.UpdatedTime, "updated_time": acc.UpdatedTime,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func flattenRgAcl(rgAcls []account.RecordACL) []map[string]interface{} { func flattenRgAcl(rgAcls []account.RecordACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, rgAcl := range rgAcls { for _, rgAcl := range rgAcls {
temp := map[string]interface{}{ temp := map[string]interface{}{
"explicit": rgAcl.IsExplicit, "explicit": rgAcl.IsExplicit,
"guid": rgAcl.GUID, "guid": rgAcl.GUID,
"right": rgAcl.Rights, "right": rgAcl.Rights,
"status": rgAcl.Status, "status": rgAcl.Status,
"type": rgAcl.Type, "type": rgAcl.Type,
"user_group_id": rgAcl.UgroupID, "user_group_id": rgAcl.UgroupID,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountList, err := utilityAccountListCheckPresence(ctx, d, m) accountList, err := utilityAccountListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountList(accountList))
d.Set("items", flattenAccountList(accountList)) d.Set("entry_count", accountList.EntryCount)
d.Set("entry_count", accountList.EntryCount)
return nil
return nil }
}
func dataSourceAccountListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "by_id": {
"by_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by ID",
Description: "Filter by ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by name",
Description: "Filter by name", },
}, "acl": {
"acl": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by ACL",
Description: "Filter by ACL", },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by status",
Description: "Filter by status", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "acl": {
"acl": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "explicit": {
"explicit": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "guid": {
"guid": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "right": {
"right": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "user_group_id": {
"user_group_id": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountList() *schema.Resource {
func DataSourceAccountList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountListRead,
ReadContext: dataSourceAccountListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountListSchemaMake(),
Schema: dataSourceAccountListSchemaMake(), }
} }
}

View File

@@ -1,116 +1,110 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(ctx, d, m) accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("cu_c", accountReservedUnits.CUC)
d.Set("cu_c", accountReservedUnits.CUC) d.Set("cu_d", accountReservedUnits.CUD)
d.Set("cu_d", accountReservedUnits.CUD) d.Set("cu_i", accountReservedUnits.CUI)
d.Set("cu_dm", accountReservedUnits.CUDM) d.Set("cu_m", accountReservedUnits.CUM)
d.Set("cu_i", accountReservedUnits.CUI) d.Set("cu_np", accountReservedUnits.CUNP)
d.Set("cu_m", accountReservedUnits.CUM) d.Set("gpu_units", accountReservedUnits.GPUUnits)
d.Set("cu_np", accountReservedUnits.CUNP)
d.Set("gpu_units", accountReservedUnits.GPUUnits) return nil
}
return nil
} func dataSourceAccountReservedUnitsSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
func dataSourceAccountReservedUnitsSchemaMake() map[string]*schema.Schema { "account_id": {
res := map[string]*schema.Schema{ Type: schema.TypeInt,
"account_id": { Required: true,
Type: schema.TypeInt, Description: "ID of the account",
Required: true, },
Description: "ID of the account", "cu_c": {
}, Type: schema.TypeFloat,
"cu_c": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_d": {
}, Type: schema.TypeFloat,
"cu_d": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_i": {
}, Type: schema.TypeFloat,
"cu_dm": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_m": {
}, Type: schema.TypeFloat,
"cu_i": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "cu_np": {
}, Type: schema.TypeFloat,
"cu_m": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, "gpu_units": {
}, Type: schema.TypeFloat,
"cu_np": { Computed: true,
Type: schema.TypeFloat, },
Computed: true, }
}, return res
"gpu_units": { }
Type: schema.TypeFloat,
Computed: true, func DataSourceAccountReservedUnits() *schema.Resource {
}, return &schema.Resource{
} SchemaVersion: 1,
return res
} ReadContext: dataSourceAccountReservedUnitsRead,
func DataSourceAccountReservedUnits() *schema.Resource { Timeouts: &schema.ResourceTimeout{
return &schema.Resource{ Read: &constants.Timeout30s,
SchemaVersion: 1, Default: &constants.Timeout60s,
},
ReadContext: dataSourceAccountReservedUnitsRead,
Schema: dataSourceAccountReservedUnitsSchemaMake(),
Timeouts: &schema.ResourceTimeout{ }
Read: &constants.Timeout30s, }
Default: &constants.Timeout60s,
},
Schema: dataSourceAccountReservedUnitsSchemaMake(),
}
}

View File

@@ -44,7 +44,6 @@ import (
func dataSourceAccountResourceConsumptionListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountResourceConsumptionListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountResourceConsumptionList, err := utilityAccountResourceConsumptionListCheckPresence(ctx, d, m) accountResourceConsumptionList, err := utilityAccountResourceConsumptionListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -1,372 +1,371 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountRGList(argl *account.ListRG) []map[string]interface{} { func flattenAccountRGList(argl *account.ListRG) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, arg := range argl.Data { for _, arg := range argl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"computes": flattenAccRGComputes(arg.Computes), "computes": flattenAccRGComputes(arg.Computes),
"resources": flattenAccRGResources(arg.Resources), "resources": flattenAccRGResources(arg.Resources),
"created_by": arg.CreatedBy, "created_by": arg.CreatedBy,
"created_time": arg.CreatedTime, "created_time": arg.CreatedTime,
"deleted_by": arg.DeletedBy, "deleted_by": arg.DeletedBy,
"deleted_time": arg.DeletedTime, "deleted_time": arg.DeletedTime,
"rg_id": arg.RGID, "rg_id": arg.RGID,
"milestones": arg.Milestones, "milestones": arg.Milestones,
"rg_name": arg.RGName, "rg_name": arg.RGName,
"status": arg.Status, "status": arg.Status,
"updated_by": arg.UpdatedBy, "updated_by": arg.UpdatedBy,
"updated_time": arg.UpdatedTime, "updated_time": arg.UpdatedTime,
"vinses": arg.VINSes, "vinses": arg.VINSes,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func flattenAccRGComputes(argc account.RGComputes) []map[string]interface{} { func flattenAccRGComputes(argc account.RGComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"started": argc.Started, "started": argc.Started,
"stopped": argc.Stopped, "stopped": argc.Stopped,
} }
res = append(res, temp) res = append(res, temp)
return res return res
} }
func flattenAccResourceHack(r account.LimitsRG) []map[string]interface{} { func flattenAccResourceHack(r account.LimitsRG) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"cpu": r.CPU, "cpu": r.CPU,
"disksize": r.DiskSize, "disksize": r.DiskSize,
"extips": r.ExtIPs, "extips": r.ExtIPs,
"exttraffic": r.ExtTraffic, "exttraffic": r.ExtTraffic,
"gpu": r.GPU, "gpu": r.GPU,
"ram": r.RAM, "ram": r.RAM,
//"seps": flattenAccountSeps(r.SEPs), //"seps": flattenAccountSeps(r.SEPs),
} }
res = append(res, temp) res = append(res, temp)
return res return res
} }
func flattenAccResourceRg(r account.Resource) []map[string]interface{} { func flattenAccResourceRg(r account.Resource) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"cpu": r.CPU, "cpu": r.CPU,
"disksize": r.DiskSize, "disksize": r.DiskSize,
"extips": r.ExtIPs, "extips": r.ExtIPs,
"exttraffic": r.ExtTraffic, "exttraffic": r.ExtTraffic,
"gpu": r.GPU, "gpu": r.GPU,
"ram": r.RAM, "ram": r.RAM,
} }
res = append(res, temp) res = append(res, temp)
return res return res
} }
func flattenAccRGResources(argr account.RGResources) []map[string]interface{} { func flattenAccRGResources(argr account.RGResources) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{ temp := map[string]interface{}{
"consumed": flattenAccResourceRg(argr.Consumed), "consumed": flattenAccResourceRg(argr.Consumed),
"limits": flattenAccResourceHack(argr.Limits), "limits": flattenAccResourceHack(argr.Limits),
"reserved": flattenAccResourceRg(argr.Reserved), "reserved": flattenAccResourceRg(argr.Reserved),
} }
res = append(res, temp) res = append(res, temp)
return res return res
} }
func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m) accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountRGList(accountRGList))
d.Set("items", flattenAccountRGList(accountRGList)) d.Set("entry_count", accountRGList.EntryCount)
d.Set("entry_count", accountRGList.EntryCount)
return nil
return nil }
}
func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountRGListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by RG ID",
Description: "Filter by RG ID", },
}, "vins_id": {
"vins_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by ViNS ID",
Description: "Filter by ViNS ID", },
}, "vm_id": {
"vm_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by VM ID",
Description: "Filter by VM ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by name",
Description: "Filter by name", },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by status",
Description: "Filter by status", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "Search Result",
Description: "Search Result", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "computes": {
"computes": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "started": {
"started": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "stopped": {
"stopped": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "resources": {
"resources": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "consumed": {
"consumed": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "cpu": {
"cpu": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "disksize": {
"disksize": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "extips": {
"extips": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "exttraffic": {
"exttraffic": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "gpu": {
"gpu": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ram": {
"ram": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
},
"limits": {
"limits": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "cpu": {
"cpu": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "disksize": {
"disksize": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "extips": {
"extips": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "exttraffic": {
"exttraffic": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "gpu": {
"gpu": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ram": {
"ram": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "reserved": {
"reserved": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "cpu": {
"cpu": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "disksize": {
"disksize": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "extips": {
"extips": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "exttraffic": {
"exttraffic": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "gpu": {
"gpu": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ram": {
"ram": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, },
}, },
}, },
},
"created_by": {
"created_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "deleted_by": {
"deleted_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "milestones": {
"milestones": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_by": {
"updated_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "vinses": {
"vinses": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountRGList() *schema.Resource {
func DataSourceAccountRGList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountRGListRead,
ReadContext: dataSourceAccountRGListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountRGListSchemaMake(),
Schema: dataSourceAccountRGListSchemaMake(), }
} }
}

View File

@@ -1,186 +1,185 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountTemplatesList(atl *account.ListTemplates) []map[string]interface{} { func flattenAccountTemplatesList(atl *account.ListTemplates) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(atl.Data)) res := make([]map[string]interface{}, 0, len(atl.Data))
for _, at := range atl.Data { for _, at := range atl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"unc_path": at.UNCPath, "unc_path": at.UNCPath,
"account_id": at.AccountID, "account_id": at.AccountID,
"desc": at.Description, "desc": at.Description,
"template_id": at.ID, "template_id": at.ID,
"template_name": at.Name, "template_name": at.Name,
"public": at.Public, "public": at.Public,
"size": at.Size, "size": at.Size,
"status": at.Status, "status": at.Status,
"type": at.Type, "type": at.Type,
"username": at.Username, "username": at.Username,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceAccountTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(ctx, d, m) accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountTemplatesList(accountTemplatesList))
d.Set("items", flattenAccountTemplatesList(accountTemplatesList)) d.Set("entry_count", accountTemplatesList.EntryCount)
d.Set("entry_count", accountTemplatesList.EntryCount) return nil
return nil }
}
func dataSourceAccountTemplatesListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountTemplatesListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "include_deleted": {
"include_deleted": { Type: schema.TypeBool,
Type: schema.TypeBool, Optional: true,
Optional: true, },
}, "image_id": {
"image_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Find by image id",
Description: "Find by image id", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by name",
Description: "Filter by name", },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by type",
Description: "Filter by type", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "Search Result",
Description: "Search Result", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "unc_path": {
"unc_path": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "desc": {
"desc": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "template_id": {
"template_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "template_name": {
"template_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "public": {
"public": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "username": {
"username": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountTemplatessList() *schema.Resource {
func DataSourceAccountTemplatessList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountTemplatesListRead,
ReadContext: dataSourceAccountTemplatesListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountTemplatesListSchemaMake(),
Schema: dataSourceAccountTemplatesListSchemaMake(), }
} }
}

View File

@@ -1,223 +1,222 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package account package account
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} { func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, av := range avl.Data { for _, av := range avl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"account_id": av.AccountID, "account_id": av.AccountID,
"account_name": av.AccountName, "account_name": av.AccountName,
"computes": av.Computes, "computes": av.Computes,
"created_by": av.CreatedBy, "created_by": av.CreatedBy,
"created_time": av.CreatedTime, "created_time": av.CreatedTime,
"deleted_by": av.DeletedBy, "deleted_by": av.DeletedBy,
"deleted_time": av.DeletedTime, "deleted_time": av.DeletedTime,
"external_ip": av.ExternalIP, "external_ip": av.ExternalIP,
"vin_id": av.ID, "vin_id": av.ID,
"vin_name": av.Name, "vin_name": av.Name,
"network": av.Network, "network": av.Network,
"pri_vnf_dev_id": av.PriVNFDevID, "pri_vnf_dev_id": av.PriVNFDevID,
"rg_id": av.RGID, "rg_id": av.RGID,
"rg_name": av.RGName, "rg_name": av.RGName,
"status": av.Status, "status": av.Status,
"updated_by": av.UpdatedBy, "updated_by": av.UpdatedBy,
"updated_time": av.UpdatedTime, "updated_time": av.UpdatedTime,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
accountVinsList, err := utilityAccountVinsListCheckPresence(ctx, d, m) accountVinsList, err := utilityAccountVinsListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenAccountVinsList(accountVinsList))
d.Set("items", flattenAccountVinsList(accountVinsList)) d.Set("entry_count", accountVinsList.EntryCount)
d.Set("entry_count", accountVinsList.EntryCount)
return nil
return nil }
}
func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema {
func dataSourceAccountVinsListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "ID of the account",
Description: "ID of the account", },
}, "vins_id": {
"vins_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by ViNS ID",
Description: "Filter by ViNS ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by name",
Description: "Filter by name", },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by RG ID",
Description: "Filter by RG ID", },
}, "ext_ip": {
"ext_ip": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by external IP",
Description: "Filter by external IP", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "Search Result",
Description: "Search Result", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "computes": {
"computes": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "created_by": {
"created_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "deleted_by": {
"deleted_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "external_ip": {
"external_ip": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "vin_id": {
"vin_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "vin_name": {
"vin_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "network": {
"network": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "pri_vnf_dev_id": {
"pri_vnf_dev_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_by": {
"updated_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceAccountVinsList() *schema.Resource {
func DataSourceAccountVinsList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceAccountVinsListRead,
ReadContext: dataSourceAccountVinsListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceAccountVinsListSchemaMake(),
Schema: dataSourceAccountVinsListSchemaMake(), }
} }
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,298 +1,297 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package bservice package bservice
import ( import (
"context" "context"
"strconv" "strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
bs, err := utilityBasicServiceCheckPresence(ctx, d, m) bs, err := utilityBasicServiceCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
d.SetId(strconv.FormatUint(bs.ID, 10))
d.SetId(strconv.FormatUint(bs.ID, 10))
flattenService(d, bs)
flattenService(d, bs)
return nil
return nil }
}
func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema {
func dataSourceBasicServiceSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "service_id": {
"service_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, },
}, "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "base_domain": {
"base_domain": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "computes": {
"computes": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "architecture": {
"architecture": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "compgroup_id": {
"compgroup_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "compgroup_name": {
"compgroup_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "compgroup_role": {
"compgroup_role": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "id": {
"id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "stack_id": {
"stack_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
},
"cpu_total": {
"cpu_total": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "created_by": {
"created_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "deleted_by": {
"deleted_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "disk_total": {
"disk_total": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "gid": {
"gid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "groups": {
"groups": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "computes": {
"computes": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "consistency": {
"consistency": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "id": {
"id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, // "groups_name": {
// "groups_name": { // Type: schema.TypeList,
// Type: schema.TypeList, // Computed: true,
// Computed: true, // Elem: &schema.Schema{
// Elem: &schema.Schema{ // Type: schema.TypeString,
// Type: schema.TypeString, // },
// }, // },
// }, "guid": {
"guid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "milestones": {
"milestones": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "service_name": {
"service_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "parent_srv_id": {
"parent_srv_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "parent_srv_type": {
"parent_srv_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "ram_total": {
"ram_total": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "snapshots": {
"snapshots": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "guid": {
"guid": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "label": {
"label": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "timestamp": {
"timestamp": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "valid": {
"valid": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, },
}, },
}, },
},
"ssh_key": {
"ssh_key": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "ssh_user": {
"ssh_user": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_by": {
"updated_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "user_managed": {
"user_managed": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceBasicService() *schema.Resource {
func DataSourceBasicService() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceRead,
ReadContext: dataSourceBasicServiceRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceBasicServiceSchemaMake(),
Schema: dataSourceBasicServiceSchemaMake(), }
} }
}

View File

@@ -1,85 +1,84 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package bservice package bservice
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(ctx, d, m) basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenBasicServiceList(basicServiceDeletedList))
d.Set("items", flattenBasicServiceList(basicServiceDeletedList)) d.Set("entry_count", basicServiceDeletedList.EntryCount)
d.Set("entry_count", basicServiceDeletedList.EntryCount)
return nil
return nil }
}
func dataSourceBasicServiceDeletedListSchemaMake() map[string]*schema.Schema {
func dataSourceBasicServiceDeletedListSchemaMake() map[string]*schema.Schema { temp := dataSourceBasicServiceListSchemaMake()
temp := dataSourceBasicServiceListSchemaMake()
delete(temp, "by_id")
delete(temp, "by_id") delete(temp, "name")
delete(temp, "name") delete(temp, "rg_name")
delete(temp, "rg_name") delete(temp, "status")
delete(temp, "status") delete(temp, "tech_status")
delete(temp, "tech_status") delete(temp, "account_name")
delete(temp, "account_name")
return temp
return temp }
}
func DataSourceBasicServiceDeletedList() *schema.Resource {
func DataSourceBasicServiceDeletedList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceDeletedListRead,
ReadContext: dataSourceBasicServiceDeletedListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceBasicServiceDeletedListSchemaMake(),
Schema: dataSourceBasicServiceDeletedListSchemaMake(), }
} }
}

View File

@@ -1,305 +1,304 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package bservice package bservice
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m) bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("account_id", bsg.AccountID)
d.Set("account_id", bsg.AccountID) d.Set("account_name", bsg.AccountName)
d.Set("account_name", bsg.AccountName) d.Set("computes", flattenBSGroupComputes(bsg.Computes))
d.Set("computes", flattenBSGroupComputes(bsg.Computes)) d.Set("consistency", bsg.Consistency)
d.Set("consistency", bsg.Consistency) d.Set("cpu", bsg.CPU)
d.Set("cpu", bsg.CPU) d.Set("created_by", bsg.CreatedBy)
d.Set("created_by", bsg.CreatedBy) d.Set("created_time", bsg.CreatedTime)
d.Set("created_time", bsg.CreatedTime) d.Set("deleted_by", bsg.DeletedBy)
d.Set("deleted_by", bsg.DeletedBy) d.Set("deleted_time", bsg.DeletedTime)
d.Set("deleted_time", bsg.DeletedTime) d.Set("disk", bsg.Disk)
d.Set("disk", bsg.Disk) d.Set("driver", bsg.Driver)
d.Set("driver", bsg.Driver) d.Set("extnets", bsg.ExtNets)
d.Set("extnets", bsg.ExtNets) d.Set("gid", bsg.GID)
d.Set("gid", bsg.GID) d.Set("guid", bsg.GUID)
d.Set("guid", bsg.GUID) d.Set("image_id", bsg.ImageID)
d.Set("image_id", bsg.ImageID) d.Set("milestones", bsg.Milestones)
d.Set("milestones", bsg.Milestones) d.Set("compgroup_name", bsg.Name)
d.Set("compgroup_name", bsg.Name) d.Set("parents", bsg.Parents)
d.Set("parents", bsg.Parents) d.Set("ram", bsg.RAM)
d.Set("ram", bsg.RAM) d.Set("rg_id", bsg.RGID)
d.Set("rg_id", bsg.RGID) d.Set("rg_name", bsg.RGName)
d.Set("rg_name", bsg.RGName) d.Set("role", bsg.Role)
d.Set("role", bsg.Role) d.Set("sep_id", bsg.SEPID)
d.Set("sep_id", bsg.SEPID) d.Set("seq_no", bsg.SeqNo)
d.Set("seq_no", bsg.SeqNo) d.Set("status", bsg.Status)
d.Set("status", bsg.Status) d.Set("tech_status", bsg.TechStatus)
d.Set("tech_status", bsg.TechStatus) d.Set("timeout_start", bsg.TimeoutStart)
d.Set("timeout_start", bsg.TimeoutStart) d.Set("updated_by", bsg.UpdatedBy)
d.Set("updated_by", bsg.UpdatedBy) d.Set("updated_time", bsg.UpdatedTime)
d.Set("updated_time", bsg.UpdatedTime) d.Set("vinses", bsg.VINSes)
d.Set("vinses", bsg.VINSes) return nil
return nil }
}
func flattenBSGroupOSUsers(bsgosus bservice.ListOSUsers) []map[string]interface{} {
func flattenBSGroupOSUsers(bsgosus bservice.ListOSUsers) []map[string]interface{} { res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0) for _, bsgosu := range bsgosus {
for _, bsgosu := range bsgosus { temp := map[string]interface{}{
temp := map[string]interface{}{ "login": bsgosu.Login,
"login": bsgosu.Login, "password": bsgosu.Password,
"password": bsgosu.Password, }
} res = append(res, temp)
res = append(res, temp) }
}
return res
return res }
}
func flattenBSGroupComputes(bsgcs bservice.ListGroupComputes) []map[string]interface{} {
func flattenBSGroupComputes(bsgcs bservice.ListGroupComputes) []map[string]interface{} { res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0) for _, bsgc := range bsgcs {
for _, bsgc := range bsgcs { temp := map[string]interface{}{
temp := map[string]interface{}{ "id": bsgc.ID,
"id": bsgc.ID, "ip_addresses": bsgc.IPAddresses,
"ip_addresses": bsgc.IPAddresses, "name": bsgc.Name,
"name": bsgc.Name, "os_users": flattenBSGroupOSUsers(bsgc.OSUsers),
"os_users": flattenBSGroupOSUsers(bsgc.OSUsers), }
} res = append(res, temp)
res = append(res, temp) }
} return res
return res }
}
func dataSourceBasicServiceGroupSchemaMake() map[string]*schema.Schema {
func dataSourceBasicServiceGroupSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "service_id": {
"service_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, },
}, "compgroup_id": {
"compgroup_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, },
}, "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "computes": {
"computes": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "id": {
"id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ip_addresses": {
"ip_addresses": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeString,
Type: schema.TypeString, },
}, },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "os_users": {
"os_users": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "login": {
"login": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "password": {
"password": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, },
}, },
}, },
}, "consistency": {
"consistency": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "cpu": {
"cpu": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "created_by": {
"created_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "deleted_by": {
"deleted_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "disk": {
"disk": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "driver": {
"driver": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "extnets": {
"extnets": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeInt,
Type: schema.TypeInt, },
}, },
}, "gid": {
"gid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "guid": {
"guid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "image_id": {
"image_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "milestones": {
"milestones": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "compgroup_name": {
"compgroup_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "parents": {
"parents": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeInt,
Type: schema.TypeInt, },
}, },
}, "ram": {
"ram": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "role": {
"role": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "sep_id": {
"sep_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "seq_no": {
"seq_no": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "timeout_start": {
"timeout_start": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "updated_by": {
"updated_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "vinses": {
"vinses": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeInt,
Type: schema.TypeInt, },
}, },
}, }
} return res
return res }
}
func DataSourceBasicServiceGroup() *schema.Resource {
func DataSourceBasicServiceGroup() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceGroupRead,
ReadContext: dataSourceBasicServiceGroupRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceBasicServiceGroupSchemaMake(),
Schema: dataSourceBasicServiceGroupSchemaMake(), }
} }
}

View File

@@ -1,264 +1,263 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package bservice package bservice
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func flattenBasicServiceList(bsl *bservice.ListBasicServices) []map[string]interface{} { func flattenBasicServiceList(bsl *bservice.ListBasicServices) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, bs := range bsl.Data { for _, bs := range bsl.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"account_id": bs.AccountID, "account_id": bs.AccountID,
"account_name": bs.AccountName, "account_name": bs.AccountName,
"base_domain": bs.BaseDomain, "base_domain": bs.BaseDomain,
"created_by": bs.CreatedBy, "created_by": bs.CreatedBy,
"created_time": bs.CreatedTime, "created_time": bs.CreatedTime,
"deleted_by": bs.DeletedBy, "deleted_by": bs.DeletedBy,
"deleted_time": bs.DeletedTime, "deleted_time": bs.DeletedTime,
"gid": bs.GID, "gid": bs.GID,
"groups": bs.Groups, "groups": bs.Groups,
"guid": bs.GUID, "guid": bs.GUID,
"service_id": bs.ID, "service_id": bs.ID,
"service_name": bs.Name, "service_name": bs.Name,
"parent_srv_id": bs.ParentSrvID, "parent_srv_id": bs.ParentSrvID,
"parent_srv_type": bs.ParentSrvType, "parent_srv_type": bs.ParentSrvType,
"rg_id": bs.RGID, "rg_id": bs.RGID,
"rg_name": bs.RGName, "rg_name": bs.RGName,
"ssh_user": bs.SSHUser, "ssh_user": bs.SSHUser,
"status": bs.Status, "status": bs.Status,
"tech_status": bs.TechStatus, "tech_status": bs.TechStatus,
"updated_by": bs.UpdatedBy, "updated_by": bs.UpdatedBy,
"updated_time": bs.UpdatedTime, "updated_time": bs.UpdatedTime,
"user_managed": bs.UserManaged, "user_managed": bs.UserManaged,
} }
res = append(res, temp) res = append(res, temp)
} }
return res return res
} }
func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
basicServiceList, err := utilityBasicServiceListCheckPresence(ctx, d, m) basicServiceList, err := utilityBasicServiceListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenBasicServiceList(basicServiceList))
d.Set("items", flattenBasicServiceList(basicServiceList)) d.Set("entry_count", basicServiceList.EntryCount)
d.Set("entry_count", basicServiceList.EntryCount)
return nil
return nil }
}
func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema {
func dataSourceBasicServiceListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "by_id": {
"by_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by ID",
Description: "Filter by ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by bservice name",
Description: "Filter by bservice name", },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by resource group name",
Description: "Filter by resource group name", },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by status",
Description: "Filter by status", },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by tech status",
Description: "Filter by tech status", },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by account name",
Description: "Filter by account name", },
}, "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "ID of the account to query for BasicService instances",
Description: "ID of the account to query for BasicService instances", },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "ID of the resource group to query for BasicService instances",
Description: "ID of the resource group to query for BasicService instances", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "base_domain": {
"base_domain": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_by": {
"created_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "deleted_by": {
"deleted_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "gid": {
"gid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "groups": {
"groups": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeInt,
Type: schema.TypeInt, },
}, },
}, "guid": {
"guid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "service_id": {
"service_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "service_name": {
"service_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "parent_srv_id": {
"parent_srv_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "parent_srv_type": {
"parent_srv_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "ssh_user": {
"ssh_user": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_by": {
"updated_by": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "updated_time": {
"updated_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "user_managed": {
"user_managed": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceBasicServiceList() *schema.Resource {
func DataSourceBasicServiceList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceBasicServiceListRead,
ReadContext: dataSourceBasicServiceListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceBasicServiceListSchemaMake(),
Schema: dataSourceBasicServiceListSchemaMake(), }
} }
}

View File

@@ -44,14 +44,13 @@ import (
func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(ctx, d, m) basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
d.Set("items", flattenBasicServiceSnapshotsList(basicServiceSnapshotList)) d.Set("items", flattenBasicServiceSnapshots(basicServiceSnapshotList.Data))
d.Set("entry_count", basicServiceSnapshotList.EntryCount)
return nil return nil
} }
@@ -86,10 +85,6 @@ func dataSourceBasicServiceSnapshotListSchemaMake() map[string]*schema.Schema {
}, },
}, },
}, },
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
} }
return res return res
} }

View File

@@ -111,7 +111,7 @@ func flattenBasicServiceComputes(bscs bservice.ListComputes) []map[string]interf
} }
func flattenBasicServiceSnapshots(bsrvss bservice.ListSnapshots) []map[string]interface{} { func flattenBasicServiceSnapshots(bsrvss bservice.ListSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(bsrvss)) res := make([]map[string]interface{}, 0)
for _, bsrvs := range bsrvss { for _, bsrvs := range bsrvss {
temp := map[string]interface{}{ temp := map[string]interface{}{
"guid": bsrvs.GUID, "guid": bsrvs.GUID,
@@ -123,17 +123,3 @@ func flattenBasicServiceSnapshots(bsrvss bservice.ListSnapshots) []map[string]in
} }
return res return res
} }
func flattenBasicServiceSnapshotsList(bsrvss *bservice.ListInfoSnapshots) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(bsrvss.Data))
for _, bsrvs := range bsrvss.Data {
temp := map[string]interface{}{
"guid": bsrvs.GUID,
"label": bsrvs.Label,
"timestamp": bsrvs.Timestamp,
"valid": bsrvs.Valid,
}
res = append(res, temp)
}
return res
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,64 +1,64 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package bservice package bservice
import ( import (
"context" "context"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
) )
func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListInfoSnapshots, error) { func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListInfoSnapshots, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
var id uint64 var id uint64
if serviceId, ok := d.GetOk("service_id"); ok { if serviceId, ok := d.GetOk("service_id"); ok {
id = uint64(serviceId.(int)) id = uint64(serviceId.(int))
} }
req := bservice.SnapshotListRequest{ req := bservice.SnapshotListRequest{
ServiceID: id, ServiceID: id,
} }
log.Debugf("utilityBasicServiceSnapshotListCheckPresence") log.Debugf("utilityBasicServiceSnapshotListCheckPresence")
basicServiceSnapshotList, err := c.CloudAPI().BService().SnapshotList(ctx, req) basicServiceSnapshotList, err := c.CloudAPI().BService().SnapshotList(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return basicServiceSnapshotList, nil return basicServiceSnapshotList, nil
} }

View File

@@ -47,7 +47,6 @@ import (
func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
disk, err := utilityDiskCheckPresence(ctx, d, m) disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -1,500 +1,499 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package disks package disks
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diskList, err := utilityDiskListCheckPresence(ctx, d, m) diskList, err := utilityDiskListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenDiskList(diskList))
d.Set("items", flattenDiskList(diskList)) d.Set("entry_count", diskList.EntryCount)
d.Set("entry_count", diskList.EntryCount)
return nil
return nil }
}
func dataSourceDiskListSchemaMake() map[string]*schema.Schema {
func dataSourceDiskListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "by_id": {
"by_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Find by ID",
Description: "Find by ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Find by name",
Description: "Find by name", },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Find by account name",
Description: "Find by account name", },
}, "disk_max_size": {
"disk_max_size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Find by max disk size",
Description: "Find by max disk size", },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Find by status",
Description: "Find by status", },
}, "shared": {
"shared": { Type: schema.TypeBool,
Type: schema.TypeBool, Optional: true,
Optional: true, Description: "Find by shared field",
Description: "Find by shared field", },
}, "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "ID of the account the disks belong to",
Description: "ID of the account the disks belong to", },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "type of the disks",
Description: "type of the disks", },
}, "sep_id": {
"sep_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "find by sep ID",
Description: "find by sep ID", },
}, "pool_name": {
"pool_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "find by pool name",
Description: "find by pool name", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "The unique ID of the subscriber-owner of the disk",
Description: "The unique ID of the subscriber-owner of the disk", },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "The name of the subscriber '(account') to whom this disk belongs",
Description: "The name of the subscriber '(account') to whom this disk belongs", },
}, "acl": {
"acl": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, // "boot_partition": {
// "boot_partition": { // Type: schema.TypeInt,
// Type: schema.TypeInt, // Computed: true,
// Computed: true, // Description: "Number of disk partitions",
// Description: "Number of disk partitions", // },
// }, "computes": {
"computes": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "compute_id": {
"compute_id": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "compute_name": {
"compute_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "created_time": {
"created_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Created time",
Description: "Created time", },
}, "deleted_time": {
"deleted_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Deleted time",
Description: "Deleted time", },
}, "desc": {
"desc": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Description of disk",
Description: "Description of disk", },
}, "destruction_time": {
"destruction_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Time of final deletion",
Description: "Time of final deletion", },
}, "devicename": {
"devicename": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Name of the device",
Description: "Name of the device", },
}, // "disk_path": {
// "disk_path": { // Type: schema.TypeString,
// Type: schema.TypeString, // Computed: true,
// Computed: true, // Description: "Disk path",
// Description: "Disk path", // },
// }, "gid": {
"gid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "ID of the grid (platform)",
Description: "ID of the grid (platform)", },
}, // "guid": {
// "guid": { // Type: schema.TypeInt,
// Type: schema.TypeInt, // Computed: true,
// Computed: true, // Description: "Disk ID on the storage side",
// Description: "Disk ID on the storage side", // },
// }, "disk_id": {
"disk_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "The unique ID of the subscriber-owner of the disk",
Description: "The unique ID of the subscriber-owner of the disk", },
}, "image_id": {
"image_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Image ID",
Description: "Image ID", },
}, "images": {
"images": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeString,
Type: schema.TypeString, },
}, Description: "IDs of images using the disk",
Description: "IDs of images using the disk", },
}, "iotune": {
"iotune": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "read_bytes_sec": {
"read_bytes_sec": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Number of bytes to read per second",
Description: "Number of bytes to read per second", },
}, "read_bytes_sec_max": {
"read_bytes_sec_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Maximum number of bytes to read",
Description: "Maximum number of bytes to read", },
}, "read_iops_sec": {
"read_iops_sec": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Number of io read operations per second",
Description: "Number of io read operations per second", },
}, "read_iops_sec_max": {
"read_iops_sec_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Maximum number of io read operations",
Description: "Maximum number of io read operations", },
}, "size_iops_sec": {
"size_iops_sec": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Size of io operations",
Description: "Size of io operations", },
}, "total_bytes_sec": {
"total_bytes_sec": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Total size bytes per second",
Description: "Total size bytes per second", },
}, "total_bytes_sec_max": {
"total_bytes_sec_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Maximum total size of bytes per second",
Description: "Maximum total size of bytes per second", },
}, "total_iops_sec": {
"total_iops_sec": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Total number of io operations per second",
Description: "Total number of io operations per second", },
}, "total_iops_sec_max": {
"total_iops_sec_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Maximum total number of io operations per second",
Description: "Maximum total number of io operations per second", },
}, "write_bytes_sec": {
"write_bytes_sec": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Number of bytes to write per second",
Description: "Number of bytes to write per second", },
}, "write_bytes_sec_max": {
"write_bytes_sec_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Maximum number of bytes to write per second",
Description: "Maximum number of bytes to write per second", },
}, "write_iops_sec": {
"write_iops_sec": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Number of write operations per second",
Description: "Number of write operations per second", },
}, "write_iops_sec_max": {
"write_iops_sec_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Maximum number of write operations per second",
Description: "Maximum number of write operations per second", },
}, },
}, },
}, },
}, // "iqn": {
// "iqn": { // Type: schema.TypeString,
// Type: schema.TypeString, // Computed: true,
// Computed: true, // Description: "Disk IQN",
// Description: "Disk IQN", // },
// }, // "login": {
// "login": { // Type: schema.TypeString,
// Type: schema.TypeString, // Computed: true,
// Computed: true, // Description: "Login to access the disk",
// Description: "Login to access the disk", // },
// }, "machine_id": {
"machine_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Machine ID",
Description: "Machine ID", },
}, "machine_name": {
"machine_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Machine name",
Description: "Machine name", },
}, // "milestones": {
// "milestones": { // Type: schema.TypeInt,
// Type: schema.TypeInt, // Computed: true,
// Computed: true, // Description: "Milestones",
// Description: "Milestones", // },
// }, "disk_name": {
"disk_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Name of disk",
Description: "Name of disk", },
}, "order": {
"order": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Disk order",
Description: "Disk order", },
}, "params": {
"params": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Disk params",
Description: "Disk params", },
}, "parent_id": {
"parent_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "ID of the parent disk",
Description: "ID of the parent disk", },
}, // "passwd": {
// "passwd": { // Type: schema.TypeString,
// Type: schema.TypeString, // Computed: true,
// Computed: true, // Description: "Password to access the disk",
// Description: "Password to access the disk", // },
// }, "pci_slot": {
"pci_slot": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "ID of the pci slot to which the disk is connected",
Description: "ID of the pci slot to which the disk is connected", },
}, "pool": {
"pool": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Pool for disk location",
Description: "Pool for disk location", },
}, "present_to": {
"present_to": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeInt,
Type: schema.TypeInt, },
}, },
}, // "purge_attempts": {
// "purge_attempts": { // Type: schema.TypeInt,
// Type: schema.TypeInt, // Computed: true,
// Computed: true, // Description: "Number of deletion attempts",
// Description: "Number of deletion attempts", // },
// }, "purge_time": {
"purge_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Time of the last deletion attempt",
Description: "Time of the last deletion attempt", },
}, // "reality_device_number": {
// "reality_device_number": { // Type: schema.TypeInt,
// Type: schema.TypeInt, // Computed: true,
// Computed: true, // Description: "Reality device number",
// Description: "Reality device number", // },
// }, // "reference_id": {
// "reference_id": { // Type: schema.TypeString,
// Type: schema.TypeString, // Computed: true,
// Computed: true, // Description: "ID of the reference to the disk",
// Description: "ID of the reference to the disk", // },
// }, "res_id": {
"res_id": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Resource ID",
Description: "Resource ID", },
}, "res_name": {
"res_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Name of the resource",
Description: "Name of the resource", },
}, "role": {
"role": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Disk role",
Description: "Disk role", },
}, "sep_id": {
"sep_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Storage endpoint provider ID to create disk",
Description: "Storage endpoint provider ID to create disk", },
}, "sep_type": {
"sep_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform",
Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform", },
}, "shareable": {
"shareable": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "size_max": {
"size_max": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Size in GB",
Description: "Size in GB", },
}, "size_used": {
"size_used": { Type: schema.TypeFloat,
Type: schema.TypeFloat, Computed: true,
Computed: true, Description: "Number of used space, in GB",
Description: "Number of used space, in GB", },
}, "snapshots": {
"snapshots": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "guid": {
"guid": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "ID of the snapshot",
Description: "ID of the snapshot", },
}, "label": {
"label": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Name of the snapshot",
Description: "Name of the snapshot", },
}, "res_id": {
"res_id": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Reference to the snapshot",
Description: "Reference to the snapshot", },
}, "snap_set_guid": {
"snap_set_guid": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "The set snapshot ID",
Description: "The set snapshot ID", },
}, "snap_set_time": {
"snap_set_time": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "The set time of the snapshot",
Description: "The set time of the snapshot", },
}, "timestamp": {
"timestamp": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Snapshot time",
Description: "Snapshot time", },
}, },
}, },
}, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Disk status",
Description: "Disk status", },
}, "tech_status": {
"tech_status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "Technical status of the disk",
Description: "Technical status of the disk", },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'", },
}, "vmid": {
"vmid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, Description: "Virtual Machine ID (Deprecated)",
Description: "Virtual Machine ID (Deprecated)", },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceDiskList() *schema.Resource {
func DataSourceDiskList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceDiskListRead,
ReadContext: dataSourceDiskListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceDiskListSchemaMake(),
Schema: dataSourceDiskListSchemaMake(), }
} }
}

View File

@@ -44,7 +44,6 @@ import (
func dataSourceDiskListTypesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskListTypesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listTypes, err := utilityDiskListTypesCheckPresence(ctx, d, m) listTypes, err := utilityDiskListTypesCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -47,8 +47,8 @@ func flattenDiskListTypesDetailed(tld *disks.ListTypes) []map[string]interface{}
for _, typeListDetailed := range tld.Data { for _, typeListDetailed := range tld.Data {
toMap := typeListDetailed.(map[string]interface{}) toMap := typeListDetailed.(map[string]interface{})
temp := map[string]interface{}{ temp := map[string]interface{}{
"pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})), "pools": flattenListTypesDetailedPools(toMap["pools"].([]interface{})),
"sep_id": toMap["sepId"].(float64), "sep_id": toMap["sepId"].(float64),
"sep_name": toMap["sepName"].(string), "sep_name": toMap["sepName"].(string),
} }
res = append(res, temp) res = append(res, temp)
@@ -61,9 +61,9 @@ func flattenListTypesDetailedPools(pools []interface{}) []interface{} {
for _, pool := range pools { for _, pool := range pools {
toMap := pool.(map[string]interface{}) toMap := pool.(map[string]interface{})
temp := map[string]interface{}{ temp := map[string]interface{}{
"name": toMap["name"].(string), "name": toMap["name"].(string),
"system": toMap["system"].(string), "system": toMap["system"].(string),
"types": toMap["types"].([]interface{}), "types": toMap["types"].([]interface{}),
} }
res = append(res, temp) res = append(res, temp)
} }
@@ -74,7 +74,6 @@ func flattenListTypesDetailedPools(pools []interface{}) []interface{} {
func dataSourceDiskListTypesDetailedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskListTypesDetailedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
listTypesDetailed, err := utilityDiskListTypesDetailedCheckPresence(ctx, d, m) listTypesDetailed, err := utilityDiskListTypesDetailedCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -113,8 +112,8 @@ func dataSourceDiskListTypesDetailedSchemaMake() map[string]*schema.Schema {
Description: "Pool name", Description: "Pool name",
}, },
"system": { "system": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"types": { "types": {
Type: schema.TypeList, Type: schema.TypeList,
@@ -133,8 +132,8 @@ func dataSourceDiskListTypesDetailedSchemaMake() map[string]*schema.Schema {
Description: "Storage endpoint provider ID to create disk", Description: "Storage endpoint provider ID to create disk",
}, },
"sep_name": { "sep_name": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
}, },
}, },

View File

@@ -44,7 +44,6 @@ import (
func dataSourceDiskListUnattachedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskListUnattachedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diskListUnattached, err := utilityDiskListUnattachedCheckPresence(ctx, d, m) diskListUnattached, err := utilityDiskListUnattachedCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -376,11 +375,6 @@ func dataSourceDiskListUnattachedSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
Description: "Storage endpoint provider ID to create disk", Description: "Storage endpoint provider ID to create disk",
}, },
"shareable": {
Type: schema.TypeBool,
Computed: true,
Description: "shareable",
},
"size_max": { "size_max": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,

View File

@@ -45,7 +45,6 @@ import (
func dataSourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
disk, err := utilityDiskCheckPresence(ctx, d, m) disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -44,7 +44,6 @@ import (
func dataSourceDiskSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
disk, err := utilityDiskCheckPresence(ctx, d, m) disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -45,7 +45,6 @@ import (
func dataSourceDiskListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceDiskListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
diskList, err := utilityDiskListDeletedCheckPresence(ctx, d, m) diskList, err := utilityDiskListDeletedCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -56,7 +56,6 @@ func flattenDiskListUnattached(ul *disks.ListDisksUnattached) []map[string]inter
"res_name": unattachedDisk.ResName, "res_name": unattachedDisk.ResName,
"role": unattachedDisk.Role, "role": unattachedDisk.Role,
"sep_id": unattachedDisk.SEPID, "sep_id": unattachedDisk.SEPID,
"shareable": unattachedDisk.Shareable,
"size_max": unattachedDisk.SizeMax, "size_max": unattachedDisk.SizeMax,
"size_used": unattachedDisk.SizeUsed, "size_used": unattachedDisk.SizeUsed,
"snapshots": flattenDiskSnapshotList(unattachedDisk.Snapshots), "snapshots": flattenDiskSnapshotList(unattachedDisk.Snapshots),

View File

@@ -95,7 +95,6 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
diskId, err := c.CloudAPI().Disks().Create(ctx, req) diskId, err := c.CloudAPI().Disks().Create(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -220,7 +219,6 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
disk, err := utilityDiskCheckPresence(ctx, d, m) disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -233,20 +231,23 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
return diag.Errorf("The resource cannot be updated because it has been destroyed") return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceDiskCreate(ctx, d, m) // return resourceDiskCreate(ctx, d, m)
case status.Deleted: case status.Deleted:
hasChangeState = true if restore, ok:= d.GetOk("restore"); ok && restore.(bool) {
req := disks.RestoreRequest{ hasChangeState = true
DiskID: disk.ID, 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.CloudAPI().Disks().Restore(ctx, req)
if err != nil {
warnings.Add(err)
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
} else {
req.Reason = "Terraform automatic restore"
}
_, err := c.CloudAPI().Disks().Restore(ctx, req)
if err != nil {
warnings.Add(err)
} }
case status.Assigned: case status.Assigned:
case status.Modeled: case status.Modeled:
@@ -359,10 +360,18 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
} }
req := disks.DeleteRequest{ req := disks.DeleteRequest{
DiskID: disk.ID, DiskID: disk.ID,
Detach: d.Get("detach").(bool), }
Permanently: d.Get("permanently").(bool),
Reason: d.Get("reason").(string), if detach, ok := d.GetOk("detach"); ok {
req.Detach = detach.(bool)
}
if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool)
}
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
} }
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
@@ -379,9 +388,9 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
func resourceDiskSchemaMake() map[string]*schema.Schema { func resourceDiskSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{ rets := map[string]*schema.Schema{
"account_id": { "account_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "The unique ID of the subscriber-owner of the disk", Description: "The unique ID of the subscriber-owner of the disk",
}, },
"disk_name": { "disk_name": {
@@ -395,9 +404,9 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Description: "Size in GB", Description: "Size in GB",
}, },
"gid": { "gid": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "ID of the grid (platform)", Description: "ID of the grid (platform)",
}, },
"pool": { "pool": {
@@ -448,6 +457,11 @@ func resourceDiskSchemaMake() map[string]*schema.Schema {
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"restore": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"iotune": { "iotune": {
Type: schema.TypeList, Type: schema.TypeList,
Optional: true, Optional: true,

View File

@@ -83,7 +83,6 @@ func resourceDiskSnapshotCreate(ctx context.Context, d *schema.ResourceData, m i
func resourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceDiskSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
disk, err := utilityDiskCheckPresence(ctx, d, m) disk, err := utilityDiskCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -170,15 +169,15 @@ func resourceDiskSnapshotDelete(ctx context.Context, d *schema.ResourceData, m i
func resourceDiskSnapshotSchemaMake() map[string]*schema.Schema { func resourceDiskSnapshotSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{ rets := map[string]*schema.Schema{
"disk_id": { "disk_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "The unique ID of the subscriber-owner of the disk", Description: "The unique ID of the subscriber-owner of the disk",
}, },
"label": { "label": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "Name of the snapshot", Description: "Name of the snapshot",
}, },
"rollback": { "rollback": {

View File

@@ -1,286 +1,285 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru> Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package extnet package extnet
import ( import (
"context" "context"
"strconv" "strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
e, err := utilityExtnetCheckPresence(ctx, d, m) e, err := utilityExtnetCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
d.SetId(strconv.FormatUint(e.ID, 10))
d.SetId(strconv.FormatUint(e.ID, 10)) flattenExtnet(d, e)
flattenExtnet(d, e)
return nil
return nil }
}
func dataSourceExtnetSchemaMake() map[string]*schema.Schema {
func dataSourceExtnetSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "net_id": {
"net_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, },
}, "ckey": {
"ckey": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "meta": {
"meta": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeString,
Type: schema.TypeString, },
}, Description: "meta",
Description: "meta", },
}, "check_ips": {
"check_ips": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeString,
Type: schema.TypeString, },
}, },
}, "default": {
"default": { Type: schema.TypeBool,
Type: schema.TypeBool, Computed: true,
Computed: true, },
}, "default_qos": {
"default_qos": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "e_rate": {
"e_rate": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "e_burst": {
"e_burst": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "guid": {
"guid": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "in_burst": {
"in_burst": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "in_rate": {
"in_rate": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "desc": {
"desc": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "dns": {
"dns": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeString,
Type: schema.TypeString, },
}, },
}, "excluded": {
"excluded": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "client_type": {
"client_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "mac": {
"mac": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "ip": {
"ip": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "vm_id": {
"vm_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "free_ips": {
"free_ips": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "gateway": {
"gateway": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "gid": {
"gid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "guid": {
"guid": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ipcidr": {
"ipcidr": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "milestones": {
"milestones": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "net_name": {
"net_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "network": {
"network": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "network_id": {
"network_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "pre_reservations_num": {
"pre_reservations_num": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "prefix": {
"prefix": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "pri_vnf_dev_id": {
"pri_vnf_dev_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "reservations": {
"reservations": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "client_type": {
"client_type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "domainname": {
"domainname": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "hostname": {
"hostname": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "desc": {
"desc": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "ip": {
"ip": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "mac": {
"mac": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "type": {
"type": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "vm_id": {
"vm_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "shared_with": {
"shared_with": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Schema{
Elem: &schema.Schema{ Type: schema.TypeInt,
Type: schema.TypeInt, },
}, },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "vlan_id": {
"vlan_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "vnfs": {
"vnfs": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "dhcp": {
"dhcp": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, }
} return res
return res }
}
func DataSourceExtnet() *schema.Resource {
func DataSourceExtnet() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceExtnetRead,
ReadContext: dataSourceExtnetRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceExtnetSchemaMake(),
Schema: dataSourceExtnetSchemaMake(), }
} }
}

View File

@@ -1,162 +1,161 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package extnet package extnet
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceExtnetComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceExtnetComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
extnetComputesList, err := utilityExtnetComputesListCheckPresence(ctx, d, m) extnetComputesList, err := utilityExtnetComputesListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenExtnetComputesList(extnetComputesList))
d.Set("items", flattenExtnetComputesList(extnetComputesList)) d.Set("entry_count", extnetComputesList.EntryCount)
d.Set("entry_count", extnetComputesList.EntryCount) return nil
return nil }
}
func dataSourceExtnetComputesListSchemaMake() map[string]*schema.Schema {
func dataSourceExtnetComputesListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Required: true,
Required: true, Description: "filter by account ID",
Description: "filter by account ID", },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by RG ID",
Description: "Filter by RG ID", },
}, "compute_id": {
"compute_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by compute ID",
Description: "Filter by compute ID", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "account_name": {
"account_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "extnets": {
"extnets": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "net_id": {
"net_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ipaddr": {
"ipaddr": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "ipcidr": {
"ipcidr": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "id": {
"id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "rg_id": {
"rg_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "rg_name": {
"rg_name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
}, },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceExtnetComputesList() *schema.Resource {
func DataSourceExtnetComputesList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceExtnetComputesListRead,
ReadContext: dataSourceExtnetComputesListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceExtnetComputesListSchemaMake(),
Schema: dataSourceExtnetComputesListSchemaMake(), }
} }
}

View File

@@ -1,86 +1,85 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package extnet package extnet
import ( import (
"context" "context"
"strconv" "strconv"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
extnetId, err := utilityExtnetDefaultCheckPresence(ctx, m) extnetId, err := utilityExtnetDefaultCheckPresence(ctx, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) extnetIdInt, err := strconv.ParseInt(extnetId, 10, 32)
extnetIdInt, err := strconv.ParseInt(extnetId, 10, 32) if err != nil {
if err != nil { return diag.FromErr(err)
return diag.FromErr(err) }
} d.Set("net_id", extnetIdInt)
d.Set("net_id", extnetIdInt)
return nil
return nil }
}
func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema {
func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "net_id": {
"net_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
} return res
return res }
}
func DataSourceExtnetDefault() *schema.Resource {
func DataSourceExtnetDefault() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceExtnetDefaultRead,
ReadContext: dataSourceExtnetDefaultRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceExtnetDefaultSchemaMake(),
Schema: dataSourceExtnetDefaultSchemaMake(), }
} }
}

View File

@@ -1,150 +1,145 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package extnet package extnet
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
extnetList, err := utilityExtnetListCheckPresence(ctx, d, m) extnetList, err := utilityExtnetListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenExtnetList(extnetList))
d.Set("items", flattenExtnetList(extnetList)) d.Set("entry_count", extnetList.EntryCount)
d.Set("entry_count", extnetList.EntryCount)
return nil
return nil }
}
func dataSourceExtnetListSchemaMake() map[string]*schema.Schema {
func dataSourceExtnetListSchemaMake() map[string]*schema.Schema { res := map[string]*schema.Schema{
res := map[string]*schema.Schema{ "account_id": {
"account_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Find by account ID",
Description: "Find by account ID", },
}, "by_id": {
"by_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Find by ID",
Description: "Find by ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Find by name",
Description: "Find by name", },
}, "network": {
"network": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, },
}, "vlan_id": {
"vlan_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Find by VLAN ID",
Description: "Find by VLAN ID", },
}, "vnfdev_id": {
"vnfdev_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Find by VnfDEV ID",
Description: "Find by VnfDEV ID", },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Find by status",
Description: "Find by status", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page number",
Description: "Page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Page size",
Description: "Page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: map[string]*schema.Schema{
Schema: map[string]*schema.Schema{ "net_id": {
"net_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, "ipcidr": {
"ipcidr": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Computed: true,
Computed: true, },
}, },
"status": { },
Type: schema.TypeString, },
Computed: true, "entry_count": {
}, Type: schema.TypeInt,
}, Computed: true,
}, },
}, }
"entry_count": { return res
Type: schema.TypeInt, }
Computed: true,
}, func DataSourceExtnetList() *schema.Resource {
} return &schema.Resource{
return res SchemaVersion: 1,
}
ReadContext: dataSourceExtnetListRead,
func DataSourceExtnetList() *schema.Resource {
return &schema.Resource{ Timeouts: &schema.ResourceTimeout{
SchemaVersion: 1, Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
ReadContext: dataSourceExtnetListRead, },
Timeouts: &schema.ResourceTimeout{ Schema: dataSourceExtnetListSchemaMake(),
Read: &constants.Timeout30s, }
Default: &constants.Timeout60s, }
},
Schema: dataSourceExtnetListSchemaMake(),
}
}

View File

@@ -92,7 +92,7 @@ func flattenExtnetVNFS(evnfs extnet.VNFs) []map[string]interface{} {
} }
func flattenExtnetsComputes(ecs extnet.ListExtNetExtends) []map[string]interface{} { func flattenExtnetsComputes(ecs extnet.ListExtNetExtends) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ecs)) res := make([]map[string]interface{}, 0, len (ecs))
for _, ec := range ecs { for _, ec := range ecs {
temp := map[string]interface{}{ temp := map[string]interface{}{
"net_id": ec.ID, "net_id": ec.ID,
@@ -129,7 +129,6 @@ func flattenExtnetList(el *extnet.ListExtNets) []map[string]interface{} {
"net_id": e.ID, "net_id": e.ID,
"ipcidr": e.IPCIDR, "ipcidr": e.IPCIDR,
"name": e.Name, "name": e.Name,
"status": e.Status,
} }
res = append(res, temp) res = append(res, temp)
} }

View File

@@ -66,10 +66,6 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"client_ids": { "client_ids": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@@ -89,26 +85,10 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": { "default_gw": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": { "desc": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@@ -141,28 +121,16 @@ func dataSourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"network": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
},
"status": { "status": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"updated_by": { "net_mask": {
Type: schema.TypeString, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"updated_time": { "ckey": {
Type: schema.TypeInt, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
} }

View File

@@ -185,13 +185,6 @@ func dataSourceFlipgroupListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}, },
}, },
}, },

View File

@@ -36,21 +36,15 @@ package flipgroup
import ( import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/flipgroup"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
) )
func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.RecordFLIPGroup) { func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.RecordFLIPGroup) {
d.Set("account_id", fg.AccountID) d.Set("account_id", fg.AccountID)
d.Set("account_name", fg.AccountName)
d.Set("client_ids", fg.ClientIDs) d.Set("client_ids", fg.ClientIDs)
d.Set("client_type", fg.ClientType) d.Set("client_type", fg.ClientType)
d.Set("conn_id", fg.ConnID) d.Set("conn_id", fg.ConnID)
d.Set("conn_type", fg.ConnType) d.Set("conn_type", fg.ConnType)
d.Set("created_by", fg.CreatedBy)
d.Set("created_time", fg.CreatedTime)
d.Set("default_gw", fg.DefaultGW) d.Set("default_gw", fg.DefaultGW)
d.Set("deleted_by", fg.DeletedBy)
d.Set("deleted_time", fg.DeletedTime)
d.Set("desc", fg.Description) d.Set("desc", fg.Description)
d.Set("gid", fg.GID) d.Set("gid", fg.GID)
d.Set("guid", fg.GUID) d.Set("guid", fg.GUID)
@@ -60,20 +54,13 @@ func flattenFlipgroup(d *schema.ResourceData, fg *flipgroup.RecordFLIPGroup) {
d.Set("name", fg.Name) d.Set("name", fg.Name)
d.Set("net_id", fg.NetID) d.Set("net_id", fg.NetID)
d.Set("net_type", fg.NetType) d.Set("net_type", fg.NetType)
d.Set("network", fg.Network)
d.Set("rg_id", fg.RGID)
d.Set("rg_name", fg.RGName)
d.Set("status", fg.Status) d.Set("status", fg.Status)
d.Set("updated_by", fg.UpdatedBy)
d.Set("updated_time", fg.UpdatedTime)
} }
func flattenFlipgroupList(fg_list *flipgroup.ListFLIPGroups) []map[string]interface{} { func flattenFlipgroupList(fg_list *flipgroup.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0) res := make([]map[string]interface{}, 0)
for _, fg := range fg_list.Data { for _, fg := range fg_list.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"ckey": fg.CKey,
"meta": flattens.FlattenMeta(fg.Meta),
"account_id": fg.AccountID, "account_id": fg.AccountID,
"client_ids": fg.ClientIDs, "client_ids": fg.ClientIDs,
"client_type": fg.ClientType, "client_type": fg.ClientType,
@@ -89,7 +76,6 @@ func flattenFlipgroupList(fg_list *flipgroup.ListFLIPGroups) []map[string]interf
"name": fg.Name, "name": fg.Name,
"net_id": fg.NetID, "net_id": fg.NetID,
"net_type": fg.NetType, "net_type": fg.NetType,
"net_mask": fg.NetMask,
"status": fg.Status, "status": fg.Status,
} }
res = append(res, temp) res = append(res, temp)

View File

@@ -64,7 +64,6 @@ func resourceFlipgroupCreate(ctx context.Context, d *schema.ResourceData, m inte
resp, err := c.CloudAPI().FLIPGroup().Create(ctx, req) resp, err := c.CloudAPI().FLIPGroup().Create(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -137,7 +136,6 @@ func resourceFlipgroupDelete(ctx context.Context, d *schema.ResourceData, m inte
fg, err := utilityFlipgroupCheckPresence(ctx, d, m) fg, err := utilityFlipgroupCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -150,8 +148,6 @@ func resourceFlipgroupDelete(ctx context.Context, d *schema.ResourceData, m inte
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId("")
return nil return nil
} }
@@ -209,10 +205,6 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"conn_id": { "conn_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@@ -221,26 +213,10 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": { "default_gw": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"gid": { "gid": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@@ -257,26 +233,14 @@ func resourceFlipgroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"network": { "net_mask": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"rg_name": { "ckey": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
} }
} }

View File

@@ -34,8 +34,8 @@ package image
import ( import (
"context" "context"
"strconv"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
@@ -44,11 +44,12 @@ import (
func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
image, err := utilityImageCheckPresence(ctx, d, m) image, err := utilityImageCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId(strconv.Itoa(int(image.ID))) id := uuid.New()
d.SetId(id.String())
flattenImage(d, image) flattenImage(d, image)

View File

@@ -1,160 +1,159 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package image package image
import ( import (
"context" "context"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
) )
func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
imageList, err := utilityImageListCheckPresence(ctx, d, m) imageList, err := utilityImageListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
} id := uuid.New()
id := uuid.New() d.SetId(id.String())
d.SetId(id.String()) d.Set("items", flattenImageList(imageList))
d.Set("items", flattenImageList(imageList)) d.Set("entry_count", imageList.EntryCount)
d.Set("entry_count", imageList.EntryCount)
return nil
return nil }
}
func dataSourceImageListSchemaMake() map[string]*schema.Schema {
func dataSourceImageListSchemaMake() map[string]*schema.Schema { rets := map[string]*schema.Schema{
rets := map[string]*schema.Schema{ "sep_id": {
"sep_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by Storage Endpoint ID",
Description: "Filter by Storage Endpoint ID", },
}, "by_id": {
"by_id": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by ID",
Description: "Filter by ID", },
}, "name": {
"name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by name",
Description: "Filter by name", },
}, "status": {
"status": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by status",
Description: "Filter by status", },
}, "architecture": {
"architecture": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by architecture",
Description: "Filter by architecture", },
}, "type_image": {
"type_image": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by image type",
Description: "Filter by image type", },
}, "image_size": {
"image_size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "Filter by image size",
Description: "Filter by image size", },
}, "sep_name": {
"sep_name": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by SEP name",
Description: "Filter by SEP name", },
}, "pool": {
"pool": { Type: schema.TypeString,
Type: schema.TypeString, Optional: true,
Optional: true, Description: "Filter by pool",
Description: "Filter by pool", },
}, "public": {
"public": { Type: schema.TypeBool,
Type: schema.TypeBool, Optional: true,
Optional: true, Description: "Find public/private images",
Description: "Find public/private images", },
}, "hot_resize": {
"hot_resize": { Type: schema.TypeBool,
Type: schema.TypeBool, Optional: true,
Optional: true, Description: "Find hot resizable images",
Description: "Find hot resizable images", },
}, "bootable": {
"bootable": { Type: schema.TypeBool,
Type: schema.TypeBool, Optional: true,
Optional: true, Description: "Find bootable images",
Description: "Find bootable images", },
}, "page": {
"page": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "page number",
Description: "page number", },
}, "size": {
"size": { Type: schema.TypeInt,
Type: schema.TypeInt, Optional: true,
Optional: true, Description: "page size",
Description: "page size", },
}, "items": {
"items": { Type: schema.TypeList,
Type: schema.TypeList, Computed: true,
Computed: true, Description: "image list",
Description: "image list", Elem: &schema.Resource{
Elem: &schema.Resource{ Schema: dataSourceImageSchemaMake(),
Schema: dataSourceImageSchemaMake(), },
}, },
}, "entry_count": {
"entry_count": { Type: schema.TypeInt,
Type: schema.TypeInt, Computed: true,
Computed: true, },
}, }
}
return rets
return rets }
}
func DataSourceImageList() *schema.Resource {
func DataSourceImageList() *schema.Resource { return &schema.Resource{
return &schema.Resource{ SchemaVersion: 1,
SchemaVersion: 1,
ReadContext: dataSourceImageListRead,
ReadContext: dataSourceImageListRead,
Timeouts: &schema.ResourceTimeout{
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout30s,
Read: &constants.Timeout30s, Default: &constants.Timeout60s,
Default: &constants.Timeout60s, },
},
Schema: dataSourceImageListSchemaMake(),
Schema: dataSourceImageListSchemaMake(), }
} }
}

View File

@@ -3,7 +3,6 @@ package image
import ( import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
"strconv"
) )
func flattenHistory(history []image.History) []map[string]interface{} { func flattenHistory(history []image.History) []map[string]interface{} {
@@ -24,7 +23,7 @@ func flattenImage(d *schema.ResourceData, img *image.RecordImage) {
d.Set("unc_path", img.UNCPath) d.Set("unc_path", img.UNCPath)
d.Set("ckey", img.CKey) d.Set("ckey", img.CKey)
d.Set("account_id", img.AccountID) d.Set("account_id", img.AccountID)
d.Set("acl", FlattenACL(img.ACL)) d.Set("acl", img.ACL)
d.Set("architecture", img.Architecture) d.Set("architecture", img.Architecture)
d.Set("boot_type", img.BootType) d.Set("boot_type", img.BootType)
d.Set("bootable", img.Bootable) d.Set("bootable", img.Bootable)
@@ -86,18 +85,3 @@ func flattenImageList(il *image.ListImages) []map[string]interface{} {
} }
return res return res
} }
func FlattenACL(acl interface{}) string {
switch d := acl.(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 ""
}
}

View File

@@ -1,276 +1,274 @@
/* /*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved. Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors: Authors:
Petr Krutov, <petr.krutov@digitalenergy.online> Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online> Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru> Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/* /*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp. Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it Please see README.md to learn where to place source code so that it
builds seamlessly. builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/ */
package image package image
import ( import (
"context" "context"
"strconv" "strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/schema"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants" "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/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
) )
func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string)) log.Debugf("resourceImageCreate: called for image %s", d.Get("name").(string))
haveGID, err := existGID(ctx, d, m) haveGID, err := existGID(ctx, d, m)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
if !haveGID { if !haveGID {
return diag.Errorf("resourceImageCreate: can't create Image because GID %d is not allowed or does not exist", d.Get("gid").(int)) return diag.Errorf("resourceImageCreate: can't create Image because GID %d is not allowed or does not exist", d.Get("gid").(int))
} }
if _, ok := d.GetOk("account_id"); ok { if _, ok := d.GetOk("account_id"); ok {
haveAccountID, err := existAccountID(ctx, d, m) haveAccountID, err := existAccountID(ctx, d, m)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
if !haveAccountID { if !haveAccountID {
return diag.Errorf("resourceImageCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int)) return diag.Errorf("resourceImageCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
} }
} }
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := image.CreateRequest{} req := image.CreateRequest{}
req.Name = d.Get("name").(string) req.Name = d.Get("name").(string)
req.URL = d.Get("url").(string) req.URL = d.Get("url").(string)
req.GID = uint64(d.Get("gid").(int)) req.GID = uint64(d.Get("gid").(int))
req.BootType = d.Get("boot_type").(string) req.BootType = d.Get("boot_type").(string)
req.ImageType = d.Get("type").(string) req.ImageType = d.Get("type").(string)
drivers := []string{} drivers := []string{}
for _, driver := range d.Get("drivers").([]interface{}) { for _, driver := range d.Get("drivers").([]interface{}) {
drivers = append(drivers, driver.(string)) drivers = append(drivers, driver.(string))
} }
req.Drivers = drivers req.Drivers = drivers
if hotresize, ok := d.GetOk("hot_resize"); ok { if hotresize, ok := d.GetOk("hot_resize"); ok {
req.HotResize = hotresize.(bool) req.HotResize = hotresize.(bool)
} }
if username, ok := d.GetOk("username"); ok { if username, ok := d.GetOk("username"); ok {
req.Username = username.(string) req.Username = username.(string)
} }
if password, ok := d.GetOk("password"); ok { if password, ok := d.GetOk("password"); ok {
req.Password = password.(string) req.Password = password.(string)
} }
if accountId, ok := d.GetOk("account_id"); ok { if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int)) req.AccountID = uint64(accountId.(int))
} }
if usernameDL, ok := d.GetOk("username_dl"); ok { if usernameDL, ok := d.GetOk("username_dl"); ok {
req.UsernameDL = usernameDL.(string) req.UsernameDL = usernameDL.(string)
} }
if passwordDL, ok := d.GetOk("password_dl"); ok { if passwordDL, ok := d.GetOk("password_dl"); ok {
req.PasswordDL = passwordDL.(string) req.PasswordDL = passwordDL.(string)
} }
if sepId, ok := d.GetOk("sep_id"); ok { if sepId, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sepId.(int)) req.SEPID = uint64(sepId.(int))
} }
if poolName, ok := d.GetOk("pool_name"); ok { if poolName, ok := d.GetOk("pool_name"); ok {
req.Pool = poolName.(string) req.Pool = poolName.(string)
} }
if architecture, ok := d.GetOk("architecture"); ok { if architecture, ok := d.GetOk("architecture"); ok {
req.Architecture = architecture.(string) req.Architecture = architecture.(string)
} }
imageId, err := c.CloudAPI().Image().Create(ctx, req) imageId, err := c.CloudAPI().Image().Create(ctx, req)
if err != nil { if err != nil {
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
d.SetId(strconv.FormatUint(imageId, 10))
d.SetId(strconv.FormatUint(imageId, 10)) d.Set("image_id", imageId)
d.Set("image_id", imageId)
_, err = utilityImageCheckPresence(ctx, d, m)
_, err = utilityImageCheckPresence(ctx, d, m) if err != nil {
if err != nil { return diag.FromErr(err)
return diag.FromErr(err) }
}
return resourceImageRead(ctx, d, m)
return resourceImageRead(ctx, d, m) }
}
func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageRead: called for %s id: %s", d.Get("name").(string), d.Id())
log.Debugf("resourceImageRead: called for %s id: %s", d.Get("name").(string), d.Id())
img, err := utilityImageCheckPresence(ctx, d, m)
img, err := utilityImageCheckPresence(ctx, d, m) if img == nil {
if img == nil { d.SetId("")
d.SetId("") return diag.FromErr(err)
return diag.FromErr(err) }
}
switch img.Status {
switch img.Status { case status.Modeled:
case status.Modeled: return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status)
return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status) case status.Creating:
case status.Creating: case status.Created:
case status.Created: case status.Destroyed, status.Purged:
case status.Destroyed, status.Purged: d.SetId("")
d.SetId("") return diag.Errorf("The resource cannot be updated because it has been destroyed")
return diag.Errorf("The resource cannot be updated because it has been destroyed") // return resourceImageCreate(ctx, d, m)
// return resourceImageCreate(ctx, d, m) }
}
flattenImage(d, img)
flattenImage(d, img)
return nil
return nil }
}
func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Debugf("resourceImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
log.Debugf("resourceImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
_, err := utilityImageCheckPresence(ctx, d, m)
_, err := utilityImageCheckPresence(ctx, d, m) if err != nil {
if err != nil { return diag.FromErr(err)
d.SetId("") }
return diag.FromErr(err)
} c := m.(*controller.ControllerCfg)
req := image.DeleteRequest{
c := m.(*controller.ControllerCfg) ImageID: uint64(d.Get("image_id").(int)),
req := image.DeleteRequest{ }
ImageID: uint64(d.Get("image_id").(int)),
} if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool)
if permanently, ok := d.GetOk("permanently"); ok { }
req.Permanently = permanently.(bool)
} _, err = c.CloudAPI().Image().Delete(ctx, req)
if err != nil {
_, err = c.CloudAPI().Image().Delete(ctx, req) return diag.FromErr(err)
if err != nil { }
return diag.FromErr(err)
} d.SetId("")
d.SetId("") return nil
}
return nil
} func resourceImageRename(ctx context.Context, d *schema.ResourceData, m interface{}) error {
log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id())
func resourceImageRename(ctx context.Context, d *schema.ResourceData, m interface{}) error { c := m.(*controller.ControllerCfg)
log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id()) req := image.RenameRequest{
c := m.(*controller.ControllerCfg) ImageID: uint64(d.Get("image_id").(int)),
req := image.RenameRequest{ Name: d.Get("name").(string),
ImageID: uint64(d.Get("image_id").(int)), }
Name: d.Get("name").(string),
} _, err := c.CloudAPI().Image().Rename(ctx, req)
if err != nil {
_, err := c.CloudAPI().Image().Rename(ctx, req) return err
if err != nil { }
return err
} return nil
}
return nil
} func resourceImageUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageUpdate: called for %s, id: %s", d.Get("name").(string), d.Id())
func resourceImageUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceImageUpdate: called for %s, id: %s", d.Get("name").(string), d.Id()) haveGID, err := existGID(ctx, d, m)
if err != nil {
haveGID, err := existGID(ctx, d, m) return diag.FromErr(err)
if err != nil { }
return diag.FromErr(err)
} if !haveGID {
return diag.Errorf("resourceImageUpdate: can't update Image because GID %d is not allowed or does not exist", d.Get("gid").(int))
if !haveGID { }
return diag.Errorf("resourceImageUpdate: can't update Image because GID %d is not allowed or does not exist", d.Get("gid").(int))
} if _, ok := d.GetOk("account_id"); ok {
haveAccountID, err := existAccountID(ctx, d, m)
if _, ok := d.GetOk("account_id"); ok { if err != nil {
haveAccountID, err := existAccountID(ctx, d, m) return diag.FromErr(err)
if err != nil { }
return diag.FromErr(err)
} if !haveAccountID {
return diag.Errorf("resourceImageUpdate: can't update Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
if !haveAccountID { }
return diag.Errorf("resourceImageUpdate: can't update Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int)) }
}
} image, err := utilityImageCheckPresence(ctx, d, m)
if image == nil {
image, err := utilityImageCheckPresence(ctx, d, m) if err != nil {
if image == nil { return diag.FromErr(err)
if err != nil { }
return diag.FromErr(err) return nil
} }
return nil
} switch image.Status {
case status.Modeled:
switch image.Status { return diag.Errorf("The image is in status: %s, please, contact support for more information", image.Status)
case status.Modeled: case status.Creating:
return diag.Errorf("The image is in status: %s, please, contact support for more information", image.Status) case status.Created:
case status.Creating: case status.Destroyed, status.Purged:
case status.Created: d.SetId("")
case status.Destroyed, status.Purged: return diag.Errorf("The resource cannot be updated because it has been destroyed")
d.SetId("") // return resourceImageCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed") }
// return resourceImageCreate(ctx, d, m)
} if d.HasChange("name") {
err := resourceImageRename(ctx, d, m)
if d.HasChange("name") { if err != nil {
err := resourceImageRename(ctx, d, m) return diag.FromErr(err)
if err != nil { }
return diag.FromErr(err) }
}
} return resourceImageRead(ctx, d, m)
}
return resourceImageRead(ctx, d, m)
} func ResourceImage() *schema.Resource {
return &schema.Resource{
func ResourceImage() *schema.Resource { SchemaVersion: 1,
return &schema.Resource{
SchemaVersion: 1, CreateContext: resourceImageCreate,
ReadContext: resourceImageRead,
CreateContext: resourceImageCreate, UpdateContext: resourceImageUpdate,
ReadContext: resourceImageRead, DeleteContext: resourceImageDelete,
UpdateContext: resourceImageUpdate,
DeleteContext: resourceImageDelete, Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Importer: &schema.ResourceImporter{ },
StateContext: schema.ImportStatePassthroughContext,
}, Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Timeouts: &schema.ResourceTimeout{ Read: &constants.Timeout300s,
Create: &constants.Timeout600s, Update: &constants.Timeout300s,
Read: &constants.Timeout300s, Delete: &constants.Timeout300s,
Update: &constants.Timeout300s, Default: &constants.Timeout300s,
Delete: &constants.Timeout300s, },
Default: &constants.Timeout300s,
}, Schema: resourceImageSchemaMake(dataSourceImageExtendSchemaMake()),
}
Schema: resourceImageSchemaMake(dataSourceImageExtendSchemaMake()), }
}
}

View File

@@ -50,7 +50,6 @@ import (
func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
cluster, err := utilityDataK8sCheckPresence(ctx, d, m) cluster, err := utilityDataK8sCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId(strconv.FormatUint(cluster.ID, 10)) d.SetId(strconv.FormatUint(cluster.ID, 10))
@@ -400,10 +399,6 @@ func dataSourceK8sSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"network_plugin": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": { "rg_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,

View File

@@ -271,10 +271,6 @@ func createK8sListSchema() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"network_plugin": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": { "rg_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,

View File

@@ -47,7 +47,6 @@ func dataSourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interfac
wg, workersComputeList, err := utilityDataK8sWgCheckPresence(ctx, d, m) wg, workersComputeList, err := utilityDataK8sWgCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -47,7 +47,6 @@ func dataSourceK8sWgCloudInitRead(ctx context.Context, d *schema.ResourceData, m
metaData, err := utilityK8sWgCloudInitCheckPresence(ctx, d, m) metaData, err := utilityK8sWgCloudInitCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -45,7 +45,6 @@ import (
func dataSourceK8sWgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceK8sWgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
wgList, err := utilityK8sWgListCheckPresence(ctx, d, m) wgList, err := utilityK8sWgListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -106,7 +106,7 @@ func flattenWorkerComputes(cluster *k8s.RecordK8S) []map[string]interface{} {
} }
func flattenAclList(aclList k8s.ListACL) []map[string]interface{} { func flattenAclList(aclList k8s.ListACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(aclList)) res := make([]map[string]interface{}, 0, len (aclList))
for _, acl := range aclList { for _, acl := range aclList {
temp := map[string]interface{}{ temp := map[string]interface{}{
"explicit": acl.Explicit, "explicit": acl.Explicit,
@@ -134,7 +134,7 @@ func flattenAcl(acl k8s.RecordACL) []map[string]interface{} {
} }
func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface{} { func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(interfaces)) res := make([]map[string]interface{}, 0, len (interfaces))
for _, interfaceCompute := range interfaces { for _, interfaceCompute := range interfaces {
temp := map[string]interface{}{ temp := map[string]interface{}{
"def_gw": interfaceCompute.DefGW, "def_gw": interfaceCompute.DefGW,
@@ -147,7 +147,7 @@ func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface
} }
func flattenDetailedInfo(detailedInfoList k8s.ListDetailedInfo, computes []compute.RecordCompute) []map[string]interface{} { func flattenDetailedInfo(detailedInfoList k8s.ListDetailedInfo, computes []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(detailedInfoList)) res := make([]map[string]interface{}, 0, len (detailedInfoList))
if computes != nil { if computes != nil {
for i, detailedInfo := range detailedInfoList { for i, detailedInfo := range detailedInfoList {
temp := map[string]interface{}{ temp := map[string]interface{}{
@@ -247,7 +247,6 @@ func flattenK8sData(d *schema.ResourceData, cluster k8s.RecordK8S, masters []com
d.Set("workers", flattenK8sGroup(cluster.K8SGroups.Workers, workers)) d.Set("workers", flattenK8sGroup(cluster.K8SGroups.Workers, workers))
d.Set("lb_id", cluster.LBID) d.Set("lb_id", cluster.LBID)
d.Set("name", cluster.Name) d.Set("name", cluster.Name)
d.Set("network_plugin", cluster.NetworkPlugin)
d.Set("rg_id", cluster.RGID) d.Set("rg_id", cluster.RGID)
d.Set("rg_name", cluster.RGName) d.Set("rg_name", cluster.RGName)
d.Set("status", cluster.Status) d.Set("status", cluster.Status)
@@ -268,7 +267,7 @@ func flattenServiceAccount(serviceAccount k8s.RecordServiceAccount) []map[string
} }
func flattenWorkersGroup(workersGroups k8s.ListK8SGroups) []map[string]interface{} { func flattenWorkersGroup(workersGroups k8s.ListK8SGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(workersGroups)) res := make([]map[string]interface{}, 0, len (workersGroups))
for _, worker := range workersGroups { for _, worker := range workersGroups {
temp := map[string]interface{}{ temp := map[string]interface{}{
"annotations": worker.Annotations, "annotations": worker.Annotations,
@@ -289,11 +288,11 @@ func flattenWorkersGroup(workersGroups k8s.ListK8SGroups) []map[string]interface
} }
func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} { func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(k8sItems.Data)) res := make([]map[string]interface{}, 0, len (k8sItems.Data))
for _, item := range k8sItems.Data { for _, item := range k8sItems.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"account_id": item.AccountID, "account_id": item.AccountID,
"account_name": item.AccountName, "account_name": item.Name,
"acl": item.ACL, "acl": item.ACL,
"bservice_id": item.BServiceID, "bservice_id": item.BServiceID,
"ci_id": item.CIID, "ci_id": item.CIID,
@@ -309,7 +308,6 @@ func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} {
"lb_id": item.LBID, "lb_id": item.LBID,
"milestones": item.Milestones, "milestones": item.Milestones,
"k8s_name": item.Name, "k8s_name": item.Name,
"network_plugin": item.NetworkPlugin,
"rg_id": item.RGID, "rg_id": item.RGID,
"rg_name": item.RGName, "rg_name": item.RGName,
"service_account": flattenServiceAccount(item.ServiceAccount), "service_account": flattenServiceAccount(item.ServiceAccount),

View File

@@ -1,396 +0,0 @@
package k8s
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceK8sCPSchemaV1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the cluster.",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "Resource group ID that this instance belongs to.",
},
"k8sci_id": {
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "ID of the k8s catalog item to base this instance on.",
},
"network_plugin": {
Type: schema.TypeString,
Required: true,
Description: "Network plugin to be used",
ValidateFunc: validation.StringInSlice([]string{"flannel", "weavenet", "calico"}, true),
},
"num": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntInSlice([]int{1, 3}),
Description: "Number of VMs to create. Can be either 1 or 3",
},
"cpu": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Node CPU count.",
},
"ram": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Node RAM in MB.",
},
"disk": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Node boot disk size in GB.",
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Storage Endpoint ID",
},
"sep_pool": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Storage Endpoint Pool",
},
"with_lb": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Create k8s with load balancer if true.",
},
"extnet_only": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Use only selected ExtNet for infrastructure connections",
},
// /4.4.0
"cloud_init": {
Type: schema.TypeString,
Optional: true,
Description: "Meta data for working group computes, format YAML 'user_data': 1111",
},
"join_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to configure the behavior and settings for joining a node to a cluster. It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting.",
},
"kube_proxy_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster. It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations. insert a valid JSON string with all levels of nesting.",
},
"kubelet_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster. It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations. insert a valid JSON string with all levels of nesting.",
},
"cluster_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to define global settings and configurations for the entire cluster. It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations. insert a valid JSON string with all levels of nesting.",
},
"init_config": {
Type: schema.TypeString,
Optional: true,
Description: "is used to define settings and actions that should be performed before any other component in the cluster starts. It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting.",
},
"additional_sans": {
Type: schema.TypeList,
Optional: true,
Description: "Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"ha_mode": {
Type: schema.TypeBool,
Optional: true,
Description: "Use Highly Available schema for LB deploy",
},
"lb_sysctl_params": {
Type: schema.TypeString,
Optional: true,
Description: "Custom sysctl values for Load Balancer instance. Applied on boot.",
},
"oidc_cert": {
Type: schema.TypeString,
Optional: true,
Description: "insert ssl certificate in x509 pem format",
},
////
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
//ForceNew: true,
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Description: "Text description of this instance.",
},
"start": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Start k8s cluster.",
},
"detailed_info": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"compute_id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tech_status": {
Type: schema.TypeString,
Computed: true,
},
"interfaces": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"def_gw": {
Type: schema.TypeString,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"natable_vins_ip": {
Type: schema.TypeString,
Computed: true,
},
"natable_vins_network": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"master_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Master group ID.",
},
"master_name": {
Type: schema.TypeString,
Computed: true,
Description: "Master group name.",
},
"acl": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_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,
},
},
},
},
"k8s_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,
},
},
},
},
"rg_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,
},
},
},
},
},
},
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
},
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"bservice_id": {
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,
},
"k8s_ci_name": {
Type: schema.TypeString,
Computed: true,
},
"lb_id": {
Type: schema.TypeInt,
Computed: true,
},
"k8s_id": {
Type: schema.TypeInt,
Computed: true,
},
"lb_ip": {
Type: schema.TypeString,
Computed: true,
Description: "IP address of default load balancer.",
},
"rg_name": {
Type: schema.TypeString,
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,
},
"kubeconfig": {
Type: schema.TypeString,
Computed: true,
Description: "Kubeconfig for cluster access.",
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "ID of default vins for this instace.",
},
},
}
}

View File

@@ -189,6 +189,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
if oidcCertificate, ok := d.GetOk("oidc_cert"); ok { if oidcCertificate, ok := d.GetOk("oidc_cert"); ok {
createReq.OidcCertificate = oidcCertificate.(string) createReq.OidcCertificate = oidcCertificate.(string)
} }
///
createReq.ExtNetOnly = d.Get("extnet_only").(bool) createReq.ExtNetOnly = d.Get("extnet_only").(bool)
@@ -198,19 +199,12 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
createReq.ExtNetID = 0 createReq.ExtNetID = 0
} }
if vins, ok := d.GetOk("vins_id"); ok {
createReq.VinsId = uint64(vins.(int))
} else {
createReq.VinsId = 0
}
if desc, ok := d.GetOk("desc"); ok { if desc, ok := d.GetOk("desc"); ok {
createReq.Description = desc.(string) createReq.Description = desc.(string)
} }
resp, err := c.CloudAPI().K8S().Create(ctx, createReq) resp, err := c.CloudAPI().K8S().Create(ctx, createReq)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -316,7 +310,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
} }
} }
k8sList, err := utilityK8sListForResourceCheckPresence(ctx, d, m) k8sList, err := utilityK8sListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
@@ -515,7 +509,7 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
} }
} }
return resourceK8sRead(ctx, d, m) return nil
} }
func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -551,15 +545,15 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Description: "Name of the cluster.", Description: "Name of the cluster.",
}, },
"rg_id": { "rg_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "Resource group ID that this instance belongs to.", Description: "Resource group ID that this instance belongs to.",
}, },
"k8sci_id": { "k8sci_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "ID of the k8s catalog item to base this instance on.", Description: "ID of the k8s catalog item to base this instance on.",
}, },
"wg_name": { "wg_name": {
@@ -598,7 +592,7 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Type: schema.TypeList, Type: schema.TypeList,
Optional: true, Optional: true,
Computed: true, Computed: true,
//ForceNew: true, ForceNew: true,
MaxItems: 1, MaxItems: 1,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: mastersSchemaMake(), Schema: mastersSchemaMake(),
@@ -627,17 +621,11 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Description: "Use only selected ExtNet for infrastructure connections", Description: "Use only selected ExtNet for infrastructure connections",
}, },
"extnet_id": { "extnet_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true,
Computed: true,
//ForceNew: true,
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
},
"permanently": {
Type: schema.TypeBool,
Optional: true, Optional: true,
Default: false, Computed: true,
Description: "Determines if cluster should be destroyed", ForceNew: true,
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
}, },
///4.4.0 ///4.4.0
@@ -705,6 +693,7 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Default: true, Default: true,
Description: "Start k8s cluster", Description: "Start k8s cluster",
}, },
"acl": { "acl": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@@ -753,6 +742,13 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
Description: "IP address of default load balancer.", Description: "IP address of default load balancer.",
}, },
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Determines if cluster should be destroyed",
},
"rg_name": { "rg_name": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

View File

@@ -159,9 +159,9 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
createReq.JoinConfiguration = joinConfig.(string) createReq.JoinConfiguration = joinConfig.(string)
} }
// if cloudInit, ok := d.GetOk("cloud_init"); ok { if cloudInit, ok := d.GetOk("cloud_init"); ok {
// createReq.UserData = cloudInit.(string) createReq.UserData = cloudInit.(string)
// } }
if initConfig, ok := d.GetOk("init_config"); ok { if initConfig, ok := d.GetOk("init_config"); ok {
createReq.InitConfiguration = initConfig.(string) createReq.InitConfiguration = initConfig.(string)
@@ -176,6 +176,8 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
log.Debug(createReq.OidcCertificate) log.Debug(createReq.OidcCertificate)
} }
///
createReq.ExtNetOnly = d.Get("extnet_only").(bool) createReq.ExtNetOnly = d.Get("extnet_only").(bool)
if extNet, ok := d.GetOk("extnet_id"); ok { if extNet, ok := d.GetOk("extnet_id"); ok {
@@ -184,19 +186,12 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
createReq.ExtNetID = 0 createReq.ExtNetID = 0
} }
if vins, ok := d.GetOk("vins_id"); ok {
createReq.VinsId = uint64(vins.(int))
} else {
createReq.VinsId = 0
}
if desc, ok := d.GetOk("desc"); ok { if desc, ok := d.GetOk("desc"); ok {
createReq.Description = desc.(string) createReq.Description = desc.(string)
} }
resp, err := c.CloudAPI().K8S().Create(ctx, createReq) resp, err := c.CloudAPI().K8S().Create(ctx, createReq)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -317,7 +312,7 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{
} }
} }
k8sList, err := utilityK8sListForResourceCheckPresence(ctx, d, m) k8sList, err := utilityK8sListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("") d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
@@ -532,16 +527,15 @@ func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interfac
} }
} }
return resourceK8sCPRead(ctx, d, m) return nil
} }
func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceK8sControlPlaneDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int)) log.Debugf("resourceK8sDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
cluster, err := utilityK8sCheckPresence(ctx, d, m) cluster, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -558,9 +552,8 @@ func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId("")
return nil return nil
} }
func resourceK8sCPSchemaMake() map[string]*schema.Schema { func resourceK8sCPSchemaMake() map[string]*schema.Schema {
@@ -571,15 +564,15 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Description: "Name of the cluster.", Description: "Name of the cluster.",
}, },
"rg_id": { "rg_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "Resource group ID that this instance belongs to.", Description: "Resource group ID that this instance belongs to.",
}, },
"k8sci_id": { "k8sci_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, ForceNew: true,
Description: "ID of the k8s catalog item to base this instance on.", Description: "ID of the k8s catalog item to base this instance on.",
}, },
"network_plugin": { "network_plugin": {
@@ -641,6 +634,12 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Default: false, Default: false,
Description: "Use only selected ExtNet for infrastructure connections", Description: "Use only selected ExtNet for infrastructure connections",
}, },
///4.4.0
"cloud_init": {
Type: schema.TypeString,
Optional: true,
Description: "Meta data for working group computes, format YAML 'user_data': 1111",
},
"join_config": { "join_config": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@@ -689,11 +688,19 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Optional: true, Optional: true,
Description: "insert ssl certificate in x509 pem format", Description: "insert ssl certificate in x509 pem format",
}, },
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Determines if cluster should be destroyed",
},
////
"extnet_id": { "extnet_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Computed: true, Computed: true,
//ForceNew: true, ForceNew: true,
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.", Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
}, },
"desc": { "desc": {
@@ -776,12 +783,6 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
Description: "IP address of default load balancer.", Description: "IP address of default load balancer.",
}, },
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Determines if cluster should be destroyed",
},
"rg_name": { "rg_name": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
@@ -809,7 +810,6 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
}, },
"vins_id": { "vins_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true,
Computed: true, Computed: true,
Description: "ID of default vins for this instace.", Description: "ID of default vins for this instace.",
}, },
@@ -818,7 +818,7 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
func ResourceK8sCP() *schema.Resource { func ResourceK8sCP() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
SchemaVersion: 2, SchemaVersion: 1,
CreateContext: resourceK8sCPCreate, CreateContext: resourceK8sCPCreate,
ReadContext: resourceK8sCPRead, ReadContext: resourceK8sCPRead,
@@ -838,12 +838,5 @@ func ResourceK8sCP() *schema.Resource {
}, },
Schema: resourceK8sCPSchemaMake(), Schema: resourceK8sCPSchemaMake(),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceK8sCPSchemaV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceK8sCPStateUpgradeV1,
Version: 1,
},
},
} }
} }

View File

@@ -202,7 +202,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
} }
} }
return resourceK8sWgRead(ctx, d, m) return nil
} }
func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -210,7 +210,6 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac
wg, err := utilityK8sWgCheckPresence(ctx, d, m) wg, err := utilityK8sWgCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -225,8 +224,6 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId("")
return nil return nil
} }
@@ -235,14 +232,14 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
"k8s_id": { "k8s_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
//ForceNew: true, // ForceNew: true,
Description: "ID of k8s instance.", Description: "ID of k8s instance.",
}, },
"name": { "name": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
//ForceNew: true, // ForceNew: true,
Description: "Name of the worker group.", Description: "Name of the worker group.",
}, },
@@ -256,7 +253,7 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
"cpu": { "cpu": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
//ForceNew: true, // ForceNew: true,
Default: 1, Default: 1,
Description: "Worker node CPU count.", Description: "Worker node CPU count.",
}, },

View File

@@ -1,15 +0,0 @@
package k8s
import (
"context"
log "github.com/sirupsen/logrus"
)
func resourceK8sCPStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceK8sCPStateUpgradeV1: upgrading state")
delete(rawState, "cloud_init")
return rawState, nil
}

View File

@@ -273,22 +273,7 @@ func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m
req.Size = uint64(size.(int)) req.Size = uint64(size.(int))
} }
k8sList, err := c.CloudAPI().K8S().List(ctx, req)
if err != nil {
return nil, err
}
return k8sList, nil
}
func utilityK8sListForResourceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8SClusters, error) {
c := m.(*controller.ControllerCfg)
req := k8s.ListRequest{
IncludeDeleted: false,
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
k8sList, err := c.CloudAPI().K8S().List(ctx, req) k8sList, err := c.CloudAPI().K8S().List(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -125,7 +125,7 @@ func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m in
return nil, fmt.Errorf("not found wg with id: %v in k8s cluster: %v", wgId, cluster.ID) return nil, fmt.Errorf("not found wg with id: %v in k8s cluster: %v", wgId, cluster.ID)
} }
func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SGroups, error) { func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SGroups, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := k8s.GetRequest{ req := k8s.GetRequest{
K8SID: uint64(d.Get("k8s_id").(int)), K8SID: uint64(d.Get("k8s_id").(int)),
@@ -142,7 +142,7 @@ func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData,
func utilityK8sWgCloudInitCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) { func utilityK8sWgCloudInitCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
req := k8s.GetWorkerNodesMetaDataRequest{ req := k8s.GetWorkerNodesMetaDataRequest{
K8SID: uint64(d.Get("k8s_id").(int)), K8SID: uint64(d.Get("k8s_id").(int)),
WorkersGroupID: uint64(d.Get("wg_id").(int)), WorkersGroupID: uint64(d.Get("wg_id").(int)),
} }

View File

@@ -54,7 +54,6 @@ func findInExtraDisks(DiskId uint, ExtraDisks []interface{}) bool {
func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
compute, err := utilityDataComputeCheckPresence(ctx, d, m) compute, err := utilityDataComputeCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId(strconv.Itoa(int(compute.ID))) d.SetId(strconv.Itoa(int(compute.ID)))
@@ -291,10 +290,6 @@ func computeListDisksSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"image_name": {
Type: schema.TypeString,
Computed: true,
},
"images": { "images": {
Type: schema.TypeList, Type: schema.TypeList,
Computed: true, Computed: true,
@@ -449,10 +444,6 @@ func computeInterfacesSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"flip_group_id": { "flip_group_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
@@ -615,7 +606,7 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
}, },
}, },
"boot_disk_size": { "bootdisk_size": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
@@ -720,10 +711,6 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"need_reboot" : {
Type: schema.TypeBool,
Computed: true,
},
"natable_vins_id": { "natable_vins_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputeAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeAudits, err := utilityComputeAuditsCheckPresence(ctx, d, m) computeAudits, err := utilityComputeAuditsCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputeGetAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeGetAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeAudits, err := utilityComputeGetAuditsCheckPresence(ctx, d, m) computeAudits, err := utilityComputeGetAuditsCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -45,13 +45,12 @@ import (
func dataSourceComputeGetConsoleUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeGetConsoleUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeConsoleUrl, err := utilityComputeGetConsoleUrlCheckPresence(ctx, d, m) computeConsoleUrl, err := utilityComputeGetConsoleUrlCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()
d.SetId(id.String()) d.SetId(id.String())
result := strings.ReplaceAll(computeConsoleUrl, "\"", "") result := strings.ReplaceAll(string(computeConsoleUrl), "\"", "")
result = strings.ReplaceAll(result, "\\", "") result = strings.ReplaceAll(string(result), "\\", "")
d.Set("console_url", result) d.Set("console_url", result)
return nil return nil
} }

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputeGetLogRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeGetLogRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeGetLog, err := utilityComputeGetLogCheckPresence(ctx, d, m) computeGetLog, err := utilityComputeGetLogCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputeListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeList, err := utilityDataComputeListCheckPresence(ctx, d, m) computeList, err := utilityDataComputeListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -124,7 +123,7 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
}, },
}, },
"boot_disk_size": { "bootdisk_size": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
@@ -233,10 +232,6 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"need_reboot": {
Type: schema.TypeBool,
Computed: true,
},
"pinned": { "pinned": {
Type: schema.TypeBool, Type: schema.TypeBool,
Computed: true, Computed: true,

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputeListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeList, err := utilityDataComputeListDeletedCheckPresence(ctx, d, m) computeList, err := utilityDataComputeListDeletedCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputePCIDeviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputePCIDeviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computePCIDeviceList, err := utilityComputePCIDeviceListCheckPresence(ctx, d, m) computePCIDeviceList, err := utilityComputePCIDeviceListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()
@@ -81,13 +80,13 @@ func dataSourceComputePCIDeviceListSchemaMake() map[string]*schema.Schema {
Description: "Find by status", Description: "Find by status",
}, },
"page": { "page": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Description: "Page number", Description: "Page number",
}, },
"size": { "size": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Description: "Page size", Description: "Page size",
}, },
"items": { "items": {

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputePfwListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputePfwListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computePfwList, err := utilityComputePfwListCheckPresence(ctx, d, m) computePfwList, err := utilityComputePfwListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -12,7 +12,6 @@ import (
func dataSourceComputeSnapshotUsageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeSnapshotUsageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeSnapshotUsage, err := utilityComputeSnapshotUsageCheckPresence(ctx, d, m) computeSnapshotUsage, err := utilityComputeSnapshotUsageCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputeUserListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeUserListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeUserList, err := utilityComputeUserListCheckPresence(ctx, d, m) computeUserList, err := utilityComputeUserListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -44,7 +44,6 @@ import (
func dataSourceComputeVGPUListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceComputeVGPUListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
computeVGPUList, err := utilityComputeVGPUListCheckPresence(ctx, d, m) computeVGPUList, err := utilityComputeVGPUListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()
@@ -76,18 +75,18 @@ func dataSourceComputeVGPUListSchemaMake() map[string]*schema.Schema {
Description: "Find by status", Description: "Find by status",
}, },
"includedeleted": { "includedeleted": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Description: "Include deleted computes. If using field 'status', then includedeleted will be ignored", Description: "Include deleted computes. If using field 'status', then includedeleted will be ignored",
}, },
"page": { "page": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Description: "Page number", Description: "Page number",
}, },
"size": { "size": {
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
Description: "Page size", Description: "Page size",
}, },
"items": { "items": {
@@ -95,6 +94,7 @@ func dataSourceComputeVGPUListSchemaMake() map[string]*schema.Schema {
Computed: true, Computed: true,
Elem: &schema.Schema{ Elem: &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
}, },
}, },
"entry_count": { "entry_count": {

View File

@@ -73,7 +73,6 @@ func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface
"conn_id": interfaceItem.ConnID, "conn_id": interfaceItem.ConnID,
"conn_type": interfaceItem.ConnType, "conn_type": interfaceItem.ConnType,
"def_gw": interfaceItem.DefGW, "def_gw": interfaceItem.DefGW,
"enabled": interfaceItem.Enabled,
"flip_group_id": interfaceItem.FLIPGroupID, "flip_group_id": interfaceItem.FLIPGroupID,
"guid": interfaceItem.GUID, "guid": interfaceItem.GUID,
"ip_address": interfaceItem.IPAddress, "ip_address": interfaceItem.IPAddress,
@@ -164,7 +163,7 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"anti_affinity_rules": flattenListRules(compute.AntiAffinityRules), "anti_affinity_rules": flattenListRules(compute.AntiAffinityRules),
"arch": compute.Architecture, "arch": compute.Architecture,
"boot_order": compute.BootOrder, "boot_order": compute.BootOrder,
"boot_disk_size": compute.BootDiskSize, "bootdisk_size": compute.BootDiskSize,
"clone_reference": compute.CloneReference, "clone_reference": compute.CloneReference,
"clones": compute.Clones, "clones": compute.Clones,
"computeci_id": compute.ComputeCIID, "computeci_id": compute.ComputeCIID,
@@ -189,7 +188,6 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"migrationjob": compute.MigrationJob, "migrationjob": compute.MigrationJob,
"milestones": compute.Milestones, "milestones": compute.Milestones,
"name": compute.Name, "name": compute.Name,
"need_reboot": compute.NeedReboot,
"pinned": compute.Pinned, "pinned": compute.Pinned,
"ram": compute.RAM, "ram": compute.RAM,
"reference_id": compute.ReferenceID, "reference_id": compute.ReferenceID,
@@ -267,6 +265,7 @@ func flattenComputeDisksDemo(ctx context.Context, d *schema.ResourceData, disksL
} }
res = append(res, temp) res = append(res, temp)
} }
sort.Slice(res, func(i, j int) bool { sort.Slice(res, func(i, j int) bool {
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64) return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
}) })
@@ -332,7 +331,6 @@ func flattenCompute(ctx context.Context, d *schema.ResourceData, computeRec comp
d.Set("affinity_weight", computeRec.AffinityWeight) d.Set("affinity_weight", computeRec.AffinityWeight)
d.Set("arch", computeRec.Architecture) d.Set("arch", computeRec.Architecture)
d.Set("boot_order", computeRec.BootOrder) d.Set("boot_order", computeRec.BootOrder)
// we intentionally use the SizeMax field, do not change it until the BootDiskSize field is fixed on the platform
d.Set("boot_disk_size", bootDisk.SizeMax) d.Set("boot_disk_size", bootDisk.SizeMax)
d.Set("boot_disk", flattenBootDisk(bootDisk)) d.Set("boot_disk", flattenBootDisk(bootDisk))
d.Set("boot_disk_id", bootDisk.ID) d.Set("boot_disk_id", bootDisk.ID)
@@ -369,7 +367,6 @@ func flattenCompute(ctx context.Context, d *schema.ResourceData, computeRec comp
d.Set("migrationjob", computeRec.MigrationJob) d.Set("migrationjob", computeRec.MigrationJob)
d.Set("milestones", computeRec.Milestones) d.Set("milestones", computeRec.Milestones)
d.Set("name", computeRec.Name) d.Set("name", computeRec.Name)
d.Set("need_reboot", computeRec.NeedReboot)
d.Set("natable_vins_id", computeRec.NatableVINSID) d.Set("natable_vins_id", computeRec.NatableVINSID)
d.Set("natable_vins_ip", computeRec.NatableVINSIP) d.Set("natable_vins_ip", computeRec.NatableVINSIP)
d.Set("natable_vins_name", computeRec.NatableVINSName) d.Set("natable_vins_name", computeRec.NatableVINSName)
@@ -389,7 +386,7 @@ func flattenCompute(ctx context.Context, d *schema.ResourceData, computeRec comp
d.Set("stateless_sep_id", computeRec.StatelessSepID) d.Set("stateless_sep_id", computeRec.StatelessSepID)
d.Set("stateless_sep_type", computeRec.StatelessSepType) d.Set("stateless_sep_type", computeRec.StatelessSepType)
d.Set("status", computeRec.Status) d.Set("status", computeRec.Status)
// d.Set("tags", flattenTags(computeRec.Tags)) d.Set("tags", flattenTags(computeRec.Tags))
d.Set("tech_status", computeRec.TechStatus) d.Set("tech_status", computeRec.TechStatus)
d.Set("updated_by", computeRec.UpdatedBy) d.Set("updated_by", computeRec.UpdatedBy)
d.Set("updated_time", computeRec.UpdatedTime) d.Set("updated_time", computeRec.UpdatedTime)
@@ -563,7 +560,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("anti_affinity_rules", flattenListRules(computeRec.AntiAffinityRules)) d.Set("anti_affinity_rules", flattenListRules(computeRec.AntiAffinityRules))
d.Set("arch", computeRec.Architecture) d.Set("arch", computeRec.Architecture)
d.Set("boot_order", computeRec.BootOrder) d.Set("boot_order", computeRec.BootOrder)
d.Set("boot_disk_size", computeRec.BootDiskSize) d.Set("bootdisk_size", computeRec.BootDiskSize)
d.Set("clone_reference", computeRec.CloneReference) d.Set("clone_reference", computeRec.CloneReference)
d.Set("clones", computeRec.Clones) d.Set("clones", computeRec.Clones)
d.Set("computeci_id", computeRec.ComputeCIID) d.Set("computeci_id", computeRec.ComputeCIID)
@@ -581,7 +578,6 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("guid", computeRec.GUID) d.Set("guid", computeRec.GUID)
d.Set("compute_id", computeRec.ID) d.Set("compute_id", computeRec.ID)
d.Set("image_id", computeRec.ImageID) d.Set("image_id", computeRec.ImageID)
d.Set("image_name", computeRec.ImageName)
d.Set("interfaces", flattenInterfaces(computeRec.Interfaces)) d.Set("interfaces", flattenInterfaces(computeRec.Interfaces))
d.Set("lock_status", computeRec.LockStatus) d.Set("lock_status", computeRec.LockStatus)
d.Set("manager_id", computeRec.ManagerID) d.Set("manager_id", computeRec.ManagerID)
@@ -589,7 +585,6 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("migrationjob", computeRec.MigrationJob) d.Set("migrationjob", computeRec.MigrationJob)
d.Set("milestones", computeRec.Milestones) d.Set("milestones", computeRec.Milestones)
d.Set("name", computeRec.Name) d.Set("name", computeRec.Name)
d.Set("need_reboot", computeRec.NeedReboot)
d.Set("natable_vins_id", computeRec.NatableVINSID) d.Set("natable_vins_id", computeRec.NatableVINSID)
d.Set("natable_vins_ip", computeRec.NatableVINSIP) d.Set("natable_vins_ip", computeRec.NatableVINSIP)
d.Set("natable_vins_name", computeRec.NatableVINSName) d.Set("natable_vins_name", computeRec.NatableVINSName)
@@ -682,19 +677,19 @@ func flattenSnapshotUsage(computeSnapshotUsages compute.ListUsageSnapshots) []ma
return res return res
} }
// func flattenSnapshotList(computeSnapshotUsages *compute.ListSnapShots) []map[string]interface{} { func flattenSnapshotList(computeSnapshotUsages *compute.ListSnapShots) []map[string]interface{} {
// res := make([]map[string]interface{}, 0, len(computeSnapshotUsages.Data)) res := make([]map[string]interface{}, 0, len(computeSnapshotUsages.Data))
// for _, computeUsage := range computeSnapshotUsages.Data { for _, computeUsage := range computeSnapshotUsages.Data {
// temp := map[string]interface{}{ temp := map[string]interface{}{
// "disks": computeUsage.Disks, "disks": computeUsage.Disks,
// "guid": computeUsage.GUID, "guid": computeUsage.GUID,
// "label": computeUsage.Label, "label": computeUsage.Label,
// "timestamp": computeUsage.Timestamp, "timestamp": computeUsage.Timestamp,
// } }
// res = append(res, temp) res = append(res, temp)
// } }
// return res return res
// } }
func flattenVGPU(m []interface{}) []string { func flattenVGPU(m []interface{}) []string {
output := []string{} output := []string{}

View File

@@ -160,32 +160,6 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
} }
} }
createReqPPC.Interfaces = make([]kvmppc.Interface, 0)
if networks, ok := d.GetOk("network"); ok {
if networks.(*schema.Set).Len() > 0 {
ns := networks.(*schema.Set).List()
interfaces := make([]kvmppc.Interface, 0)
for _, elem := range ns {
netInterfaceVal := elem.(map[string]interface{})
reqInterface := kvmppc.Interface{
NetType: netInterfaceVal["net_type"].(string),
NetID: uint64(netInterfaceVal["net_id"].(int)),
}
ipaddr, ipSet := netInterfaceVal["ip_address"]
if ipSet {
reqInterface.IPAddr = ipaddr.(string)
}
interfaces = append(interfaces, reqInterface)
}
createReqPPC.Interfaces = interfaces
}
}
argVal, ok = d.GetOk("cloud_init") argVal, ok = d.GetOk("cloud_init")
if ok { if ok {
userdata := argVal.(string) userdata := argVal.(string)
@@ -273,81 +247,33 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
} }
} }
if disks, ok := d.GetOk("disks"); ok { // Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
log.Debugf("resourceComputeCreate: Create disks on ComputeID: %d", computeId) // now we need to start it before we report the sequence complete
addedDisks := disks.([]interface{}) if d.Get("started").(bool) {
if len(addedDisks) > 0 { req := compute.StartRequest{ComputeID: computeId}
for _, disk := range addedDisks { log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId)
diskConv := disk.(map[string]interface{}) if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil {
req := compute.DiskAddRequest{ warnings.Add(err)
ComputeID: computeId, }
DiskName: diskConv["disk_name"].(string), }
Size: uint64(diskConv["size"].(int)),
}
if diskConv["sep_id"].(int) != 0 { if enabled, ok := d.GetOk("enabled"); ok {
req.SepID = uint64(diskConv["sep_id"].(int)) if enabled.(bool) {
} req := compute.EnableRequest{ComputeID: computeId}
if diskConv["disk_type"].(string) != "" { log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", enabled, computeId)
req.DiskType = diskConv["disk_type"].(string) if _, err := c.CloudAPI().Compute().Enable(ctx, req); err != nil {
} warnings.Add(err)
if diskConv["pool"].(string) != "" { }
req.Pool = diskConv["pool"].(string) } else {
} req := compute.DisableRequest{ComputeID: computeId}
if diskConv["desc"].(string) != "" { log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", enabled, computeId)
req.Description = diskConv["desc"].(string) if _, err := c.CloudAPI().Compute().Disable(ctx, req); err != nil {
} warnings.Add(err)
if diskConv["image_id"].(int) != 0 {
req.ImageID = uint64(diskConv["image_id"].(int))
}
diskId, err := c.CloudAPI().Compute().DiskAdd(ctx, req)
if err != nil {
cleanup = true
return diag.FromErr(err)
}
ctx = context.WithValue(ctx, DiskKey(strconv.Itoa(int(diskId))), diskConv["permanently"].(bool))
} }
} }
} }
if !cleanup { if !cleanup {
if enabled, ok := d.GetOk("enabled"); ok {
if enabled.(bool) {
req := compute.EnableRequest{ComputeID: computeId}
log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", enabled, computeId)
if _, err := c.CloudAPI().Compute().Enable(ctx, req); err != nil {
warnings.Add(err)
}
} else {
req := compute.DisableRequest{ComputeID: computeId}
log.Debugf("resourceComputeCreate: enable=%t Compute ID %d after completing its resource configuration", enabled, computeId)
if _, err := c.CloudAPI().Compute().Disable(ctx, req); err != nil {
warnings.Add(err)
}
}
}
// Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
// now we need to start it before we report the sequence complete
if start, ok := d.GetOk("started"); ok {
if start.(bool) {
req := compute.StartRequest{ComputeID: computeId}
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", computeId)
if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil {
warnings.Add(err)
}
}
if !start.(bool) {
req := compute.StopRequest{ComputeID: computeId}
log.Debugf("resourceComputeCreate: stoping Compute ID %d after completing its resource configuration", computeId)
if _, err := c.CloudAPI().Compute().Stop(ctx, req); err != nil {
warnings.Add(err)
}
}
}
if affinityLabel, ok := d.GetOk("affinity_label"); ok { if affinityLabel, ok := d.GetOk("affinity_label"); ok {
req := compute.AffinityLabelSetRequest{ req := compute.AffinityLabelSetRequest{
ComputeID: computeId, ComputeID: computeId,
@@ -360,6 +286,43 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
} }
} }
if disks, ok := d.GetOk("disks"); ok {
log.Debugf("resourceComputeCreate: Create disks on ComputeID: %d", computeId)
addedDisks := disks.([]interface{})
if len(addedDisks) > 0 {
for _, disk := range addedDisks {
diskConv := disk.(map[string]interface{})
req := compute.DiskAddRequest{
ComputeID: computeId,
DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)),
SepID: uint64(diskConv["sep_id"].(int)),
}
if diskConv["disk_type"].(string) != "" {
req.DiskType = diskConv["disk_type"].(string)
}
if diskConv["pool"].(string) != "" {
req.Pool = diskConv["pool"].(string)
}
if diskConv["desc"].(string) != "" {
req.Description = diskConv["desc"].(string)
}
if diskConv["image_id"].(int) != 0 {
req.ImageID = uint64(diskConv["image_id"].(int))
}
diskId, err := c.CloudAPI().Compute().DiskAdd(ctx, req)
if err != nil {
cleanup = true
return diag.FromErr(err)
}
ctx = context.WithValue(ctx, DiskKey(strconv.Itoa(int(diskId))), diskConv["permanently"].(bool))
}
}
}
if ars, ok := d.GetOk("affinity_rules"); ok { if ars, ok := d.GetOk("affinity_rules"); ok {
log.Debugf("resourceComputeCreate: Create affinity rules on ComputeID: %d", computeId) log.Debugf("resourceComputeCreate: Create affinity rules on ComputeID: %d", computeId)
addedAR := ars.([]interface{}) addedAR := ars.([]interface{})
@@ -405,134 +368,133 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
} }
} }
} }
}
if tags, ok := d.GetOk("tags"); ok { if tags, ok := d.GetOk("tags"); ok {
log.Debugf("resourceComputeCreate: Create tags on ComputeID: %d", computeId) log.Debugf("resourceComputeCreate: Create tags on ComputeID: %d", computeId)
addedTags := tags.(*schema.Set).List() addedTags := tags.(*schema.Set).List()
if len(addedTags) > 0 { if len(addedTags) > 0 {
for _, tagInterface := range addedTags { for _, tagInterface := range addedTags {
tagItem := tagInterface.(map[string]interface{}) tagItem := tagInterface.(map[string]interface{})
req := compute.TagAddRequest{ req := compute.TagAddRequest{
ComputeID: computeId,
Key: tagItem["key"].(string),
Value: tagItem["value"].(string),
}
_, err := c.CloudAPI().Compute().TagAdd(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
if pfws, ok := d.GetOk("port_forwarding"); ok {
log.Debugf("resourceComputeCreate: Create port farwarding on ComputeID: %d", computeId)
addedPfws := pfws.(*schema.Set).List()
if len(addedPfws) > 0 {
for _, pfwInterface := range addedPfws {
pfwItem := pfwInterface.(map[string]interface{})
req := compute.PFWAddRequest{
ComputeID: computeId,
PublicPortStart: uint64(pfwItem["public_port_start"].(int)),
LocalBasePort: uint64(pfwItem["local_port"].(int)),
Proto: pfwItem["proto"].(string),
}
if pfwItem["public_port_end"].(int) != 0 {
req.PublicPortEnd = int64(pfwItem["public_port_end"].(int))
}
_, err := c.CloudAPI().Compute().PFWAdd(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
if userAcess, ok := d.GetOk("user_access"); ok {
log.Debugf("resourceComputeCreate: Create user access on ComputeID: %d", computeId)
usersAcess := userAcess.(*schema.Set).List()
if len(usersAcess) > 0 {
for _, userAcessInterface := range usersAcess {
userAccessItem := userAcessInterface.(map[string]interface{})
req := compute.UserGrantRequest{
ComputeID: computeId,
Username: userAccessItem["username"].(string),
AccessType: userAccessItem["access_type"].(string),
}
_, err := c.CloudAPI().Compute().UserGrant(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
if snapshotList, ok := d.GetOk("snapshot"); ok {
log.Debugf("resourceComputeCreate: Create snapshot on ComputeID: %d", computeId)
snapshots := snapshotList.(*schema.Set).List()
if len(snapshots) > 0 {
for _, snapshotInterface := range snapshots {
snapshotItem := snapshotInterface.(map[string]interface{})
req := compute.SnapshotCreateRequest{
ComputeID: computeId,
Label: snapshotItem["label"].(string),
}
_, err := c.CloudAPI().Compute().SnapshotCreate(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
if cdtList, ok := d.GetOk("cd"); ok {
log.Debugf("resourceComputeCreate: Create cd on ComputeID: %d", computeId)
cds := cdtList.(*schema.Set).List()
if len(cds) > 0 {
snapshotItem := cds[0].(map[string]interface{})
req := compute.CDInsertRequest{
ComputeID: computeId, ComputeID: computeId,
CDROMID: uint64(snapshotItem["cdrom_id"].(int)), Key: tagItem["key"].(string),
Value: tagItem["value"].(string),
} }
_, err := c.CloudAPI().Compute().CDInsert(ctx, req) _, err := c.CloudAPI().Compute().TagAdd(ctx, req)
if err != nil { if err != nil {
warnings.Add(err) warnings.Add(err)
} }
} }
} }
}
if d.Get("pin_to_stack").(bool) { if pfws, ok := d.GetOk("port_forwarding"); ok {
req := compute.PinToStackRequest{ log.Debugf("resourceComputeCreate: Create port farwarding on ComputeID: %d", computeId)
ComputeID: computeId, addedPfws := pfws.(*schema.Set).List()
} if len(addedPfws) > 0 {
_, err := c.CloudAPI().Compute().PinToStack(ctx, req) for _, pfwInterface := range addedPfws {
if err != nil { pfwItem := pfwInterface.(map[string]interface{})
warnings.Add(err) req := compute.PFWAddRequest{
ComputeID: computeId,
PublicPortStart: uint64(pfwItem["public_port_start"].(int)),
PublicPortEnd: int64(pfwItem["public_port_end"].(int)),
LocalBasePort: uint64(pfwItem["local_port"].(int)),
Proto: pfwItem["proto"].(string),
}
_, err := c.CloudAPI().Compute().PFWAdd(ctx, req)
if err != nil {
warnings.Add(err)
}
} }
} }
}
if userAcess, ok := d.GetOk("user_access"); ok {
log.Debugf("resourceComputeCreate: Create user access on ComputeID: %d", computeId)
usersAcess := userAcess.(*schema.Set).List()
if len(usersAcess) > 0 {
for _, userAcessInterface := range usersAcess {
userAccessItem := userAcessInterface.(map[string]interface{})
req := compute.UserGrantRequest{
ComputeID: computeId,
Username: userAccessItem["username"].(string),
AccessType: userAccessItem["access_type"].(string),
}
if d.Get("pause").(bool) { _, err := c.CloudAPI().Compute().UserGrant(ctx, req)
req := compute.PauseRequest{ if err != nil {
ComputeID: computeId, warnings.Add(err)
}
} }
_, err := c.CloudAPI().Compute().Pause(ctx, req) }
}
if snapshotList, ok := d.GetOk("snapshot"); ok {
log.Debugf("resourceComputeCreate: Create snapshot on ComputeID: %d", computeId)
snapshots := snapshotList.(*schema.Set).List()
if len(snapshots) > 0 {
for _, snapshotInterface := range snapshots {
snapshotItem := snapshotInterface.(map[string]interface{})
req := compute.SnapshotCreateRequest{
ComputeID: computeId,
Label: snapshotItem["label"].(string),
}
_, err := c.CloudAPI().Compute().SnapshotCreate(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
}
if cdtList, ok := d.GetOk("cd"); ok {
log.Debugf("resourceComputeCreate: Create cd on ComputeID: %d", computeId)
cds := cdtList.(*schema.Set).List()
if len(cds) > 0 {
snapshotItem := cds[0].(map[string]interface{})
req := compute.CDInsertRequest{
ComputeID: computeId,
CDROMID: uint64(snapshotItem["cdrom_id"].(int)),
}
_, err := c.CloudAPI().Compute().CDInsert(ctx, req)
if err != nil { if err != nil {
warnings.Add(err) warnings.Add(err)
} }
} }
} }
if d.Get("pin_to_stack").(bool) == true {
req := compute.PinToStackRequest{
ComputeID: computeId,
}
_, err := c.CloudAPI().Compute().PinToStack(ctx, req)
if err != nil {
warnings.Add(err)
}
}
if d.Get("pause").(bool) == true {
req := compute.PauseRequest{
ComputeID: computeId,
}
_, err := c.CloudAPI().Compute().Pause(ctx, req)
if err != nil {
warnings.Add(err)
}
}
log.Debugf("resourceComputeCreate: new Compute ID %d, name %s creation sequence complete", computeId, d.Get("name").(string)) log.Debugf("resourceComputeCreate: new Compute ID %d, name %s creation sequence complete", computeId, d.Get("name").(string))
// We may reuse dataSourceComputeRead here as we maintain similarity // We may reuse dataSourceComputeRead here as we maintain similarity
// between Compute resource and Compute data source schemas // between Compute resource and Compute data source schemas
// Compute read function will also update resource ID on success, so that Terraform // Compute read function will also update resource ID on success, so that Terraform
// will know the resource exists // will know the resource exists
return append(warnings.Get(), resourceComputeRead(ctx, d, m)...) defer resourceComputeRead(ctx, d, m)
return warnings.Get()
} }
func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -543,7 +505,6 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
computeRec, err := utilityComputeCheckPresence(ctx, d, m) computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -647,76 +608,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err) return diag.FromErr(err)
} }
hasChanged := false
// check compute statuses
switch computeRec.Status {
case status.Deleted:
if restore, ok := d.GetOk("restore"); ok && restore.(bool) {
restoreReq := compute.RestoreRequest{ComputeID: computeRec.ID}
_, err := c.CloudAPI().Compute().Restore(ctx, restoreReq)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
if enabled, ok := d.GetOk("enabled"); ok {
if enabled.(bool) {
enableReq := compute.EnableRequest{ComputeID: computeRec.ID}
_, err = c.CloudAPI().Compute().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
}
if !enabled.(bool) {
enableReq := compute.DisableRequest{ComputeID: computeRec.ID}
_, err = c.CloudAPI().Compute().Disable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
}
}
if start, ok := d.GetOk("started"); ok {
if start.(bool) {
req := compute.StartRequest{ComputeID: computeRec.ID}
if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil {
return diag.FromErr(err)
}
}
if !start.(bool) {
req := compute.StopRequest{ComputeID: computeRec.ID}
if _, err := c.CloudAPI().Compute().Stop(ctx, req); err != nil {
return diag.FromErr(err)
}
}
}
hasChanged = true
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceComputeCreate(ctx, d, m)
case status.Disabled:
log.Debugf("The compute is in status: %s, may troubles can be occured with update. Please, enable compute first.", computeRec.Status)
case status.Redeploying:
case status.Deleting:
case status.Destroying:
return diag.Errorf("The compute is in progress with status: %s", computeRec.Status)
case status.Modeled:
return diag.Errorf("The compute is in status: %s, please, contant the support for more information", computeRec.Status)
}
if hasChanged {
computeRec, err = utilityComputeCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("enabled") { if d.HasChange("enabled") {
enabled := d.Get("enabled").(bool) enabled := d.Get("enabled").(bool)
if enabled { if enabled {
@@ -739,39 +630,45 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
log.Debugf("resourceComputeUpdate: enable=%s Compute ID %v after completing its resource configuration", d.Id(), enabled) log.Debugf("resourceComputeUpdate: enable=%s Compute ID %v after completing its resource configuration", d.Id(), enabled)
} }
if d.HasChange("started") { // check compute statuses
start := d.Get("started").(bool) switch computeRec.Status {
if start { case status.Deleted:
req := compute.StartRequest{ComputeID: computeRec.ID} restoreReq := compute.RestoreRequest{ComputeID: computeRec.ID}
enableReq := compute.EnableRequest{ComputeID: computeRec.ID}
if _, err := c.CloudAPI().Compute().Start(ctx, req); err != nil { _, err := c.CloudAPI().Compute().Restore(ctx, restoreReq)
return diag.FromErr(err) if err != nil {
} return diag.FromErr(err)
} }
if !start {
req := compute.StopRequest{ComputeID: computeRec.ID}
if _, err := c.CloudAPI().Compute().Stop(ctx, req); err != nil { _, err = c.CloudAPI().Compute().Enable(ctx, enableReq)
return diag.FromErr(err) if err != nil {
} return diag.FromErr(err)
} }
case status.Destroyed:
d.SetId("")
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceComputeCreate(ctx, d, m)
case status.Disabled:
log.Debugf("The compute is in status: %s, may troubles can be occured with update. Please, enable compute first.", computeRec.Status)
case status.Redeploying:
case status.Deleting:
case status.Destroying:
return diag.Errorf("The compute is in progress with status: %s", computeRec.Status)
case status.Modeled:
return diag.Errorf("The compute is in status: %s, please, contant the support for more information", computeRec.Status)
} }
doUpdate := false doUpdate := false
resizeReq := compute.ResizeRequest{ resizeReq := compute.ResizeRequest{
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
} Force: true,
forceResize, ok := d.GetOk("force_resize")
if ok {
resizeReq.Force = forceResize.(bool)
} }
warnings := dc.Warnings{} warnings := dc.Warnings{}
oldCpu, newCpu := d.GetChange("cpu") oldCpu, newCpu := d.GetChange("cpu")
if oldCpu.(int) > newCpu.(int) && !forceResize.(bool) {
return diag.Errorf("Cannot resize compute ID %d: enable 'force_resize' to reduce compute vCPUs", computeRec.ID)
}
if oldCpu.(int) != newCpu.(int) { if oldCpu.(int) != newCpu.(int) {
resizeReq.CPU = uint64(newCpu.(int)) resizeReq.CPU = uint64(newCpu.(int))
doUpdate = true doUpdate = true
@@ -839,16 +736,14 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
} }
} }
if d.HasChanges("description", "name") { if d.HasChange("description") || d.HasChange("name") {
req := compute.UpdateRequest{ req := compute.UpdateRequest{
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
Name: d.Get("name").(string),
} }
if d.HasChange("name") { if desc, ok := d.GetOk("description"); ok {
req.Name = d.Get("name").(string) req.Description = desc.(string)
}
if d.HasChange("description") {
req.Description = d.Get("description").(string)
} }
if _, err := c.CloudAPI().Compute().Update(ctx, req); err != nil { if _, err := c.CloudAPI().Compute().Update(ctx, req); err != nil {
@@ -958,11 +853,9 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
DiskName: diskConv["disk_name"].(string), DiskName: diskConv["disk_name"].(string),
Size: uint64(diskConv["size"].(int)), Size: uint64(diskConv["size"].(int)),
SepID: uint64(diskConv["sep_id"].(int)),
} }
if diskConv["sep_id"].(int) != 0 {
req.SepID = uint64(diskConv["sep_id"].(int))
}
if diskConv["disk_type"].(string) != "" { if diskConv["disk_type"].(string) != "" {
req.DiskType = diskConv["disk_type"].(string) req.DiskType = diskConv["disk_type"].(string)
} }
@@ -1410,7 +1303,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if d.HasChange("pin_to_stack") { if d.HasChange("pin_to_stack") {
oldPin, newPin := d.GetChange("pin_to_stack") oldPin, newPin := d.GetChange("pin_to_stack")
if !newPin.(bool) { if oldPin.(bool) == true && newPin.(bool) == false {
req := compute.UnpinFromStackRequest{ req := compute.UnpinFromStackRequest{
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
} }
@@ -1420,7 +1313,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
if !oldPin.(bool) { if oldPin.(bool) == false && newPin.(bool) == true {
req := compute.PinToStackRequest{ req := compute.PinToStackRequest{
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
} }
@@ -1434,7 +1327,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if d.HasChange("pause") { if d.HasChange("pause") {
oldPause, newPause := d.GetChange("pause") oldPause, newPause := d.GetChange("pause")
if !newPause.(bool) { if oldPause.(bool) == true && newPause.(bool) == false {
req := compute.ResumeRequest{ req := compute.ResumeRequest{
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
} }
@@ -1443,7 +1336,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
if !oldPause.(bool) { if oldPause.(bool) == false && newPause.(bool) == true {
req := compute.PauseRequest{ req := compute.PauseRequest{
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
} }
@@ -1456,8 +1349,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
} }
if d.HasChange("reset") { if d.HasChange("reset") {
_, newReset := d.GetChange("reset") oldReset, newReset := d.GetChange("reset")
if newReset.(bool) { if oldReset.(bool) == false && newReset.(bool) == true {
req := compute.ResetRequest{ req := compute.ResetRequest{
ComputeID: computeRec.ID, ComputeID: computeRec.ID,
} }
@@ -1537,8 +1430,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
// we may reuse dataSourceComputeRead here as we maintain similarity // we may reuse dataSourceComputeRead here as we maintain similarity
// between Compute resource and Compute data source schemas // between Compute resource and Compute data source schemas
defer resourceComputeRead(ctx, d, m)
return append(warnings.Get(), resourceComputeRead(ctx, d, m)...) return warnings.Get()
} }
func isResizeDisk(els []interface{}, el interface{}) bool { func isResizeDisk(els []interface{}, el interface{}) bool {
@@ -1611,8 +1504,6 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId("")
return nil return nil
} }
@@ -1662,6 +1553,7 @@ func disksSubresourceSchemaMake() map[string]*schema.Schema {
"permanently": { "permanently": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: false,
Description: "Disk deletion status", Description: "Disk deletion status",
}, },
"disk_id": { "disk_id": {
@@ -2036,12 +1928,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Default: false, Default: false,
}, },
"restore": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"auto_start": { "auto_start": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
@@ -2054,12 +1940,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Default: false, Default: false,
Description: "Flag for redeploy compute", Description: "Flag for redeploy compute",
}, },
"force_resize": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Flag for resize compute",
},
"data_disks": { "data_disks": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@@ -2198,10 +2078,6 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,
}, },
"need_reboot": {
Type: schema.TypeBool,
Computed: true,
},
"natable_vins_id": { "natable_vins_id": {
Type: schema.TypeInt, Type: schema.TypeInt,
Computed: true, Computed: true,

View File

@@ -34,17 +34,18 @@ package kvmvm
import ( import (
"context" "context"
log "github.com/sirupsen/logrus"
"regexp" "regexp"
"strconv"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute" "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
) )
func matchComputes(computeList *compute.ListComputes) *compute.ListComputes { func matchComputes(computeList *compute.ListComputes) *compute.ListComputes {
matched, _ := regexp.Compile(`[a-zA-Z]+\\d+-[a-zA-Z]+\\d+-[a-zA-Z]+\\d+`) matched, _ := regexp.Compile("[a-zA-Z]+\\d+-[a-zA-Z]+\\d+-[a-zA-Z]+\\d+")
result := computeList.FilterFunc(func(ic compute.ItemCompute) bool { result := computeList.FilterFunc(func(ic compute.ItemCompute) bool {
res := matched.Match([]byte(ic.Name)) res := matched.Match([]byte(ic.Name))
return !res return !res
@@ -175,6 +176,17 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
old_set, new_set := d.GetChange("network") old_set, new_set := d.GetChange("network")
req := compute.StopRequest{
ComputeID: computeID,
Force: true,
}
log.Debugf("utilityComputeNetworksConfigure: stopping compute %d", computeID)
_, err := c.CloudAPI().Compute().Stop(ctx, req)
if err != nil {
return err
}
apiErrCount := 0 apiErrCount := 0
var lastSavedError error var lastSavedError error
@@ -234,17 +246,6 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
} }
} }
needStart:= false
if d.Get("network").(*schema.Set).Len() == 1 || old_set.(*schema.Set).Len() < 1 {
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
if err := utilityComputeStop(ctx, computeId, m); err != nil {
apiErrCount++
lastSavedError = err
}
needStart = true
}
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set)) attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", attach_set.Len(), d.Id()) log.Debugf("utilityComputeNetworksConfigure: attach set has %d items for Compute ID %s", attach_set.Len(), d.Id())
for _, runner := range attach_set.List() { for _, runner := range attach_set.List() {
@@ -269,12 +270,13 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
} }
} }
if needStart { startReq := compute.StartRequest{ComputeID: computeID}
computeId, _ := strconv.ParseUint(d.Id(), 10, 64)
if numErr, err := utilityComputeStart(ctx, computeId, m); err != nil { log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID)
apiErrCount+= numErr _, err = c.CloudAPI().Compute().Start(ctx, startReq)
lastSavedError = err if err != nil {
} apiErrCount++
lastSavedError = err
} }
if apiErrCount > 0 { if apiErrCount > 0 {
@@ -300,30 +302,3 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m
return *computeRecord, nil return *computeRecord, nil
} }
func utilityComputeStop(ctx context.Context, computeID uint64, m interface{}) error {
c := m.(*controller.ControllerCfg)
req := compute.StopRequest{
ComputeID: computeID,
Force: true,
}
log.Debugf("utilityComputeNetworksConfigure: stopping compute %d", computeID)
_, err := c.CloudAPI().Compute().Stop(ctx, req)
if err != nil {
return err
}
return nil
}
func utilityComputeStart(ctx context.Context, computeID uint64, m interface{}) (int, error) {
c := m.(*controller.ControllerCfg)
startReq := compute.StartRequest{ComputeID: computeID}
log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID)
_, err := c.CloudAPI().Compute().Start(ctx, startReq)
if err != nil {
return 1, err
}
return 0, nil
}

View File

@@ -44,7 +44,6 @@ import (
func dataSourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lb, err := utilityLBCheckPresence(ctx, d, m) lb, err := utilityLBCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -44,7 +44,6 @@ import (
func dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lbList, err := utilityLBListCheckPresence(ctx, d, m) lbList, err := utilityLBListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -44,7 +44,6 @@ import (
func dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lbList, err := utilityLBListDeletedCheckPresence(ctx, d, m) lbList, err := utilityLBListDeletedCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
id := uuid.New() id := uuid.New()

View File

@@ -78,12 +78,6 @@ func lbResourceSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
} }
sch["safe"] = &schema.Schema{
Type: schema.TypeBool,
Default: true,
Optional: true,
}
sch["config_reset"] = &schema.Schema{ sch["config_reset"] = &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,
@@ -99,6 +93,7 @@ func lbResourceSchemaMake() map[string]*schema.Schema {
Optional: true, Optional: true,
} }
/// ///
sch["permanently"] = &schema.Schema{ sch["permanently"] = &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,

View File

@@ -42,7 +42,6 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb" "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/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller" "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" "repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
) )
@@ -95,16 +94,21 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
lbId, err := c.CloudAPI().LB().Create(ctx, req) lbId, err := c.CloudAPI().LB().Create(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId(strconv.FormatUint(lbId, 10)) lbIdParsed := strconv.Itoa(int(lbId))
d.SetId(lbIdParsed)
d.Set("lb_id", lbId) d.Set("lb_id", lbId)
w := dc.Warnings{} _, err = utilityLBCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if enable, ok := d.GetOk("enable"); ok { if enable, ok := d.GetOk("enable"); ok {
lbId := uint64(d.Get("lb_id").(int))
req := lb.DisableEnableRequest{ req := lb.DisableEnableRequest{
LBID: lbId, LBID: lbId,
} }
@@ -112,33 +116,17 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
if enable.(bool) { if enable.(bool) {
_, err := c.CloudAPI().LB().Enable(ctx, req) _, err := c.CloudAPI().LB().Enable(ctx, req)
if err != nil { if err != nil {
w.Add(err) return diag.FromErr(err)
} }
} else { } else {
_, err := c.CloudAPI().LB().Disable(ctx, req) _, err := c.CloudAPI().LB().Disable(ctx, req)
if err != nil { if err != nil {
w.Add(err) return diag.FromErr(err)
}
}
if start, ok := d.GetOk("start"); ok && enable.(bool) {
if start.(bool) {
req := lb.StartRequest{LBID: lbId}
_, err := c.CloudAPI().LB().Start(ctx, req)
if err != nil {
w.Add(err)
}
} else {
req := lb.StopRequest{LBID: lbId}
_, err := c.CloudAPI().LB().Stop(ctx, req)
if err != nil {
w.Add(err)
}
} }
} }
} }
return append(w.Get(), resourceLBRead(ctx, d, m)...) return resourceLBRead(ctx, d, m)
} }
func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -205,17 +193,21 @@ func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{})
func resourceLBDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func resourceLBDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBDelete") log.Debugf("resourceLBDelete")
_, err := utilityLBCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg) c := m.(*controller.ControllerCfg)
lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := lb.DeleteRequest{ req := lb.DeleteRequest{
LBID: lbId, LBID: uint64(d.Get("lb_id").(int)),
} }
if permanently, ok := d.GetOk("permanently"); ok { if permanently, ok := d.GetOk("permanently"); ok {
req.Permanently = permanently.(bool) req.Permanently = permanently.(bool)
} }
_, err := c.CloudAPI().LB().Delete(ctx, req) _, err = c.CloudAPI().LB().Delete(ctx, req)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -271,47 +263,19 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
case status.Created: case status.Created:
case status.Deleting: case status.Deleting:
case status.Deleted: case status.Deleted:
if restore, ok := d.GetOk("restore"); ok && restore.(bool) { lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
restoreReq := lb.RestoreRequest{LBID: lbRec.ID} restoreReq := lb.RestoreRequest{LBID: lbId}
enableReq := lb.DisableEnableRequest{LBID: lbId}
_, err := c.CloudAPI().LB().Restore(ctx, restoreReq) _, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
}
} }
if enable, ok := d.GetOk("enable"); ok { _, err = c.CloudAPI().LB().Enable(ctx, enableReq)
req := lb.DisableEnableRequest{ if err != nil {
LBID: lbRec.ID, return diag.FromErr(err)
}
if enable.(bool) {
_, err := c.CloudAPI().LB().Enable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
_, err := c.CloudAPI().LB().Disable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
if start, ok := d.GetOk("start"); ok && enable.(bool) {
if start.(bool) {
req := lb.StartRequest{LBID: lbRec.ID}
_, err := c.CloudAPI().LB().Start(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
req := lb.StopRequest{LBID: lbRec.ID}
_, err := c.CloudAPI().LB().Stop(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
} }
hasChanged = true hasChanged = true
case status.Destroying: case status.Destroying:
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status) return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
@@ -338,7 +302,7 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
if d.HasChange("ha_mode") { if d.HasChange("ha_mode") {
hamode := d.Get("ha_mode").(bool) hamode := d.Get("ha_mode").(bool)
if hamode { if hamode {
req := lb.HighlyAvailableRequest{ req:= lb.HighlyAvailableRequest {
LBID: uint64(d.Get("lb_id").(int)), LBID: uint64(d.Get("lb_id").(int)),
} }
_, err := c.CloudAPI().LB().HighlyAvailable(ctx, req) _, err := c.CloudAPI().LB().HighlyAvailable(ctx, req)
@@ -363,6 +327,7 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
if err != nil { if err != nil {
return diag.FromErr(err) return diag.FromErr(err)
} }
} }
} }
@@ -402,9 +367,6 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
req := lb.RestartRequest{ req := lb.RestartRequest{
LBID: uint64(d.Get("lb_id").(int)), LBID: uint64(d.Get("lb_id").(int)),
} }
if safe, ok:= d.GetOk("safe"); ok {
req.Safe = safe.(bool)
}
_, err := c.CloudAPI().LB().Restart(ctx, req) _, err := c.CloudAPI().LB().Restart(ctx, req)
if err != nil { if err != nil {

View File

@@ -94,7 +94,6 @@ func resourceLBBackendCreate(ctx context.Context, d *schema.ResourceData, m inte
_, err = c.CloudAPI().LB().BackendCreate(ctx, req) _, err = c.CloudAPI().LB().BackendCreate(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -102,7 +101,6 @@ func resourceLBBackendCreate(ctx context.Context, d *schema.ResourceData, m inte
_, err = utilityLBBackendCheckPresence(ctx, d, m) _, err = utilityLBBackendCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -130,7 +128,6 @@ func resourceLBBackendDelete(ctx context.Context, d *schema.ResourceData, m inte
_, err := utilityLBBackendCheckPresence(ctx, d, m) _, err := utilityLBBackendCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -142,7 +139,6 @@ func resourceLBBackendDelete(ctx context.Context, d *schema.ResourceData, m inte
_, err = c.CloudAPI().LB().BackendDelete(ctx, req) _, err = c.CloudAPI().LB().BackendDelete(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -199,7 +195,6 @@ func resourceLBBackendUpdate(ctx context.Context, d *schema.ResourceData, m inte
_, err = c.CloudAPI().LB().BackendUpdate(ctx, req) _, err = c.CloudAPI().LB().BackendUpdate(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -98,7 +98,6 @@ func resourceLBBackendServerCreate(ctx context.Context, d *schema.ResourceData,
_, err = c.CloudAPI().LB().BackendServerAdd(ctx, req) _, err = c.CloudAPI().LB().BackendServerAdd(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -106,7 +105,6 @@ func resourceLBBackendServerCreate(ctx context.Context, d *schema.ResourceData,
_, err = utilityLBBackendServerCheckPresence(ctx, d, m) _, err = utilityLBBackendServerCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -135,7 +133,6 @@ func resourceLBBackendServerDelete(ctx context.Context, d *schema.ResourceData,
_, err := utilityLBBackendServerCheckPresence(ctx, d, m) _, err := utilityLBBackendServerCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -148,7 +145,6 @@ func resourceLBBackendServerDelete(ctx context.Context, d *schema.ResourceData,
_, err = c.CloudAPI().LB().BackendServerDelete(ctx, req) _, err = c.CloudAPI().LB().BackendServerDelete(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
d.SetId("") d.SetId("")
@@ -162,7 +158,6 @@ func resourceLBBackendServerUpdate(ctx context.Context, d *schema.ResourceData,
haveLBID, err := existLBID(ctx, d, m) haveLBID, err := existLBID(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -208,7 +203,6 @@ func resourceLBBackendServerUpdate(ctx context.Context, d *schema.ResourceData,
_, err = c.CloudAPI().LB().BackendServerUpdate(ctx, req) _, err = c.CloudAPI().LB().BackendServerUpdate(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -66,7 +66,6 @@ func resourceLBFrontendCreate(ctx context.Context, d *schema.ResourceData, m int
_, err = c.CloudAPI().LB().FrontendCreate(ctx, req) _, err = c.CloudAPI().LB().FrontendCreate(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -74,7 +73,6 @@ func resourceLBFrontendCreate(ctx context.Context, d *schema.ResourceData, m int
_, err = utilityLBFrontendCheckPresence(ctx, d, m) _, err = utilityLBFrontendCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -102,7 +100,6 @@ func resourceLBFrontendDelete(ctx context.Context, d *schema.ResourceData, m int
_, err := utilityLBFrontendCheckPresence(ctx, d, m) _, err := utilityLBFrontendCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -114,7 +111,6 @@ func resourceLBFrontendDelete(ctx context.Context, d *schema.ResourceData, m int
_, err = c.CloudAPI().LB().FrontendDelete(ctx, req) _, err = c.CloudAPI().LB().FrontendDelete(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -68,7 +68,6 @@ func resourceLBFrontendBindCreate(ctx context.Context, d *schema.ResourceData, m
_, err = c.CloudAPI().LB().FrontendBind(ctx, req) _, err = c.CloudAPI().LB().FrontendBind(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -76,7 +75,6 @@ func resourceLBFrontendBindCreate(ctx context.Context, d *schema.ResourceData, m
_, err = utilityLBFrontendBindCheckPresence(ctx, d, m) _, err = utilityLBFrontendBindCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -105,7 +103,6 @@ func resourceLBFrontendBindDelete(ctx context.Context, d *schema.ResourceData, m
_, err := utilityLBFrontendBindCheckPresence(ctx, d, m) _, err := utilityLBFrontendBindCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -118,7 +115,6 @@ func resourceLBFrontendBindDelete(ctx context.Context, d *schema.ResourceData, m
_, err = c.CloudAPI().LB().FrontendBindDelete(ctx, req) _, err = c.CloudAPI().LB().FrontendBindDelete(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -156,7 +152,6 @@ func resourceLBFrontendBindUpdate(ctx context.Context, d *schema.ResourceData, m
_, err = c.CloudAPI().LB().FrontendBindUpdate(ctx, req) _, err = c.CloudAPI().LB().FrontendBindUpdate(ctx, req)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -44,12 +44,11 @@ import (
) )
func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{} { func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(ll.Data)) res := make([]map[string]interface{}, 0)
for _, l := range ll.Data { for _, l := range ll.Data {
temp := map[string]interface{}{ temp := map[string]interface{}{
"ckey": l.CKey, "ckey": l.CKey,
"meta": flattens.FlattenMeta(l.Meta), "meta": flattens.FlattenMeta(l.Meta),
"auth_broker": l.AuthBroker,
"flag": l.Flag, "flag": l.Flag,
"gid": l.GID, "gid": l.GID,
"guid": l.GUID, "guid": l.GUID,
@@ -66,7 +65,6 @@ func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{}
func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
locations, err := utilityLocationsListCheckPresence(ctx, d, m) locations, err := utilityLocationsListCheckPresence(ctx, d, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }
@@ -128,13 +126,6 @@ func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString, Type: schema.TypeString,
}, },
}, },
"auth_broker": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"flag": { "flag": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,

View File

@@ -45,7 +45,6 @@ import (
func dataSourceLocationUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func dataSourceLocationUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
url, err := utilityLocationUrlCheckPresence(ctx, m) url, err := utilityLocationUrlCheckPresence(ctx, m)
if err != nil { if err != nil {
d.SetId("")
return diag.FromErr(err) return diag.FromErr(err)
} }

View File

@@ -42,172 +42,145 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
) )
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { func sepsSchemaMake() map[string]*schema.Schema {
rg, err := utilityResgroupCheckPresence(ctx, d, m) res := map[string]*schema.Schema{
if err != nil { "sep_id": {
d.SetId("") // ensure ID is empty in this case Type: schema.TypeString,
return diag.FromErr(err) Computed: true,
} },
d.SetId(strconv.Itoa(d.Get("rg_id").(int))) "data_name": {
flattenRg(d, *rg) Type: schema.TypeString,
return nil Computed: true,
} },
"disk_size": {
func DataSourceResgroup() *schema.Resource { Type: schema.TypeFloat,
return &schema.Resource{ Computed: true,
SchemaVersion: 1, },
"disk_size_max": {
ReadContext: dataSourceResgroupRead, Type: schema.TypeInt,
Computed: true,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
}, },
Schema: dataSourceRgSchemaMake(),
} }
return res
} }
func resourcesSchemaMake() map[string]*schema.Schema {
res := 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.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.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"map": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
"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,
},
"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.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sep_id": {
Type: schema.TypeString,
Computed: true,
},
"map": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
}
// func sepsSchemaMake() map[string]*schema.Schema { return res
// res := 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.TypeInt,
// Computed: true,
// },
// }
// return res
// }
// func resourcesSchemaMake() map[string]*schema.Schema {
// res := 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.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.TypeSet,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "sep_id": {
// Type: schema.TypeString,
// Computed: true,
// },
// "map": {
// Type: schema.TypeMap,
// Computed: true,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// },
// },
// },
// },
// },
// },
// },
// },
// "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,
// },
// "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.TypeSet,
// Computed: true,
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "sep_id": {
// Type: schema.TypeString,
// Computed: true,
// },
// "map": {
// Type: schema.TypeMap,
// Computed: true,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// },
// },
// },
// },
// },
// },
// },
// },
// }
// return res
// }
func aclSchemaMake() map[string]*schema.Schema { func aclSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{ res := map[string]*schema.Schema{
@@ -419,4 +392,28 @@ func dataSourceRgSchemaMake() map[string]*schema.Schema {
return res return res
} }
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
rg, err := utilityDataResgroupCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
d.SetId(strconv.Itoa(d.Get("rg_id").(int)))
flattenRg(d, *rg)
return nil
}
func DataSourceResgroup() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceResgroupRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceRgSchemaMake(),
}
}

Some files were not shown because too many files have changed in this diff Show More