parent
84b7a80e1b
commit
db1760cb72
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package location
|
package location
|
||||||
|
|
||||||
const LocationsListAPI = "/restmachine/cloudapi/locations/list" // Returns list of GridRecord on success
|
const LOCATIONS_LIST_API = "/restmachine/cloudapi/locations/list" // Returns list of GridRecord on success
|
||||||
|
@ -1,102 +1,106 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListComputes, error) {
|
func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListComputes, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
var id uint64
|
var id uint64
|
||||||
|
|
||||||
id = uint64(d.Get("account_id").(int))
|
id = uint64(d.Get("account_id").(int))
|
||||||
|
|
||||||
req := account.ListComputesRequest{
|
req := account.ListComputesRequest{
|
||||||
AccountID: id,
|
AccountID: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if compute_id, ok := d.GetOk("compute_id"); ok {
|
if compute_id, ok := d.GetOk("compute_id"); ok {
|
||||||
req.ComputeID = uint64(compute_id.(int))
|
req.ComputeID = uint64(compute_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rg_name, ok := d.GetOk("rg_name"); ok {
|
if rg_name, ok := d.GetOk("rg_name"); ok {
|
||||||
req.RGName = rg_name.(string)
|
req.RGName = rg_name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rg_id.(int))
|
req.RGID = uint64(rg_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if tech_status, ok := d.GetOk("tech_status"); ok {
|
if tech_status, ok := d.GetOk("tech_status"); ok {
|
||||||
req.TechStatus = tech_status.(string)
|
req.TechStatus = tech_status.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ip_address, ok := d.GetOk("ip_address"); ok {
|
if ip_address, ok := d.GetOk("ip_address"); ok {
|
||||||
req.IPAddress = ip_address.(string)
|
req.IPAddress = ip_address.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if extnet_name, ok := d.GetOk("extnet_name"); ok {
|
if extnet_name, ok := d.GetOk("extnet_name"); ok {
|
||||||
req.ExtNetName = extnet_name.(string)
|
req.ExtNetName = extnet_name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if extnet_id, ok := d.GetOk("extnet_id"); ok {
|
if extnet_id, ok := d.GetOk("extnet_id"); ok {
|
||||||
req.ExtNetID = uint64(extnet_id.(int))
|
req.ExtNetID = uint64(extnet_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
|
if size, ok := d.GetOk("size"); ok {
|
||||||
accountComputesList, err := c.CloudAPI().Account().ListComputes(ctx, req)
|
req.Size = uint64(size.(int))
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
|
||||||
|
accountComputesList, err := c.CloudAPI().Account().ListComputes(ctx, req)
|
||||||
return accountComputesList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountComputesList, nil
|
||||||
|
}
|
||||||
|
@ -1,76 +1,80 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) {
|
func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
req := account.ListDeletedRequest{}
|
req := account.ListDeletedRequest{}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if size, ok := d.GetOk("size"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Size = uint64(size.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if acl, ok := d.GetOk("acl"); ok {
|
if acl, ok := d.GetOk("acl"); ok {
|
||||||
req.ACL = acl.(string)
|
req.ACL = acl.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountDeletedListCheckPresence: load")
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
accountDeletedList, err := c.CloudAPI().Account().ListDeleted(ctx, req)
|
req.SortBy = sortBy.(string)
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityAccountDeletedListCheckPresence: load")
|
||||||
return accountDeletedList, nil
|
accountDeletedList, err := c.CloudAPI().Account().ListDeleted(ctx, req)
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return accountDeletedList, nil
|
||||||
|
}
|
||||||
|
@ -1,84 +1,88 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListDisks, error) {
|
func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListDisks, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
var id uint64
|
var id uint64
|
||||||
|
|
||||||
id = uint64(d.Get("account_id").(int))
|
id = uint64(d.Get("account_id").(int))
|
||||||
|
|
||||||
req := account.ListDisksRequest{
|
req := account.ListDisksRequest{
|
||||||
AccountID: id,
|
AccountID: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if disk_id, ok := d.GetOk("disk_id"); ok {
|
if disk_id, ok := d.GetOk("disk_id"); ok {
|
||||||
req.DiskID = uint64(disk_id.(int))
|
req.DiskID = uint64(disk_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
||||||
req.DiskMaxSize = uint64(disk_max_size.(int))
|
req.DiskMaxSize = uint64(disk_max_size.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if typeVal, ok := d.GetOk("type"); ok {
|
if typeVal, ok := d.GetOk("type"); ok {
|
||||||
req.Type = typeVal.(string)
|
req.Type = typeVal.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
accountDisksList, err := c.CloudAPI().Account().ListDisks(ctx, req)
|
if size, ok := d.GetOk("size"); ok {
|
||||||
if err != nil {
|
req.Size = uint64(size.(int))
|
||||||
return nil, err
|
}
|
||||||
}
|
|
||||||
|
accountDisksList, err := c.CloudAPI().Account().ListDisks(ctx, req)
|
||||||
return accountDisksList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountDisksList, nil
|
||||||
|
}
|
||||||
|
@ -1,79 +1,83 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) {
|
func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListAccounts, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := account.ListRequest{}
|
req := account.ListRequest{}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if size, ok := d.GetOk("size"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Size = uint64(size.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if acl, ok := d.GetOk("acl"); ok {
|
if acl, ok := d.GetOk("acl"); ok {
|
||||||
req.ACL = acl.(string)
|
req.ACL = acl.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, ok := d.GetOk("status"); ok {
|
if status, ok := d.GetOk("status"); ok {
|
||||||
req.Status = status.(string)
|
req.Status = status.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountListCheckPresence: load account list")
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
accountList, err := c.CloudAPI().Account().List(ctx, req)
|
req.SortBy = sortBy.(string)
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityAccountListCheckPresence: load account list")
|
||||||
|
accountList, err := c.CloudAPI().Account().List(ctx, req)
|
||||||
return accountList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountList, nil
|
||||||
|
}
|
||||||
|
@ -1,90 +1,94 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListRG, error) {
|
func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListRG, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
var id uint64
|
var id uint64
|
||||||
|
|
||||||
id = uint64(d.Get("account_id").(int))
|
id = uint64(d.Get("account_id").(int))
|
||||||
|
|
||||||
req := account.ListRGRequest{
|
req := account.ListRGRequest{
|
||||||
AccountID: id,
|
AccountID: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if size, ok := d.GetOk("size"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Size = uint64(size.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rg_id.(int))
|
req.RGID = uint64(rg_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if vins_id, ok := d.GetOk("vins_id"); ok {
|
if vins_id, ok := d.GetOk("vins_id"); ok {
|
||||||
req.VINSID = uint64(vins_id.(int))
|
req.VINSID = uint64(vins_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if vm_id, ok := d.GetOk("vm_id"); ok {
|
if vm_id, ok := d.GetOk("vm_id"); ok {
|
||||||
req.VMID = uint64(vm_id.(int))
|
req.VMID = uint64(vm_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, ok := d.GetOk("status"); ok {
|
if status, ok := d.GetOk("status"); ok {
|
||||||
req.Status = status.(string)
|
req.Status = status.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountRGListCheckPresence: load account list")
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
accountRGList, err := c.CloudAPI().Account().ListRG(ctx, req)
|
req.SortBy = sortBy.(string)
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityAccountRGListCheckPresence: load account list")
|
||||||
|
accountRGList, err := c.CloudAPI().Account().ListRG(ctx, req)
|
||||||
return accountRGList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountRGList, nil
|
||||||
|
}
|
||||||
|
@ -1,80 +1,83 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListTemplates, error) {
|
func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListTemplates, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
id := uint64(d.Get("account_id").(int))
|
id := uint64(d.Get("account_id").(int))
|
||||||
|
|
||||||
req := account.ListTemplatesRequest{
|
req := account.ListTemplatesRequest{
|
||||||
AccountID: id,
|
AccountID: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if include_deleted, ok := d.GetOk("include_deleted"); ok {
|
if include_deleted, ok := d.GetOk("include_deleted"); ok {
|
||||||
req.IncludeDeleted = include_deleted.(bool)
|
req.IncludeDeleted = include_deleted.(bool)
|
||||||
}
|
}
|
||||||
if imageId, ok := d.GetOk("image_id"); ok {
|
if imageId, ok := d.GetOk("image_id"); ok {
|
||||||
req.ImageID = uint64(imageId.(int))
|
req.ImageID = uint64(imageId.(int))
|
||||||
}
|
}
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
if typeTemplates, ok := d.GetOk("type"); ok {
|
if typeTemplates, ok := d.GetOk("type"); ok {
|
||||||
req.Type = typeTemplates.(string)
|
req.Type = typeTemplates.(string)
|
||||||
}
|
}
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
if size, ok := d.GetOk("size"); ok {
|
||||||
log.Debugf("utilityAccountTemplatesListCheckPresence: load")
|
req.Size = uint64(size.(int))
|
||||||
accountTemplatesList, err := c.CloudAPI().Account().ListTemplates(ctx, req)
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
log.Debugf("utilityAccountTemplatesListCheckPresence: load")
|
||||||
}
|
accountTemplatesList, err := c.CloudAPI().Account().ListTemplates(ctx, req)
|
||||||
|
if err != nil {
|
||||||
return accountTemplatesList, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return accountTemplatesList, nil
|
||||||
|
}
|
||||||
|
@ -1,86 +1,90 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListVINS, error) {
|
func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListVINS, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
var id uint64
|
var id uint64
|
||||||
|
|
||||||
id = uint64(d.Get("account_id").(int))
|
id = uint64(d.Get("account_id").(int))
|
||||||
|
|
||||||
req := account.ListVINSRequest{
|
req := account.ListVINSRequest{
|
||||||
AccountID: id,
|
AccountID: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if vins_id, ok := d.GetOk("vins_id"); ok {
|
if vins_id, ok := d.GetOk("vins_id"); ok {
|
||||||
req.VINSID = uint64(vins_id.(int))
|
req.VINSID = uint64(vins_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rg_id.(int))
|
req.RGID = uint64(rg_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if size, ok := d.GetOk("size"); ok {
|
||||||
req.Name = name.(string)
|
req.Size = uint64(size.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ext_ip, ok := d.GetOk("ext_ip"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.ExtIP = ext_ip.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
if ext_ip, ok := d.GetOk("ext_ip"); ok {
|
||||||
accountVinsList, err := c.CloudAPI().Account().ListVINS(ctx, req)
|
req.ExtIP = ext_ip.(string)
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
||||||
|
accountVinsList, err := c.CloudAPI().Account().ListVINS(ctx, req)
|
||||||
return accountVinsList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountVinsList, nil
|
||||||
|
}
|
||||||
|
@ -1,69 +1,73 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package bservice
|
package bservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
|
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := bservice.ListDeletedRequest{}
|
req := bservice.ListDeletedRequest{}
|
||||||
|
|
||||||
if accountId, ok := d.GetOk("account_id"); ok {
|
if accountId, ok := d.GetOk("account_id"); ok {
|
||||||
req.AccountID = uint64(accountId.(int))
|
req.AccountID = uint64(accountId.(int))
|
||||||
}
|
}
|
||||||
if rgId, ok := d.GetOk("rg_id"); ok {
|
if rgId, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rgId.(int))
|
req.RGID = uint64(rgId.(int))
|
||||||
}
|
}
|
||||||
if page, ok := d.GetOk("page"); ok {
|
|
||||||
req.Page = uint64(page.(int))
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
}
|
req.SortBy = sortBy.(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("utilityBasicServiceDeletedListCheckPresence")
|
if size, ok := d.GetOk("size"); ok {
|
||||||
basicServiceDeletedList, err := c.CloudAPI().BService().ListDeleted(ctx, req)
|
req.Size = uint64(size.(int))
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityBasicServiceDeletedListCheckPresence")
|
||||||
|
basicServiceDeletedList, err := c.CloudAPI().BService().ListDeleted(ctx, req)
|
||||||
return basicServiceDeletedList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return basicServiceDeletedList, nil
|
||||||
|
}
|
||||||
|
@ -1,93 +1,96 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package bservice
|
package bservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
|
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*bservice.ListBasicServices, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := bservice.ListRequest{}
|
req := bservice.ListRequest{}
|
||||||
|
|
||||||
if accountId, ok := d.GetOk("account_id"); ok {
|
if accountId, ok := d.GetOk("account_id"); ok {
|
||||||
req.AccountID = uint64(accountId.(int))
|
req.AccountID = uint64(accountId.(int))
|
||||||
}
|
}
|
||||||
if rgId, ok := d.GetOk("rg_id"); ok {
|
if rgId, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rgId.(int))
|
req.RGID = uint64(rgId.(int))
|
||||||
}
|
}
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
if size, ok := d.GetOk("size"); ok {
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
req.Size = uint64(size.(int))
|
||||||
req.ByID = uint64(by_id.(int))
|
}
|
||||||
}
|
|
||||||
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
if name, ok := d.GetOk("name"); ok {
|
req.ByID = uint64(by_id.(int))
|
||||||
req.Name = name.(string)
|
}
|
||||||
}
|
|
||||||
|
if name, ok := d.GetOk("name"); ok {
|
||||||
if rg_name, ok := d.GetOk("rg_name"); ok {
|
req.Name = name.(string)
|
||||||
req.RGName = rg_name.(string)
|
}
|
||||||
}
|
|
||||||
|
if rg_name, ok := d.GetOk("rg_name"); ok {
|
||||||
if tech_status, ok := d.GetOk("tech_status"); ok {
|
req.RGName = rg_name.(string)
|
||||||
req.TechStatus = tech_status.(string)
|
}
|
||||||
}
|
|
||||||
|
if tech_status, ok := d.GetOk("tech_status"); ok {
|
||||||
if status, ok := d.GetOk("status"); ok {
|
req.TechStatus = tech_status.(string)
|
||||||
req.Status = status.(string)
|
}
|
||||||
}
|
|
||||||
|
if status, ok := d.GetOk("status"); ok {
|
||||||
if acc_name, ok := d.GetOk("account_name"); ok {
|
req.Status = status.(string)
|
||||||
req.AccountName = acc_name.(string)
|
}
|
||||||
}
|
|
||||||
|
if acc_name, ok := d.GetOk("account_name"); ok {
|
||||||
log.Debugf("utilityBasicServiceListCheckPresence")
|
req.AccountName = acc_name.(string)
|
||||||
basicServiceList, err := c.CloudAPI().BService().List(ctx, req)
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
log.Debugf("utilityBasicServiceListCheckPresence")
|
||||||
}
|
basicServiceList, err := c.CloudAPI().BService().List(ctx, req)
|
||||||
|
if err != nil {
|
||||||
return basicServiceList, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return basicServiceList, nil
|
||||||
|
}
|
||||||
|
@ -0,0 +1,480 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Authors:
|
||||||
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
|
Please see README.md to learn where to place source code so that it
|
||||||
|
builds seamlessly.
|
||||||
|
|
||||||
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
|
*/
|
||||||
|
|
||||||
|
package disks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dataSourceDiskReplicationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("dataSourceDiskReplicationRead: called for disk with ID: %s", d.Id())
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
req := disks.ReplicationStatusRequest{
|
||||||
|
DiskID: uint64(d.Get("disk_id").(int)),
|
||||||
|
}
|
||||||
|
|
||||||
|
status, err := c.CloudAPI().Disks().ReplicationStatus(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
id := uuid.New()
|
||||||
|
d.SetId(id.String())
|
||||||
|
|
||||||
|
disk, err := utilityDiskReplicaCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
flattenDiskReplica(d, disk, status)
|
||||||
|
|
||||||
|
log.Debugf("dataSourceDiskReplicationRead: read complete for disk with ID: %s", d.Id())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func dataSourceDiskReplicationSchemaMake() map[string]*schema.Schema {
|
||||||
|
rets := map[string]*schema.Schema{
|
||||||
|
"disk_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "Id of primary disk",
|
||||||
|
},
|
||||||
|
"replica_disk_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "Id of secondary disk",
|
||||||
|
},
|
||||||
|
"status_replication": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Status of replication",
|
||||||
|
},
|
||||||
|
"account_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The unique ID of the subscriber-owner of the disk",
|
||||||
|
},
|
||||||
|
"account_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The name of the subscriber '(account') to whom this disk belongs",
|
||||||
|
},
|
||||||
|
"acl": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
// "boot_partition": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Number of disk partitions",
|
||||||
|
// },
|
||||||
|
"computes": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"compute_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"compute_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"created_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Created time",
|
||||||
|
},
|
||||||
|
"deleted_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Deleted time",
|
||||||
|
},
|
||||||
|
"desc": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Description of disk",
|
||||||
|
},
|
||||||
|
"destruction_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Time of final deletion",
|
||||||
|
},
|
||||||
|
"devicename": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Name of the device",
|
||||||
|
},
|
||||||
|
// "disk_path": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Disk path",
|
||||||
|
// },
|
||||||
|
"gid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the grid (platform)",
|
||||||
|
},
|
||||||
|
// "guid": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Disk ID on the storage side",
|
||||||
|
// },
|
||||||
|
"image_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Image ID",
|
||||||
|
},
|
||||||
|
"images": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
},
|
||||||
|
Description: "IDs of images using the disk",
|
||||||
|
},
|
||||||
|
"iotune": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"read_bytes_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of bytes to read per second",
|
||||||
|
},
|
||||||
|
"read_bytes_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of bytes to read",
|
||||||
|
},
|
||||||
|
"read_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of io read operations per second",
|
||||||
|
},
|
||||||
|
"read_iops_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of io read operations",
|
||||||
|
},
|
||||||
|
"size_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Size of io operations",
|
||||||
|
},
|
||||||
|
"total_bytes_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Total size bytes per second",
|
||||||
|
},
|
||||||
|
"total_bytes_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum total size of bytes per second",
|
||||||
|
},
|
||||||
|
"total_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Total number of io operations per second",
|
||||||
|
},
|
||||||
|
"total_iops_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum total number of io operations per second",
|
||||||
|
},
|
||||||
|
"write_bytes_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of bytes to write per second",
|
||||||
|
},
|
||||||
|
"write_bytes_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of bytes to write per second",
|
||||||
|
},
|
||||||
|
"write_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of write operations per second",
|
||||||
|
},
|
||||||
|
"write_iops_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of write operations per second",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "iqn": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Disk IQN",
|
||||||
|
// },
|
||||||
|
// "login": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Login to access the disk",
|
||||||
|
// },
|
||||||
|
// "milestones": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Milestones",
|
||||||
|
// },
|
||||||
|
"disk_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Name of disk",
|
||||||
|
},
|
||||||
|
"order": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk order",
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk params",
|
||||||
|
},
|
||||||
|
"parent_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the parent disk",
|
||||||
|
},
|
||||||
|
// "passwd": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Password to access the disk",
|
||||||
|
// },
|
||||||
|
"pci_slot": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the pci slot to which the disk is connected",
|
||||||
|
},
|
||||||
|
"pool": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Pool for disk location",
|
||||||
|
},
|
||||||
|
"present_to": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "purge_attempts": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Number of deletion attempts",
|
||||||
|
// },
|
||||||
|
"purge_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Time of the last deletion attempt",
|
||||||
|
},
|
||||||
|
"replication": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"disk_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"pool_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"role": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"self_volume_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"storage_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"volume_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Description: "Replication status",
|
||||||
|
},
|
||||||
|
// "reality_device_number": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Reality device number",
|
||||||
|
// },
|
||||||
|
// "reference_id": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "ID of the reference to the disk",
|
||||||
|
// },
|
||||||
|
"res_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Resource ID",
|
||||||
|
},
|
||||||
|
"res_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Name of the resource",
|
||||||
|
},
|
||||||
|
"role": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk role",
|
||||||
|
},
|
||||||
|
"sep_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Storage endpoint provider ID to create disk",
|
||||||
|
},
|
||||||
|
"sep_type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform",
|
||||||
|
},
|
||||||
|
"shareable": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"size_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Size in GB",
|
||||||
|
},
|
||||||
|
"size_used": {
|
||||||
|
Type: schema.TypeFloat,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of used space, in GB",
|
||||||
|
},
|
||||||
|
"snapshots": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"guid": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the snapshot",
|
||||||
|
},
|
||||||
|
"label": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Name of the snapshot",
|
||||||
|
},
|
||||||
|
"res_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Reference to the snapshot",
|
||||||
|
},
|
||||||
|
"snap_set_guid": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The set snapshot ID",
|
||||||
|
},
|
||||||
|
"snap_set_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The set time of the snapshot",
|
||||||
|
},
|
||||||
|
"timestamp": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Snapshot time",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk status",
|
||||||
|
},
|
||||||
|
"tech_status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Technical status of the disk",
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
|
||||||
|
},
|
||||||
|
"vmid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Virtual Machine ID (Deprecated)",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return rets
|
||||||
|
}
|
||||||
|
|
||||||
|
func DataSourceDiskReplication() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
ReadContext: dataSourceDiskReplicationRead,
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Read: &constants.Timeout30s,
|
||||||
|
Default: &constants.Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceDiskReplicationSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,642 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Authors:
|
||||||
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
|
Please see README.md to learn where to place source code so that it
|
||||||
|
builds seamlessly.
|
||||||
|
|
||||||
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
|
*/
|
||||||
|
|
||||||
|
package disks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resourceDiskReplicationCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
diskId := uint64(d.Get("disk_id").(int))
|
||||||
|
|
||||||
|
log.Debugf("resourceDiskReplicationCreate: called for disk with ID: %d", diskId)
|
||||||
|
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
err := existDiskID(ctx, diskId, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
reqCreate := disks.ReplicateRequest{
|
||||||
|
DiskID: diskId,
|
||||||
|
Name: d.Get("disk_name").(string),
|
||||||
|
SepID: uint64(d.Get("sep_id").(int)),
|
||||||
|
PoolName: d.Get("pool_name").(string),
|
||||||
|
}
|
||||||
|
|
||||||
|
diskReplicaId, err := c.CloudAPI().Disks().Replicate(ctx, reqCreate)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetId(strconv.FormatUint(diskReplicaId, 10))
|
||||||
|
d.Set("replica_disk_id", diskReplicaId)
|
||||||
|
|
||||||
|
log.Debugf("resourceDiskReplicationCreate: create replica complete for disk with ID: %d", diskId)
|
||||||
|
|
||||||
|
warnings := dc.Warnings{}
|
||||||
|
|
||||||
|
if start, ok := d.GetOk("start"); ok && !start.(bool) {
|
||||||
|
log.Debugf("resourceDiskReplicationCreate: replication between disk with ID: %d and replica with ID: %d, try to stop", diskId, diskReplicaId)
|
||||||
|
reqStop := disks.ReplicationStopRequest{
|
||||||
|
DiskID: diskId,
|
||||||
|
}
|
||||||
|
_, err = c.CloudAPI().Disks().ReplicationStop(ctx, reqStop)
|
||||||
|
if err != nil {
|
||||||
|
warnings.Add(err)
|
||||||
|
}
|
||||||
|
log.Debugf("resourceDiskReplicationCreate: replication between disk with ID: %d and replica with ID: %d, stoped", diskId, diskReplicaId)
|
||||||
|
}
|
||||||
|
return append(resourceDiskReplicationRead(ctx, d, m), warnings.Get()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceDiskReplicationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("resourceDiskReplicationRead: called for disk with ID: %s", d.Id())
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
req := disks.ReplicationStatusRequest{
|
||||||
|
DiskID: uint64(d.Get("disk_id").(int)),
|
||||||
|
}
|
||||||
|
|
||||||
|
status, err := c.CloudAPI().Disks().ReplicationStatus(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
diskReplica, err := utilityDiskReplicaCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
flattenDiskReplica(d, diskReplica, status)
|
||||||
|
|
||||||
|
log.Debugf("resourceDiskReplicationRead: read complete for disk with ID: %s", d.Id())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceDiskReplicationUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
diskId := uint64(d.Get("disk_id").(int))
|
||||||
|
log.Debugf("resourceDiskReplicationUpdate: called for disk with ID: %d", diskId)
|
||||||
|
|
||||||
|
err := existDiskID(ctx, diskId, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.HasChange("start") {
|
||||||
|
if err := utilityDiskReplicationUpdateStartStop(ctx, d, m); err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.HasChange("pause") {
|
||||||
|
if err := utilityDiskReplicationUpdatePause(ctx, d, m); err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.HasChange("reverse") {
|
||||||
|
if err := utilityDiskReplicationUpdateReverse(ctx, d, m); err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("resourceDiskReplicationUpdate: read complete for disk with ID: %d", diskId)
|
||||||
|
return resourceDiskReplicationRead(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceDiskReplicationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
diskId := uint64(d.Get("disk_id").(int))
|
||||||
|
log.Debugf("resourceDiskReplicationDelete: called for disk with ID: %d", diskId)
|
||||||
|
|
||||||
|
disk, err := utilityDiskReplicaCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
if d.Get("start").(bool) {
|
||||||
|
reqStop := disks.ReplicationStopRequest{
|
||||||
|
DiskID: uint64(d.Get("disk_id").(int)),
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("resourceDiskReplicationDelete: stop replication for disk with ID: %d", diskId)
|
||||||
|
_, err = c.CloudAPI().Disks().ReplicationStop(ctx, reqStop)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
log.Debugf("resourceDiskReplicationDelete: stop replication for disk with ID: %d, complete", diskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
reqDelete := disks.DeleteRequest{
|
||||||
|
DiskID: disk.ID,
|
||||||
|
Detach: d.Get("detach").(bool),
|
||||||
|
Permanently: d.Get("permanently").(bool),
|
||||||
|
Reason: d.Get("reason").(string),
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("resourceDiskReplicationDelete: delete disk replica for disk with ID: %d", diskId)
|
||||||
|
_, err = c.CloudAPI().Disks().Delete(ctx, reqDelete)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
log.Debugf("resourceDiskReplicationDelete: delete disk replica for disk with ID: %d, complete", diskId)
|
||||||
|
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceDiskReplicationSchemaMake() map[string]*schema.Schema {
|
||||||
|
rets := map[string]*schema.Schema{
|
||||||
|
"disk_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "Id of primary disk",
|
||||||
|
},
|
||||||
|
"disk_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
Description: "Name of disk replica",
|
||||||
|
},
|
||||||
|
"sep_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "Storage endpoint provider ID to create disk replica",
|
||||||
|
},
|
||||||
|
"pool_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
Description: "Pool for disk location",
|
||||||
|
},
|
||||||
|
"pause": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Description: "Resume replication",
|
||||||
|
},
|
||||||
|
"reverse": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "Reverse replication",
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: true,
|
||||||
|
Description: "Start/Stop replication",
|
||||||
|
},
|
||||||
|
"detach": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "Detach disk from machine first",
|
||||||
|
},
|
||||||
|
"permanently": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "Delete disk permanently",
|
||||||
|
},
|
||||||
|
"reason": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Description: "Reason for disk deletion",
|
||||||
|
},
|
||||||
|
"replica_disk_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Id of replica disk",
|
||||||
|
},
|
||||||
|
"status_replication": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Status of replication",
|
||||||
|
},
|
||||||
|
"account_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The unique ID of the subscriber-owner of the disk",
|
||||||
|
},
|
||||||
|
"account_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The name of the subscriber '(account') to whom this disk belongs",
|
||||||
|
},
|
||||||
|
"acl": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
// "boot_partition": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Number of disk partitions",
|
||||||
|
// },
|
||||||
|
"computes": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"compute_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"compute_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"created_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Created time",
|
||||||
|
},
|
||||||
|
"deleted_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Deleted time",
|
||||||
|
},
|
||||||
|
"desc": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Description of disk",
|
||||||
|
},
|
||||||
|
"destruction_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Time of final deletion",
|
||||||
|
},
|
||||||
|
"devicename": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Name of the device",
|
||||||
|
},
|
||||||
|
// "disk_path": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Disk path",
|
||||||
|
// },
|
||||||
|
"gid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the grid (platform)",
|
||||||
|
},
|
||||||
|
// "guid": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Disk ID on the storage side",
|
||||||
|
// },
|
||||||
|
"image_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Image ID",
|
||||||
|
},
|
||||||
|
"images": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
},
|
||||||
|
Description: "IDs of images using the disk",
|
||||||
|
},
|
||||||
|
"iotune": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"read_bytes_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of bytes to read per second",
|
||||||
|
},
|
||||||
|
"read_bytes_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of bytes to read",
|
||||||
|
},
|
||||||
|
"read_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of io read operations per second",
|
||||||
|
},
|
||||||
|
"read_iops_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of io read operations",
|
||||||
|
},
|
||||||
|
"size_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Size of io operations",
|
||||||
|
},
|
||||||
|
"total_bytes_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Total size bytes per second",
|
||||||
|
},
|
||||||
|
"total_bytes_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum total size of bytes per second",
|
||||||
|
},
|
||||||
|
"total_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Total number of io operations per second",
|
||||||
|
},
|
||||||
|
"total_iops_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum total number of io operations per second",
|
||||||
|
},
|
||||||
|
"write_bytes_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of bytes to write per second",
|
||||||
|
},
|
||||||
|
"write_bytes_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of bytes to write per second",
|
||||||
|
},
|
||||||
|
"write_iops_sec": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of write operations per second",
|
||||||
|
},
|
||||||
|
"write_iops_sec_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Maximum number of write operations per second",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "iqn": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Disk IQN",
|
||||||
|
// },
|
||||||
|
// "login": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Login to access the disk",
|
||||||
|
// },
|
||||||
|
// "milestones": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Milestones",
|
||||||
|
// },
|
||||||
|
"order": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk order",
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk params",
|
||||||
|
},
|
||||||
|
"parent_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the parent disk",
|
||||||
|
},
|
||||||
|
// "passwd": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Password to access the disk",
|
||||||
|
// },
|
||||||
|
"pci_slot": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the pci slot to which the disk is connected",
|
||||||
|
},
|
||||||
|
"present_to": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "purge_attempts": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Number of deletion attempts",
|
||||||
|
// },
|
||||||
|
"purge_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Time of the last deletion attempt",
|
||||||
|
},
|
||||||
|
"replication": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"disk_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"pool_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"role": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"self_volume_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"storage_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"volume_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Description: "Replication status",
|
||||||
|
},
|
||||||
|
// "reality_device_number": {
|
||||||
|
// Type: schema.TypeInt,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "Reality device number",
|
||||||
|
// },
|
||||||
|
// "reference_id": {
|
||||||
|
// Type: schema.TypeString,
|
||||||
|
// Computed: true,
|
||||||
|
// Description: "ID of the reference to the disk",
|
||||||
|
// },
|
||||||
|
"res_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Resource ID",
|
||||||
|
},
|
||||||
|
"res_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Name of the resource",
|
||||||
|
},
|
||||||
|
"role": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk role",
|
||||||
|
},
|
||||||
|
"sep_type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Type SEP. Defines the type of storage system and contains one of the values set in the cloud platform",
|
||||||
|
},
|
||||||
|
"shareable": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"size_max": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Size in GB",
|
||||||
|
},
|
||||||
|
"size_used": {
|
||||||
|
Type: schema.TypeFloat,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Number of used space, in GB",
|
||||||
|
},
|
||||||
|
"snapshots": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"guid": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "ID of the snapshot",
|
||||||
|
},
|
||||||
|
"label": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Name of the snapshot",
|
||||||
|
},
|
||||||
|
"res_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Reference to the snapshot",
|
||||||
|
},
|
||||||
|
"snap_set_guid": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The set snapshot ID",
|
||||||
|
},
|
||||||
|
"snap_set_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The set time of the snapshot",
|
||||||
|
},
|
||||||
|
"timestamp": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Snapshot time",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Disk status",
|
||||||
|
},
|
||||||
|
"tech_status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Technical status of the disk",
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
Description: "The type of disk in terms of its role in compute: 'B=Boot, D=Data, T=Temp'",
|
||||||
|
},
|
||||||
|
"vmid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Virtual Machine ID (Deprecated)",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return rets
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResourceDiskReplication() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
CreateContext: resourceDiskReplicationCreate,
|
||||||
|
ReadContext: resourceDiskReplicationRead,
|
||||||
|
UpdateContext: resourceDiskReplicationUpdate,
|
||||||
|
DeleteContext: resourceDiskReplicationDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
StateContext: schema.ImportStatePassthroughContext,
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: &constants.Timeout600s,
|
||||||
|
Read: &constants.Timeout300s,
|
||||||
|
Update: &constants.Timeout300s,
|
||||||
|
Delete: &constants.Timeout300s,
|
||||||
|
Default: &constants.Timeout300s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: resourceDiskReplicationSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
@ -1,94 +1,97 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package disks
|
package disks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) {
|
func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.ListDisks, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := disks.ListRequest{}
|
req := disks.ListRequest{}
|
||||||
|
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
if account_name, ok := d.GetOk("account_name"); ok {
|
if account_name, ok := d.GetOk("account_name"); ok {
|
||||||
req.AccountName = account_name.(string)
|
req.AccountName = account_name.(string)
|
||||||
}
|
}
|
||||||
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
if disk_max_size, ok := d.GetOk("disk_max_size"); ok {
|
||||||
req.DiskMaxSize = int64(disk_max_size.(int))
|
req.DiskMaxSize = int64(disk_max_size.(int))
|
||||||
}
|
}
|
||||||
if status, ok := d.GetOk("status"); ok {
|
if status, ok := d.GetOk("status"); ok {
|
||||||
req.Status = status.(string)
|
req.Status = status.(string)
|
||||||
}
|
}
|
||||||
if shared, ok := d.GetOk("shared"); ok {
|
if shared, ok := d.GetOk("shared"); ok {
|
||||||
req.Shared = shared.(bool)
|
req.Shared = shared.(bool)
|
||||||
}
|
}
|
||||||
if accountId, ok := d.GetOk("account_id"); ok {
|
if accountId, ok := d.GetOk("account_id"); ok {
|
||||||
req.AccountID = uint64(accountId.(int))
|
req.AccountID = uint64(accountId.(int))
|
||||||
}
|
}
|
||||||
if diskType, ok := d.GetOk("type"); ok {
|
if diskType, ok := d.GetOk("type"); ok {
|
||||||
req.Type = strings.ToUpper(diskType.(string))
|
req.Type = strings.ToUpper(diskType.(string))
|
||||||
}
|
}
|
||||||
if sepId, ok := d.GetOk("sep_id"); ok {
|
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||||
req.AccountID = uint64(sepId.(int))
|
req.AccountID = uint64(sepId.(int))
|
||||||
}
|
}
|
||||||
if pool_name, ok := d.GetOk("pool_name"); ok {
|
if pool_name, ok := d.GetOk("pool_name"); ok {
|
||||||
req.Pool = pool_name.(string)
|
req.Pool = pool_name.(string)
|
||||||
}
|
}
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
if size, ok := d.GetOk("size"); ok {
|
||||||
log.Debugf("utilityDiskListCheckPresence: load disk list")
|
req.Size = uint64(size.(int))
|
||||||
diskList, err := c.CloudAPI().Disks().List(ctx, req)
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
log.Debugf("utilityDiskListCheckPresence: load disk list")
|
||||||
}
|
diskList, err := c.CloudAPI().Disks().List(ctx, req)
|
||||||
|
if err != nil {
|
||||||
return diskList, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return diskList, nil
|
||||||
|
}
|
||||||
|
@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019-2024 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
|
Authors:
|
||||||
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
|
Please see README.md to learn where to place source code so that it
|
||||||
|
builds seamlessly.
|
||||||
|
|
||||||
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
|
*/
|
||||||
|
|
||||||
|
package disks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilityDiskReplicationUpdateStartStop(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
|
diskId := uint64(d.Get("disk_id").(int))
|
||||||
|
targetDiskId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||||
|
|
||||||
|
log.Debugf("utilityDiskReplicationUpdateStartStop: start update for disk replica with ID: %d", diskId)
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
start, ok := d.GetOk("start")
|
||||||
|
|
||||||
|
if ok && start.(bool) {
|
||||||
|
log.Debugf("utilityDiskReplicationUpdateStartStop: start disk replication from Disk with ID: %d to Disk with ID: %d", diskId, targetDiskId)
|
||||||
|
req := disks.ReplicationStartRequest{
|
||||||
|
DiskID: diskId,
|
||||||
|
TargetDiskID: targetDiskId,
|
||||||
|
}
|
||||||
|
_, err := c.CloudAPI().Disks().ReplicationStart(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("utilityDiskReplicationUpdateStartStop: start disk replication from Disk with ID: %d to Disk with ID: %d, complete", diskId, targetDiskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok && !start.(bool) {
|
||||||
|
log.Debugf("utilityDiskReplicationUpdateStartStop: stop disk replication from Disk with ID: %d to Disk with ID: %d", targetDiskId, diskId)
|
||||||
|
req := disks.ReplicationStopRequest{
|
||||||
|
DiskID: targetDiskId,
|
||||||
|
}
|
||||||
|
_, err := c.CloudAPI().Disks().ReplicationStop(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("utilityDiskReplicationUpdateStartStop: stop disk replication from Disk with ID: %d to Disk with ID: %d, complete", targetDiskId, diskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("utilityDiskReplicationUpdateStartStop: complete update for disk replica with ID: %d", diskId)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func utilityDiskReplicationUpdatePause(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
|
diskId := uint64(d.Get("disk_id").(int))
|
||||||
|
log.Debugf("utilityDiskReplicationUpdatePause: start update for disk replica with ID: %d", diskId)
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
pause, ok := d.GetOk("pause")
|
||||||
|
|
||||||
|
if ok && pause.(bool) {
|
||||||
|
log.Debugf("utilityDiskReplicationUpdatePause: pause disk replication with ID: %d", diskId)
|
||||||
|
req := disks.ReplicationSuspendRequest{
|
||||||
|
DiskID: diskId,
|
||||||
|
}
|
||||||
|
_, err := c.CloudAPI().Disks().ReplicationSuspend(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("utilityDiskReplicationUpdatePause: pause disk replication with ID: %d, complete", diskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok && !pause.(bool) {
|
||||||
|
log.Debugf("utilityDiskReplicationUpdatePause: resume disk replication with ID: %d", diskId)
|
||||||
|
req := disks.ReplicationResumeRequest{
|
||||||
|
DiskID: diskId,
|
||||||
|
}
|
||||||
|
_, err := c.CloudAPI().Disks().ReplicationResume(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("utilityDiskReplicationUpdatePause: resume disk replication with ID: %d, complete", diskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("utilityDiskReplicationUpdatePause: complete update for disk replica with ID: %d", diskId)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func utilityDiskReplicationUpdateReverse(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
|
diskId := uint64(d.Get("disk_id").(int))
|
||||||
|
targetDiskId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||||
|
|
||||||
|
log.Debugf("utilityDiskReplicaUpdateReverse: start update for disk replica with ID: %d", diskId)
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
reverse, ok := d.GetOk("reverse")
|
||||||
|
|
||||||
|
if ok && reverse.(bool) {
|
||||||
|
log.Debugf("utilityDiskReplicaUpdateReverse: reverse disk replication from Disk with ID: %d to Disk with ID: %d", diskId, targetDiskId)
|
||||||
|
req := disks.ReplicationReverseRequest{
|
||||||
|
DiskID: diskId,
|
||||||
|
}
|
||||||
|
_, err := c.CloudAPI().Disks().ReplicationReverse(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("utilityDiskReplicaUpdateReverse: reverse disk replication from Disk with ID: %d to Disk with ID: %d, complete", diskId, targetDiskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok && !reverse.(bool) {
|
||||||
|
log.Debugf("utilityDiskReplicaUpdateReverse: reverse disk replication from Disk with ID: %d to Disk with ID: %d", targetDiskId, diskId)
|
||||||
|
req := disks.ReplicationReverseRequest{
|
||||||
|
DiskID: targetDiskId,
|
||||||
|
}
|
||||||
|
_, err := c.CloudAPI().Disks().ReplicationReverse(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("utilityDiskReplicaUpdateReverse: reverse disk replication from Disk with ID: %d to Disk with ID: %d, complete", targetDiskId, diskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("utilityDiskReplicaUpdateReverse: complete update for disk replica with ID: %d", diskId)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func utilityDiskReplicaCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*disks.RecordDisk, error) {
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
|
req := disks.GetRequest{}
|
||||||
|
|
||||||
|
if d.Id() != "" {
|
||||||
|
diskId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||||
|
req.DiskID = diskId
|
||||||
|
} else {
|
||||||
|
req.DiskID = uint64(d.Get("replica_disk_id").(int))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("utilityDiskReplicaCheckPresence: load disk")
|
||||||
|
disk, err := c.CloudAPI().Disks().Get(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return disk, nil
|
||||||
|
}
|
@ -1,72 +1,74 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package extnet
|
package extnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNetComputes, error) {
|
func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNetComputes, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := extnet.ListComputesRequest{
|
req := extnet.ListComputesRequest{
|
||||||
AccountID: uint64(d.Get("account_id").(int)),
|
AccountID: uint64(d.Get("account_id").(int)),
|
||||||
}
|
}
|
||||||
|
|
||||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rg_id.(int))
|
req.RGID = uint64(rg_id.(int))
|
||||||
}
|
}
|
||||||
if compute_id, ok := d.GetOk("compute_id"); ok {
|
if compute_id, ok := d.GetOk("compute_id"); ok {
|
||||||
req.ComputeID = uint64(compute_id.(int))
|
req.ComputeID = uint64(compute_id.(int))
|
||||||
}
|
}
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
if size, ok := d.GetOk("size"); ok {
|
||||||
|
req.Size = uint64(size.(int))
|
||||||
log.Debugf("utilityExtnetComputesListCheckPresence")
|
}
|
||||||
extnetComputesList, err := c.CloudAPI().ExtNet().ListComputes(ctx, req)
|
|
||||||
if err != nil {
|
log.Debugf("utilityExtnetComputesListCheckPresence")
|
||||||
return nil, err
|
extnetComputesList, err := c.CloudAPI().ExtNet().ListComputes(ctx, req)
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
return extnetComputesList, nil
|
}
|
||||||
}
|
|
||||||
|
return extnetComputesList, nil
|
||||||
|
}
|
||||||
|
@ -1,84 +1,87 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package extnet
|
package extnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/extnet"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNets, error) {
|
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNets, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := extnet.ListRequest{}
|
req := extnet.ListRequest{}
|
||||||
|
|
||||||
if accountId, ok := d.GetOk("account_id"); ok {
|
if accountId, ok := d.GetOk("account_id"); ok {
|
||||||
req.AccountID = uint64(accountId.(int))
|
req.AccountID = uint64(accountId.(int))
|
||||||
}
|
}
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
if network, ok := d.GetOk("network"); ok {
|
if network, ok := d.GetOk("network"); ok {
|
||||||
req.Network = network.(string)
|
req.Network = network.(string)
|
||||||
}
|
}
|
||||||
if vlan_id, ok := d.GetOk("vlan_id"); ok {
|
if vlan_id, ok := d.GetOk("vlan_id"); ok {
|
||||||
req.VLANID = uint64(vlan_id.(int))
|
req.VLANID = uint64(vlan_id.(int))
|
||||||
}
|
}
|
||||||
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
|
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
|
||||||
req.VNFDevID = uint64(vnfdev_id.(int))
|
req.VNFDevID = uint64(vnfdev_id.(int))
|
||||||
}
|
}
|
||||||
if status, ok := d.GetOk("status"); ok {
|
if status, ok := d.GetOk("status"); ok {
|
||||||
req.Status = status.(string)
|
req.Status = status.(string)
|
||||||
}
|
}
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
if size, ok := d.GetOk("size"); ok {
|
||||||
log.Debugf("utilityExtnetListCheckPresence")
|
req.Size = uint64(size.(int))
|
||||||
extnetList, err := c.CloudAPI().ExtNet().List(ctx, req)
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
log.Debugf("utilityExtnetListCheckPresence")
|
||||||
}
|
extnetList, err := c.CloudAPI().ExtNet().List(ctx, req)
|
||||||
|
if err != nil {
|
||||||
return extnetList, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return extnetList, nil
|
||||||
|
}
|
||||||
|
@ -1,216 +1,222 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
|
|
||||||
func dataSourceImageExtendSchemaMake() map[string]*schema.Schema {
|
func dataSourceImageExtendSchemaMake() map[string]*schema.Schema {
|
||||||
return map[string]*schema.Schema{
|
return map[string]*schema.Schema{
|
||||||
"image_id": {
|
"image_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"show_all": {
|
"show_all": {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Default: false,
|
Default: false,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
"unc_path": {
|
||||||
"unc_path": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"ckey": {
|
||||||
"ckey": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"account_id": {
|
||||||
"account_id": {
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"acl": {
|
||||||
"acl": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"architecture": {
|
||||||
"architecture": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"boot_type": {
|
||||||
"boot_type": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"bootable": {
|
||||||
"bootable": {
|
Type: schema.TypeBool,
|
||||||
Type: schema.TypeBool,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"compute_ci_id": {
|
||||||
"compute_ci_id": {
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"cd_presented_to": {
|
||||||
"deleted_time": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"deleted_time": {
|
||||||
"desc": {
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"desc": {
|
||||||
"drivers": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeList,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
Elem: &schema.Schema{
|
"drivers": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeList,
|
||||||
},
|
Computed: true,
|
||||||
},
|
Elem: &schema.Schema{
|
||||||
"enabled": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeBool,
|
},
|
||||||
Computed: true,
|
},
|
||||||
},
|
"enabled": {
|
||||||
"gid": {
|
Type: schema.TypeBool,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"gid": {
|
||||||
"guid": {
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"guid": {
|
||||||
"history": {
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeList,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
Elem: &schema.Resource{
|
"history": {
|
||||||
Schema: map[string]*schema.Schema{
|
Type: schema.TypeList,
|
||||||
"guid": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
Elem: &schema.Resource{
|
||||||
Computed: true,
|
Schema: map[string]*schema.Schema{
|
||||||
},
|
"guid": {
|
||||||
"id": {
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"id": {
|
||||||
"timestamp": {
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"timestamp": {
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
},
|
Computed: true,
|
||||||
},
|
},
|
||||||
"hot_resize": {
|
},
|
||||||
Type: schema.TypeBool,
|
},
|
||||||
Computed: true,
|
},
|
||||||
},
|
"hot_resize": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
"last_modified": {
|
Computed: true,
|
||||||
Type: schema.TypeInt,
|
},
|
||||||
Computed: true,
|
"last_modified": {
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
"link_to": {
|
Computed: true,
|
||||||
Type: schema.TypeInt,
|
},
|
||||||
Computed: true,
|
"link_to": {
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
"milestones": {
|
Computed: true,
|
||||||
Type: schema.TypeInt,
|
},
|
||||||
Computed: true,
|
"milestones": {
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
"image_name": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"image_name": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"password": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"network_interface_naming": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"pool_name": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"password": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"provider_name": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"pool_name": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"purge_attempts": {
|
Computed: true,
|
||||||
Type: schema.TypeInt,
|
},
|
||||||
Computed: true,
|
"provider_name": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"present_to": {
|
Computed: true,
|
||||||
Type: schema.TypeList,
|
},
|
||||||
Computed: true,
|
"purge_attempts": {
|
||||||
Elem: &schema.Schema{
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
},
|
},
|
||||||
},
|
"present_to": {
|
||||||
"res_id": {
|
Type: schema.TypeList,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
Elem: &schema.Schema{
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
"rescuecd": {
|
},
|
||||||
Type: schema.TypeBool,
|
},
|
||||||
Computed: true,
|
"res_id": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"sep_id": {
|
Computed: true,
|
||||||
Type: schema.TypeInt,
|
},
|
||||||
Computed: true,
|
"rescuecd": {
|
||||||
},
|
Type: schema.TypeBool,
|
||||||
"shared_with": {
|
Computed: true,
|
||||||
Type: schema.TypeList,
|
},
|
||||||
Computed: true,
|
"sep_id": {
|
||||||
Elem: &schema.Schema{
|
Type: schema.TypeInt,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
},
|
},
|
||||||
},
|
"shared_with": {
|
||||||
"size": {
|
Type: schema.TypeList,
|
||||||
Type: schema.TypeInt,
|
Computed: true,
|
||||||
Computed: true,
|
Elem: &schema.Schema{
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
"status": {
|
},
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"size": {
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
"tech_status": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"status": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"type": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"tech_status": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"username": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"type": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
"version": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
Computed: true,
|
"username": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
}
|
Computed: true,
|
||||||
}
|
},
|
||||||
|
"version": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,159 +1,160 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.Schema {
|
func resourceImageSchemaMake(sch map[string]*schema.Schema) map[string]*schema.Schema {
|
||||||
delete(sch, "show_all")
|
delete(sch, "show_all")
|
||||||
sch["name"] = &schema.Schema{
|
sch["name"] = &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
Description: "Name of the rescue disk",
|
Description: "Name of the rescue disk",
|
||||||
}
|
}
|
||||||
|
|
||||||
sch["url"] = &schema.Schema{
|
sch["url"] = &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
Description: "URL where to download media from",
|
Description: "URL where to download media from",
|
||||||
}
|
}
|
||||||
|
|
||||||
sch["gid"] = &schema.Schema{
|
sch["image_id"] = &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Optional: true,
|
||||||
Description: "grid (platform) ID where this template should be create in",
|
Computed: true,
|
||||||
}
|
Description: "image id",
|
||||||
|
}
|
||||||
sch["image_id"] = &schema.Schema{
|
|
||||||
Type: schema.TypeInt,
|
sch["boot_type"] = &schema.Schema{
|
||||||
Optional: true,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Required: true,
|
||||||
Description: "image id",
|
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
|
||||||
}
|
Description: "Boot type of image bios or uefi",
|
||||||
|
}
|
||||||
sch["boot_type"] = &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
sch["type"] = &schema.Schema{
|
||||||
Required: true,
|
Type: schema.TypeString,
|
||||||
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
|
Required: true,
|
||||||
Description: "Boot type of image bios or uefi",
|
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
|
||||||
}
|
Description: "Image type linux, windows or other",
|
||||||
|
}
|
||||||
sch["type"] = &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
sch["hot_resize"] = &schema.Schema{
|
||||||
Required: true,
|
Type: schema.TypeBool,
|
||||||
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
|
Optional: true,
|
||||||
Description: "Image type linux, windows or other",
|
Computed: true,
|
||||||
}
|
Description: "Does this machine supports hot resize",
|
||||||
|
}
|
||||||
sch["hot_resize"] = &schema.Schema{
|
|
||||||
Type: schema.TypeBool,
|
sch["username"] = &schema.Schema{
|
||||||
Optional: true,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Optional: true,
|
||||||
Description: "Does this machine supports hot resize",
|
Computed: true,
|
||||||
}
|
Description: "Optional username for the image",
|
||||||
|
}
|
||||||
sch["username"] = &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
sch["password"] = &schema.Schema{
|
||||||
Optional: true,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Optional: true,
|
||||||
Description: "Optional username for the image",
|
Computed: true,
|
||||||
}
|
Description: "Optional password for the image",
|
||||||
|
}
|
||||||
sch["password"] = &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
sch["account_id"] = &schema.Schema{
|
||||||
Optional: true,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Required: true,
|
||||||
Description: "Optional password for the image",
|
Description: "AccountId to make the image exclusive",
|
||||||
}
|
}
|
||||||
|
|
||||||
sch["account_id"] = &schema.Schema{
|
sch["username_dl"] = &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Description: "username for upload binary media",
|
||||||
Description: "AccountId to make the image exclusive",
|
}
|
||||||
}
|
|
||||||
|
sch["password_dl"] = &schema.Schema{
|
||||||
sch["username_dl"] = &schema.Schema{
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Optional: true,
|
||||||
Optional: true,
|
Description: "password for upload binary media",
|
||||||
Description: "username for upload binary media",
|
}
|
||||||
}
|
|
||||||
|
sch["pool_name"] = &schema.Schema{
|
||||||
sch["password_dl"] = &schema.Schema{
|
Type: schema.TypeString,
|
||||||
Type: schema.TypeString,
|
Optional: true,
|
||||||
Optional: true,
|
Computed: true,
|
||||||
Description: "password for upload binary media",
|
Description: "pool for image create",
|
||||||
}
|
}
|
||||||
|
|
||||||
sch["pool_name"] = &schema.Schema{
|
sch["sep_id"] = &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "pool for image create",
|
Description: "storage endpoint provider ID",
|
||||||
}
|
}
|
||||||
|
|
||||||
sch["sep_id"] = &schema.Schema{
|
sch["architecture"] = &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "storage endpoint provider ID",
|
ValidateFunc: validation.StringInSlice([]string{"X86_64", "PPC64_LE"}, true),
|
||||||
}
|
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
|
||||||
|
}
|
||||||
sch["architecture"] = &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
sch["drivers"] = &schema.Schema{
|
||||||
Optional: true,
|
Type: schema.TypeList,
|
||||||
Computed: true,
|
Required: true,
|
||||||
ValidateFunc: validation.StringInSlice([]string{"X86_64", "PPC64_LE"}, true),
|
Elem: &schema.Schema{
|
||||||
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
|
Type: schema.TypeString,
|
||||||
}
|
},
|
||||||
|
}
|
||||||
sch["drivers"] = &schema.Schema{
|
|
||||||
Type: schema.TypeList,
|
sch["permanently"] = &schema.Schema{
|
||||||
Required: true,
|
Type: schema.TypeBool,
|
||||||
Elem: &schema.Schema{
|
Optional: true,
|
||||||
Type: schema.TypeString,
|
Default: false,
|
||||||
},
|
Description: "whether to completely delete the image",
|
||||||
}
|
}
|
||||||
|
|
||||||
sch["permanently"] = &schema.Schema{
|
sch["network_interface_naming"] = &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: false,
|
Computed: true,
|
||||||
Description: "whether to completely delete the image",
|
ValidateFunc: validation.StringInSlice([]string{"eth", "ens"}, true),
|
||||||
}
|
Description: "select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming",
|
||||||
|
}
|
||||||
return sch
|
|
||||||
}
|
return sch
|
||||||
|
}
|
||||||
|
@ -0,0 +1,508 @@
|
|||||||
|
/*
|
||||||
|
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 image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resourceImageFromBlankComputeCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
computeId := uint64(d.Get("compute_id").(int))
|
||||||
|
name := d.Get("name").(string)
|
||||||
|
|
||||||
|
log.Debugf("resourceImageFromBlankComputeCreate: called for image %s", name)
|
||||||
|
|
||||||
|
err := existComputeID(ctx, computeId, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.Errorf("resourceImageFromBlankComputeCreate: can't create Image: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := d.GetOk("account_id"); ok {
|
||||||
|
haveAccountID, err := existAccountID(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !haveAccountID {
|
||||||
|
return diag.Errorf("resourceImageFromBlankComputeCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
req := compute.CreateTemplateFromBlankRequest{
|
||||||
|
ComputeID: computeId,
|
||||||
|
Name: name,
|
||||||
|
BootType: d.Get("boot_type").(string),
|
||||||
|
ImageType: d.Get("type").(string),
|
||||||
|
}
|
||||||
|
|
||||||
|
if username, ok := d.GetOk("username"); ok {
|
||||||
|
req.Username = username.(string)
|
||||||
|
}
|
||||||
|
if password, ok := d.GetOk("password"); ok {
|
||||||
|
req.Password = password.(string)
|
||||||
|
}
|
||||||
|
if accountId, ok := d.GetOk("account_id"); ok {
|
||||||
|
req.AccountID = uint64(accountId.(int))
|
||||||
|
}
|
||||||
|
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||||
|
req.SepID = uint64(sepId.(int))
|
||||||
|
}
|
||||||
|
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||||
|
req.PoolName = poolName.(string)
|
||||||
|
}
|
||||||
|
if hotresize, ok := d.GetOk("hot_resize"); ok {
|
||||||
|
req.HotResize = hotresize.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
var imageId uint64
|
||||||
|
asyncMode := d.Get("async_mode").(bool)
|
||||||
|
if !asyncMode {
|
||||||
|
imageId, err = c.CloudAPI().Compute().CreateTemplateFromBlank(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
taskId, err := c.CloudAPI().Compute().CreateTemplateFromBlankAsync(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
taskReq := tasks.GetRequest{
|
||||||
|
AuditID: strings.Trim(taskId, `"`),
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("resourceImageFromBlankComputeCreate: instance creating - %s", task.Stage)
|
||||||
|
|
||||||
|
if task.Completed {
|
||||||
|
if task.Error != "" {
|
||||||
|
return diag.FromErr(fmt.Errorf("cannot create image instance: %v", task.Error))
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := task.Result.ID()
|
||||||
|
imageId = uint64(id)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second * 20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetId(strconv.FormatUint(imageId, 10))
|
||||||
|
d.Set("image_id", imageId)
|
||||||
|
|
||||||
|
_, err = utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceImageFromBlankComputeRead(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromBlankComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("resourceImageFromBlankComputeRead: called for %s id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
|
img, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if img == nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch img.Status {
|
||||||
|
case status.Modeled:
|
||||||
|
return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status)
|
||||||
|
case status.Creating:
|
||||||
|
case status.Created:
|
||||||
|
case status.Destroyed, status.Purged:
|
||||||
|
d.SetId("")
|
||||||
|
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||||
|
// return resourceImageCreate(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
flattenImage(d, img)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromBlankComputeDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("resourceImageFromBlankComputeDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
|
_, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
req := image.DeleteRequest{
|
||||||
|
ImageID: uint64(d.Get("image_id").(int)),
|
||||||
|
}
|
||||||
|
|
||||||
|
if permanently, ok := d.GetOk("permanently"); ok {
|
||||||
|
req.Permanently = permanently.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = c.CloudAPI().Image().Delete(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromBlankComputeRename(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
|
log.Debugf("resourceImageFromBlankComputeRename: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
req := image.RenameRequest{
|
||||||
|
ImageID: uint64(d.Get("image_id").(int)),
|
||||||
|
Name: d.Get("name").(string),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := c.CloudAPI().Image().Rename(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromBlankComputeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("resourceImageFromBlankComputeUpdate: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
|
// we do not allow change of compute_id, but allow resource update after import
|
||||||
|
old, _ := d.GetChange("compute_id")
|
||||||
|
if old.(int) != 0 && d.HasChange("compute_id") {
|
||||||
|
return diag.Errorf("resourceImageFromBlankComputeUpdate: can't update Image because compute_id is not allowed to be changed")
|
||||||
|
}
|
||||||
|
|
||||||
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch image.Status {
|
||||||
|
case status.Modeled:
|
||||||
|
return diag.Errorf("The image is in status: %s, please, contact support for more information", image.Status)
|
||||||
|
case status.Creating:
|
||||||
|
case status.Created:
|
||||||
|
case status.Destroyed, status.Purged:
|
||||||
|
d.SetId("")
|
||||||
|
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||||
|
// return resourceImageCreate(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.HasChange("name") {
|
||||||
|
err := resourceImageFromBlankComputeRename(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceImageFromBlankComputeRead(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResourceImageFromBlankCompute() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
CreateContext: resourceImageFromBlankComputeCreate,
|
||||||
|
ReadContext: resourceImageFromBlankComputeRead,
|
||||||
|
UpdateContext: resourceImageFromBlankComputeUpdate,
|
||||||
|
DeleteContext: resourceImageFromBlankComputeDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
StateContext: schema.ImportStatePassthroughContext,
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: &constants.Timeout30m,
|
||||||
|
Read: &constants.Timeout900s,
|
||||||
|
Update: &constants.Timeout900s,
|
||||||
|
Delete: &constants.Timeout900s,
|
||||||
|
Default: &constants.Timeout900s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: resourceImageFromBlankComputeSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromBlankComputeSchemaMake() map[string]*schema.Schema {
|
||||||
|
return map[string]*schema.Schema{
|
||||||
|
"compute_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "Compute Id",
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
Description: "Name of the rescue disk",
|
||||||
|
},
|
||||||
|
"boot_type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
|
||||||
|
Description: "Boot type of image BIOS or UEFI",
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
|
||||||
|
Description: "Image type linux, windows or other",
|
||||||
|
},
|
||||||
|
|
||||||
|
"username": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Optional username for the image",
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Optional password for the image",
|
||||||
|
},
|
||||||
|
"account_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "AccountId to make the image exclusive",
|
||||||
|
},
|
||||||
|
"sep_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "storage endpoint provider ID",
|
||||||
|
},
|
||||||
|
"pool_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "pool for image create",
|
||||||
|
},
|
||||||
|
"hot_resize": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Does this machine supports hot resize",
|
||||||
|
},
|
||||||
|
"async_mode": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "create an image in async/sync mode",
|
||||||
|
},
|
||||||
|
"permanently": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "whether to completely delete the image",
|
||||||
|
},
|
||||||
|
|
||||||
|
"image_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"unc_path": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"ckey": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"acl": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"architecture": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"bootable": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"compute_ci_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"cd_presented_to": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"deleted_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"desc": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"drivers": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"enabled": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"gid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"guid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"history": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"guid": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"timestamp": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"last_modified": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"link_to": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"milestones": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"image_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"network_interface_naming": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"provider_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"purge_attempts": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"present_to": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"res_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"rescuecd": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"shared_with": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"size": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"tech_status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"version": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,506 @@
|
|||||||
|
/*
|
||||||
|
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 image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/disks"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
|
||||||
|
"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/statefuncs"
|
||||||
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resourceImageFromPlatformDiskCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
diskId := uint64(d.Get("disk_id").(int))
|
||||||
|
name := d.Get("name").(string)
|
||||||
|
|
||||||
|
log.Debugf("resourceImageFromPlatformDiskCreate: called for image %s", name)
|
||||||
|
|
||||||
|
err := existDiskID(ctx, diskId, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.Errorf("resourceImageFromPlatformDiskCreate: can't create Image: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := d.GetOk("account_id"); ok {
|
||||||
|
haveAccountID, err := existAccountID(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !haveAccountID {
|
||||||
|
return diag.Errorf("resourceImageFromPlatformDiskCreate: can't create Image because AccountID %d is not allowed or does not exist", d.Get("account_id").(int))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
req := disks.FromPlatformDiskRequest{
|
||||||
|
DiskID: diskId,
|
||||||
|
Name: name,
|
||||||
|
BootType: d.Get("boot_type").(string),
|
||||||
|
ImageType: d.Get("type").(string),
|
||||||
|
Architecture: d.Get("architecture").(string),
|
||||||
|
Bootable: d.Get("bootable").(bool), // default value - true
|
||||||
|
}
|
||||||
|
|
||||||
|
if username, ok := d.GetOk("username"); ok {
|
||||||
|
req.Username = username.(string)
|
||||||
|
}
|
||||||
|
if password, ok := d.GetOk("password"); ok {
|
||||||
|
req.Password = password.(string)
|
||||||
|
}
|
||||||
|
if accountId, ok := d.GetOk("account_id"); ok {
|
||||||
|
req.AccountID = uint64(accountId.(int))
|
||||||
|
}
|
||||||
|
if sepId, ok := d.GetOk("sep_id"); ok {
|
||||||
|
req.SepID = uint64(sepId.(int))
|
||||||
|
}
|
||||||
|
if poolName, ok := d.GetOk("pool_name"); ok {
|
||||||
|
req.PoolName = poolName.(string)
|
||||||
|
}
|
||||||
|
if driversInterface, ok := d.GetOk("drivers"); ok {
|
||||||
|
for _, d := range driversInterface.([]interface{}) {
|
||||||
|
req.Drivers = append(req.Drivers, d.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hotresize, ok := d.GetOk("hot_resize"); ok {
|
||||||
|
req.HotResize = hotresize.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
var imageId uint64
|
||||||
|
asyncMode := d.Get("async_mode").(bool)
|
||||||
|
if !asyncMode {
|
||||||
|
imageId, err = c.CloudAPI().Disks().FromPlatformDisk(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
taskId, err := c.CloudAPI().Disks().FromPlatformDiskAsync(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
taskReq := tasks.GetRequest{
|
||||||
|
AuditID: strings.Trim(taskId, `"`),
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
task, err := c.CloudAPI().Tasks().Get(ctx, taskReq)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("resourceImageFromPlatformDiskCreate: instance creating - %s", task.Stage)
|
||||||
|
|
||||||
|
if task.Completed {
|
||||||
|
if task.Error != "" {
|
||||||
|
return diag.FromErr(fmt.Errorf("cannot create image instance: %v", task.Error))
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := task.Result.ID()
|
||||||
|
imageId = uint64(id)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second * 20)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetId(strconv.FormatUint(imageId, 10))
|
||||||
|
d.Set("image_id", imageId)
|
||||||
|
|
||||||
|
_, err = utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceImageFromPlatformDiskRead(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromPlatformDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("resourceImageFromPlatformDiskRead: called for %s id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
|
img, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if img == nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch img.Status {
|
||||||
|
case status.Modeled:
|
||||||
|
return diag.Errorf("The image is in status: %s, please, contact support for more information", img.Status)
|
||||||
|
case status.Creating:
|
||||||
|
case status.Created:
|
||||||
|
case status.Destroyed, status.Purged:
|
||||||
|
d.SetId("")
|
||||||
|
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||||
|
}
|
||||||
|
|
||||||
|
flattenImage(d, img)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromPlatformDiskDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("resourceImageFromPlatformDiskDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
|
_, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
|
req := image.DeleteRequest{
|
||||||
|
ImageID: uint64(d.Get("image_id").(int)),
|
||||||
|
}
|
||||||
|
|
||||||
|
if permanently, ok := d.GetOk("permanently"); ok {
|
||||||
|
req.Permanently = permanently.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = c.CloudAPI().Image().Delete(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetId("")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromPlatformDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
|
log.Debugf("resourceImageFromPlatformDiskUpdate: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
|
// we do not allow change of disk_id, but allow resource update after import
|
||||||
|
old, _ := d.GetChange("disk_id")
|
||||||
|
if old.(int) != 0 && d.HasChange("disk_id") {
|
||||||
|
return diag.Errorf("resourceImageFromPlatformDiskUpdate: can't update Image because disk_id is not allowed to be changed")
|
||||||
|
}
|
||||||
|
|
||||||
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch image.Status {
|
||||||
|
case status.Modeled:
|
||||||
|
return diag.Errorf("The image is in status: %s, please, contact support for more information", image.Status)
|
||||||
|
case status.Creating:
|
||||||
|
case status.Created:
|
||||||
|
case status.Destroyed, status.Purged:
|
||||||
|
d.SetId("")
|
||||||
|
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.HasChange("name") {
|
||||||
|
err := resourceImageRename(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceImageFromPlatformDiskRead(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResourceImageFromPlatformDisk() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
CreateContext: resourceImageFromPlatformDiskCreate,
|
||||||
|
ReadContext: resourceImageFromPlatformDiskRead,
|
||||||
|
UpdateContext: resourceImageFromPlatformDiskUpdate,
|
||||||
|
DeleteContext: resourceImageFromPlatformDiskDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
StateContext: schema.ImportStatePassthroughContext,
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: &constants.Timeout30m,
|
||||||
|
Read: &constants.Timeout900s,
|
||||||
|
Update: &constants.Timeout900s,
|
||||||
|
Delete: &constants.Timeout900s,
|
||||||
|
Default: &constants.Timeout900s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: resourceImageFromPlatformDiskSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceImageFromPlatformDiskSchemaMake() map[string]*schema.Schema {
|
||||||
|
return map[string]*schema.Schema{
|
||||||
|
"disk_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Required: true,
|
||||||
|
Description: "Disk Id",
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
Description: "Name of the rescue disk",
|
||||||
|
},
|
||||||
|
"boot_type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
ValidateFunc: validation.StringInSlice([]string{"bios", "uefi"}, true),
|
||||||
|
Description: "Boot type of image BIOS or UEFI",
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
ValidateFunc: validation.StringInSlice([]string{"linux", "windows", "other"}, true),
|
||||||
|
Description: "Image type linux, windows or other",
|
||||||
|
},
|
||||||
|
"architecture": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
ValidateFunc: validation.StringInSlice([]string{"X86_64", "PPC64_LE"}, true),
|
||||||
|
Description: "binary architecture of this image, one of X86_64 of PPC64_LE",
|
||||||
|
},
|
||||||
|
|
||||||
|
"username": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Optional username for the image",
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Optional password for the image",
|
||||||
|
},
|
||||||
|
"account_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "AccountId to make the image exclusive",
|
||||||
|
},
|
||||||
|
"sep_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "storage endpoint provider ID",
|
||||||
|
},
|
||||||
|
"pool_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "pool for image create",
|
||||||
|
},
|
||||||
|
"drivers": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
StateFunc: statefuncs.StateFuncToUpper,
|
||||||
|
ValidateFunc: validation.StringInSlice([]string{"SVA_KVM_X86", "KVM_X86", "KVM_PPC"}, false), // observe case while validating
|
||||||
|
Type: schema.TypeString,
|
||||||
|
},
|
||||||
|
Description: "List of types of compute suitable for image. Example: [ \"KVM_X86\" ]",
|
||||||
|
},
|
||||||
|
"bootable": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: true,
|
||||||
|
Description: "bootable image",
|
||||||
|
},
|
||||||
|
"hot_resize": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
Description: "Does this machine supports hot resize",
|
||||||
|
},
|
||||||
|
"async_mode": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "create an image in async/sync mode",
|
||||||
|
},
|
||||||
|
"permanently": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
Description: "whether to completely delete the image",
|
||||||
|
},
|
||||||
|
|
||||||
|
"image_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"unc_path": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"ckey": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"acl": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"compute_ci_id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"cd_presented_to": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"deleted_time": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"desc": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"enabled": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"gid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"guid": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"history": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"guid": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"timestamp": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"last_modified": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"link_to": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"milestones": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"image_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"network_interface_naming": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"provider_name": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"purge_attempts": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"present_to": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"res_id": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"rescuecd": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"shared_with": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"size": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"tech_status": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"version": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -1,111 +1,115 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/image"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) {
|
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListImages, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := image.ListRequest{}
|
req := image.ListRequest{}
|
||||||
|
|
||||||
if sep_id, ok := d.GetOk("sep_id"); ok {
|
if sep_id, ok := d.GetOk("sep_id"); ok {
|
||||||
req.SEPID = uint64(sep_id.(int))
|
req.SEPID = uint64(sep_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, ok := d.GetOk("status"); ok {
|
if status, ok := d.GetOk("status"); ok {
|
||||||
req.Status = status.(string)
|
req.Status = status.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if architecture, ok := d.GetOk("architecture"); ok {
|
if architecture, ok := d.GetOk("architecture"); ok {
|
||||||
req.Architecture = architecture.(string)
|
req.Architecture = architecture.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if type_image, ok := d.GetOk("type_image"); ok {
|
if type_image, ok := d.GetOk("type_image"); ok {
|
||||||
req.TypeImage = type_image.(string)
|
req.TypeImage = type_image.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if image_size, ok := d.GetOk("image_size"); ok {
|
if image_size, ok := d.GetOk("image_size"); ok {
|
||||||
req.ImageSize = uint64(image_size.(int))
|
req.ImageSize = uint64(image_size.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if sep_name, ok := d.GetOk("sep_name"); ok {
|
if sep_name, ok := d.GetOk("sep_name"); ok {
|
||||||
req.SEPName = sep_name.(string)
|
req.SEPName = sep_name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pool, ok := d.GetOk("pool"); ok {
|
if pool, ok := d.GetOk("pool"); ok {
|
||||||
req.Pool = pool.(string)
|
req.Pool = pool.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if public, ok := d.GetOk("public"); ok {
|
if public, ok := d.GetOk("public"); ok {
|
||||||
req.Public = public.(bool)
|
req.Public = public.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
if hot_resize, ok := d.GetOk("hot_resize"); ok {
|
if hot_resize, ok := d.GetOk("hot_resize"); ok {
|
||||||
req.HotResize = hot_resize.(bool)
|
req.HotResize = hot_resize.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bootable, ok := d.GetOk("bootable"); ok {
|
if bootable, ok := d.GetOk("bootable"); ok {
|
||||||
req.Bootable = bootable.(bool)
|
req.Bootable = bootable.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(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("utilityImageListCheckPresence: load image list")
|
if size, ok := d.GetOk("size"); ok {
|
||||||
imageList, err := c.CloudAPI().Image().List(ctx, req)
|
req.Size = uint64(size.(int))
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityImageListCheckPresence: load image list")
|
||||||
|
imageList, err := c.CloudAPI().Image().List(ctx, req)
|
||||||
return imageList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageList, nil
|
||||||
|
}
|
||||||
|
@ -1,71 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package lb
|
package lb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
lb, err := utilityLBCheckPresence(ctx, d, m)
|
lb, err := utilityLBCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetId(strconv.FormatUint(lb.ID, 10))
|
d.SetId(strconv.FormatUint(lb.ID, 10))
|
||||||
|
|
||||||
flattenLB(d, lb)
|
flattenLB(d, lb)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DataSourceLB() *schema.Resource {
|
func DataSourceLB() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
|
|
||||||
ReadContext: dataSourceLBRead,
|
ReadContext: dataSourceLBRead,
|
||||||
|
|
||||||
Timeouts: &schema.ResourceTimeout{
|
Timeouts: &schema.ResourceTimeout{
|
||||||
Read: &constants.Timeout30s,
|
Read: &constants.Timeout30s,
|
||||||
Default: &constants.Timeout60s,
|
Default: &constants.Timeout60s,
|
||||||
},
|
},
|
||||||
|
|
||||||
Schema: dsLBSchemaMake(),
|
Schema: dsLBSchemaMake(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package lb
|
package lb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceLBListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
lbList, err := utilityLBListCheckPresence(ctx, d, m)
|
lbList, err := utilityLBListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
d.SetId(id.String())
|
d.SetId(id.String())
|
||||||
d.Set("items", flattenLBList(lbList))
|
d.Set("items", flattenLBList(lbList))
|
||||||
d.Set("entry_count", lbList.EntryCount)
|
d.Set("entry_count", lbList.EntryCount)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DataSourceLBList() *schema.Resource {
|
func DataSourceLBList() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
|
|
||||||
ReadContext: dataSourceLBListRead,
|
ReadContext: dataSourceLBListRead,
|
||||||
|
|
||||||
Timeouts: &schema.ResourceTimeout{
|
Timeouts: &schema.ResourceTimeout{
|
||||||
Read: &constants.Timeout30s,
|
Read: &constants.Timeout30s,
|
||||||
Default: &constants.Timeout60s,
|
Default: &constants.Timeout60s,
|
||||||
},
|
},
|
||||||
|
|
||||||
Schema: dsLBListSchemaMake(),
|
Schema: dsLBListSchemaMake(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package lb
|
package lb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceLBListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
lbList, err := utilityLBListDeletedCheckPresence(ctx, d, m)
|
lbList, err := utilityLBListDeletedCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
d.SetId(id.String())
|
d.SetId(id.String())
|
||||||
d.Set("items", flattenLBList(lbList))
|
d.Set("items", flattenLBList(lbList))
|
||||||
d.Set("entry_count", lbList.EntryCount)
|
d.Set("entry_count", lbList.EntryCount)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DataSourceLBListDeleted() *schema.Resource {
|
func DataSourceLBListDeleted() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
|
|
||||||
ReadContext: dataSourceLBListDeletedRead,
|
ReadContext: dataSourceLBListDeletedRead,
|
||||||
|
|
||||||
Timeouts: &schema.ResourceTimeout{
|
Timeouts: &schema.ResourceTimeout{
|
||||||
Read: &constants.Timeout30s,
|
Read: &constants.Timeout30s,
|
||||||
Default: &constants.Timeout60s,
|
Default: &constants.Timeout60s,
|
||||||
},
|
},
|
||||||
|
|
||||||
Schema: dsLBListDeletedSchemaMake(),
|
Schema: dsLBListDeletedSchemaMake(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,186 +1,195 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package lb
|
package lb
|
||||||
|
|
||||||
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
|
|
||||||
func dsLBSchemaMake() map[string]*schema.Schema {
|
func dsLBSchemaMake() map[string]*schema.Schema {
|
||||||
sch := createLBSchema()
|
sch := createLBSchema()
|
||||||
sch["lb_id"] = &schema.Schema{
|
sch["lb_id"] = &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Required: true,
|
||||||
}
|
}
|
||||||
return sch
|
return sch
|
||||||
}
|
}
|
||||||
|
|
||||||
func dsLBListDeletedSchemaMake() map[string]*schema.Schema {
|
func dsLBListDeletedSchemaMake() map[string]*schema.Schema {
|
||||||
return map[string]*schema.Schema{
|
return map[string]*schema.Schema{
|
||||||
"by_id": {
|
"by_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by ID",
|
Description: "Filter by ID",
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by name",
|
Description: "Filter by name",
|
||||||
},
|
},
|
||||||
"account_id": {
|
"account_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by Account ID",
|
Description: "Filter by Account ID",
|
||||||
},
|
},
|
||||||
"rg_id": {
|
"rg_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by RG ID",
|
Description: "Filter by RG ID",
|
||||||
},
|
},
|
||||||
"tech_status": {
|
"tech_status": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by TechStatus",
|
Description: "Filter by TechStatus",
|
||||||
},
|
},
|
||||||
"front_ip": {
|
"front_ip": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by FrontIP",
|
Description: "Filter by FrontIP",
|
||||||
},
|
},
|
||||||
"back_ip": {
|
"back_ip": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by BackIP",
|
Description: "Filter by BackIP",
|
||||||
},
|
},
|
||||||
"page": {
|
"sort_by": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: 0,
|
Description: "sort by one of supported fields, format +|-(field)",
|
||||||
},
|
},
|
||||||
"size": {
|
"page": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: 0,
|
Default: 0,
|
||||||
},
|
},
|
||||||
"items": {
|
"size": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Optional: true,
|
||||||
Elem: &schema.Resource{
|
Default: 0,
|
||||||
Schema: dsLBItemSchemaMake(),
|
},
|
||||||
},
|
"items": {
|
||||||
},
|
Type: schema.TypeList,
|
||||||
"entry_count": {
|
Computed: true,
|
||||||
Type: schema.TypeInt,
|
Elem: &schema.Resource{
|
||||||
Computed: true,
|
Schema: dsLBItemSchemaMake(),
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
"entry_count": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
func dsLBListSchemaMake() map[string]*schema.Schema {
|
Computed: true,
|
||||||
return map[string]*schema.Schema{
|
},
|
||||||
"by_id": {
|
}
|
||||||
Type: schema.TypeInt,
|
}
|
||||||
Optional: true,
|
|
||||||
Description: "Filter by ID",
|
func dsLBListSchemaMake() map[string]*schema.Schema {
|
||||||
},
|
return map[string]*schema.Schema{
|
||||||
"name": {
|
"by_id": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by name",
|
Description: "Filter by ID",
|
||||||
},
|
},
|
||||||
"account_id": {
|
"name": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by Account ID",
|
Description: "Filter by name",
|
||||||
},
|
},
|
||||||
"rg_id": {
|
"account_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by RG ID",
|
Description: "Filter by Account ID",
|
||||||
},
|
},
|
||||||
"tech_status": {
|
"rg_id": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by TechStatus",
|
Description: "Filter by RG ID",
|
||||||
},
|
},
|
||||||
"status": {
|
"tech_status": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by Status",
|
Description: "Filter by TechStatus",
|
||||||
},
|
},
|
||||||
"front_ip": {
|
"status": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by FrontIP",
|
Description: "Filter by Status",
|
||||||
},
|
},
|
||||||
"back_ip": {
|
"front_ip": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by BackIP",
|
Description: "Filter by FrontIP",
|
||||||
},
|
},
|
||||||
"includedeleted": {
|
"back_ip": {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: false,
|
Description: "Filter by BackIP",
|
||||||
},
|
},
|
||||||
"page": {
|
"includedeleted": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: 0,
|
Default: false,
|
||||||
},
|
},
|
||||||
"size": {
|
"sort_by": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: 0,
|
Description: "sort by one of supported fields, format +|-(field)",
|
||||||
},
|
},
|
||||||
"items": {
|
"page": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Optional: true,
|
||||||
Elem: &schema.Resource{
|
Default: 0,
|
||||||
Schema: dsLBItemSchemaMake(),
|
},
|
||||||
},
|
"size": {
|
||||||
},
|
Type: schema.TypeInt,
|
||||||
"entry_count": {
|
Optional: true,
|
||||||
Type: schema.TypeInt,
|
Default: 0,
|
||||||
Computed: true,
|
},
|
||||||
},
|
"items": {
|
||||||
}
|
Type: schema.TypeList,
|
||||||
}
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
func dsLBItemSchemaMake() map[string]*schema.Schema {
|
Schema: dsLBItemSchemaMake(),
|
||||||
sch := createLBSchema()
|
},
|
||||||
sch["dp_api_password"] = &schema.Schema{
|
},
|
||||||
Type: schema.TypeString,
|
"entry_count": {
|
||||||
Computed: true,
|
Type: schema.TypeInt,
|
||||||
}
|
Computed: true,
|
||||||
delete(sch, "part_k8s")
|
},
|
||||||
return sch
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dsLBItemSchemaMake() map[string]*schema.Schema {
|
||||||
|
sch := createLBSchema()
|
||||||
|
sch["dp_api_password"] = &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
}
|
||||||
|
return sch
|
||||||
|
}
|
||||||
|
@ -1,470 +1,510 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package lb
|
package lb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceLBCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceLBCreate")
|
log.Debugf("resourceLBCreate")
|
||||||
|
|
||||||
haveRGID, err := existRGID(ctx, d, m)
|
haveRGID, err := existRGID(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !haveRGID {
|
if !haveRGID {
|
||||||
return diag.Errorf("resourceLBCreate: can't create LB because RGID %d is not allowed or does not exist", d.Get("rg_id").(int))
|
return diag.Errorf("resourceLBCreate: can't create LB because RGID %d is not allowed or does not exist", d.Get("rg_id").(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
haveExtNetID, err := existExtNetID(ctx, d, m)
|
haveExtNetID, err := existExtNetID(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !haveExtNetID {
|
if !haveExtNetID {
|
||||||
return diag.Errorf("resourceLBCreate: can't create LB because ExtNetID %d is not allowed or does not exist", d.Get("extnet_id").(int))
|
return diag.Errorf("resourceLBCreate: can't create LB because ExtNetID %d is not allowed or does not exist", d.Get("extnet_id").(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
haveVins, err := existViNSID(ctx, d, m)
|
haveVins, err := existViNSID(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !haveVins {
|
if !haveVins {
|
||||||
return diag.Errorf("resourceLBCreate: can't create LB because ViNSID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
return diag.Errorf("resourceLBCreate: can't create LB because ViNSID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := lb.CreateRequest{
|
req := lb.CreateRequest{
|
||||||
Name: d.Get("name").(string),
|
Name: d.Get("name").(string),
|
||||||
RGID: uint64(d.Get("rg_id").(int)),
|
RGID: uint64(d.Get("rg_id").(int)),
|
||||||
ExtNetID: uint64(d.Get("extnet_id").(int)),
|
ExtNetID: uint64(d.Get("extnet_id").(int)),
|
||||||
VINSID: uint64(d.Get("vins_id").(int)),
|
VINSID: uint64(d.Get("vins_id").(int)),
|
||||||
Start: d.Get("start").(bool),
|
Start: d.Get("start").(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
if desc, ok := d.GetOk("desc"); ok {
|
if desc, ok := d.GetOk("desc"); ok {
|
||||||
req.Description = desc.(string)
|
req.Description = desc.(string)
|
||||||
}
|
}
|
||||||
|
if haMode, ok := d.GetOk("ha_mode"); ok {
|
||||||
if haMode, ok := d.GetOk("ha_mode"); ok {
|
req.HighlyAvailable = haMode.(bool)
|
||||||
req.HighlyAvailable = haMode.(bool)
|
}
|
||||||
}
|
if sysctlParams, ok := d.GetOk("sysctl_params"); ok {
|
||||||
|
syscrlSliceMaps := sysctlParams.([]map[string]string)
|
||||||
lbId, err := c.CloudAPI().LB().Create(ctx, req)
|
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||||
if err != nil {
|
for _, syscrlMap := range syscrlSliceMaps {
|
||||||
d.SetId("")
|
tempMap := make(map[string]interface{})
|
||||||
return diag.FromErr(err)
|
for k, v := range syscrlMap {
|
||||||
}
|
if intVal, err := strconv.Atoi(v); err == nil {
|
||||||
|
tempMap[k] = intVal
|
||||||
d.SetId(strconv.FormatUint(lbId, 10))
|
continue
|
||||||
d.Set("lb_id", lbId)
|
}
|
||||||
|
tempMap[k] = v
|
||||||
w := dc.Warnings{}
|
}
|
||||||
|
res = append(res, tempMap)
|
||||||
if enable, ok := d.GetOk("enable"); ok {
|
}
|
||||||
req := lb.DisableEnableRequest{
|
req.SysctlParams = res
|
||||||
LBID: lbId,
|
}
|
||||||
}
|
|
||||||
|
lbId, err := c.CloudAPI().LB().Create(ctx, req)
|
||||||
if enable.(bool) {
|
if err != nil {
|
||||||
_, err := c.CloudAPI().LB().Enable(ctx, req)
|
d.SetId("")
|
||||||
if err != nil {
|
return diag.FromErr(err)
|
||||||
w.Add(err)
|
}
|
||||||
}
|
|
||||||
} else {
|
d.SetId(strconv.FormatUint(lbId, 10))
|
||||||
_, err := c.CloudAPI().LB().Disable(ctx, req)
|
d.Set("lb_id", lbId)
|
||||||
if err != nil {
|
|
||||||
w.Add(err)
|
w := dc.Warnings{}
|
||||||
}
|
|
||||||
}
|
if enable, ok := d.GetOk("enable"); ok {
|
||||||
|
req := lb.DisableEnableRequest{
|
||||||
if start, ok := d.GetOk("start"); ok && enable.(bool) {
|
LBID: lbId,
|
||||||
if start.(bool) {
|
}
|
||||||
req := lb.StartRequest{LBID: lbId}
|
|
||||||
_, err := c.CloudAPI().LB().Start(ctx, req)
|
if enable.(bool) {
|
||||||
if err != nil {
|
_, err := c.CloudAPI().LB().Enable(ctx, req)
|
||||||
w.Add(err)
|
if err != nil {
|
||||||
}
|
w.Add(err)
|
||||||
} else {
|
}
|
||||||
req := lb.StopRequest{LBID: lbId}
|
} else {
|
||||||
_, err := c.CloudAPI().LB().Stop(ctx, req)
|
_, err := c.CloudAPI().LB().Disable(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Add(err)
|
w.Add(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
if start, ok := d.GetOk("start"); ok && enable.(bool) {
|
||||||
|
if start.(bool) {
|
||||||
return append(w.Get(), resourceLBRead(ctx, d, m)...)
|
req := lb.StartRequest{LBID: lbId}
|
||||||
}
|
_, err := c.CloudAPI().LB().Start(ctx, req)
|
||||||
|
if err != nil {
|
||||||
func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
w.Add(err)
|
||||||
log.Debugf("resourceLBRead")
|
}
|
||||||
|
} else {
|
||||||
// c := m.(*controller.ControllerCfg)
|
req := lb.StopRequest{LBID: lbId}
|
||||||
|
_, err := c.CloudAPI().LB().Stop(ctx, req)
|
||||||
lbRec, err := utilityLBCheckPresence(ctx, d, m)
|
if err != nil {
|
||||||
if lbRec == nil {
|
w.Add(err)
|
||||||
d.SetId("")
|
}
|
||||||
return diag.FromErr(err)
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
hasChanged := false
|
|
||||||
|
return append(w.Get(), resourceLBRead(ctx, d, m)...)
|
||||||
switch lbRec.Status {
|
}
|
||||||
case status.Modeled:
|
|
||||||
return diag.Errorf("The LB is in status: %s, please, contact support for more information", lbRec.Status)
|
func resourceLBRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
case status.Creating:
|
log.Debugf("resourceLBRead")
|
||||||
case status.Created:
|
|
||||||
case status.Deleting:
|
// c := m.(*controller.ControllerCfg)
|
||||||
case status.Deleted:
|
|
||||||
// lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
lbRec, err := utilityLBCheckPresence(ctx, d, m)
|
||||||
// restoreReq := lb.RestoreRequest{LBID: lbId}
|
if lbRec == nil {
|
||||||
// enableReq := lb.DisableEnableRequest{LBID: lbId}
|
d.SetId("")
|
||||||
|
return diag.FromErr(err)
|
||||||
// _, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
|
}
|
||||||
// if err != nil {
|
|
||||||
// return diag.FromErr(err)
|
hasChanged := false
|
||||||
// }
|
|
||||||
// _, err = c.CloudAPI().LB().Enable(ctx, enableReq)
|
switch lbRec.Status {
|
||||||
// if err != nil {
|
case status.Modeled:
|
||||||
// return diag.FromErr(err)
|
return diag.Errorf("The LB is in status: %s, please, contact support for more information", lbRec.Status)
|
||||||
// }
|
case status.Creating:
|
||||||
|
case status.Created:
|
||||||
// hasChanged = true
|
case status.Deleting:
|
||||||
case status.Destroying:
|
case status.Deleted:
|
||||||
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
|
// lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||||
case status.Destroyed:
|
// restoreReq := lb.RestoreRequest{LBID: lbId}
|
||||||
d.SetId("")
|
// enableReq := lb.DisableEnableRequest{LBID: lbId}
|
||||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
|
||||||
// return resourceLBCreate(ctx, d, m)
|
// _, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
|
||||||
case status.Enabled:
|
// if err != nil {
|
||||||
case status.Enabling:
|
// return diag.FromErr(err)
|
||||||
case status.Disabling:
|
// }
|
||||||
case status.Disabled:
|
// _, err = c.CloudAPI().LB().Enable(ctx, enableReq)
|
||||||
log.Debugf("The LB is in status: %s, troubles may occur with update. Please, enable LB first.", lbRec.Status)
|
// if err != nil {
|
||||||
case status.Restoring:
|
// return diag.FromErr(err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
if hasChanged {
|
// hasChanged = true
|
||||||
lbRec, err = utilityLBCheckPresence(ctx, d, m)
|
case status.Destroying:
|
||||||
if err != nil {
|
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
|
||||||
d.SetId("")
|
case status.Destroyed:
|
||||||
return diag.FromErr(err)
|
d.SetId("")
|
||||||
}
|
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||||
}
|
// return resourceLBCreate(ctx, d, m)
|
||||||
|
case status.Enabled:
|
||||||
flattenResourceLB(d, lbRec)
|
case status.Enabling:
|
||||||
|
case status.Disabling:
|
||||||
return nil
|
case status.Disabled:
|
||||||
}
|
log.Debugf("The LB is in status: %s, troubles may occur with update. Please, enable LB first.", lbRec.Status)
|
||||||
|
case status.Restoring:
|
||||||
func resourceLBDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
}
|
||||||
log.Debugf("resourceLBDelete")
|
|
||||||
|
if hasChanged {
|
||||||
c := m.(*controller.ControllerCfg)
|
lbRec, err = utilityLBCheckPresence(ctx, d, m)
|
||||||
lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
if err != nil {
|
||||||
req := lb.DeleteRequest{
|
d.SetId("")
|
||||||
LBID: lbId,
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if permanently, ok := d.GetOk("permanently"); ok {
|
|
||||||
req.Permanently = permanently.(bool)
|
flattenResourceLB(d, lbRec)
|
||||||
}
|
|
||||||
|
return nil
|
||||||
_, err := c.CloudAPI().LB().Delete(ctx, req)
|
}
|
||||||
if err != nil {
|
|
||||||
return diag.FromErr(err)
|
func resourceLBDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
}
|
log.Debugf("resourceLBDelete")
|
||||||
|
|
||||||
d.SetId("")
|
c := m.(*controller.ControllerCfg)
|
||||||
|
lbId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||||
return nil
|
req := lb.DeleteRequest{
|
||||||
}
|
LBID: lbId,
|
||||||
|
}
|
||||||
func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
|
||||||
log.Debugf("resourceLBUpdate")
|
if permanently, ok := d.GetOk("permanently"); ok {
|
||||||
c := m.(*controller.ControllerCfg)
|
req.Permanently = permanently.(bool)
|
||||||
|
}
|
||||||
haveRGID, err := existRGID(ctx, d, m)
|
|
||||||
if err != nil {
|
_, err := c.CloudAPI().LB().Delete(ctx, req)
|
||||||
return diag.FromErr(err)
|
if err != nil {
|
||||||
}
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
if !haveRGID {
|
|
||||||
return diag.Errorf("resourceLBUpdate: can't update LB because RGID %d is not allowed or does not exist", d.Get("rg_id").(int))
|
d.SetId("")
|
||||||
}
|
|
||||||
|
return nil
|
||||||
haveExtNetID, err := existExtNetID(ctx, d, m)
|
}
|
||||||
if err != nil {
|
|
||||||
return diag.FromErr(err)
|
func resourceLBUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
}
|
log.Debugf("resourceLBUpdate")
|
||||||
|
c := m.(*controller.ControllerCfg)
|
||||||
if !haveExtNetID {
|
|
||||||
return diag.Errorf("resourceLBUpdate: can't update LB because ExtNetID %d is not allowed or does not exist", d.Get("extnet_id").(int))
|
haveRGID, err := existRGID(ctx, d, m)
|
||||||
}
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
haveVins, err := existViNSID(ctx, d, m)
|
}
|
||||||
if err != nil {
|
|
||||||
return diag.FromErr(err)
|
if !haveRGID {
|
||||||
}
|
return diag.Errorf("resourceLBUpdate: can't update LB because RGID %d is not allowed or does not exist", d.Get("rg_id").(int))
|
||||||
|
}
|
||||||
if !haveVins {
|
|
||||||
return diag.Errorf("resourceLBUpdate: can't update LB because ViNSID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
haveExtNetID, err := existExtNetID(ctx, d, m)
|
||||||
}
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
lbRec, err := utilityLBCheckPresence(ctx, d, m)
|
}
|
||||||
if lbRec == nil {
|
|
||||||
d.SetId("")
|
if !haveExtNetID {
|
||||||
return diag.FromErr(err)
|
return diag.Errorf("resourceLBUpdate: can't update LB because ExtNetID %d is not allowed or does not exist", d.Get("extnet_id").(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
hasChanged := false
|
haveVins, err := existViNSID(ctx, d, m)
|
||||||
|
if err != nil {
|
||||||
switch lbRec.Status {
|
return diag.FromErr(err)
|
||||||
case status.Modeled:
|
}
|
||||||
return diag.Errorf("The LB is in status: %s, please, contact support for more information", lbRec.Status)
|
|
||||||
case status.Creating:
|
if !haveVins {
|
||||||
case status.Created:
|
return diag.Errorf("resourceLBUpdate: can't update LB because ViNSID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
||||||
case status.Deleting:
|
}
|
||||||
case status.Deleted:
|
|
||||||
if restore, ok := d.GetOk("restore"); ok && restore.(bool) {
|
lbRec, err := utilityLBCheckPresence(ctx, d, m)
|
||||||
restoreReq := lb.RestoreRequest{LBID: lbRec.ID}
|
if lbRec == nil {
|
||||||
|
d.SetId("")
|
||||||
_, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
|
return diag.FromErr(err)
|
||||||
if err != nil {
|
}
|
||||||
return diag.FromErr(err)
|
|
||||||
}
|
hasChanged := false
|
||||||
}
|
|
||||||
if enable, ok := d.GetOk("enable"); ok {
|
switch lbRec.Status {
|
||||||
req := lb.DisableEnableRequest{
|
case status.Modeled:
|
||||||
LBID: lbRec.ID,
|
return diag.Errorf("The LB is in status: %s, please, contact support for more information", lbRec.Status)
|
||||||
}
|
case status.Creating:
|
||||||
|
case status.Created:
|
||||||
if enable.(bool) {
|
case status.Deleting:
|
||||||
_, err := c.CloudAPI().LB().Enable(ctx, req)
|
case status.Deleted:
|
||||||
if err != nil {
|
if restore, ok := d.GetOk("restore"); ok && restore.(bool) {
|
||||||
return diag.FromErr(err)
|
restoreReq := lb.RestoreRequest{LBID: lbRec.ID}
|
||||||
}
|
|
||||||
} else {
|
_, err := c.CloudAPI().LB().Restore(ctx, restoreReq)
|
||||||
_, err := c.CloudAPI().LB().Disable(ctx, req)
|
if err != nil {
|
||||||
if err != nil {
|
return diag.FromErr(err)
|
||||||
return diag.FromErr(err)
|
}
|
||||||
}
|
}
|
||||||
}
|
if enable, ok := d.GetOk("enable"); ok {
|
||||||
|
req := lb.DisableEnableRequest{
|
||||||
if start, ok := d.GetOk("start"); ok && enable.(bool) {
|
LBID: lbRec.ID,
|
||||||
if start.(bool) {
|
}
|
||||||
req := lb.StartRequest{LBID: lbRec.ID}
|
|
||||||
_, err := c.CloudAPI().LB().Start(ctx, req)
|
if enable.(bool) {
|
||||||
if err != nil {
|
_, err := c.CloudAPI().LB().Enable(ctx, req)
|
||||||
return diag.FromErr(err)
|
if err != nil {
|
||||||
}
|
return diag.FromErr(err)
|
||||||
} else {
|
}
|
||||||
req := lb.StopRequest{LBID: lbRec.ID}
|
} else {
|
||||||
_, err := c.CloudAPI().LB().Stop(ctx, req)
|
_, err := c.CloudAPI().LB().Disable(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
if start, ok := d.GetOk("start"); ok && enable.(bool) {
|
||||||
hasChanged = true
|
if start.(bool) {
|
||||||
case status.Destroying:
|
req := lb.StartRequest{LBID: lbRec.ID}
|
||||||
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
|
_, err := c.CloudAPI().LB().Start(ctx, req)
|
||||||
case status.Destroyed:
|
if err != nil {
|
||||||
d.SetId("")
|
return diag.FromErr(err)
|
||||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
}
|
||||||
// return resourceLBCreate(ctx, d, m)
|
} else {
|
||||||
case status.Enabled:
|
req := lb.StopRequest{LBID: lbRec.ID}
|
||||||
case status.Enabling:
|
_, err := c.CloudAPI().LB().Stop(ctx, req)
|
||||||
case status.Disabling:
|
if err != nil {
|
||||||
case status.Disabled:
|
return diag.FromErr(err)
|
||||||
log.Debugf("The LB is in status: %s, troubles may occur with update. Please, enable LB first.", lbRec.Status)
|
}
|
||||||
case status.Restoring:
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if hasChanged {
|
hasChanged = true
|
||||||
_, err = utilityLBCheckPresence(ctx, d, m)
|
case status.Destroying:
|
||||||
if err != nil {
|
return diag.Errorf("The LB is in progress with status: %s", lbRec.Status)
|
||||||
d.SetId("")
|
case status.Destroyed:
|
||||||
return diag.FromErr(err)
|
d.SetId("")
|
||||||
}
|
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||||
}
|
// return resourceLBCreate(ctx, d, m)
|
||||||
|
case status.Enabled:
|
||||||
if d.HasChange("ha_mode") {
|
case status.Enabling:
|
||||||
hamode := d.Get("ha_mode").(bool)
|
case status.Disabling:
|
||||||
if hamode {
|
case status.Disabled:
|
||||||
req := lb.HighlyAvailableRequest{
|
log.Debugf("The LB is in status: %s, troubles may occur with update. Please, enable LB first.", lbRec.Status)
|
||||||
LBID: uint64(d.Get("lb_id").(int)),
|
case status.Restoring:
|
||||||
}
|
}
|
||||||
_, err := c.CloudAPI().LB().HighlyAvailable(ctx, req)
|
|
||||||
if err != nil {
|
if hasChanged {
|
||||||
return diag.FromErr(err)
|
_, err = utilityLBCheckPresence(ctx, d, m)
|
||||||
}
|
if err != nil {
|
||||||
}
|
d.SetId("")
|
||||||
}
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
if d.HasChange("enable") {
|
}
|
||||||
enable := d.Get("enable").(bool)
|
|
||||||
req := lb.DisableEnableRequest{
|
if d.HasChange("ha_mode") {
|
||||||
LBID: uint64(d.Get("lb_id").(int)),
|
hamode := d.Get("ha_mode").(bool)
|
||||||
}
|
if hamode {
|
||||||
if enable {
|
req := lb.HighlyAvailableRequest{
|
||||||
_, err := c.CloudAPI().LB().Enable(ctx, req)
|
LBID: uint64(d.Get("lb_id").(int)),
|
||||||
if err != nil {
|
}
|
||||||
return diag.FromErr(err)
|
_, err := c.CloudAPI().LB().HighlyAvailable(ctx, req)
|
||||||
}
|
if err != nil {
|
||||||
} else {
|
return diag.FromErr(err)
|
||||||
_, err := c.CloudAPI().LB().Disable(ctx, req)
|
}
|
||||||
if err != nil {
|
}
|
||||||
return diag.FromErr(err)
|
}
|
||||||
}
|
|
||||||
}
|
if d.HasChange("sysctl_params") {
|
||||||
}
|
syscrlSliceMaps := d.Get("sysctl_params").([]map[string]string)
|
||||||
|
res := make([]map[string]interface{}, 0, len(syscrlSliceMaps))
|
||||||
if d.HasChange("start") {
|
for _, syscrlMap := range syscrlSliceMaps {
|
||||||
start := d.Get("start").(bool)
|
tempMap := make(map[string]interface{})
|
||||||
lbId := uint64(d.Get("lb_id").(int))
|
for k, v := range syscrlMap {
|
||||||
if start {
|
if intVal, err := strconv.Atoi(v); err == nil {
|
||||||
req := lb.StartRequest{LBID: lbId}
|
tempMap[k] = intVal
|
||||||
_, err := c.CloudAPI().LB().Start(ctx, req)
|
continue
|
||||||
if err != nil {
|
}
|
||||||
return diag.FromErr(err)
|
tempMap[k] = v
|
||||||
}
|
}
|
||||||
} else {
|
res = append(res, tempMap)
|
||||||
req := lb.StopRequest{LBID: lbId}
|
}
|
||||||
_, err := c.CloudAPI().LB().Stop(ctx, req)
|
|
||||||
if err != nil {
|
req := lb.UpdateSysctParamsRequest{
|
||||||
return diag.FromErr(err)
|
LBID: uint64(d.Get("lb_id").(int)),
|
||||||
}
|
SysctlParams: res,
|
||||||
}
|
}
|
||||||
}
|
_, err := c.CloudAPI().LB().UpdateSysctlParams(ctx, req)
|
||||||
|
if err != nil {
|
||||||
if d.HasChange("desc") {
|
return diag.FromErr(err)
|
||||||
req := lb.UpdateRequest{
|
}
|
||||||
LBID: uint64(d.Get("lb_id").(int)),
|
}
|
||||||
Description: d.Get("desc").(string),
|
|
||||||
}
|
if d.HasChange("enable") {
|
||||||
|
enable := d.Get("enable").(bool)
|
||||||
_, err := c.CloudAPI().LB().Update(ctx, req)
|
req := lb.DisableEnableRequest{
|
||||||
if err != nil {
|
LBID: uint64(d.Get("lb_id").(int)),
|
||||||
return diag.FromErr(err)
|
}
|
||||||
}
|
if enable {
|
||||||
}
|
_, err := c.CloudAPI().LB().Enable(ctx, req)
|
||||||
|
if err != nil {
|
||||||
if d.HasChange("restart") {
|
return diag.FromErr(err)
|
||||||
restart := d.Get("restart").(bool)
|
}
|
||||||
if restart {
|
} else {
|
||||||
req := lb.RestartRequest{
|
_, err := c.CloudAPI().LB().Disable(ctx, req)
|
||||||
LBID: uint64(d.Get("lb_id").(int)),
|
if err != nil {
|
||||||
}
|
return diag.FromErr(err)
|
||||||
if safe, ok:= d.GetOk("safe"); ok {
|
}
|
||||||
req.Safe = safe.(bool)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := c.CloudAPI().LB().Restart(ctx, req)
|
if d.HasChange("start") {
|
||||||
if err != nil {
|
start := d.Get("start").(bool)
|
||||||
return diag.FromErr(err)
|
lbId := uint64(d.Get("lb_id").(int))
|
||||||
}
|
if start {
|
||||||
}
|
req := lb.StartRequest{LBID: lbId}
|
||||||
}
|
_, err := c.CloudAPI().LB().Start(ctx, req)
|
||||||
|
if err != nil {
|
||||||
if d.HasChange("restore") {
|
return diag.FromErr(err)
|
||||||
restore := d.Get("restore").(bool)
|
}
|
||||||
if restore {
|
} else {
|
||||||
req := lb.RestoreRequest{
|
req := lb.StopRequest{LBID: lbId}
|
||||||
LBID: uint64(d.Get("lb_id").(int)),
|
_, err := c.CloudAPI().LB().Stop(ctx, req)
|
||||||
}
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
_, err := c.CloudAPI().LB().Restore(ctx, req)
|
}
|
||||||
if err != nil {
|
}
|
||||||
return diag.FromErr(err)
|
}
|
||||||
}
|
|
||||||
}
|
if d.HasChange("desc") {
|
||||||
}
|
req := lb.UpdateRequest{
|
||||||
|
LBID: uint64(d.Get("lb_id").(int)),
|
||||||
if d.HasChange("config_reset") {
|
Description: d.Get("desc").(string),
|
||||||
cfgReset := d.Get("config_reset").(bool)
|
}
|
||||||
if cfgReset {
|
|
||||||
req := lb.ConfigResetRequest{
|
_, err := c.CloudAPI().LB().Update(ctx, req)
|
||||||
LBID: uint64(d.Get("lb_id").(int)),
|
if err != nil {
|
||||||
}
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
_, err := c.CloudAPI().LB().ConfigReset(ctx, req)
|
}
|
||||||
if err != nil {
|
|
||||||
return diag.FromErr(err)
|
if d.HasChange("restart") {
|
||||||
}
|
restart := d.Get("restart").(bool)
|
||||||
}
|
if restart {
|
||||||
}
|
req := lb.RestartRequest{
|
||||||
|
LBID: uint64(d.Get("lb_id").(int)),
|
||||||
return resourceLBRead(ctx, d, m)
|
}
|
||||||
}
|
if safe, ok := d.GetOk("safe"); ok {
|
||||||
|
req.Safe = safe.(bool)
|
||||||
func ResourceLB() *schema.Resource {
|
}
|
||||||
return &schema.Resource{
|
|
||||||
SchemaVersion: 1,
|
_, err := c.CloudAPI().LB().Restart(ctx, req)
|
||||||
|
if err != nil {
|
||||||
CreateContext: resourceLBCreate,
|
return diag.FromErr(err)
|
||||||
ReadContext: resourceLBRead,
|
}
|
||||||
UpdateContext: resourceLBUpdate,
|
}
|
||||||
DeleteContext: resourceLBDelete,
|
}
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
if d.HasChange("restore") {
|
||||||
StateContext: schema.ImportStatePassthroughContext,
|
restore := d.Get("restore").(bool)
|
||||||
},
|
if restore {
|
||||||
|
req := lb.RestoreRequest{
|
||||||
Timeouts: &schema.ResourceTimeout{
|
LBID: uint64(d.Get("lb_id").(int)),
|
||||||
Create: &constants.Timeout600s,
|
}
|
||||||
Read: &constants.Timeout300s,
|
|
||||||
Update: &constants.Timeout300s,
|
_, err := c.CloudAPI().LB().Restore(ctx, req)
|
||||||
Delete: &constants.Timeout300s,
|
if err != nil {
|
||||||
Default: &constants.Timeout300s,
|
return diag.FromErr(err)
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Schema: lbResourceSchemaMake(),
|
}
|
||||||
}
|
|
||||||
}
|
if d.HasChange("config_reset") {
|
||||||
|
cfgReset := d.Get("config_reset").(bool)
|
||||||
|
if cfgReset {
|
||||||
|
req := lb.ConfigResetRequest{
|
||||||
|
LBID: uint64(d.Get("lb_id").(int)),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := c.CloudAPI().LB().ConfigReset(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return diag.FromErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceLBRead(ctx, d, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResourceLB() *schema.Resource {
|
||||||
|
return &schema.Resource{
|
||||||
|
SchemaVersion: 1,
|
||||||
|
|
||||||
|
CreateContext: resourceLBCreate,
|
||||||
|
ReadContext: resourceLBRead,
|
||||||
|
UpdateContext: resourceLBUpdate,
|
||||||
|
DeleteContext: resourceLBDelete,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
StateContext: schema.ImportStatePassthroughContext,
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeouts: &schema.ResourceTimeout{
|
||||||
|
Create: &constants.Timeout600s,
|
||||||
|
Read: &constants.Timeout300s,
|
||||||
|
Update: &constants.Timeout300s,
|
||||||
|
Delete: &constants.Timeout300s,
|
||||||
|
Default: &constants.Timeout300s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: lbResourceSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,99 +1,103 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package lb
|
package lb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
|
func utilityLBListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := lb.ListRequest{}
|
req := lb.ListRequest{}
|
||||||
|
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if account_id, ok := d.GetOk("account_id"); ok {
|
if account_id, ok := d.GetOk("account_id"); ok {
|
||||||
req.AccountID = uint64(account_id.(int))
|
req.AccountID = uint64(account_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rg_id.(int))
|
req.RGID = uint64(rg_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if tech_status, ok := d.GetOk("tech_status"); ok {
|
if tech_status, ok := d.GetOk("tech_status"); ok {
|
||||||
req.TechStatus = tech_status.(string)
|
req.TechStatus = tech_status.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, ok := d.GetOk("status"); ok {
|
if status, ok := d.GetOk("status"); ok {
|
||||||
req.Status = status.(string)
|
req.Status = status.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if front_ip, ok := d.GetOk("front_ip"); ok {
|
if front_ip, ok := d.GetOk("front_ip"); ok {
|
||||||
req.FrontIP = front_ip.(string)
|
req.FrontIP = front_ip.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if back_ip, ok := d.GetOk("back_ip"); ok {
|
if back_ip, ok := d.GetOk("back_ip"); ok {
|
||||||
req.BackIP = back_ip.(string)
|
req.BackIP = back_ip.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if includedeleted, ok := d.GetOk("includedeleted"); ok {
|
if includedeleted, ok := d.GetOk("includedeleted"); ok {
|
||||||
req.IncludeDeleted = includedeleted.(bool)
|
req.IncludeDeleted = includedeleted.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(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("utilityLBListCheckPresence: load lb list")
|
if size, ok := d.GetOk("size"); ok {
|
||||||
lbList, err := c.CloudAPI().LB().List(ctx, req)
|
req.Size = uint64(size.(int))
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityLBListCheckPresence: load lb list")
|
||||||
|
lbList, err := c.CloudAPI().LB().List(ctx, req)
|
||||||
return lbList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return lbList, nil
|
||||||
|
}
|
||||||
|
@ -1,91 +1,95 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package lb
|
package lb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityLBListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
|
func utilityLBListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*lb.ListLB, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := lb.ListDeletedRequest{}
|
req := lb.ListDeletedRequest{}
|
||||||
|
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.Name = name.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if account_id, ok := d.GetOk("account_id"); ok {
|
if account_id, ok := d.GetOk("account_id"); ok {
|
||||||
req.AccountID = uint64(account_id.(int))
|
req.AccountID = uint64(account_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||||
req.RGID = uint64(rg_id.(int))
|
req.RGID = uint64(rg_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if tech_status, ok := d.GetOk("tech_status"); ok {
|
if tech_status, ok := d.GetOk("tech_status"); ok {
|
||||||
req.TechStatus = tech_status.(string)
|
req.TechStatus = tech_status.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if front_ip, ok := d.GetOk("front_ip"); ok {
|
if front_ip, ok := d.GetOk("front_ip"); ok {
|
||||||
req.FrontIP = front_ip.(string)
|
req.FrontIP = front_ip.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if back_ip, ok := d.GetOk("back_ip"); ok {
|
if back_ip, ok := d.GetOk("back_ip"); ok {
|
||||||
req.BackIP = back_ip.(string)
|
req.BackIP = back_ip.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(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("utilityLBListDeletedCheckPresence: load lb list")
|
if size, ok := d.GetOk("size"); ok {
|
||||||
lbList, err := c.CloudAPI().LB().ListDeleted(ctx, req)
|
req.Size = uint64(size.(int))
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityLBListDeletedCheckPresence: load lb list")
|
||||||
|
lbList, err := c.CloudAPI().LB().ListDeleted(ctx, req)
|
||||||
return lbList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return lbList, nil
|
||||||
|
}
|
||||||
|
@ -1,190 +1,195 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package locations
|
package locations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||||
)
|
)
|
||||||
|
|
||||||
func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{} {
|
func flattenLocationsList(ll *locations.ListLocations) []map[string]interface{} {
|
||||||
res := make([]map[string]interface{}, 0, len(ll.Data))
|
res := make([]map[string]interface{}, 0, len(ll.Data))
|
||||||
for _, l := range ll.Data {
|
for _, l := range ll.Data {
|
||||||
temp := map[string]interface{}{
|
temp := map[string]interface{}{
|
||||||
"ckey": l.CKey,
|
"ckey": l.CKey,
|
||||||
"meta": flattens.FlattenMeta(l.Meta),
|
"meta": flattens.FlattenMeta(l.Meta),
|
||||||
"auth_broker": l.AuthBroker,
|
"auth_broker": l.AuthBroker,
|
||||||
"flag": l.Flag,
|
"flag": l.Flag,
|
||||||
"gid": l.GID,
|
"gid": l.GID,
|
||||||
"guid": l.GUID,
|
"guid": l.GUID,
|
||||||
"id": l.ID,
|
"id": l.ID,
|
||||||
"location_code": l.LocationCode,
|
"location_code": l.LocationCode,
|
||||||
"name": l.Name,
|
"name": l.Name,
|
||||||
}
|
}
|
||||||
res = append(res, temp)
|
res = append(res, temp)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceLocationsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
locations, err := utilityLocationsListCheckPresence(ctx, d, m)
|
locations, err := utilityLocationsListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
d.SetId(id.String())
|
d.SetId(id.String())
|
||||||
|
|
||||||
d.Set("items", flattenLocationsList(locations))
|
d.Set("items", flattenLocationsList(locations))
|
||||||
d.Set("entry_count", locations.EntryCount)
|
d.Set("entry_count", locations.EntryCount)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
|
func dataSourceLocationsListSchemaMake() map[string]*schema.Schema {
|
||||||
return map[string]*schema.Schema{
|
return map[string]*schema.Schema{
|
||||||
"flag": {
|
"flag": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by flag",
|
Description: "Filter by flag",
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by name",
|
Description: "Filter by name",
|
||||||
},
|
},
|
||||||
"by_id": {
|
"by_id": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by ID",
|
Description: "Filter by ID",
|
||||||
},
|
},
|
||||||
"location_code": {
|
"location_code": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Filter by location code",
|
Description: "Filter by location code",
|
||||||
},
|
},
|
||||||
"page": {
|
"sort_by": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "page number",
|
Description: "sort by one of supported fields, format +|-(field)",
|
||||||
},
|
},
|
||||||
"size": {
|
"page": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "page size",
|
Description: "page number",
|
||||||
},
|
},
|
||||||
"items": {
|
"size": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Optional: true,
|
||||||
Description: "Locations list",
|
Description: "page size",
|
||||||
Elem: &schema.Resource{
|
},
|
||||||
Schema: map[string]*schema.Schema{
|
"items": {
|
||||||
"ckey": {
|
Type: schema.TypeList,
|
||||||
Type: schema.TypeString,
|
Computed: true,
|
||||||
Computed: true,
|
Description: "Locations list",
|
||||||
},
|
Elem: &schema.Resource{
|
||||||
"meta": {
|
Schema: map[string]*schema.Schema{
|
||||||
Type: schema.TypeList,
|
"ckey": {
|
||||||
Computed: true,
|
Type: schema.TypeString,
|
||||||
Elem: &schema.Schema{
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
},
|
||||||
},
|
"meta": {
|
||||||
},
|
Type: schema.TypeList,
|
||||||
"auth_broker": {
|
Computed: true,
|
||||||
Type: schema.TypeList,
|
Elem: &schema.Schema{
|
||||||
Computed: true,
|
Type: schema.TypeString,
|
||||||
Elem: &schema.Schema{
|
},
|
||||||
Type: schema.TypeString,
|
},
|
||||||
},
|
"auth_broker": {
|
||||||
},
|
Type: schema.TypeList,
|
||||||
"flag": {
|
Computed: true,
|
||||||
Type: schema.TypeString,
|
Elem: &schema.Schema{
|
||||||
Computed: true,
|
Type: schema.TypeString,
|
||||||
},
|
},
|
||||||
"gid": {
|
},
|
||||||
Type: schema.TypeInt,
|
"flag": {
|
||||||
Computed: true,
|
Type: schema.TypeString,
|
||||||
Description: "Grid id",
|
Computed: true,
|
||||||
},
|
},
|
||||||
"guid": {
|
"gid": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "location id",
|
Description: "Grid id",
|
||||||
},
|
},
|
||||||
"id": {
|
"guid": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "location id",
|
Description: "location id",
|
||||||
},
|
},
|
||||||
"location_code": {
|
"id": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "Location code",
|
Description: "location id",
|
||||||
},
|
},
|
||||||
"name": {
|
"location_code": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "Location name",
|
Description: "Location code",
|
||||||
},
|
},
|
||||||
},
|
"name": {
|
||||||
},
|
Type: schema.TypeString,
|
||||||
},
|
Computed: true,
|
||||||
"entry_count": {
|
Description: "Location name",
|
||||||
Type: schema.TypeInt,
|
},
|
||||||
Computed: true,
|
},
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
"entry_count": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
func DataSourceLocationsList() *schema.Resource {
|
Computed: true,
|
||||||
return &schema.Resource{
|
},
|
||||||
SchemaVersion: 1,
|
}
|
||||||
|
}
|
||||||
ReadContext: dataSourceLocationsListRead,
|
|
||||||
|
func DataSourceLocationsList() *schema.Resource {
|
||||||
Timeouts: &schema.ResourceTimeout{
|
return &schema.Resource{
|
||||||
Read: &constants.Timeout30s,
|
SchemaVersion: 1,
|
||||||
Default: &constants.Timeout60s,
|
|
||||||
},
|
ReadContext: dataSourceLocationsListRead,
|
||||||
|
|
||||||
Schema: dataSourceLocationsListSchemaMake(),
|
Timeouts: &schema.ResourceTimeout{
|
||||||
}
|
Read: &constants.Timeout30s,
|
||||||
}
|
Default: &constants.Timeout60s,
|
||||||
|
},
|
||||||
|
|
||||||
|
Schema: dataSourceLocationsListSchemaMake(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,85 +1,85 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package locations
|
package locations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceLocationUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceLocationUrlRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
url, err := utilityLocationUrlCheckPresence(ctx, m)
|
url, err := utilityLocationUrlCheckPresence(ctx, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
d.SetId(id.String())
|
d.SetId(id.String())
|
||||||
|
|
||||||
url = strings.ReplaceAll(url, "\\", "")
|
url = strings.ReplaceAll(url, "\\", "")
|
||||||
url = strings.ReplaceAll(url, "\"", "")
|
url = strings.ReplaceAll(url, "\"", "")
|
||||||
d.Set("url", url)
|
d.Set("url", url)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceLocationUrlSchemaMake() map[string]*schema.Schema {
|
func dataSourceLocationUrlSchemaMake() map[string]*schema.Schema {
|
||||||
return map[string]*schema.Schema{
|
return map[string]*schema.Schema{
|
||||||
"url": {
|
"url": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "Location url",
|
Description: "Location url",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DataSourceLocationUrl() *schema.Resource {
|
func DataSourceLocationUrl() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
|
|
||||||
ReadContext: dataSourceLocationUrlRead,
|
ReadContext: dataSourceLocationUrlRead,
|
||||||
|
|
||||||
Timeouts: &schema.ResourceTimeout{
|
Timeouts: &schema.ResourceTimeout{
|
||||||
Read: &constants.Timeout30s,
|
Read: &constants.Timeout30s,
|
||||||
Default: &constants.Timeout60s,
|
Default: &constants.Timeout60s,
|
||||||
},
|
},
|
||||||
|
|
||||||
Schema: dataSourceLocationUrlSchemaMake(),
|
Schema: dataSourceLocationUrlSchemaMake(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,80 +1,84 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||||
Authors:
|
Authors:
|
||||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||||
Orchestration Technology) with Terraform by Hashicorp.
|
Orchestration Technology) with Terraform by Hashicorp.
|
||||||
|
|
||||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||||
|
|
||||||
Please see README.md to learn where to place source code so that it
|
Please see README.md to learn where to place source code so that it
|
||||||
builds seamlessly.
|
builds seamlessly.
|
||||||
|
|
||||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package locations
|
package locations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
|
||||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*locations.ListLocations, error) {
|
func utilityLocationsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*locations.ListLocations, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
req := locations.ListRequest{}
|
req := locations.ListRequest{}
|
||||||
|
|
||||||
if page, ok := d.GetOk("page"); ok {
|
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||||
req.Page = uint64(page.(int))
|
req.SortBy = sortBy.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if size, ok := d.GetOk("size"); ok {
|
if page, ok := d.GetOk("page"); ok {
|
||||||
req.Size = uint64(size.(int))
|
req.Page = uint64(page.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if by_id, ok := d.GetOk("by_id"); ok {
|
if size, ok := d.GetOk("size"); ok {
|
||||||
req.ByID = uint64(by_id.(int))
|
req.Size = uint64(size.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag, ok := d.GetOk("flag"); ok {
|
if by_id, ok := d.GetOk("by_id"); ok {
|
||||||
req.Flag = flag.(string)
|
req.ByID = uint64(by_id.(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := d.GetOk("name"); ok {
|
if flag, ok := d.GetOk("flag"); ok {
|
||||||
req.Name = name.(string)
|
req.Flag = flag.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if location_code, ok := d.GetOk("location_code"); ok {
|
if name, ok := d.GetOk("name"); ok {
|
||||||
req.LocationCode = location_code.(string)
|
req.Name = name.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityLocationsListCheckPresence: load locations list")
|
if location_code, ok := d.GetOk("location_code"); ok {
|
||||||
locationsList, err := c.CloudAPI().Locations().List(ctx, req)
|
req.LocationCode = location_code.(string)
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
log.Debugf("utilityLocationsListCheckPresence: load locations list")
|
||||||
|
locationsList, err := c.CloudAPI().Locations().List(ctx, req)
|
||||||
return locationsList, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return locationsList, nil
|
||||||
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue