Compare commits

...

10 Commits
4.3.2 ... 4.4.0

Author SHA1 Message Date
Nikita Sorokin
28b60de115 4.4.0-static-route-updated 2023-10-09 13:15:11 +03:00
Nikita Sorokin
b705ce4aab 4.4.0 2023-09-28 19:41:26 +03:00
Nikita Sorokin
83ca627cea 4.4.0 2023-09-28 16:08:15 +03:00
Nikita Sorokin
739289fbb8 4.3.8 2023-09-27 16:17:35 +03:00
Nikita Sorokin
c89574c3e6 4.3.7 2023-09-22 12:49:22 +03:00
Nikita Sorokin
a1e61674c8 4.3.6 2023-09-04 11:15:01 +03:00
Nikita Sorokin
cb9ff26bb0 4.3.5 2023-08-29 16:26:37 +03:00
Nikita Sorokin
6932f9d305 4.3.5 2023-08-28 13:02:41 +03:00
Nikita Sorokin
712f8edf9e 4.3.4 2023-08-23 16:32:48 +03:00
Nikita Sorokin
805ffe1f29 4.3.3 2023-08-22 13:15:17 +03:00
71 changed files with 3065 additions and 419 deletions

2
.gitignore vendored
View File

@@ -3,3 +3,5 @@ examples/
url_scrapping/
terraform-provider-decort*
.vscode/
.DS_Store

View File

@@ -1,5 +1,11 @@
## Version 4.3.2
## Version 4.4.0
## Bugfixes
- Fixed bootdisk flattens
- Updated golang-decort-sdk version with fixed permamently field in cloudapi/cloudbroker/compute/diskDel
### Bugfix
- Fixed bug with restore and new create resources at plan and refresh
## Feature
- Add in cloudapi in stack data_source_stack_list and data_source_stack
- Add in cloudapi in vins data_source_route, data_source_route_list, resource_static_route
- Cloudapi/lb/resource_lb extnet_id and vins_id can be equal to 0, but not together. If the value is 0, the api assigns it itself. Add Highly Available schema for LB deploy (parameter ha_mode). Cloudapi/lb/data_source_lb add parametr backend_haip, frontend_haip, part_k8s, data_source_lb_list, data_source_lb_list_deleted add parametr backend_haip, frontend_haip
- Cloudapi/bservice/resource_bservice_group added the ability to create a resource with the following sep_id, sep_pool and cloud_init
- Cloudapi/k8s/resource_k8s and resource_k8s_cp added the ability to create a resource with config (parameters cluster_config, kubelet_config, kube_proxy_config, join_config, cloud_init, init_config). Added the ability to create a resource with Highly Available schema for LB deploy (parameter ha_mode). Added the ability to create a resource with additional_sans. Added the ability to create a resource in extnet_only mode

View File

@@ -7,11 +7,8 @@ ZIPDIR = ./zip
BINARY=${NAME}
WORKPATH= ./examples/terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAMESPACE}/${VERSION}/${OS_ARCH}
MAINPATH = ./cmd/decort/
VERSION=4.3.2
VERSION=4.4.0
OS_ARCH=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)
# OS_ARCH=darwin_arm64
# OS_ARCH=windows_amd64
# OS_ARCH=linux_amd64
FILES = ${BINARY}_${VERSION}_darwin_amd64\
${BINARY}_${VERSION}_darwin_arm64\

View File

@@ -6,6 +6,7 @@ Terraform provider для платформы Digital Energy Cloud Orchestration
| Версия DECORT API | Версия провайдера Terraform |
| ------ | ------ |
| 3.8.8 | 4.4.x |
| 3.8.7 | 4.3.x |
| 3.8.6 | 4.0.x, 4.1.x, 4.2.x |
| 3.8.5 | 3.4.x |
@@ -29,6 +30,8 @@ Terraform provider для платформы Digital Energy Cloud Orchestration
- Работа с disks,
- Работа с k8s,
- Работа с image,
- Работа с flipgroups,
- Работа с stacks,
- Работа с reource groups,
- Работа с VINS,
- Работа с pfw,

12
go.mod
View File

@@ -8,8 +8,8 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/sirupsen/logrus v1.9.0
golang.org/x/net v0.12.0
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3
golang.org/x/net v0.15.0
repository.basistech.ru/BASIS/decort-golang-sdk v1.6.2
)
require (
@@ -24,7 +24,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.1 // indirect
github.com/go-playground/validator/v10 v10.15.4 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
@@ -67,9 +67,9 @@ require (
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/zclconf/go-cty v1.12.1 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 // indirect
google.golang.org/grpc v1.51.0 // indirect

24
go.sum
View File

@@ -55,8 +55,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-playground/validator/v10 v10.15.4 h1:zMXza4EpOdooxPel5xDqXEdXG5r+WggpvnAKMsalBjs=
github.com/go-playground/validator/v10 v10.15.4/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU=
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
@@ -249,8 +249,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -265,8 +265,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -293,8 +293,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
@@ -304,8 +304,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
@@ -339,5 +339,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3 h1:Rt5tE4EZcUr4ONK9u/XYe2mG1CC37xLUnNuCLYKDwYs=
repository.basistech.ru/BASIS/decort-golang-sdk v1.5.3/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE=
repository.basistech.ru/BASIS/decort-golang-sdk v1.6.2 h1:wi2iK7fblgejdylNsW/44fTbBaSoVld0PPcgKErSKyQ=
repository.basistech.ru/BASIS/decort-golang-sdk v1.6.2/go.mod h1:szsTGa73O75ckCWVGJPvTtRbhA/ubuYrYhMkPjvHlmE=

View File

@@ -34,6 +34,7 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/locations"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/rg"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/snapshot"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/stack"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudapi/vins"
cb_account "repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/account"
@@ -74,6 +75,8 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_vins_list_deleted": vins.DataSourceVinsListDeleted(),
"decort_vins_ext_net_list": vins.DataSourceVinsExtNetList(),
"decort_vins_nat_rule_list": vins.DataSourceVinsNatRuleList(),
"decort_vins_static_route_list": vins.DataSourceStaticRouteList(),
"decort_vins_static_route": vins.DataSourceStaticRoute(),
"decort_snapshot_list": snapshot.DataSourceSnapshotList(),
"decort_disk": disks.DataSourceDisk(),
"decort_disk_list": disks.DataSourceDiskList(),
@@ -124,6 +127,8 @@ func newDataSourcesMap() map[string]*schema.Resource {
"decort_lb_list_deleted": lb.DataSourceLBListDeleted(),
"decort_flipgroup": flipgroup.DataSourceFlipgroup(),
"decort_flipgroup_list": flipgroup.DataSourceFlipGroupList(),
"decort_stack": stack.DataSourceStack(),
"decort_stack_list": stack.DataSourceStackList(),
"decort_cb_account": cb_account.DataSourceAccount(),
"decort_cb_account_list": cb_account.DataSourceAccountList(),

View File

@@ -72,6 +72,7 @@ func newResourcesMap() map[string]*schema.Resource {
"decort_lb_frontend": lb.ResourceLBFrontend(),
"decort_lb_frontend_bind": lb.ResourceLBFrontendBind(),
"decort_flipgroup": flipgroup.ResourceFlipgroup(),
"decort_vins_static_route": vins.ResourceStaticRoute(),
"decort_cb_account": cb_account.ResourceAccount(),
"decort_cb_extnet": cb_extnet.ResourceExtnetCB(),

View File

@@ -54,7 +54,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceAccountRead: called for account with ID: %v", d.Id())
c := m.(*controller.ControllerCfg)
// c := m.(*controller.ControllerCfg)
acc, err := utilityAccountCheckPresence(ctx, d, m)
if err != nil {
@@ -67,22 +67,23 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interfac
switch acc.Status {
case status.Destroyed:
d.SetId("")
return resourceAccountCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceAccountCreate(ctx, d, m)
case status.Destroying:
return diag.Errorf("The account is in progress with status: %s", acc.Status)
case status.Deleted:
id, _ := strconv.ParseUint(d.Id(), 10, 64)
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
req := account.RestoreRequest{
AccountID: id,
}
// req := account.RestoreRequest{
// AccountID: id,
// }
_, err := c.CloudAPI().Account().Restore(ctx, req)
if err != nil {
return diag.FromErr(err)
}
// _, err := c.CloudAPI().Account().Restore(ctx, req)
// if err != nil {
// return diag.FromErr(err)
// }
hasChanged = true
// hasChanged = true
case status.Disabled:
log.Debugf("The account is in status: %s, troubles may occur with update. Please, enable account first.", acc.Status)
case status.Confirmed:
@@ -142,7 +143,8 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interf
switch acc.Status {
case status.Destroyed:
d.SetId("")
return resourceAccountCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceAccountCreate(ctx, d, m)
case status.Destroying:
return diag.Errorf("The account is in progress with status: %s", acc.Status)
case status.Deleted:

View File

@@ -30,6 +30,7 @@ func flattenResourceBasicServiceGroup(d *schema.ResourceData, bsg *bservice.Reco
d.Set("rg_name", bsg.RGName)
d.Set("role", bsg.Role)
d.Set("sep_id", bsg.SEPID)
d.Set("sep_pool", bsg.PoolName)
d.Set("seq_no", bsg.SeqNo)
d.Set("status", bsg.Status)
d.Set("tech_status", bsg.TechStatus)

View File

@@ -77,13 +77,30 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i
d.SetId(strconv.FormatUint(serviceId, 10))
d.Set("service_id", serviceId)
service, err := utilityBasicServiceCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if d.Get("enable").(bool) && (service.Status == status.Disabled || service.Status == status.Created) {
log.Debugf("trying to enable bservice %v", serviceId)
_, err := c.CloudAPI().BService().Enable(ctx, bservice.EnableRequest{
ServiceID: serviceId,
})
if err != nil {
return diag.FromErr(err)
}
}
return resourceBasicServiceRead(ctx, d, m)
}
func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceBasicServiceRead")
c := m.(*controller.ControllerCfg)
// c := m.(*controller.ControllerCfg)
bs, err := utilityBasicServiceCheckPresence(ctx, d, m)
if err != nil {
@@ -104,29 +121,30 @@ func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m int
case status.Disabling:
log.Debugf("The basic service is in status: %s, troubles can occur with the update.", bs.Status)
case status.Deleted:
id, _ := strconv.ParseUint(d.Id(), 10, 64)
restoreReq := bservice.RestoreRequest{
ServiceID: id,
}
enableReq := bservice.EnableRequest{
ServiceID: id,
}
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
// restoreReq := bservice.RestoreRequest{
// ServiceID: id,
// }
// enableReq := bservice.EnableRequest{
// ServiceID: id,
// }
_, err := c.CloudAPI().BService().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
// _, err := c.CloudAPI().BService().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
_, err = c.CloudAPI().BService().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
// _, err = c.CloudAPI().BService().Enable(ctx, enableReq)
// if err != nil {
// return diag.FromErr(err)
// }
hasChanged = true
// hasChanged = true
case status.Deleting:
case status.Destroyed:
d.SetId("")
return resourceBasicServiceCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceBasicServiceCreate(ctx, d, m)
case status.Destroying:
return diag.Errorf("The basic service is in progress with status: %s", bs.Status)
case status.Restoring:
@@ -224,7 +242,8 @@ func resourceBasicServiceUpdate(ctx context.Context, d *schema.ResourceData, m i
case status.Deleting:
case status.Destroyed:
d.SetId("")
return resourceBasicServiceCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceBasicServiceCreate(ctx, d, m)
case status.Destroying:
return diag.Errorf("The basic service is in progress with status: %s", bs.Status)
case status.Restoring:

View File

@@ -68,6 +68,20 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData
req.TimeoutStart = uint64(timeoutStart.(int))
}
///4.4.0
if sepId, ok := d.GetOk("sep_id"); ok {
req.SEPID = uint64(sepId.(int))
}
if sepPool, ok := d.GetOk("sep_pool"); ok {
req.SEPPool = sepPool.(string)
}
if cloudInit, ok := d.GetOk("cloud_init"); ok {
req.UserData = cloudInit.(string)
}
///
if vinses, ok := d.GetOk("vinses"); ok {
res := []uint64{}
for _, vins := range vinses.([]interface{}) {
@@ -362,6 +376,25 @@ func resourceBasicServiceGroupSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "compute driver like a KVM_X86, KVM_PPC, etc.",
},
///4.4.0
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "storage endpoint provider ID",
},
"sep_pool": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "pool to use if sepId is set, can be also empty if needed to be chosen by system",
},
"cloud_init": {
Type: schema.TypeString,
Optional: true,
Description: "Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases.",
},
///
"role": {
Type: schema.TypeString,
Optional: true,
@@ -524,10 +557,6 @@ func resourceBasicServiceGroupSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"seq_no": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -142,7 +142,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
}
func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
// c := m.(*controller.ControllerCfg)
warnings := dc.Warnings{}
disk, err := utilityDiskCheckPresence(ctx, d, m)
@@ -157,23 +157,24 @@ func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}
case status.Destroyed, status.Purged:
d.Set("disk_id", 0)
d.SetId("")
return resourceDiskCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceDiskCreate(ctx, d, m)
case status.Deleted:
hasChangeState = true
req := disks.RestoreRequest{
DiskID: disk.ID,
}
// hasChangeState = true
// req := disks.RestoreRequest{
// DiskID: disk.ID,
// }
if reason, ok := d.GetOk("reason"); ok {
req.Reason = reason.(string)
} else {
req.Reason = "Terraform automatic restore"
}
// 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)
}
// _, err := c.CloudAPI().Disks().Restore(ctx, req)
// if err != nil {
// warnings.Add(err)
// }
case status.Assigned:
case status.Modeled:
return diag.Errorf("The disk is in status: %s, please, contact support for more information", disk.Status)
@@ -227,7 +228,8 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
case status.Destroyed, status.Purged:
d.Set("disk_id", 0)
d.SetId("")
return resourceDiskCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceDiskCreate(ctx, d, m)
case status.Deleted:
hasChangeState = true
req := disks.RestoreRequest{
@@ -271,7 +273,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
Size: uint64(newSize.(int)),
}
_, err := c.CloudAPI().Disks().Resize(ctx, req)
_, err := c.CloudAPI().Disks().Resize2(ctx, req)
if err != nil {
return diag.FromErr(err)
}

View File

@@ -144,7 +144,8 @@ func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{
case status.Created:
case status.Destroyed, status.Purged:
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)
}
flattenImage(d, img)
@@ -233,7 +234,8 @@ func resourceImageUpdate(ctx context.Context, d *schema.ResourceData, m interfac
case status.Created:
case status.Destroyed, status.Purged:
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") {

View File

@@ -80,10 +80,6 @@ func computesSchemaMake() map[string]*schema.Schema {
}
}
func workerComputesSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{}
}
func dataSourceK8sComputesSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"k8s_id": {

View File

@@ -222,15 +222,15 @@ func flattenK8sGroup(k8SGroupList k8s.ListK8SGroups, workers []compute.RecordCom
return res
}
func flattenK8sGroups(k8sGroups k8s.RecordK8SGroups, masters []compute.RecordCompute, workers []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"masters": flattenMasterGroup(k8sGroups.Masters, masters),
"workers": flattenK8sGroup(k8sGroups.Workers, workers),
}
res = append(res, temp)
return res
}
// func flattenK8sGroups(k8sGroups k8s.RecordK8SGroups, masters []compute.RecordCompute, workers []compute.RecordCompute) []map[string]interface{} {
// res := make([]map[string]interface{}, 0)
// temp := map[string]interface{}{
// "masters": flattenMasterGroup(k8sGroups.Masters, masters),
// "workers": flattenK8sGroup(k8sGroups.Workers, workers),
// }
// res = append(res, temp)
// return res
// }
func flattenK8sData(d *schema.ResourceData, cluster k8s.RecordK8S, masters []compute.RecordCompute, workers []compute.RecordCompute) {
d.Set("acl", flattenAcl(cluster.ACL))

View File

@@ -145,6 +145,54 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
createReq.WithLB = d.Get("with_lb").(bool)
///4.4.0
createReq.HighlyAvailable = d.Get("ha_mode").(bool)
if additionalSans, ok := d.GetOk("additional_sans"); ok {
addSans := additionalSans.([]interface{})
resSans := make([]string, 0)
for _, san := range addSans {
resSans = append(resSans, san.(string))
}
createReq.AdditionalSANs = resSans
}
if clusterConfig, ok := d.GetOk("cluster_config"); ok {
createReq.ClusterConfiguration = clusterConfig.(string)
}
if kubeletConfig, ok := d.GetOk("kubelet_config"); ok {
createReq.KubeletConfiguration = kubeletConfig.(string)
}
if kubeProxyConfig, ok := d.GetOk("kube_proxy_config"); ok {
createReq.KubeProxyConfiguration = kubeProxyConfig.(string)
}
if joinConfig, ok := d.GetOk("join_config"); ok {
createReq.JoinConfiguration = joinConfig.(string)
}
if cloudInit, ok := d.GetOk("cloud_init"); ok {
createReq.UserData = cloudInit.(string)
}
if initConfig, ok := d.GetOk("init_config"); ok {
createReq.InitConfiguration = initConfig.(string)
}
if lbSysctlParams, ok := d.GetOk("lb_sysctl_params"); ok {
createReq.LbSysctlParams = lbSysctlParams.(string)
}
if oidcCertificate, ok := d.GetOk("oidc_cert"); ok {
createReq.OidcCertificate = oidcCertificate.(string)
}
///
createReq.ExtNetOnly = d.Get("extnet_only").(bool)
if extNet, ok := d.GetOk("extnet_id"); ok {
createReq.ExtNetID = uint64(extNet.(int))
} else {
@@ -181,7 +229,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
break
}
time.Sleep(time.Second * 10)
time.Sleep(time.Second * 20)
}
return resourceK8sRead(ctx, d, m)
@@ -205,31 +253,32 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
case status.Created:
case status.Deleting:
case status.Deleted:
id, _ := strconv.ParseUint(d.Id(), 10, 64)
restoreReq := k8s.RestoreRequest{
K8SID: id,
}
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
// restoreReq := k8s.RestoreRequest{
// K8SID: id,
// }
_, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
// _, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
enableReq := k8s.DisableEnableRequest{
K8SID: id,
}
// enableReq := k8s.DisableEnableRequest{
// K8SID: id,
// }
_, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
// _, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
// if err != nil {
// return diag.FromErr(err)
// }
hasChanged = true
// hasChanged = true
case status.Destroying:
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
case status.Destroyed:
d.SetId("")
return resourceK8sCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceK8sCreate(ctx, d, m)
case status.Enabling:
case status.Enabled:
case status.Disabling:
@@ -388,7 +437,8 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
case status.Destroyed:
d.SetId("")
return resourceK8sCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceK8sCreate(ctx, d, m)
case status.Enabling:
case status.Enabled:
case status.Disabling:
@@ -561,6 +611,12 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
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",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
@@ -568,6 +624,63 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
ForceNew: true,
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
},
///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",
},
////
"desc": {
Type: schema.TypeString,
Optional: true,
@@ -660,6 +773,7 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
},
"vins_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "ID of default vins for this instace.",
},

View File

@@ -129,6 +129,56 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
createReq.WithLB = d.Get("with_lb").(bool)
///4.4.0
createReq.HighlyAvailable = d.Get("ha_mode").(bool)
if additionalSans, ok := d.GetOk("additional_sans"); ok {
addSans := additionalSans.([]interface{})
resSans := make([]string, 0)
for _, san := range addSans {
resSans = append(resSans, san.(string))
}
createReq.AdditionalSANs = resSans
}
if clusterConfig, ok := d.GetOk("cluster_config"); ok {
createReq.ClusterConfiguration = clusterConfig.(string)
}
if kubeletConfig, ok := d.GetOk("kubelet_config"); ok {
createReq.KubeletConfiguration = kubeletConfig.(string)
}
if kubeProxyConfig, ok := d.GetOk("kube_proxy_config"); ok {
createReq.KubeProxyConfiguration = kubeProxyConfig.(string)
}
if joinConfig, ok := d.GetOk("join_config"); ok {
createReq.JoinConfiguration = joinConfig.(string)
}
if cloudInit, ok := d.GetOk("cloud_init"); ok {
createReq.UserData = cloudInit.(string)
}
if initConfig, ok := d.GetOk("init_config"); ok {
createReq.InitConfiguration = initConfig.(string)
}
if lbSysctlParams, ok := d.GetOk("lb_sysctl_params"); ok {
createReq.LbSysctlParams = lbSysctlParams.(string)
}
if oidcCertificate, ok := d.GetOk("oidc_cert"); ok {
createReq.OidcCertificate = oidcCertificate.(string)
log.Debug(createReq.OidcCertificate)
}
///
createReq.ExtNetOnly = d.Get("extnet_only").(bool)
if extNet, ok := d.GetOk("extnet_id"); ok {
createReq.ExtNetID = uint64(extNet.(int))
} else {
@@ -165,7 +215,7 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
break
}
time.Sleep(time.Second * 10)
time.Sleep(time.Second * 20)
}
cluster, err := utilityK8sCheckPresence(ctx, d, m)
@@ -204,31 +254,32 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{
case status.Created:
case status.Deleting:
case status.Deleted:
id, _ := strconv.ParseUint(d.Id(), 10, 64)
restoreReq := k8s.RestoreRequest{
K8SID: id,
}
// id, _ := strconv.ParseUint(d.Id(), 10, 64)
// restoreReq := k8s.RestoreRequest{
// K8SID: id,
// }
_, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
// _, err := c.CloudAPI().K8S().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
enableReq := k8s.DisableEnableRequest{
K8SID: id,
}
// enableReq := k8s.DisableEnableRequest{
// K8SID: id,
// }
_, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
// _, err = c.CloudAPI().K8S().Enable(ctx, enableReq)
// if err != nil {
// return diag.FromErr(err)
// }
hasChanged = true
// hasChanged = true
case status.Destroying:
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
case status.Destroyed:
d.SetId("")
return resourceK8sCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceK8sCreate(ctx, d, m)
case status.Enabling:
case status.Enabled:
case status.Disabling:
@@ -291,7 +342,7 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{
if _, ok := d.GetOk("k8s_id"); !ok {
for _, worker := range cluster.K8SGroups.Workers {
err := fmt.Errorf("Found worker-group with ID %d. Make sure to import it to decort_k8s_wg resource if you wish to manage it", worker.ID)
err := fmt.Errorf("found worker-group with ID %d. Make sure to import it to decort_k8s_wg resource if you wish to manage it", worker.ID)
warnings.Add(err)
}
}
@@ -387,7 +438,8 @@ func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interfac
return diag.Errorf("The k8s cluster is in progress with status: %s", cluster.Status)
case status.Destroyed:
d.SetId("")
return resourceK8sCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceK8sCreate(ctx, d, m)
case status.Enabling:
case status.Enabled:
case status.Disabling:
@@ -567,6 +619,67 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
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,

View File

@@ -110,7 +110,7 @@ func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{
return diag.FromErr(err)
}
workersComputeList := make([]compute.RecordCompute, 0, 0)
workersComputeList := make([]compute.RecordCompute, 0)
for _, info := range wg.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
if err != nil {

View File

@@ -70,7 +70,7 @@ func utilityDataK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData,
return nil, nil, fmt.Errorf("WG with id %v in k8s cluster %v not found", wgId, k8sId)
}
workersComputeList := make([]compute.RecordCompute, 0, 0)
workersComputeList := make([]compute.RecordCompute, 0)
for _, info := range curWg.DetailedInfo {
compute, err := utilityComputeCheckPresence(ctx, d, m, info.ID)
if err != nil {
@@ -121,7 +121,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) {

View File

@@ -637,10 +637,10 @@ func dataSourceComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
// "custom_fields": {
// Type: schema.TypeString,
// Computed: true,
// },
"custom_fields": {
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,

View File

@@ -154,10 +154,10 @@ func itemComputeSchemaMake() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
// "custom_fields": { //NEED
// Type: schema.TypeString,
// Computed: true,
// },
"custom_fields": { //NEED
Type: schema.TypeString,
Computed: true,
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,

View File

@@ -36,7 +36,6 @@ import (
"encoding/json"
"sort"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
@@ -151,7 +150,7 @@ func flattenListACL(listAcl compute.ListACL) []map[string]interface{} {
func flattenComputeList(computes *compute.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, compute := range computes.Data {
// customFields, _ := json.Marshal(compute.CustomFields)
customFields, _ := json.Marshal(compute.CustomFields)
devices, _ := json.Marshal(compute.Devices)
temp := map[string]interface{}{
"acl": flattenListACL(compute.ACL),
@@ -170,44 +169,44 @@ func flattenComputeList(computes *compute.ListComputes) []map[string]interface{}
"cpus": compute.CPU,
"created_by": compute.CreatedBy,
"created_time": compute.CreatedTime,
// "custom_fields": string(customFields),
"deleted_by": compute.DeletedBy,
"deleted_time": compute.DeletedTime,
"desc": compute.Description,
"devices": string(devices),
"disks": flattenDisks(compute.Disks),
"driver": compute.Driver,
"gid": compute.GID,
"guid": compute.GUID,
"compute_id": compute.ID,
"image_id": compute.ImageID,
"interfaces": flattenInterfaces(compute.Interfaces),
"lock_status": compute.LockStatus,
"manager_id": compute.ManagerID,
"manager_type": compute.ManagerType,
"migrationjob": compute.MigrationJob,
"milestones": compute.Milestones,
"name": compute.Name,
"pinned": compute.Pinned,
"ram": compute.RAM,
"reference_id": compute.ReferenceID,
"registered": compute.Registered,
"res_name": compute.ResName,
"rg_id": compute.RGID,
"rg_name": compute.RGName,
"snap_sets": flattenSnapSets(compute.SnapSets),
"stateless_sep_id": compute.StatelessSepID,
"stateless_sep_type": compute.StatelessSepType,
"status": compute.Status,
"tags": flattenTags(compute.Tags),
"tech_status": compute.TechStatus,
"total_disk_size": compute.TotalDiskSize,
"updated_by": compute.UpdatedBy,
"updated_time": compute.UpdatedTime,
"user_managed": compute.UserManaged,
"vgpus": compute.VGPUs,
"vins_connected": compute.VINSConnected,
"virtual_image_id": compute.VirtualImageID,
"custom_fields": string(customFields),
"deleted_by": compute.DeletedBy,
"deleted_time": compute.DeletedTime,
"desc": compute.Description,
"devices": string(devices),
"disks": flattenDisks(compute.Disks),
"driver": compute.Driver,
"gid": compute.GID,
"guid": compute.GUID,
"compute_id": compute.ID,
"image_id": compute.ImageID,
"interfaces": flattenInterfaces(compute.Interfaces),
"lock_status": compute.LockStatus,
"manager_id": compute.ManagerID,
"manager_type": compute.ManagerType,
"migrationjob": compute.MigrationJob,
"milestones": compute.Milestones,
"name": compute.Name,
"pinned": compute.Pinned,
"ram": compute.RAM,
"reference_id": compute.ReferenceID,
"registered": compute.Registered,
"res_name": compute.ResName,
"rg_id": compute.RGID,
"rg_name": compute.RGName,
"snap_sets": flattenSnapSets(compute.SnapSets),
"stateless_sep_id": compute.StatelessSepID,
"stateless_sep_type": compute.StatelessSepType,
"status": compute.Status,
"tags": flattenTags(compute.Tags),
"tech_status": compute.TechStatus,
"total_disk_size": compute.TotalDiskSize,
"updated_by": compute.UpdatedBy,
"updated_time": compute.UpdatedTime,
"user_managed": compute.UserManaged,
"vgpus": compute.VGPUs,
"vins_connected": compute.VINSConnected,
"virtual_image_id": compute.VirtualImageID,
}
res = append(res, temp)
}
@@ -237,10 +236,10 @@ func flattenBootDisk(bootDisk *compute.ItemComputeDisk) []map[string]interface{}
return res
}
func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []interface{}) []map[string]interface{} {
func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []interface{}, bootDiskId uint64) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(disksList))
for _, disk := range disksList {
if strings.Contains(disk.Name, "bootdisk") || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
if disk.ID == bootDiskId || findInExtraDisks(uint(disk.ID), extraDisks) { //skip main bootdisk and extraDisks
continue
}
temp := map[string]interface{}{
@@ -261,6 +260,7 @@ func flattenComputeDisksDemo(disksList compute.ListComputeDisks, extraDisks []in
sort.Slice(res, func(i, j int) bool {
return res[i]["disk_id"].(uint64) < res[j]["disk_id"].(uint64)
})
return res
}
@@ -281,7 +281,7 @@ func flattenNetwork(interfaces compute.ListInterfaces) []map[string]interface{}
func findBootDisk(disks compute.ListComputeDisks) *compute.ItemComputeDisk {
for _, disk := range disks {
if strings.Contains(disk.Name, "bootdisk") {
if disk.Type == "B" {
return &disk
}
}
@@ -301,7 +301,7 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er
//check extraDisks, ipa_type, is,
d.SetId(strconv.FormatUint(computeRec.ID, 10))
d.Set("acl", flattenACL(computeRec.ACL))
// d.Set("acl", flattenACL(computeRec.ACL))
d.Set("account_id", computeRec.AccountID)
d.Set("account_name", computeRec.AccountName)
d.Set("affinity_weight", computeRec.AffinityWeight)
@@ -317,11 +317,12 @@ func flattenCompute(d *schema.ResourceData, computeRec compute.RecordCompute) er
d.Set("computeci_id", computeRec.ComputeCIID)
d.Set("created_by", computeRec.CreatedBy)
d.Set("created_time", computeRec.CreatedTime)
// d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
d.Set("deleted_by", computeRec.DeletedBy)
d.Set("deleted_time", computeRec.DeletedTime)
d.Set("description", computeRec.Description)
d.Set("devices", string(devices))
err := d.Set("disks", flattenComputeDisksDemo(computeRec.Disks, d.Get("extra_disks").(*schema.Set).List()))
err := d.Set("disks", flattenComputeDisksDemo(computeRec.Disks, d.Get("extra_disks").(*schema.Set).List(), bootDisk.ID))
if err != nil {
return err
}
@@ -542,7 +543,7 @@ func flattenDataCompute(d *schema.ResourceData, computeRec compute.RecordCompute
d.Set("cpus", computeRec.CPU)
d.Set("created_by", computeRec.CreatedBy)
d.Set("created_time", computeRec.CreatedTime)
// d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
d.Set("custom_fields", flattenCustomFields(computeRec.CustomFields))
d.Set("deleted_by", computeRec.DeletedBy)
d.Set("deleted_time", computeRec.DeletedTime)
d.Set("desc", computeRec.Description)

View File

@@ -0,0 +1,550 @@
package kvmvm
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/statefuncs"
)
func resourceComputeResourceV1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of this compute. Compute names are case sensitive and must be unique in the resource group.",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
Description: "ID of the resource group where this compute should be deployed.",
},
"driver": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: statefuncs.StateFuncToUpper,
ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86", "KVM_PPC"}, false), // observe case while validating
Description: "Hardware architecture of this compute instance.",
},
"cpu": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, constants.MaxCpusPerCompute),
Description: "Number of CPUs to allocate to this compute instance.",
},
"ram": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntAtLeast(constants.MinRamPerCompute),
Description: "Amount of RAM in MB to allocate to this compute instance.",
},
"image_id": {
Type: schema.TypeInt,
Required: true,
//ForceNew: true, //REDEPLOY
Description: "ID of the OS image to base this compute instance on.",
},
"boot_disk_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "This compute instance boot disk size in GB. Make sure it is large enough to accomodate selected OS image.",
},
"affinity_label": {
Type: schema.TypeString,
Optional: true,
Description: "Set affinity label for compute",
},
"affinity_rules": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"topology": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"node", "compute"}, false),
Description: "compute or node, for whom rule applies",
},
"policy": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"RECOMMENDED", "REQUIRED"}, false),
Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule",
},
"mode": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"EQ", "NE", "ANY"}, false),
Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'",
},
"key": {
Type: schema.TypeString,
Required: true,
Description: "key that are taken into account when analyzing this rule will be identified",
},
"value": {
Type: schema.TypeString,
Required: true,
Description: "value that must match the key to be taken into account when analyzing this rule",
},
},
},
},
"anti_affinity_rules": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"topology": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"node", "compute"}, false),
Description: "compute or node, for whom rule applies",
},
"policy": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"RECOMMENDED", "REQUIRED"}, false),
Description: "RECOMMENDED or REQUIRED, the degree of 'strictness' of this rule",
},
"mode": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"EQ", "NE", "ANY"}, false),
Description: "EQ or NE or ANY - the comparison mode is 'value', recorded by the specified 'key'",
},
"key": {
Type: schema.TypeString,
Required: true,
Description: "key that are taken into account when analyzing this rule will be identified",
},
"value": {
Type: schema.TypeString,
Required: true,
Description: "value that must match the key to be taken into account when analyzing this rule",
},
},
},
},
"disks": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: disksSubresourceSchemaMake(),
},
},
"custom_fields": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Computed: true,
},
"val": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"stateless": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Compute will be stateless (SVA_KVM_X86) if set to True",
},
"with_default_vins": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Create compute with default resgroup ViNS (true) or without any interfaces (false). This parameter is ignored if network block is specified",
},
"boot_disk": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: disksSubresourceSchemaMake(),
},
},
"sep_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Description: "ID of SEP to create bootDisk on. Uses image's sepId if not set.",
},
"pool": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "Pool to use if sepId is set, can be also empty if needed to be chosen by system.",
},
"extra_disks": {
Type: schema.TypeSet,
Optional: true,
MaxItems: constants.MaxExtraDisksPerCompute,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "Optional list of IDs of extra disks to attach to this compute. You may specify several extra disks.",
},
"network": {
Type: schema.TypeSet,
Optional: true,
MinItems: 1,
MaxItems: constants.MaxNetworksPerCompute,
Elem: &schema.Resource{
Schema: networkSubresourceSchemaMake(),
},
Description: "Optional network connection(s) for this compute. You may specify several network blocks, one for each connection.",
},
"tags": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: tagsSubresourceSchemaMake(),
},
},
"port_forwarding": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: portForwardingSubresourceSchemaMake(),
},
},
"user_access": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: userAccessSubresourceSchemaMake(),
},
},
"snapshot": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: snapshotSubresourceSchemaMake(),
},
},
"rollback": {
Type: schema.TypeSet,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: snapshotRollbackSubresourceSchemaMake(),
},
},
"cd": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: cdSubresourceSchemaMake(),
},
},
"pin_to_stack": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "Optional text description of this compute instance.",
},
"cloud_init": {
Type: schema.TypeString,
Optional: true,
Description: "Optional cloud_init parameters. Applied when creating new compute instance only, ignored in all other cases.",
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "If true - enable compute, else - disable",
},
"pause": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"reset": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"auto_start": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Flag for redeploy compute",
},
"force_stop": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Flag for redeploy compute",
},
"data_disks": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"KEEP", "DETACH", "DESTROY"}, false),
Default: "DETACH",
Description: "Flag for redeploy compute",
},
"started": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Is compute started.",
},
"detach_disks": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"permanently": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"is": {
Type: schema.TypeString,
Optional: true,
Description: "system name",
},
"ipa_type": {
Type: schema.TypeString,
Optional: true,
Description: "compute purpose",
},
// The rest are Compute properties, which are "computed" once it is created
"account_id": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of the account this compute instance belongs to.",
},
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the account this compute instance belongs to.",
},
"affinity_weight": {
Type: schema.TypeInt,
Computed: true,
},
"arch": {
Type: schema.TypeString,
Computed: true,
},
"boot_order": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"boot_disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "This compute instance boot disk ID.",
},
"clone_reference": {
Type: schema.TypeInt,
Computed: true,
},
"clones": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"computeci_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,
},
"devices": {
Type: schema.TypeString,
Computed: true,
},
"gid": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"compute_id": {
Type: schema.TypeInt,
Computed: true,
},
"interfaces": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: computeInterfacesSchemaMake(),
},
},
"lock_status": {
Type: schema.TypeString,
Computed: true,
},
"manager_id": {
Type: schema.TypeInt,
Computed: true,
},
"manager_type": {
Type: schema.TypeString,
Computed: true,
},
"migrationjob": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"natable_vins_id": {
Type: schema.TypeInt,
Computed: true,
},
"natable_vins_ip": {
Type: schema.TypeString,
Computed: true,
},
"natable_vins_name": {
Type: schema.TypeString,
Computed: true,
},
"natable_vins_network": {
Type: schema.TypeString,
Computed: true,
},
"natable_vins_network_name": {
Type: schema.TypeString,
Computed: true,
},
"os_users": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: osUsersSubresourceSchemaMake(),
},
Description: "Guest OS users provisioned on this compute instance.",
},
"pinned": {
Type: schema.TypeBool,
Computed: true,
},
"reference_id": {
Type: schema.TypeString,
Computed: true,
},
"registered": {
Type: schema.TypeBool,
Computed: true,
},
"res_name": {
Type: schema.TypeString,
Computed: true,
},
"rg_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the resource group where this compute instance is located.",
},
"snap_sets": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: computeSnapSetsSchemaMake(),
},
},
"stateless_sep_id": {
Type: schema.TypeInt,
Computed: true,
},
"stateless_sep_type": {
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,
},
"user_managed": {
Type: schema.TypeBool,
Computed: true,
},
"vgpus": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"virtual_image_id": {
Type: schema.TypeInt,
Computed: true,
},
"virtual_image_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

