This commit is contained in:
2023-07-26 13:32:39 +03:00
parent f731cf246f
commit 272e385318
167 changed files with 5194 additions and 890 deletions

View File

@@ -48,7 +48,7 @@ func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceDat
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAccountList(accountDeletedList))
d.Set("items", flattenListDeleted(accountDeletedList))
return nil
}

View File

@@ -8,7 +8,7 @@ import (
func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("dc_location", acc.DCLocation)
d.Set("resources", flattenAccResources(acc.Resources))
// d.Set("resources", flattenAccResources(acc.Resources))
d.Set("ckey", acc.CKey)
d.Set("acl", flattenAccAcl(acc.ACL))
d.Set("company", acc.Company)
@@ -32,7 +32,7 @@ func flattenResourceAccount(d *schema.ResourceData, acc *account.RecordAccount)
func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
d.Set("dc_location", acc.DCLocation)
d.Set("resources", flattenAccResources(acc.Resources))
// d.Set("resources", flattenAccResources(acc.Resources))
d.Set("ckey", acc.CKey)
// d.Set("meta", flattens.FlattenMeta(acc.))
d.Set("acl", flattenAccAcl(acc.ACL))
@@ -57,9 +57,9 @@ func flattenDataAccount(d *schema.ResourceData, acc *account.RecordAccount) {
}
func flattenAccountRGList(argl account.ListRG) []map[string]interface{} {
func flattenAccountRGList(argl *account.ListRG) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, arg := range argl {
for _, arg := range argl.Data {
temp := map[string]interface{}{
"computes": flattenAccRGComputes(arg.Computes),
"resources": flattenAccRGResources(arg.Resources),
@@ -102,7 +102,7 @@ func flattenAccRGResources(argr account.RGResuorces) []map[string]interface{} {
return res
}
func flattenAccResources(r account.RecordResources) []map[string]interface{} {
func flattenAccResources(r account.RecordResourceConsumption) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"current": flattenAccResource(r.Current),
@@ -201,9 +201,51 @@ func flattenRgAcl(rgAcls []account.ACL) []map[string]interface{} {
return res
}
func flattenAccountList(al account.ListAccounts) []map[string]interface{} {
func flattenListDeleted(al *account.ListAccounts) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, acc := range al {
for _, acc := range al.Data {
temp := map[string]interface{}{
"dc_location": acc.DCLocation,
"ckey": acc.CKey,
"meta": flattens.FlattenMeta(acc.Meta),
"acl": flattenRgAcl(acc.ACL),
"company": acc.Company,
"companyurl": acc.CompanyURL,
"created_by": acc.CreatedBy,
"created_time": acc.CreatedTime,
"deactivation_time": acc.DeactivationTime,
"deleted_by": acc.DeletedBy,
"deleted_time": acc.DeletedTime,
"displayname": acc.DisplayName,
"guid": acc.GUID,
"account_id": acc.ID,
"account_name": acc.Name,
"resource_limits": flattenRgResourceLimits(acc.ResourceLimits),
"send_access_emails": acc.SendAccessEmails,
// "service_account": acc.ServiceAccount,
"status": acc.Status,
"updated_time": acc.UpdatedTime,
"version": acc.Version,
"vins": acc.VINS,
}
res = append(res, temp)
}
return res
}
func flattenAccountList(al *account.ListAccounts) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, acc := range al.Data {
temp := map[string]interface{}{
"dc_location": acc.DCLocation,
"ckey": acc.CKey,
@@ -258,9 +300,9 @@ func flattenAccountAuditsList(aal account.ListAudits) []map[string]interface{} {
return res
}
func flattenAccountComputesList(acl account.ListComputes) []map[string]interface{} {
func flattenAccountComputesList(acl *account.ListComputes) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, acc := range acl {
for _, acc := range acl.Data {
temp := map[string]interface{}{
"account_id": acc.AccountID,
"account_name": acc.AccountName,
@@ -288,9 +330,9 @@ func flattenAccountComputesList(acl account.ListComputes) []map[string]interface
return res
}
func flattenAccountDisksList(adl account.ListDisks) []map[string]interface{} {
func flattenAccountDisksList(adl *account.ListDisks) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, ad := range adl {
for _, ad := range adl.Data {
temp := map[string]interface{}{
"disk_id": ad.ID,
"disk_name": ad.Name,
@@ -304,9 +346,9 @@ func flattenAccountDisksList(adl account.ListDisks) []map[string]interface{} {
return res
}
func flattenAccountFlipGroupsList(afgl account.ListFLIPGroups) []map[string]interface{} {
func flattenAccountFlipGroupsList(afgl *account.ListFLIPGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, afg := range afgl {
for _, afg := range afgl.Data {
temp := map[string]interface{}{
"account_id": afg.AccountID,
"client_type": afg.ClientType,
@@ -335,9 +377,9 @@ func flattenAccountFlipGroupsList(afgl account.ListFLIPGroups) []map[string]inte
return res
}
func flattenAccountVinsList(avl account.ListVINS) []map[string]interface{} {
func flattenAccountVinsList(avl *account.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, av := range avl {
for _, av := range avl.Data {
temp := map[string]interface{}{
"account_id": av.AccountID,
"account_name": av.AccountName,

View File

@@ -41,7 +41,7 @@ import (
"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)
req := account.ListComputesRequest{
AccountID: uint64(d.Get("account_id").(int)),

View File

@@ -41,7 +41,7 @@ import (
"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)
req := account.ListDeletedRequest{}

View File

@@ -41,7 +41,7 @@ import (
"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)
req := account.ListDisksRequest{
AccountID: uint64(d.Get("account_id").(int)),

View File

@@ -41,7 +41,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (account.ListFLIPGroups, error) {
func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*account.ListFLIPGroups, error) {
c := m.(*controller.ControllerCfg)
req := account.ListFLIPGroupsRequest{
AccountID: uint64(d.Get("account_id").(int)),

View File

@@ -41,7 +41,7 @@ import (
"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)
req := account.ListRequest{}

View File

@@ -41,7 +41,7 @@ import (
"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)
req := account.ListRGRequest{
AccountID: uint64(d.Get("account_id").(int)),

View File

@@ -41,7 +41,7 @@ import (
"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)
req := account.ListVINSRequest{
AccountID: uint64(d.Get("account_id").(int)),

View File

@@ -76,9 +76,9 @@ func flattenIOTune(iot disks.IOTune) []map[string]interface{} {
return res
}
func flattenDiskList(dl disks.ListDisks) []map[string]interface{} {
func flattenDiskList(dl *disks.ListDisks) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, disk := range dl {
for _, disk := range dl.Data {
diskAcl, _ := json.Marshal(disk.ACL)
temp := map[string]interface{}{
"account_id": disk.AccountID,

View File

@@ -42,7 +42,7 @@ import (
"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)
req := disks.ListRequest{}

View File

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

View File

@@ -0,0 +1,80 @@
/*
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 extnet
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
extnetId, err := utilityExtnetDefaultCheckPresence(ctx, m)
if err != nil {
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("net_id", extnetId)
return nil
}
func dataSourceExtnetDefaultSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"net_id": {
Type: schema.TypeInt,
Computed: true,
},
}
}
func DataSourceExtnetDefaultCB() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceExtnetDefaultRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceExtnetDefaultSchemaMake(),
}
}

View File

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

View File

@@ -0,0 +1,161 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenListExtnet(extList *extnet.ListExtNet) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range extList.Data {
temp := map[string]interface{}{
"ckey": item.CKey,
"meta": flattens.FlattenMeta(item.Meta),
"default": item.Default,
"desc": item.Description,
"free_ips": item.FreeIPs,
"gid": item.GID,
"guid": item.GUID,
"extnet_id": item.ID,
"ipcidr": item.IPCIDR,
"milestones": item.Milestones,
"name": item.Name,
"network_id": item.NetworkID,
"ovs_bridge": item.OVSBridge,
"pre_reservations_num": item.PreReservationsNum,
"pri_vnfdev_id": item.PriVNFDevID,
"shared_with": item.SharedWith,
"status": item.Status,
"vlan_id": item.VLANID,
"check_ips": item.CheckIPs,
}
res = append(res, temp)
}
return res
}
func flattenRecordExtnet(d *schema.ResourceData, recNet *extnet.RecordExtNet) {
d.Set("ckey", recNet.CKey)
d.Set("meta", flattens.FlattenMeta(recNet.Meta))
d.Set("default", recNet.Default)
d.Set("desc", recNet.Description)
d.Set("free_ips", recNet.FreeIPs)
d.Set("gid", recNet.GID)
d.Set("guid", recNet.GUID)
d.Set("extnet_id", recNet.ID)
d.Set("ipcidr", recNet.IPCIDR)
d.Set("milestones", recNet.Milestones)
d.Set("name", recNet.Name)
d.Set("network_id", recNet.NetworkID)
d.Set("ovs_bridge", recNet.OVSBridge)
d.Set("pre_reservations_num", recNet.PreReservationsNum)
d.Set("pri_vnfdev_id", recNet.PriVNFDevID)
d.Set("shared_with", recNet.SharedWith)
d.Set("status", recNet.Status)
d.Set("vlan_id", recNet.VLANID)
d.Set("check_ips", recNet.CheckIPs)
d.Set("dns", recNet.DNS)
d.Set("excluded", flattenExtnetExcluded(recNet.Excluded))
d.Set("gateway", recNet.Gateway)
d.Set("network", recNet.Network)
d.Set("prefix", recNet.Prefix)
d.Set("default_qos", flattenExtnetDefaultQos(recNet.DefaultQOS))
d.Set("vnfs", flattenExtnetVNFS(recNet.VNFs))
d.Set("reservations", flattenExtnetReservations(recNet.Reservations))
}
func flattenExtnetExcluded(ers extnet.ListReservations) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, er := range ers {
temp := map[string]interface{}{
"client_type": er.ClientType,
"domain_name": er.DomainName,
"hostname": er.Hostname,
"ip": er.IP,
"mac": er.MAC,
"type": er.Type,
"vm_id": er.VMID,
}
res = append(res, temp)
}
return res
}
func flattenExtnetReservations(ers extnet.ListReservations) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, er := range ers {
temp := map[string]interface{}{
"client_type": er.ClientType,
"domain_name": er.DomainName,
"hostname": er.Hostname,
"desc": er.Description,
"ip": er.IP,
"mac": er.MAC,
"type": er.Type,
"vm_id": er.VMID,
}
res = append(res, temp)
}
return res
}
func flattenExtnetVNFS(evnfs extnet.VNFs) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"dhcp": evnfs.DHCP,
}
res = append(res, temp)
return res
}
func flattenExtnetDefaultQos(edqos extnet.QOS) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"e_rate": edqos.ERate,
"guid": edqos.GUID,
"in_burst": edqos.InBurst,
"in_rate": edqos.InRate,
}
res = append(res, temp)
return res
}

View File

@@ -0,0 +1,542 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceExtnetCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("cloudbroker: resourceExtnetCreate called with name '%s'", d.Get("name").(string))
c := m.(*controller.ControllerCfg)
req := extnet.CreateRequest{
Name: d.Get("name").(string),
GID: uint64(d.Get("gid").(int)),
IPCIDR: d.Get("ipcidr").(string),
VLANID: uint64(d.Get("vlan_id").(int)),
}
if gateway, ok := d.GetOk("gateway"); ok {
req.Gateway = gateway.(string)
}
if dns, ok := d.GetOk("dns"); ok {
res := make([]string, 0)
for _, elem := range dns.([]interface{}) {
res = append(res, elem.(string))
}
req.DNS = res
}
if ntp, ok := d.GetOk("ntp"); ok {
res := make([]string, 0)
for _, elem := range ntp.([]interface{}) {
res = append(res, elem.(string))
}
req.NTP = res
}
if check_ips, ok := d.GetOk("check_ips"); ok {
res := make([]string, 0)
for _, elem := range check_ips.([]interface{}) {
res = append(res, elem.(string))
}
req.CheckIPs = res
}
if virtual, ok := d.GetOk("virtual"); ok {
req.Virtual = virtual.(bool)
}
if desc, ok := d.GetOk("desc"); ok {
req.Description = desc.(string)
}
if start_ip, ok := d.GetOk("start_ip"); ok {
req.StartIP = start_ip.(string)
}
if end_ip, ok := d.GetOk("end_ip"); ok {
req.EndIP = end_ip.(string)
}
if vnfdev_ip, ok := d.GetOk("vnfdev_ip"); ok {
req.VNFDevIP = vnfdev_ip.(string)
}
if pre_reservations_num, ok := d.GetOk("pre_reservations_num"); ok {
req.PreReservationsNum = uint64(pre_reservations_num.(int))
}
if ovs_bridge, ok := d.GetOk("ovs_bridge"); ok {
req.OVSBridge = ovs_bridge.(string)
}
log.Debugf("cloudbroker: Sent create request")
netID, err := c.CloudBroker().ExtNet().Create(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(netID, 10))
log.Debugf("cloudbroker: Extnet with id %d successfully created on platform", netID)
if d.Get("excluded_ips").(*schema.Set).Len() > 0 {
ips := make([]string, 0)
for _, ip := range d.Get("excluded_ips").(*schema.Set).List() {
ips = append(ips, ip.(string))
}
req := extnet.IPsExcludeRequest{
NetID: netID,
IPs: ips,
}
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
if err != nil {
return diag.FromErr(err)
}
}
return resourceExtnetRead(ctx, d, m)
}
func resourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("cloudbroker: resourceExtnetRead called with id %s", d.Id())
recNet, err := utilityExtnetCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenRecordExtnet(d, recNet)
return nil
}
func resourceExtnetUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("cloudbroker: resourceExtnetUpdate called with id %s", d.Id())
c := m.(*controller.ControllerCfg)
recNet, err := utilityExtnetCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if err := handleBasicUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
if d.HasChange("enable") {
if err := handleEnableUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("default_qos") {
if err := handleDefaultQOSUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("dns") {
if err := handleDNSUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("ntp") {
if err := handleNTPUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("set_default") {
if err := handleSetDefault(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
if d.HasChange("excluded_ips") {
if err := handleExcludedIPsUpdate(ctx, d, c, recNet); err != nil {
return diag.FromErr(err)
}
}
return resourceExtnetRead(ctx, d, m)
}
func resourceExtnetDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("cloudbroker: resourceExtnetDelete called with id %s", d.Id())
c := m.(*controller.ControllerCfg)
netId, _ := strconv.ParseUint(d.Id(), 10, 64)
req := extnet.DestroyRequest{NetID: netId}
_, err := c.CloudBroker().ExtNet().Destroy(ctx, req)
if err != nil {
return diag.FromErr(err)
}
log.Debugf("cloudbroker: successfully destroyed extnet with id %s", d.Id())
return nil
}
func resourceExtnetSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "External network name",
},
"gid": {
Type: schema.TypeInt,
Required: true,
Description: "Grid (platform) ID",
},
"ipcidr": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "IP network CIDR",
},
"vlan_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "VLAN ID",
},
"gateway": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "External network gateway IP address",
},
"dns": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of DNS addresses",
},
"ntp": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of NTP addresses",
},
"check_ips": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "IPs to check network availability",
},
"virtual": {
Type: schema.TypeBool,
Optional: true,
Description: "If true - platform DHCP server will not be created",
},
"desc": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Optional description",
},
"start_ip": {
Type: schema.TypeString,
Optional: true,
Description: "Start of IP range to be explicitly included",
},
"end_ip": {
Type: schema.TypeString,
Optional: true,
Description: "End of IP range to be explicitly included",
},
"vnfdev_ip": {
Type: schema.TypeString,
Optional: true,
Description: "IP to create VNFDev with",
},
"pre_reservations_num": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Number of pre created reservations",
},
"ovs_bridge": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "OpenvSwith bridge name for ExtNet connection",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Disable/Enable extnet",
},
"set_default": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Set current extnet as default (can not be undone)",
},
"excluded_ips": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "IPs to exclude in current extnet pool",
},
"default_qos": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"e_rate": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"in_burst": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"in_rate": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
},
},
},
"ckey": {
Type: schema.TypeString,
Computed: true,
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "meta",
},
"default": {
Type: schema.TypeBool,
Computed: true,
},
"free_ips": {
Type: schema.TypeInt,
Computed: true,
},
"guid": {
Type: schema.TypeInt,
Computed: true,
},
"extnet_id": {
Type: schema.TypeInt,
Computed: true,
},
"milestones": {
Type: schema.TypeInt,
Computed: true,
},
"network_id": {
Type: schema.TypeInt,
Computed: true,
},
"pri_vnfdev_id": {
Type: schema.TypeInt,
Computed: true,
},
"shared_with": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"vnfs": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dhcp": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"excluded": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_type": {
Type: schema.TypeString,
Computed: true,
},
"domain_name": {
Type: schema.TypeString,
Computed: true,
},
"hostname": {
Type: schema.TypeString,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"mac": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"vm_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"network": {
Type: schema.TypeString,
Computed: true,
},
"prefix": {
Type: schema.TypeInt,
Computed: true,
},
"reservations": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_type": {
Type: schema.TypeString,
Computed: true,
},
"domain_name": {
Type: schema.TypeString,
Computed: true,
},
"hostname": {
Type: schema.TypeString,
Computed: true,
},
"desc": {
Type: schema.TypeString,
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"mac": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"vm_id": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
}
}
func ResourceExtnetCB() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: resourceExtnetRead,
CreateContext: resourceExtnetCreate,
UpdateContext: resourceExtnetUpdate,
DeleteContext: resourceExtnetDelete,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout300s,
Create: &constants.Timeout300s,
Update: &constants.Timeout300s,
Delete: &constants.Timeout300s,
Default: &constants.Timeout300s,
},
Schema: resourceExtnetSchemaMake(),
}
}

View File

@@ -0,0 +1,288 @@
/*
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Kasim Baybikov, <kmbaybikov@basistech.ru>
Tim Tkachev, <tvtkachev@basistech.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package extnet
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
)
func handleExcludedIPsUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
old_set, new_set := d.GetChange("excluded_ips")
detach_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
if detach_set.Len() > 0 {
ips := make([]string, 0)
for _, detach_ip := range detach_set.List() {
ips = append(ips, detach_ip.(string))
}
log.Debugf("cloudbroker: removing %d IP address(es) from excluded list", detach_set.Len())
req := extnet.IPsIncludeRequest{
NetID: recNet.ID,
IPs: ips,
}
_, err := c.CloudBroker().ExtNet().IPsInclude(ctx, req)
if err != nil {
return err
}
}
attach_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
if attach_set.Len() > 0 {
ips := make([]string, 0)
for _, attach_ip := range attach_set.List() {
ips = append(ips, attach_ip.(string))
}
log.Debugf("cloudbroker: excluding %d IP address(es) from extnet with id %d", attach_set.Len(), recNet.ID)
req := extnet.IPsExcludeRequest{
NetID: recNet.ID,
IPs: ips,
}
_, err := c.CloudBroker().ExtNet().IPsExclude(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleSetDefault(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
set_default := d.Get("set_default").(bool)
if set_default && recNet.Default == false {
req := extnet.SetDefaultRequest{
NetID: recNet.ID,
}
_, err := c.CloudBroker().ExtNet().SetDefault(ctx, req)
if err != nil {
return err
}
}
return nil
}
func handleBasicUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
doBasicUpdate := false
basiUpdateReq := extnet.UpdateRequest{NetID: recNet.ID}
if d.HasChange("name") {
basiUpdateReq.Name = d.Get("name").(string)
doBasicUpdate = true
}
if d.HasChange("desc") {
basiUpdateReq.Description = d.Get("desc").(string)
doBasicUpdate = true
}
if doBasicUpdate {
_, err := c.CloudBroker().ExtNet().Update(ctx, basiUpdateReq)
if err != nil {
return err
}
}
return nil
}
func handleEnableUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
enable := d.Get("enable").(bool)
if enable {
if recNet.Status == status.Disabled {
req := extnet.EnableRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().Enable(ctx, req)
if err != nil {
return err
}
}
} else {
if recNet.Status == status.Enabled {
req := extnet.DisableRequest{NetID: recNet.ID}
_, err := c.CloudBroker().ExtNet().Disable(ctx, req)
if err != nil {
return err
}
}
}
return nil
}
func handleDefaultQOSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
qos := d.Get("default_qos").([]interface{})[0].(map[string]interface{})
req := extnet.DefaultQOSUpdateRequest{
NetID: recNet.ID,
IngressRate: uint64(qos["in_rate"].(int)),
IngressBurst: uint64(qos["in_burst"].(int)),
EgressRate: uint64(qos["e_rate"].(int)),
}
_, err := c.CloudBroker().ExtNet().DefaultQOSUpdate(ctx, req)
if err != nil {
return err
}
return nil
}
func handleNTPUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
changed_list := d.Get("ntp").([]interface{})
ntp_list := make([]string, 0)
for _, ntp_address := range changed_list {
ntp_list = append(ntp_list, ntp_address.(string))
}
req := extnet.NTPApplyRequest{
NetID: recNet.ID,
NTPList: ntp_list,
}
_, err := c.CloudBroker().ExtNet().NTPApply(ctx, req)
if err != nil {
return err
}
return nil
}
func handleDNSUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, recNet *extnet.RecordExtNet) error {
changed_list := d.Get("dns").([]interface{})
dns_list := make([]string, 0)
for _, dns_address := range changed_list {
dns_list = append(dns_list, dns_address.(string))
}
req := extnet.DNSApplyRequest{
NetID: recNet.ID,
DNSList: dns_list,
}
_, err := c.CloudBroker().ExtNet().DNSApply(ctx, req)
if err != nil {
return err
}
return nil
}
func utilityExtnetDefaultCheckPresence(ctx context.Context, m interface{}) (uint64, error) {
c := m.(*controller.ControllerCfg)
return c.CloudBroker().ExtNet().GetDefault(ctx)
}
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.ListExtNet, error) {
c := m.(*controller.ControllerCfg)
req := extnet.ListRequest{}
if accountId, ok := d.GetOk("account_id"); ok {
req.AccountID = uint64(accountId.(int))
}
if by_id, ok := d.GetOk("by_id"); ok {
req.ByID = uint64(by_id.(int))
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
if network, ok := d.GetOk("network"); ok {
req.Network = network.(string)
}
if vlan_id, ok := d.GetOk("vlan_id"); ok {
req.VLANID = uint64(vlan_id.(int))
}
if vnfdev_id, ok := d.GetOk("vnfdev_id"); ok {
req.VNFDevID = uint64(vnfdev_id.(int))
}
if status, ok := d.GetOk("status"); ok {
req.Status = status.(string)
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))
}
if size, ok := d.GetOk("size"); ok {
req.Size = uint64(size.(int))
}
res, err := c.CloudBroker().ExtNet().List(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}
func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*extnet.RecordExtNet, error) {
c := m.(*controller.ControllerCfg)
var netId uint64
if id, ok := d.GetOk("net_id"); ok {
netId = uint64(id.(int))
} else {
parsed, _ := strconv.ParseUint(d.Id(), 10, 64)
netId = parsed
}
req := extnet.GetRequest{
NetID: netId,
}
res, err := c.CloudBroker().ExtNet().Get(ctx, req)
if err != nil {
return nil, err
}
return res, nil
}

View File

@@ -14,9 +14,9 @@ func flattenGrid(d *schema.ResourceData, grid *grid.RecordGrid) {
d.Set("id", grid.ID)
}
func flattenGridList(gl grid.ListGrids) []map[string]interface{} {
func flattenGridList(gl *grid.ListGrids) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range gl {
for _, item := range gl.Data {
temp := map[string]interface{}{
"name": item.Name,
"flag": item.Flag,

View File

@@ -41,7 +41,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityGridListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (grid.ListGrids, error) {
func utilityGridListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*grid.ListGrids, error) {
c := m.(*controller.ControllerCfg)
req := grid.ListRequest{}

View File

@@ -59,11 +59,6 @@ func dataSourceImageListSchemaMake() map[string]*schema.Schema {
Optional: true,
Description: "filter images by storage endpoint provider ID",
},
"shared_with": {
Type: schema.TypeInt,
Optional: true,
Description: "filter images by account ID availability",
},
"page": {
Type: schema.TypeInt,
Optional: true,

View File

@@ -82,9 +82,9 @@ func flattenHistory(history []image.History) []map[string]interface{} {
return temp
}
func flattenImageList(il image.ListImages) []map[string]interface{} {
func flattenImageList(il *image.ListImages) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range il {
for _, item := range il.Data {
temp := map[string]interface{}{
"name": item.Name,
"url": item.URL,
@@ -130,9 +130,9 @@ func flattenImageList(il image.ListImages) []map[string]interface{} {
return res
}
func flattenImageListStacks(_ *schema.ResourceData, stack image.ListStacks) []map[string]interface{} {
func flattenImageListStacks(_ *schema.ResourceData, stack *image.ListStacks) []map[string]interface{} {
temp := make([]map[string]interface{}, 0)
for _, item := range stack {
for _, item := range stack.Data {
t := map[string]interface{}{
"api_url": item.APIURL,
"api_key": item.APIKey,

View File

@@ -41,16 +41,13 @@ import (
"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)
req := image.ListRequest{}
if sepId, ok := d.GetOk("sep_id"); ok {
req.SepID = uint64(sepId.(int))
}
if sharedWith, ok := d.GetOk("shared_with"); ok {
req.SharedWith = uint64(sharedWith.(int))
}
if page, ok := d.GetOk("page"); ok {
req.Page = uint64(page.(int))

View File

@@ -41,7 +41,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (image.ListStacks, error) {
func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*image.ListStacks, error) {
c := m.(*controller.ControllerCfg)
req := image.ListStacksRequest{
ImageID: uint64(d.Get("image_id").(int)),

View File

@@ -75,14 +75,12 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
reqPPC.RAM = uint64(d.Get("ram").(int))
reqPPC.ImageID = uint64(d.Get("image_id").(int))
reqPPC.BootDisk = uint64(d.Get("boot_disk_size").(int))
reqPPC.NetType = "NONE"
reqPPC.Start = false
reqX86.CPU = uint64(d.Get("cpu").(int))
reqX86.RAM = uint64(d.Get("ram").(int))
reqX86.ImageID = uint64(d.Get("image_id").(int))
reqX86.BootDisk = uint64(d.Get("boot_disk_size").(int))
reqX86.NetType = "NONE"
reqX86.Start = false
argVal, argSet := d.GetOk("description")

View File

@@ -269,8 +269,8 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m
return nil, err
}
log.Debugf("utilityComputeCheckPresence: traversing decoded JSON of length %d", len(computeList))
for index, item := range computeList {
log.Debugf("utilityComputeCheckPresence: traversing decoded JSON of length %d", len(computeList.Data))
for index, item := range computeList.Data {
// need to match Compute by name, skip Computes with the same name in DESTROYED satus
if item.Name == computeName.(string) && item.Status != "DESTROYED" {
log.Debugf("utilityComputeCheckPresence: index %d, matched name %s", index, item.Name)

View File

@@ -42,9 +42,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenPcideviceList(pl pcidevice.ListPCIDevices) []map[string]interface{} {
func flattenPcideviceList(pl *pcidevice.ListPCIDevices) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range pl {
for _, item := range pl.Data {
temp := map[string]interface{}{
"ckey": item.CKey,
"meta": flattens.FlattenMeta(item.Meta),

View File

@@ -53,7 +53,7 @@ func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData,
pcideviceId = id
}
for _, pd := range pcideviceList {
for _, pd := range pcideviceList.Data {
if pd.ID == pcideviceId {
return &pd, nil
}

View File

@@ -38,10 +38,12 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityPcideviceListCheckPresence(ctx context.Context, m interface{}) (pcidevice.ListPCIDevices, error) {
func utilityPcideviceListCheckPresence(ctx context.Context, m interface{}) (*pcidevice.ListPCIDevices, error) {
c := m.(*controller.ControllerCfg)
pcideviceList, err := c.CloudBroker().PCIDevice().List(ctx)
req := pcidevice.ListRequest{}
pcideviceList, err := c.CloudBroker().PCIDevice().List(ctx, req)
if err != nil {
return nil, err
}

View File

@@ -41,9 +41,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenRgList(rgl rg.ListRG) []map[string]interface{} {
func flattenRgList(rgl *rg.ListRG) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, rg := range rgl {
for _, rg := range rgl.Data {
temp := map[string]interface{}{
"account_id": rg.AccountID,
"account_name": rg.AccountName,

View File

@@ -84,8 +84,8 @@ func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m
return nil, err
}
log.Debugf("utilityResgroupCheckPresence: traversing decoded Json of length %d", len(model))
for index, item := range model {
log.Debugf("utilityResgroupCheckPresence: traversing decoded Json of length %d", len(model.Data))
for index, item := range model.Data {
// match by RG name & account ID
if item.Name == rgName.(string) && item.AccountID == uint64(d.Get("account_id").(int)) {
log.Debugf("utilityResgroupCheckPresence: match RG name %s / ID %d, account ID %d at index %d",

View File

@@ -41,7 +41,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListRG, error) {
func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*rg.ListRG, error) {
c := m.(*controller.ControllerCfg)
req := rg.ListRequest{}

View File

@@ -43,9 +43,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenSepList(sl sep.ListSEP) []map[string]interface{} {
func flattenSepList(sl *sep.ListSEP) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, item := range sl {
for _, item := range sl.Data {
data, _ := json.Marshal(item.Config)
temp := map[string]interface{}{
"ckey": item.CKey,

View File

@@ -41,7 +41,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilitySepListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (sep.ListSEP, error) {
func utilitySepListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*sep.ListSEP, error) {
c := m.(*controller.ControllerCfg)
req := sep.ListRequest{}

View File

@@ -65,7 +65,7 @@ func utilityVGPUCheckPresence(ctx context.Context, d *schema.ResourceData, m int
return nil, err
}
for _, vgpu := range vgpus {
for _, vgpu := range vgpus.Data {
if vgpu.ID == vgpuId {
return &vgpu, nil
}

View File

@@ -41,9 +41,9 @@ import (
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func flattenVinsList(vl vins.ListVINS) []map[string]interface{} {
func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
for _, v := range vl {
for _, v := range vl.Data {
temp := map[string]interface{}{
"account_id": v.AccountID,
"account_name": v.AccountName,

View File

@@ -41,7 +41,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListVINS, error) {
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) {
c := m.(*controller.ControllerCfg)
req := vins.ListRequest{}