View File

@@ -192,6 +192,16 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
createReqX86.Driver = driver
if custom_fields, ok := d.GetOk("custom_fields"); ok {
val := custom_fields.(string)
val = strings.ReplaceAll(val, "\\", "")
val = strings.ReplaceAll(val, "\n", "")
val = strings.ReplaceAll(val, "\t", "")
val = strings.TrimSpace(val)
createReqX86.CustomFields = val
}
log.Debugf("resourceComputeCreate: creating Compute of type KVM VM x86")
apiResp, err := c.CloudAPI().KVMX86().Create(ctx, createReqX86)
if err != nil {
@@ -226,7 +236,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
argVal, ok = d.GetOk("extra_disks")
if ok && argVal.(*schema.Set).Len() > 0 {
log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len())
err = utilityComputeExtraDisksConfigure(ctx, d, m, false)
err = utilityComputeExtraDisksConfigure(ctx, d, m, false, nil)
if err != nil {
log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", computeId, err)
cleanup = true
@@ -247,13 +257,13 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
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", computeId, enabled)
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", computeId, enabled)
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)
}
@@ -486,7 +496,7 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
log.Debugf("resourceComputeRead: called for Compute name %s, RG ID %d",
d.Get("name").(string), d.Get("rg_id").(int))
c := m.(*controller.ControllerCfg)
// c := m.(*controller.ControllerCfg)
computeRec, err := utilityComputeCheckPresence(ctx, d, m)
if err != nil {
@@ -497,23 +507,24 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
switch computeRec.Status {
case status.Deleted:
restoreReq := compute.RestoreRequest{ComputeID: computeRec.ID}
enableReq := compute.EnableRequest{ComputeID: computeRec.ID}
// restoreReq := compute.RestoreRequest{ComputeID: computeRec.ID}
// enableReq := compute.EnableRequest{ComputeID: computeRec.ID}
_, err := c.CloudAPI().Compute().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
// _, err := c.CloudAPI().Compute().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
_, err = c.CloudAPI().Compute().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
// _, err = c.CloudAPI().Compute().Enable(ctx, enableReq)
// if err != nil {
// return diag.FromErr(err)
// }
hasChanged = true
// hasChanged = true
case status.Destroyed:
d.SetId("")
return resourceComputeCreate(ctx, d, m)
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, troubles may occur with update. Please, enable compute first.", computeRec.Status)
case status.Redeploying:
@@ -574,11 +585,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
switch networkData["net_type"].(string) {
case "VINS":
if vinsId, ok := existVinsId(ctx, m, networkData["net_id"].(int)); !ok {
return diag.Errorf("resourceComputeCreate: can't create compute because vins ID %d is not allowed or does not exist", vinsId)
return diag.Errorf("resourceComputeCreate: can't update compute because vins ID %d is not allowed or does not exist", vinsId)
}
case "EXTNET":
if extNetId, ok := existExtNetId(ctx, m, networkData["net_id"].(int)); !ok {
return diag.Errorf("resourceComputeCreate: can't create compute because extnet ID %d is not allowed or does not exist", extNetId)
return diag.Errorf("resourceComputeCreate: can't update compute because extnet ID %d is not allowed or does not exist", extNetId)
}
default:
@@ -632,7 +643,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
case status.Destroyed:
d.SetId("")
return resourceComputeCreate(ctx, d, m)
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:
@@ -706,7 +718,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
if d.HasChange("extra_disks") {
err := utilityComputeExtraDisksConfigure(ctx, d, m, true) // pass do_delta = true to apply changes, if any
err := utilityComputeExtraDisksConfigure(ctx, d, m, true, computeRec.Disks) // pass do_delta = true to apply changes, if any
if err != nil {
return diag.FromErr(err)
}
@@ -745,7 +757,23 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
for _, el := range oldConv {
if !isContainsDisk(newConv, el) {
deletedDisks = append(deletedDisks, el)
flag := false
extraDisks := d.Get("extra_disks").(*schema.Set).List()
delDisk := el.(map[string]interface{})
delDiskId := delDisk["disk_id"].(int)
for _, extraDiskId := range extraDisks {
if extraDiskId.(int) == delDiskId {
flag = true
break
}
}
if !flag {
deletedDisks = append(deletedDisks, el)
} else {
log.Debugf("disk %d will not be deleted because it is present in the extra_disks block", delDiskId)
}
}
}
@@ -772,7 +800,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
for _, disk := range deletedDisks {
diskConv := disk.(map[string]interface{})
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") {
if diskConv["disk_type"].(string) == "B" {
continue
}
@@ -782,6 +810,8 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
Permanently: diskConv["permanently"].(bool),
}
log.Debugf("trying to delete disk %d", req.DiskID)
_, err := c.CloudAPI().Compute().DiskDel(ctx, req)
if err != nil {
return diag.FromErr(err)
@@ -800,7 +830,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if len(addedDisks) > 0 {
for _, disk := range addedDisks {
diskConv := disk.(map[string]interface{})
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") {
if diskConv["disk_type"].(string) == "B" {
continue
}
req := compute.DiskAddRequest{
@@ -832,7 +862,7 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
if len(updatedDisks) > 0 {
for _, disk := range updatedDisks {
diskConv := disk.(map[string]interface{})
if strings.Contains(diskConv["disk_name"].(string), "bootdisk") {
if diskConv["disk_type"].(string) == "B" {
continue
}
req := compute.DiskResizeRequest{
@@ -1335,6 +1365,35 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
}
}
if d.HasChange("custom_fields") {
val := d.Get("custom_fields").(string)
val = strings.ReplaceAll(val, "\\", "")
val = strings.ReplaceAll(val, "\n", "")
val = strings.ReplaceAll(val, "\t", "")
val = strings.TrimSpace(val)
if len(val) > 0 {
req := compute.SetCustomFieldsRequest{
ComputeID: computeRec.ID,
CustomFields: val,
}
_, err := c.CloudAPI().Compute().SetCustomFields(ctx, req)
if err != nil {
return diag.FromErr(err)
}
} else {
req := compute.DeleteCustomFieldsRequest{
ComputeID: computeRec.ID,
}
_, err := c.CloudAPI().Compute().DeleteCustomFields(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
// we may reuse dataSourceComputeRead here as we maintain similarity
// between Compute resource and Compute data source schemas
defer resourceComputeRead(ctx, d, m)
@@ -1678,6 +1737,11 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
Schema: disksSubresourceSchemaMake(),
},
},
"custom_fields": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"stateless": {
Type: schema.TypeBool,
Optional: true,
@@ -1715,6 +1779,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
"extra_disks": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MaxItems: constants.MaxExtraDisksPerCompute,
Elem: &schema.Schema{
Type: schema.TypeInt,
@@ -2075,7 +2140,7 @@ func ResourceComputeSchemaMake() map[string]*schema.Schema {
func ResourceCompute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
SchemaVersion: 2,
CreateContext: resourceComputeCreate,
ReadContext: resourceComputeRead,
@@ -2095,5 +2160,12 @@ func ResourceCompute() *schema.Resource {
},
Schema: ResourceComputeSchemaMake(),
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceComputeResourceV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceCompueteStateUpgradeV1,
Version: 1,
},
},
}
}

View File

@@ -0,0 +1,33 @@
package kvmvm
import (
"context"
"fmt"
"strings"
log "github.com/sirupsen/logrus"
)
func resourceCompueteStateUpgradeV1(ctx context.Context, rawState map[string]interface{}, meta any) (map[string]interface{}, error) {
log.Debug("resourceCompueteStateUpgradeV1: upgrading state")
customFields, ok := rawState["custom_fields"]
if !ok || customFields == nil {
rawState["custom_fields"] = "{}"
return rawState, nil
}
b := &strings.Builder{}
b.WriteString("{")
oldCustomFieldsSlice := customFields.([]interface{})
for i := range oldCustomFieldsSlice {
oldCustomFields := oldCustomFieldsSlice[i].(map[string]interface{})
b.WriteString(fmt.Sprintf(`"%s":"%s"`, oldCustomFields["key"], oldCustomFields["val"]))
if i < len(oldCustomFieldsSlice)-1 {
b.WriteString(",")
}
}
b.WriteString("}")
rawState["custom_fields"] = b.String()
return rawState, nil
}

View File

@@ -54,7 +54,7 @@ func matchComputes(computeList *compute.ListComputes) *compute.ListComputes {
return &result
}
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool, disks compute.ListComputeDisks) error {
c := m.(*controller.ControllerCfg)
log.Debugf("utilityComputeExtraDisksConfigure: called for Compute ID %s with do_delta = %t", d.Id(), do_delta)
@@ -138,6 +138,22 @@ func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceDa
DiskID: uint64(diskId.(int)),
}
log.Debug("before attach HERE0")
flag := false
// check if there is an extra disk in the disks from the platform, so as not to attach it if it is already attached
for _, elem := range disks {
if elem.ID == uint64(diskId.(int)) {
flag = true
break
}
}
if flag {
continue
}
_, err := c.CloudAPI().Compute().DiskAttach(ctx, req)
if err != nil {
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
@@ -165,6 +181,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
Force: true,
}
log.Debugf("utilityComputeNetworksConfigure: stopping compute %d", computeID)
_, err := c.CloudAPI().Compute().Stop(ctx, req)
if err != nil {
return err
@@ -255,6 +272,7 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
startReq := compute.StartRequest{ComputeID: computeID}
log.Debugf("utilityComputeNetworksConfigure: starting compute %d", computeID)
_, err = c.CloudAPI().Compute().Start(ctx, startReq)
if err != nil {
apiErrCount++
@@ -279,7 +297,7 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m
computeRecord, err := c.CloudAPI().Compute().Get(ctx, req)
if err != nil {
return *computeRecord, err
return compute.RecordCompute{}, err
}
return *computeRecord, nil

View File

@@ -91,6 +91,7 @@ func flattenResourceLBBackend(d *schema.ResourceData, b *lb.ItemBackend, lbId in
func flattenResourceLB(d *schema.ResourceData, lb *lb.RecordLB) {
d.Set("ha_mode", lb.HAMode)
d.Set("backend_haip", lb.BackendHAIP)
d.Set("backends", flattenLBBackends(lb.Backends))
d.Set("created_by", lb.CreatedBy)
d.Set("created_time", lb.CreatedTime)
@@ -99,6 +100,7 @@ func flattenResourceLB(d *schema.ResourceData, lb *lb.RecordLB) {
d.Set("desc", lb.Description)
d.Set("dp_api_user", lb.DPAPIUser)
d.Set("extnet_id", lb.ExtNetID)
d.Set("frontend_haip", lb.FrontendHAIP)
d.Set("frontends", flattenFrontends(lb.Frontends))
d.Set("gid", lb.GID)
d.Set("guid", lb.GUID)
@@ -106,6 +108,7 @@ func flattenResourceLB(d *schema.ResourceData, lb *lb.RecordLB) {
d.Set("image_id", lb.ImageID)
d.Set("milestones", lb.Milestones)
d.Set("name", lb.Name)
d.Set("part_k8s", lb.PartK8s)
d.Set("primary_node", flattenNode(lb.PrimaryNode))
d.Set("rg_id", lb.RGID)
d.Set("rg_name", lb.RGName)
@@ -120,6 +123,7 @@ func flattenResourceLB(d *schema.ResourceData, lb *lb.RecordLB) {
func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) {
d.Set("ha_mode", lb.HAMode)
d.Set("backend_haip", lb.BackendHAIP)
d.Set("backends", flattenLBBackends(lb.Backends))
d.Set("created_by", lb.CreatedBy)
d.Set("created_time", lb.CreatedTime)
@@ -128,12 +132,14 @@ func flattenLB(d *schema.ResourceData, lb *lb.RecordLB) {
d.Set("desc", lb.Description)
d.Set("dp_api_user", lb.DPAPIUser)
d.Set("extnet_id", lb.ExtNetID)
d.Set("frontend_haip", lb.FrontendHAIP)
d.Set("frontends", flattenFrontends(lb.Frontends))
d.Set("gid", lb.GID)
d.Set("guid", lb.GUID)
d.Set("image_id", lb.ImageID)
d.Set("milestones", lb.Milestones)
d.Set("name", lb.Name)
d.Set("part_k8s", lb.PartK8s)
d.Set("primary_node", flattenNode(lb.PrimaryNode))
d.Set("rg_id", lb.RGID)
d.Set("rg_name", lb.RGName)
@@ -246,6 +252,7 @@ func flattenLBList(lbl *lb.ListLB) []map[string]interface{} {
for _, lb := range lbl.Data {
temp := map[string]interface{}{
"ha_mode": lb.HAMode,
"backend_haip": lb.BackendHAIP,
"backends": flattenLBBackends(lb.Backends),
"created_by": lb.CreatedBy,
"created_time": lb.CreatedTime,
@@ -255,6 +262,7 @@ func flattenLBList(lbl *lb.ListLB) []map[string]interface{} {
"dp_api_user": lb.DPAPIUser,
"dp_api_password": lb.DPAPIPassword,
"extnet_id": lb.ExtNetID,
"frontend_haip": lb.FrontendHAIP,
"frontends": flattenFrontends(lb.Frontends),
"gid": lb.GID,
"guid": lb.GUID,

View File

@@ -181,5 +181,6 @@ func dsLBItemSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
}
delete(sch, "part_k8s")
return sch
}

View File

@@ -47,12 +47,12 @@ func lbResourceSchemaMake() map[string]*schema.Schema {
sch["extnet_id"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
Optional: true,
}
sch["vins_id"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
Optional: true,
}
sch["start"] = &schema.Schema{
Type: schema.TypeBool,
@@ -83,7 +83,18 @@ func lbResourceSchemaMake() map[string]*schema.Schema {
Type: schema.TypeBool,
Optional: true,
}
///4.4.0
sch["ha_mode"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
}
sch["lb_sysctl_params"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
}
///
sch["permanently"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,

View File

@@ -40,6 +40,10 @@ func createLBSchema() map[string]*schema.Schema {
Type: schema.TypeBool,
Computed: true,
},
"backend_haip": {
Type: schema.TypeString,
Computed: true,
},
"backends": {
Type: schema.TypeList,
Computed: true,
@@ -204,6 +208,10 @@ func createLBSchema() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"frontend_haip": {
Type: schema.TypeString,
Computed: true,
},
"frontends": {
Type: schema.TypeList,
Computed: true,
@@ -272,6 +280,10 @@ func createLBSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"part_k8s": {
Type: schema.TypeBool,
Computed: true,
},
"primary_node": {
Type: schema.TypeList,
Computed: true,

View File

@@ -43,6 +43,11 @@ func existExtNetID(ctx context.Context, d *schema.ResourceData, m interface{}) (
c := m.(*controller.ControllerCfg)
extNetID := uint64(d.Get("extnet_id").(int))
// this code is needed in order to be able to pass 0
if extNetID == 0 {
return true, nil
}
req := extnet.ListRequest{}
extNetList, err := c.CloudAPI().ExtNet().List(ctx, req)
@@ -57,6 +62,11 @@ func existViNSID(ctx context.Context, d *schema.ResourceData, m interface{}) (bo
c := m.(*controller.ControllerCfg)
vinsID := uint64(d.Get("vins_id").(int))
// this code is needed in order to be able to pass 0
if vinsID == 0 {
return true, nil
}
req := vins.ListRequest{}
vinsList, err := c.CloudAPI().VINS().List(ctx, req)

View File

@@ -88,15 +88,19 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
req.Description = desc.(string)
}
if haMode, ok := d.GetOk("ha_mode"); ok {
req.HighlyAvailable = haMode.(bool)
}
lbId, err := c.CloudAPI().LB().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
lbIdParsed, _ := strconv.ParseInt(lbId, 10, 64)
lbIdParsed := strconv.Itoa(int(lbId))
d.SetId(lbId)
d.Set("lb_id", lbIdParsed)
d.SetId(lbIdParsed)
d.Set("lb_id", lbId)
_, err = utilityLBCheckPresence(ctx, d, m)
if err != nil {
@@ -128,7 +132,7 @@ func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}
func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceLBRead")
c := m.(*controller.ControllerCfg)
// c := m.(*controller.ControllerCfg)
lbRec, err := utilityLBCheckPresence(ctx, d, m)
if lbRec == nil {
@@ -145,25 +149,26 @@ func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{})
case status.Created:
case status.Deleting:
case status.Deleted:
lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
restoreReq := lb.RestoreRequest{LBID: lbId}
enableReq := lb.DisableEnableRequest{LBID: lbId}
// lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
// restoreReq := lb.RestoreRequest{LBID: lbId}
// enableReq := lb.DisableEnableRequest{LBID: lbId}
_, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
_, err = c.CloudAPI().LB().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
// _, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
// _, err = c.CloudAPI().LB().Enable(ctx, enableReq)
// if err != nil {
// return diag.FromErr(err)
// }
hasChanged = true
// hasChanged = true
case status.Destroying:
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
case status.Destroyed:
d.SetId("")
return resourceLBCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceLBCreate(ctx, d, m)
case status.Enabled:
case status.Enabling:
case status.Disabling:
@@ -276,7 +281,8 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
case status.Destroyed:
d.SetId("")
return resourceLBCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceLBCreate(ctx, d, m)
case status.Enabled:
case status.Enabling:
case status.Disabling:
@@ -286,13 +292,26 @@ func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}
}
if hasChanged {
lbRec, err = utilityLBCheckPresence(ctx, d, m)
_, err = utilityLBCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
if d.HasChange("ha_mode") {
hamode := d.Get("ha_mode").(bool)
if hamode {
req:= lb.HighlyAvailableRequest {
LBID: uint64(d.Get("lb_id").(int)),
}
_, err := c.CloudAPI().LB().HighlyAvailable(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
}
if d.HasChange("enable") {
enable := d.Get("enable").(bool)
req := lb.DisableEnableRequest{

View File

@@ -256,7 +256,7 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
log.Debugf("resourceResgroupRead: called for RG name %s, account ID %d",
d.Get("name").(string), d.Get("account_id").(int))
c := m.(*controller.ControllerCfg)
// c := m.(*controller.ControllerCfg)
rgData, err := utilityResgroupCheckPresence(ctx, d, m)
if err != nil {
@@ -272,24 +272,25 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
case status.Created:
case status.Enabled:
case status.Deleted:
restoreReq := rg.RestoreRequest{RGID: rgData.ID}
enableReq := rg.EnableRequest{RGID: rgData.ID}
// restoreReq := rg.RestoreRequest{RGID: rgData.ID}
// enableReq := rg.EnableRequest{RGID: rgData.ID}
_, err := c.CloudAPI().RG().Restore(ctx, restoreReq)
if err != nil {
return diag.FromErr(err)
}
// _, err := c.CloudAPI().RG().Restore(ctx, restoreReq)
// if err != nil {
// return diag.FromErr(err)
// }
_, err = c.CloudAPI().RG().Enable(ctx, enableReq)
if err != nil {
return diag.FromErr(err)
}
// _, err = c.CloudAPI().RG().Enable(ctx, enableReq)
// if err != nil {
// return diag.FromErr(err)
// }
hasChanged = true
// hasChanged = true
case status.Deleting:
case status.Destroyed:
d.SetId("")
return resourceResgroupCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceResgroupCreate(ctx, d, m)
case status.Destroying:
case status.Disabled:
case status.Disabling:
@@ -369,7 +370,8 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
case status.Deleting:
case status.Destroyed:
d.SetId("")
return resourceResgroupCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceResgroupCreate(ctx, d, m)
case status.Destroying:
case status.Disabled:
case status.Disabling:

View File

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

View File

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

View File

@@ -0,0 +1,69 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package stack
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/stack"
)
func flattenStackList(stackl *stack.ListStacks) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, stack := range stackl.Data {
temp := map[string]interface{}{
"stack_id": stack.ID,
"name": stack.Name,
"status": stack.Status,
"type": stack.Type,
}
res = append(res, temp)
}
return res
}
func flattenStack(d *schema.ResourceData, details stack.InfoStack) error {
log.Debugf("flattenStack: decoded Stack name %q / ID %d",
details.Name, details.ID)
d.Set("stack_id", details.ID)
d.Set("cpu_allocation_ratio", details.CPUAllocationRatio)
d.Set("name", details.Name)
d.Set("descr", details.Descr)
d.Set("mem_allocation_ratio", details.MemAllocationRatio)
d.Set("status", details.Status)
d.Set("type", details.Type)
d.Set("drivers", details.Drivers)
return nil
}

View File

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

View File

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

View File

@@ -0,0 +1,107 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vins
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(staticRoute.ID, 10))
flattenStaticRouteData(d, staticRoute)
return nil
}
func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"vins_id": {
Type: schema.TypeInt,
Required: true,
Description: "Unique ID of the ViNS",
},
"route_id": {
Type: schema.TypeInt,
Required: true,
Description: "Unique ID of the static route",
},
"compute_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"destination": {
Type: schema.TypeString,
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"netmask": {
Type: schema.TypeString,
Computed: true,
},
}
return rets
}
func DataSourceStaticRoute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceStaticRouteRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceStaticRouteSchemaMake(),
}
}

View File

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

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,8 +34,8 @@ package vins
import (
"context"
"strconv"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
@@ -47,8 +47,9 @@ func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(vins.ID, 10))
flattenVinsData(d, *vins)
id := uuid.New()
d.SetId(id.String())
flattenVinsData(d, vins)
return nil
}
@@ -640,7 +641,7 @@ func rulesSchemaMake() map[string]*schema.Schema {
}
}
func configSchrmaMake() map[string]*schema.Schema {
func natConfigSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"net_mask": {
Type: schema.TypeInt,
@@ -678,7 +679,7 @@ func natSchemaMake() map[string]*schema.Schema {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: configSchrmaMake(),
Schema: natConfigSchemaMake(),
},
},
"devices": {
@@ -768,7 +769,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Required: true,
Description: "Unique ID of the ViNS. If ViNS ID is specified, then ViNS name, rg_id and account_id are ignored.",
},
"vnf_dev": {
Type: schema.TypeList,
Computed: true,
@@ -776,10 +776,6 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Schema: vnfDevSchemaMake(),
},
},
"_ckey": {
Type: schema.TypeString,
Computed: true,
},
"account_id": {
Type: schema.TypeInt,
Computed: true,
@@ -797,6 +793,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Schema: vinsComputeSchemaMake(),
},
},
"created_by": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeInt,
Computed: true,
},
"default_gw": {
Type: schema.TypeString,
Computed: true,
@@ -808,6 +812,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Schema: qosSchemaMake(),
},
},
"deleted_by": {
Type: schema.TypeString,
Computed: true,
},
"deleted_time": {
Type: schema.TypeInt,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
@@ -874,6 +886,14 @@ func dataSourceVinsSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"updated_by": {
Type: schema.TypeString,
Computed: true,
},
"updated_time": {
Type: schema.TypeInt,
Computed: true,
},
"user_managed": {
Type: schema.TypeBool,
Computed: true,

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,7 +49,7 @@ func dataSourceVinsExtNetListRead(ctx context.Context, d *schema.ResourceData, m
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenVinsExtNetList(extNetList))
d.Set("entry_count", extNetList.EntryCount)
return nil
}
@@ -92,6 +92,10 @@ func DataSourceVinsExtNetListchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return rets
}

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,7 +49,7 @@ func dataSourceVinsIpListRead(ctx context.Context, d *schema.ResourceData, m int
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenVinsIpList(ips))
d.Set("entry_count", ips.EntryCount)
return nil
}
@@ -96,6 +96,10 @@ func DataSourceVinsIpListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return rets
}

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,6 +49,8 @@ func dataSourceVinsNatRuleListRead(ctx context.Context, d *schema.ResourceData,
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenVinsNatRuleList(natRules))
d.Set("entry_count", natRules.EntryCount)
return nil
}
@@ -99,6 +101,10 @@ func DataSourceVinsNatRuleListSchemaMake() map[string]*schema.Schema {
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
},
}
return rets
}

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -49,7 +49,7 @@ func flattenMGMT(mgmt vins.RecordMGMT) []map[string]interface{} {
return res
}
func flattenResources(resources *vins.RecordResources) []map[string]interface{} {
func flattenResources(resources vins.RecordResources) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"cpu": resources.CPU,
@@ -65,7 +65,7 @@ func flattenConfig(config vins.RecordVNFConfig) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"mgmt": flattenMGMT(config.MGMT),
"resources": flattenResources(&config.Resources),
"resources": flattenResources(config.Resources),
}
res = append(res, temp)
return res
@@ -84,8 +84,7 @@ func flattenQOS(qos vins.QOS) []map[string]interface{} {
}
func flattenInterfaces(interfaces []vins.ItemVNFInterface) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0, len(interfaces))
for _, vnfInterface := range interfaces {
temp := map[string]interface{}{
"conn_id": vnfInterface.ConnID,
@@ -141,7 +140,7 @@ func flattenVNFDev(vnfDev vins.RecordVNFDev) []map[string]interface{} {
}
func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0, len(computes))
for _, compute := range computes {
temp := map[string]interface{}{
"compute_id": compute.ID,
@@ -154,7 +153,7 @@ func flattenComputes(computes vins.ListVINSComputes) []map[string]interface{} {
}
func flattenReservations(reservations vins.ListReservations) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0, len(reservations))
for _, reservation := range reservations {
temp := map[string]interface{}{
"client_type": reservation.ClientType,
@@ -275,9 +274,9 @@ func flattenGW(gw vins.RecordGW) []map[string]interface{} {
return res
}
func flattenRules(rules vins.ListNATRules) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, rule := range rules.Data {
func flattenRules(rules vins.ListNATRulesConfig) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
tmp := map[string]interface{}{
"rule_id": rule.ID,
"local_ip": rule.LocalIP,
@@ -343,9 +342,9 @@ func flattenVNFS(vnfs vins.RecordVNFs) []map[string]interface{} {
return res
}
func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, rule := range rules.Data {
func flattenRuleBlock(rules vins.ListNATRulesConfig) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
tmp := map[string]interface{}{
"int_ip": rule.LocalIP,
"int_port": rule.LocalPort,
@@ -359,15 +358,18 @@ func flattenRuleBlock(rules vins.ListNATRules) []map[string]interface{} {
return res
}
func flattenVins(d *schema.ResourceData, vins vins.RecordVINS) {
func flattenVins(d *schema.ResourceData, vins *vins.RecordVINS) {
d.Set("vins_id", vins.ID)
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
d.Set("_ckey", vins.CKey)
d.Set("account_id", vins.AccountID)
d.Set("account_name", vins.AccountName)
d.Set("computes", flattenComputes(vins.Computes))
d.Set("created_by", vins.CreatedBy)
d.Set("created_time", vins.CreatedTime)
d.Set("default_gw", vins.DefaultGW)
d.Set("default_qos", flattenQOS(vins.DefaultQOS))
d.Set("deleted_by", vins.DeletedBy)
d.Set("deleted_time", vins.DeletedTime)
d.Set("desc", vins.Description)
d.Set("gid", vins.GID)
d.Set("guid", vins.GUID)
@@ -384,21 +386,26 @@ func flattenVins(d *schema.ResourceData, vins vins.RecordVINS) {
d.Set("rg_name", vins.RGName)
d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
d.Set("status", vins.Status)
d.Set("updated_by", vins.UpdatedBy)
d.Set("updated_time", vins.UpdatedTime)
d.Set("user_managed", vins.UserManaged)
d.Set("vnfs", flattenVNFS(vins.VNFs))
d.Set("vxlan_id", vins.VXLANID)
d.Set("nat_rule", flattenRuleBlock(vins.VNFs.NAT.Config.Rules))
}
func flattenVinsData(d *schema.ResourceData, vins vins.RecordVINS) {
func flattenVinsData(d *schema.ResourceData, vins *vins.RecordVINS) {
d.Set("vins_id", vins.ID)
d.Set("vnf_dev", flattenVNFDev(vins.VNFDev))
d.Set("_ckey", vins.CKey)
d.Set("account_id", vins.AccountID)
d.Set("account_name", vins.AccountName)
d.Set("computes", flattenComputes(vins.Computes))
d.Set("created_by", vins.CreatedBy)
d.Set("created_time", vins.CreatedTime)
d.Set("default_gw", vins.DefaultGW)
d.Set("default_qos", flattenQOS(vins.DefaultQOS))
d.Set("deleted_by", vins.DeletedBy)
d.Set("deleted_time", vins.DeletedTime)
d.Set("desc", vins.Description)
d.Set("gid", vins.GID)
d.Set("guid", vins.GUID)
@@ -415,14 +422,16 @@ func flattenVinsData(d *schema.ResourceData, vins vins.RecordVINS) {
d.Set("rg_name", vins.RGName)
d.Set("sec_vnf_dev_id", vins.SecVNFDevID)
d.Set("status", vins.Status)
d.Set("updated_by", vins.UpdatedBy)
d.Set("updated_time", vins.UpdatedTime)
d.Set("user_managed", vins.UserManaged)
d.Set("vnfs", flattenVNFS(vins.VNFs))
d.Set("vxlan_id", vins.VXLANID)
}
func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, audit := range auidts {
func flattenVinsAudits(audits vins.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(audits))
for _, audit := range audits {
temp := map[string]interface{}{
"call": audit.Call,
"response_time": audit.ResponseTime,
@@ -437,7 +446,7 @@ func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
}
func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0, len(extNetList.Data))
for _, extNet := range extNetList.Data {
temp := map[string]interface{}{
"default_gw": extNet.DefaultGW,
@@ -454,7 +463,7 @@ func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{
}
func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0, len(ips.Data))
for _, ip := range ips.Data {
temp := map[string]interface{}{
"client_type": ip.ClientType,
@@ -472,7 +481,7 @@ func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} {
}
func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
res := make([]map[string]interface{}, 0, len(vl.Data))
for _, v := range vl.Data {
temp := map[string]interface{}{
"account_id": v.AccountID,
@@ -497,8 +506,36 @@ func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
return res
}
func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} {
// /4.4.0
func flattenStaticRouteList(sr *vins.ListStaticRoutes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, staticRoute := range sr.Data {
temp := map[string]interface{}{
"route_id": staticRoute.ID,
"destination": staticRoute.Destination,
"gateway": staticRoute.Gateway,
"guid": staticRoute.GUID,
"netmask": staticRoute.Netmask,
"compute_ids": staticRoute.ComputeIds,
}
res = append(res, temp)
}
return res
}
func flattenStaticRouteData(d *schema.ResourceData, route *vins.ItemRoutes) {
d.Set("destination", route.Destination)
d.Set("gateway", route.Gateway)
d.Set("guid", route.GUID)
d.Set("netmask", route.Netmask)
d.Set("compute_ids", route.ComputeIds)
}
///
func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(natRules.Data))
for _, natRule := range natRules.Data {
temp := map[string]interface{}{
"id": natRule.ID,

View File

@@ -8,6 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
@@ -68,3 +69,16 @@ func existGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool,
return len(locationList.FilterByGID(gid).Data) != 0, nil
}
func existVinsID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
c := m.(*controller.ControllerCfg)
vinsID := uint64(d.Get("vins_id").(int))
req := vins.ListRequest{}
vinsList, err := c.CloudAPI().VINS().List(ctx, req)
if err != nil {
return false, err
}
return len(vinsList.FilterByID(vinsID).Data) != 0, nil
}

View File

@@ -0,0 +1,269 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vins
import (
"context"
"fmt"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
if _, ok := d.GetOk("vins_id"); ok {
haveVinsID, err := existVinsID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveVinsID {
return diag.Errorf("resourceStaticRouteCreate: can't create Static Route because Vins ID %d is not allowed or does not exist", d.Get("vins_id").(int))
}
}
req := vins.StaticRouteAddRequest{
VINSID: uint64(d.Get("vins_id").(int)),
Destination: d.Get("destination").(string),
Netmask: d.Get("netmask").(string),
Gateway: d.Get("gateway").(string),
}
if computesIDS, ok := d.GetOk("compute_ids"); ok {
ids := computesIDS.([]interface{})
res := make([]uint64, 10)
for _, id := range ids {
computeId := uint64(id.(int))
res = append(res, computeId)
}
req.ComputeIds = res
}
_, err := c.CloudAPI().VINS().StaticRouteAdd(ctx, req)
if err != nil {
return diag.FromErr(err)
}
staticRouteData, err := getStaticRouteData(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
d.SetId(fmt.Sprintf("%d#%d", req.VINSID, staticRouteData.ID))
return resourceStaticRouteRead(ctx, d, m)
}
func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
warnings := dc.Warnings{}
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenStaticRouteData(d, staticRouteData)
return warnings.Get()
}
func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
warnings := dc.Warnings{}
if _, ok := d.GetOk("vins_id"); ok {
haveVinsID, err := existVinsID(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
if !haveVinsID {
return diag.Errorf("resourceVinsUpdate: can't update Static Route because VinsID %d is not allowed or does not exist", d.Get("vins_id").(int))
}
}
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if d.HasChange("compute_ids") {
deletedIds := make([]uint64, 0)
addedIds := make([]uint64, 0)
oldComputeIds, newComputeIds := d.GetChange("compute_ids")
oldComputeIdsSlice := oldComputeIds.([]interface{})
newComputeIdsSlice := newComputeIds.([]interface{})
for _, el := range oldComputeIdsSlice {
if !isContainsIds(newComputeIdsSlice, el) {
convertedEl := uint64(el.(int))
deletedIds = append(deletedIds, convertedEl)
}
}
for _, el := range newComputeIdsSlice {
if !isContainsIds(oldComputeIdsSlice, el) {
convertedEl := uint64(el.(int))
addedIds = append(addedIds, convertedEl)
}
}
if len(deletedIds) > 0 {
req := vins.StaticRouteAccessRevokeRequest{
VINSID: uint64(d.Get("vins_id").(int)),
RouteId: staticRouteData.ID,
ComputeIds: deletedIds,
}
_, err := c.CloudAPI().VINS().StaticRouteAccessRevoke(ctx, req)
if err != nil {
warnings.Add(err)
}
}
if len(addedIds) > 0 {
req := vins.StaticRouteAccessGrantRequest{
VINSID: uint64(d.Get("vins_id").(int)),
RouteId: staticRouteData.ID,
ComputeIds: addedIds,
}
_, err := c.CloudAPI().VINS().StaticRouteAccessGrant(ctx, req)
if err != nil {
warnings.Add(err)
}
}
}
return append(warnings.Get(), resourceStaticRouteRead(ctx, d, m)...)
}
func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
vinsId := uint64(d.Get("vins_id").(int))
routeId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := vins.StaticRouteDelRequest{
VINSID: vinsId,
RouteId: routeId,
}
_, err := c.CloudAPI().VINS().StaticRouteDel(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceStaticRouteSchemaMake() map[string]*schema.Schema {
rets := dataSourceStaticRouteSchemaMake()
rets["route_id"] = &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Optional: true,
}
rets["compute_ids"] = &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
}
rets["destination"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
rets["gateway"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
rets["netmask"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
return rets
}
func isContainsIds(els []interface{}, el interface{}) bool {
convEl := el.(int)
for _, elOld := range els {
if convEl == elOld.(int) {
return true
}
}
return false
}
func ResourceStaticRoute() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceStaticRouteCreate,
ReadContext: resourceStaticRouteRead,
UpdateContext: resourceStaticRouteUpdate,
DeleteContext: resourceStaticRouteDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout20m,
Read: &constants.Timeout600s,
Update: &constants.Timeout20m,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceStaticRouteSchemaMake(),
}
}

View File

@@ -129,8 +129,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string)
}
req.PreReservationsNum = uint(d.Get("pre_reservations_num").(int))
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
req.PreReservationsNum = uint64(preReservationsNum.(int))
}
id, err := c.CloudAPI().VINS().CreateInRG(ctx, req)
if err != nil {
return diag.FromErr(err)
@@ -141,7 +143,6 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
req := vins.CreateInAccountRequest{
Name: d.Get("name").(string),
AccountID: uint64(accountId.(int)),
PreReservationsNum: uint64(d.Get("pre_reservations_num").(int)),
}
if gid, ok := d.GetOk("gid"); ok {
@@ -153,7 +154,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string)
}
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
req.PreReservationsNum = uint64(preReservationsNum.(int))
}
id, err := c.CloudAPI().VINS().CreateInAccount(ctx, req)
if err != nil {
return diag.FromErr(err)
@@ -214,21 +218,21 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
}
}
defer resourceVinsRead(ctx, d, m)
return warnings.Get()
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
}
func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*controller.ControllerCfg)
// c := m.(*controller.ControllerCfg)
warnings := dc.Warnings{}
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
vinsData, err := utilityDataVinsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
isEnabled := d.Get("enable").(bool)
// isEnabled := d.Get("enable").(bool)
hasChangeState := false
@@ -236,60 +240,61 @@ func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}
case status.Destroyed:
d.Set("vins_id", 0)
d.SetId("")
return resourceVinsCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceVinsCreate(ctx, d, m)
case status.Deleted:
hasChangeState = true
// hasChangeState = true
req := vins.RestoreRequest{
VINSID: vinsData.ID,
}
// req := vins.RestoreRequest{
// VINSID: vinsData.ID,
// }
_, err := c.CloudAPI().VINS().Restore(ctx, req)
if err != nil {
warnings.Add(err)
}
// _, err := c.CloudAPI().VINS().Restore(ctx, req)
// if err != nil {
// warnings.Add(err)
// }
case status.Modeled:
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vinsData.Status)
case status.Created:
case status.Enabled:
if !isEnabled {
hasChangeState = true
req := vins.DisableEnableRequest{
VINSID: vinsData.ID,
}
// if !isEnabled {
// hasChangeState = true
// req := vins.DisableEnableRequest{
// VINSID: vinsData.ID,
// }
_, err := c.CloudAPI().VINS().Disable(ctx, req)
if err != nil {
warnings.Add(err)
}
}
// _, err := c.CloudAPI().VINS().Disable(ctx, req)
// if err != nil {
// warnings.Add(err)
// }
// }
case status.Enabling:
case status.Disabled:
if isEnabled {
hasChangeState = true
req := vins.DisableEnableRequest{
VINSID: vinsData.ID,
}
// if isEnabled {
// hasChangeState = true
// req := vins.DisableEnableRequest{
// VINSID: vinsData.ID,
// }
_, err := c.CloudAPI().VINS().Enable(ctx, req)
if err != nil {
warnings.Add(err)
}
}
// _, err := c.CloudAPI().VINS().Enable(ctx, req)
// if err != nil {
// warnings.Add(err)
// }
// }
case status.Disabling:
case status.Deleting:
return diag.Errorf("ViNS are in progress with status: %s", vinsData.Status)
}
if hasChangeState {
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
vinsData, err = utilityDataVinsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
}
flattenVins(d, *vinsData)
flattenVins(d, vinsData)
return warnings.Get()
}
@@ -366,7 +371,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
vinsData, err := utilityDataVinsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
@@ -379,7 +384,8 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
switch vinsData.Status {
case status.Destroyed:
d.SetId("")
return resourceVinsCreate(ctx, d, m)
return diag.Errorf("The resource cannot be updated because it has been destroyed")
// return resourceVinsCreate(ctx, d, m)
case status.Deleted:
hasChangeState = true
@@ -425,7 +431,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
if hasChangeState {
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
vinsData, err = utilityDataVinsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
@@ -631,8 +637,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
}
}
defer resourceVinsRead(ctx, d, m)
return warnings.Get()
return append (warnings.Get(), resourceVinsRead(ctx, d, m)...)
}
func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -658,7 +663,7 @@ func extNetSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"ext_net_id": {
Type: schema.TypeInt,
Default: 0,
Default: -1,
Optional: true,
},
"ext_net_ip": {
@@ -674,6 +679,7 @@ func ipSchemaMake() map[string]*schema.Schema {
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string {"DHCP", "VIP", "EXCLUDE"}, false),
},
"ip_addr": {
Type: schema.TypeString,
@@ -823,7 +829,6 @@ func resourceVinsSchemaMake() map[string]*schema.Schema {
Optional: true,
Default: false,
}
rets["vins_id"] = &schema.Schema{
Type: schema.TypeInt,
Computed: true,

View File

@@ -0,0 +1,107 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package vins
import (
"context"
"fmt"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityDataStaticRouteCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ItemRoutes, error) {
c := m.(*controller.ControllerCfg)
req := vins.StaticRouteListRequest{}
var routeId uint64
if d.Id() != "" {
arr := strings.Split(d.Id(), "#")
if len(arr) != 2 {
return nil, fmt.Errorf("broken state id")
}
req.VINSID, _ = strconv.ParseUint(arr[0], 10, 64)
routeId, _ = strconv.ParseUint(arr[1], 10, 64)
} else {
req.VINSID = uint64(d.Get("vins_id").(int))
routeId = uint64(d.Get("route_id").(int))
}
log.Debugf("utilityStaticRouteCheckPresence, vins_id: %v", req.VINSID)
staticRouteList, err := c.CloudAPI().VINS().StaticRouteList(ctx, req)
if err != nil {
return nil, err
}
log.Debugf("utilityStaticRouteCheckPresence: ROUTE ID %v", routeId)
staticRoute := &vins.ItemRoutes{}
for _, route := range staticRouteList.Data {
if routeId == route.ID {
staticRoute = &route
return staticRoute, nil
}
}
return nil, fmt.Errorf("static route not found")
}
func getStaticRouteData(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ItemRoutes, error) {
c := m.(*controller.ControllerCfg)
req := vins.StaticRouteListRequest{}
req.VINSID = uint64(d.Get("vins_id").(int))
staticRouteList, err := c.CloudAPI().VINS().StaticRouteList(ctx, req)
if err != nil {
return nil, err
}
destination := d.Get("destination").(string)
gateway := d.Get("gateway").(string)
staticRoute := &vins.ItemRoutes{}
for _, route := range staticRouteList.Data {
if destination == route.Destination && gateway == route.Gateway {
staticRoute = &route
return staticRoute, nil
}
}
return nil, fmt.Errorf("static route not found")
}

View File

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

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -44,8 +44,13 @@ import (
func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
c := m.(*controller.ControllerCfg)
req := vins.GetRequest{
VINSID: uint64(d.Get("vins_id").(int)),
req := vins.GetRequest{}
if d.Id() != "" {
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.VINSID = rgId
} else {
req.VINSID = uint64(d.Get("vins_id").(int))
}
vins, err := c.CloudAPI().VINS().Get(ctx, req)
@@ -56,17 +61,3 @@ func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m
return vins, nil
}
func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
c := m.(*controller.ControllerCfg)
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := vins.GetRequest{
VINSID: vinsId,
}
vins, err := c.CloudAPI().VINS().Get(ctx, req)
if err != nil {
return nil, err
}
return vins, nil
}

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
@@ -42,8 +43,13 @@ import (
func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListAudits, error) {
c := m.(*controller.ControllerCfg)
req := vins.AuditsRequest{
VINSID: uint64(d.Get("vins_id").(int)),
req := vins.AuditsRequest{}
if d.Id() != "" {
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.VINSID = rgId
} else {
req.VINSID = uint64(d.Get("vins_id").(int))
}
audits, err := c.CloudAPI().VINS().Audits(ctx, req)

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
@@ -46,6 +47,13 @@ func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceD
VINSID: uint64(d.Get("vins_id").(int)),
}
if d.Id() != "" {
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.VINSID = rgId
} else {
req.VINSID = uint64(d.Get("vins_id").(int))
}
extNetList, err := c.CloudAPI().VINS().ExtNetList(ctx, req)
if err != nil {
return nil, err

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
@@ -42,8 +43,13 @@ import (
func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListIPs, error) {
c := m.(*controller.ControllerCfg)
req := vins.IPListRequest{
VINSID: uint64(d.Get("vins_id").(int)),
req := vins.IPListRequest{}
if d.Id() != "" {
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.VINSID = rgId
} else {
req.VINSID = uint64(d.Get("vins_id").(int))
}
ips, err := c.CloudAPI().VINS().IPList(ctx, req)

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
@@ -34,6 +34,7 @@ package vins
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
@@ -42,8 +43,13 @@ import (
func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListNATRules, error) {
c := m.(*controller.ControllerCfg)
req := vins.NATRuleListRequest{
VINSID: uint64(d.Get("vins_id").(int)),
req := vins.NATRuleListRequest{}
if d.Id() != "" {
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
req.VINSID = rgId
} else {
req.VINSID = uint64(d.Get("vins_id").(int))
}
natRuleList, err := c.CloudAPI().VINS().NATRuleList(ctx, req)

View File

@@ -142,6 +142,17 @@ func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interfa
}
}
if d.Get("enable").(bool) {
log.Debugf("resourceExtnetCreate: trying to enable extnet with ID %d", netID)
_, err := c.CloudBroker().ExtNet().Enable(ctx, extnet.EnableRequest{
NetID: netID,
})
if err != nil {
return diag.FromErr(err)
}
}
return resourceExtnetRead(ctx, d, m)
}

View File

@@ -0,0 +1,37 @@
/*
Получение stack по его id
*/
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
version = "4.4.0"
source = "basis/decort/decort"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
#controller_url = <DECORT_CONTROLLER_URL>
controller_url = "https://alpha.dev.decs.online"
#oauth2_url = <DECORT_SSO_URL>
oauth2_url = "https://sso-alpha.dev.decs.online"
allow_unverified_ssl = true
}
data "decort_stack" "stack" {
#обязательный параметр
#тип - число
#идентификатор стека
stack_id = 2
}
output "test" {
value = data.decort_stack.stack
}

View File

@@ -0,0 +1,64 @@
/*
Получение списка stack
*/
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
version = "4.4.0"
source = "basis/decort/decort"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
#controller_url = <DECORT_CONTROLLER_URL>
controller_url = "https://alpha.dev.decs.online"
#oauth2_url = <DECORT_SSO_URL>
oauth2_url = "https://sso-alpha.dev.decs.online"
allow_unverified_ssl = true
}
data "decort_stack_list" "stack_list" {
#необязательный параметр
#тип - число
#фильтрация списка для получения информации о конкретном stack по его id
#by_id =
#необязательный параметр
#тип - строка
#фильтрация списка для получения информации о конкретном stack по его имени
#name = "alpha-cpu-04"
#необязательный параметр
#тип - строка
#фильтрация списка для получения информации о конкретном stack по его типу
#type = "KVM"
#необязательный параметр
#тип - строка
#фильтрация списка для получения информации о конкретном stack по его статусу
#status = "ENABLED"
#номер страницы для отображения
#опциональный параметр
#тип - число
#если не задан - выводятся все доступные данные
#page = 2
#размер страницы
#опциональный параметр
#тип - число
#если не задан - выводятся все доступные данные
#size = 3
}
output "test" {
value = data.decort_stack_list.stack_list
}

View File

@@ -0,0 +1,50 @@
/*
Пример использования
Ресурса vins static routes
Ресурс позволяет:
1. Создавать static routes
2. Удалять static routes
3. Получать информацию о всех static routes в данном Vins
4. Предоставлять доступ виртуальным машинам к static routes
5. Удалять доступ виртуальным машинам к static routes
*/
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
#controller_url = <DECORT_CONTROLLER_URL>
controller_url = "https://mr4.digitalenergy.online"
#oauth2_url = <DECORT_SSO_URL>
oauth2_url = "https://sso.digitalenergy.online"
allow_unverified_ssl = true
}
data "decort_vins_static_route" "route" {
#обязательный параметр
#id vins в котором добавлены routes
#тип - число
vins_id = 1111
#обязательный параметр
#id route
#тип - число
route_id = 1
}
output "route" {
value = decort_vins_static_route.route
}

View File

@@ -0,0 +1,45 @@
/*
Пример использования
Ресурса vins static routes
Ресурс позволяет:
1. Создавать static routes
2. Удалять static routes
3. Получать информацию о всех static routes в данном Vins
4. Предоставлять доступ виртуальным машинам к static routes
5. Удалять доступ виртуальным машинам к static routes
*/
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
#controller_url = <DECORT_CONTROLLER_URL>
controller_url = "https://mr4.digitalenergy.online"
#oauth2_url = <DECORT_SSO_URL>
oauth2_url = "https://sso.digitalenergy.online"
allow_unverified_ssl = true
}
data "decort_vins_static_route_list" "list" {
#обязательный параметр
#id vins в котором добавлены routes
#тип - число
vins_id = 1111
}
output "list" {
value = decort_vins_static_route_list.list
}

View File

@@ -77,32 +77,47 @@ resource "decort_bservice_group" "bsg" {
#драйвер
#обязательный параметр
#тип - число
#тип - строка
driver = "kvm_x86"
#id сетей extnet
#обязательный параметр
#тип - массив чисел
#должен быть использован vins или extnets
extnets = [1111]
#id сетей vinses
#обязательный параметр
#тип - массив чисел
#должен быть использован vins или extnets
#vinses = [1111, 2222]
#время таймуата перед стартом
#id Storage endpoint provider
#необязательный параметр
#тип - число
#используется при создании ресурса
#timeout_start = 0
sep_id = 3
#Наименование SEPPool используется если установлен sepId, также может быть пустым
#необязательный параметр
#тип - строка
sep_pool = "name"
#тег группы
#необязательный параметр
#тип - строка
#используется при создании и редактировании ресурса
# role = "tf_test_changed"
role = "tf_test_changed"
#id сетей extnet
#необязательный параметр
#тип - массив чисел
#должен быть использован vins или extnets
extnets = [1111, 2222]
#id сетей vinses
#необязательный параметр
#тип - массив чисел
#должен быть использован vins или extnets
vinses = [1111, 2222]
#время таймуата перед стартом
#необязательный параметр
#тип - число
#используется при создании ресурса
timeout_start = 0
#Перечень аргументов для cloud-init создаваемым группам узлов Worker
#необязательный параметр
#тип - файл
cloud_init = file("initconfig.tftpl")
#id групп родителей
#необязательный параметр
@@ -113,13 +128,14 @@ resource "decort_bservice_group" "bsg" {
#принудительное обновление параметров выч. мощностей (ram,disk,cpu) и имени группы
#необязательный параметр
#тип - булев тип
#используется при редактировании
#используется при редактировании ресурса
#по-умолчанию - false
#force_update = true
#старт/стоп вычислительных мощностей
#необязательный параметр
#тип - булев тип
#используется при редактировании
#используется при редактировании ресурса
#по-умолчанию - false
#start = false
@@ -141,6 +157,7 @@ resource "decort_bservice_group" "bsg" {
#тип - строка
#используется в связке с comp_count при редактировании группы
#возможные варианты - RELATIVE и ABSOLUTE
#по-умолчанию - "RELATIVE"
#mode = "RELATIVE"
}

View File

@@ -13,11 +13,12 @@ terraform {
*/
provider "decort" {
authenticator = "oauth2"
oauth2_url = "https://sso.digitalenergy.online"
controller_url = "https://mr4.digitalenergy.online"
app_id = ""
app_secret = ""
authenticator = "oauth2"
#controller_url = <DECORT_CONTROLLER_URL>
controller_url = "https://ds1.digitalenergy.online"
#oauth2_url = <DECORT_SSO_URL>
oauth2_url = "https://sso.digitalenergy.online"
allow_unverified_ssl = true
}
resource "decort_k8s" "cluster" {
@@ -49,7 +50,6 @@ resource "decort_k8s" "cluster" {
# список labels для дефолтной worker группы
# опциональный параметр
# В скором времени параметры labels, annotations, taints будут полностью перенесены в блок workers
# тип - массив строк
labels = ["key1=val1", "key2=val2"]
@@ -80,29 +80,32 @@ resource "decort_k8s" "cluster" {
#тип - число
cpu = 2
#кол-во RAM в Мбайтах
#обязательный параметр
#тип - число
ram = 2048
#размер диска в Гбайтах
#обязательный параметр
#тип - число
disk = 10
}
#идентификатор SEP для создания загрузочных дисков для master узлов
#опциональный параметр
#тип - число
sep_id = 3
#наименование MasterSEPPool используется если установлен master sepId, также может быть пустым
#опциональный параметр
#тип - строка
sep_pool = "data_01"
}
#настройка worker группы
#опциональный параметр
#Первая указанная воркер-группа должна соответствовать изначально созданной вместе с кластером.
# labels, annotations, taints для дефолтной worker группы указываются в корне ресурса при создании кластера.
workers {
#наименование worker группы
#обязательный параметр
#тип - строка
name = "workers_wg"
#кол-во node
#обязательный параметр
#тип - число
@@ -187,6 +190,89 @@ resource "decort_k8s" "cluster" {
#тип - массив строк
taints = ["key1=value1:NoSchedule", "key2=value2:NoExecute"]
}
# id extnet
#опциональный параметр
#тип - число
extnet_id = 0
# id vins
# опциональный параметр
# тип - число
vins_id = 1234
# создать Kubernetes cluster с masters nodes с подключенным LB
# опциональный параметр
# тип - булев тип
with_lb = true
# пользовательские значения sysctl для LB
# опциональный параметр
# тип - строка
lb_sysctl_params = "some"
# позволяет создать схему отказоустройчивой LB
# опциональный параметр
# тип - булев тип
ha_mode = true
# дополнительные SAN (Subject Alternative Names) для использования в процессе автоматического выписывания сертификата Кластера Kubernetes;
# возможность взаимодействовать с кластером по FQDN
# параметр получает список строк IP-адреса и/или DNS (по формату RFC 1123 c поддержкой wildcard)
# опциональный параметр
# тип - массив строк
additional_sans = ["192.168.201.0","192.168.201.1"]
# используется для определения настроек и действий, которые должны быть выполнены перед запуском любого другого компонента в кластере
# это позволяет вам настраивать такие вещи, как регистрация node, настройка network и другие задачи инициализации
# опциональный параметр
# тип - строка
init_config = "{JSON string}"
# используется для определения глобальных настроек и конфигураций для всего кластера
# он включает в себя такие параметры, как имя кластера, настройки DNS, методы аутентификации и другие конфигурации в масштабах кластера
# опциональный параметр
# тип - строка
cluster_config = "{JSON string}"
# используется для настройки поведения и параметров Kubelet, который является агентом primary node, запускаемым на каждом node кластера
# он включает в себя такие параметры, как IP-адрес node, распределение ресурсов, политики удаления модулей и другие конфигурации, специфичные для Kubelet
# опциональный параметр
# тип - строка
kubelet_config = "{JSON string}"
# используется для настройки поведения и параметров присоединения node к кластеру
# он включает в себя такие параметры, как режим прокси-сервера, диапазоны IP-адресов кластера и другие конфигурации, специфичные для Kube-proxy
# опциональный параметр
# тип - строка
kube_proxy_config = "{JSON string}"
# используется для настройки поведения и параметров присоединения node к кластеру
# он включает в себя такие параметры, как cluster's control plane endpoint, токен и ключ сертификата
# опциональный параметр
# тип - строка
join_config = "{JSON string}"
# описание кластера
# опциональный параметр
# тип - строка
desc = "description"
# перечень аргументов для cloud-init создаваемым группам узлов Worker
# необязательный параметр
# тип - файл
cloud_init = file("initconfig.tftpl")
# при создании кластре использовать подключение только к сети ExtNet
# опциональный параметр
# тип - булев тип
extnet_only = true
# добавить ssl-сертификат в формате x509 pem
# необязательный параметр
# тип - файл
oidc_cert = file("ca.crt")
}
output "test_cluster" {

View File

@@ -41,13 +41,15 @@ resource "decort_lb" "lb" {
#тип - строка
name = "tf-test-lb"
#id внешней сети и id виртуальной сети не могут быть одновременно = 0
#id внешней сети
#обязательный параметр
#опциональный параметр
#тип - число
extnet_id = 6
#id виртуальной сети
#обязательный параметр
#опциональный параметр
#тип - число
vins_id = 758
@@ -59,6 +61,11 @@ resource "decort_lb" "lb" {
#то для успешного старта, он должен быть доступен (enable = true)
start = true
# позволяет создать схему отказоустройчивой LB
# опциональный параметр
# тип - булев тип
ha_mode = true
#описание
#опциональный параметр
#тип - строка

View File

@@ -0,0 +1,74 @@
/*
Пример использования
Ресурса vins static routes
Ресурс позволяет:
1. Создавать static routes
2. Удалять static routes
3. Получать информацию о всех static routes в данном Vins
4. Предоставлять доступ виртуальным машинам к static routes
5. Удалять доступ виртуальным машинам к static routes
*/
#Расскомментируйте этот код,
#и внесите необходимые правки в версию и путь,
#чтобы работать с установленным вручную (не через hashicorp provider registry) провайдером
/*
terraform {
required_providers {
decort = {
version = "<VERSION>"
source = "basis/decort/decort"
}
}
}
*/
provider "decort" {
authenticator = "oauth2"
#controller_url = <DECORT_CONTROLLER_URL>
controller_url = "https://mr4.digitalenergy.online"
#oauth2_url = <DECORT_SSO_URL>
oauth2_url = "https://sso.digitalenergy.online"
allow_unverified_ssl = true
}
resource "decort_vins_static_route" "sr" {
#id Vins
#обязательный параметр
#тип - число
vins_id = 1111
# destination network
# обязательный параметр
#тип - строка
destination = "192.168.201.0"
# destination network mask
#обязательный параметр
#тип - строка
netmask = "255.255.255.255"
# IP-адрес из пула свободных IP-адресов ViNS ID
#обязательный параметр
#тип - строка
gateway = "192.168.201.40"
# список виртуальных машин, которым будет предоставлен доступ к роуту
#опциональный параметр
#тип - массив чисел
compute_ids = [111,222]
}
output "sr" {
value = decort_vins_static_route.sr
}
data "decort_vins_static_routes_list" "list" {
vins_id = 1111
}
output "list" {
value = decort_vins_static_routes_list.list
}

View File

@@ -27,18 +27,19 @@ arch=$(basename $filename | cut -d '_' -f 4)
plugins_dir=~/.terraform.d/plugins/
provider_path=basis/decort/decort/$version/$os\_$arch/
print_success () {
echo "DECORT provider version $version has been successfully installed"
echo "\n"
echo "Copy this provider configuration to main.tf file"
echo "terraform {"
echo " required_providers {"
echo " decort = {"
echo " version = \"$version\""
echo " source = \"basis/decort/decort\""
echo " }"
echo " }"
echo "}"
print_info () {
cat <<EOF
Copy this provider configuration to main.tf file
terraform {
required_providers {
decort = {
version = "$version"
source = "basis/decort/decort"
}
}
}
EOF
}
install () {
@@ -47,15 +48,17 @@ install () {
echo "Provider directory already exists, checking for decort provider executable.."
if [[ ! "$(ls -A $plugins_dir$provider_path)" ]]; then
cp bin/terraform-provider-decort_$version\_$os\_$arch $plugins_dir$provider_path/terraform-provider-decort
print_success
print_info
else
echo "DECORT provider version $version is already installed. Exiting.."
print_info
fi
else
echo "Creating provider directory.."
mkdir -p $plugins_dir/$provider_path
cp bin/terraform-provider-decort_$version\_$os\_$arch $plugins_dir$provider_path/terraform-provider-decort
print_success
echo "DECORT provider version $version has been successfully installed"
print_info
fi
}