git test
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
vins, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenVinsData(d, vins)
|
||||
d.SetId(strconv.FormatUint(vins.ID, 10))
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceVins() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceVinsRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: dataSourceVinsSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceVinsAuditsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
audits, err := utilityVinsAuditsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsAudits(audits))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceVinsAudits() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceVinsAuditsRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: DataSourceVinsAuditsSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceVinsExtNetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
extNetList, err := utilityVinsExtNetListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsExtNetList(extNetList))
|
||||
d.Set("entry_count", extNetList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceVinsExtNetList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceVinsExtNetListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: DataSourceVinsExtNetListchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceVinsIpListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
ips, err := utilityVinsIpListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsIpList(ips))
|
||||
d.Set("entry_count", ips.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceVinsIpList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceVinsIpListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: DataSourceVinsIpListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
vinsList, err := utilityVinsListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsList(vinsList))
|
||||
d.Set("entry_count", vinsList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceVinsList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceVinsListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceVinsListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceVinsListDeletedRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
vinsList, err := utilityVinsListDeletedCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsListDeleted(vinsList))
|
||||
d.Set("entry_count", vinsList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceVinsListDeleted() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceVinsListDeletedRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceVinsListDeletedSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceVinsNatRuleListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
natRules, err := utilityVinsNatRuleListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenVinsNatRuleList(natRules))
|
||||
d.Set("entry_count", natRules.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceVinsNatRuleList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceVinsNatRuleListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: DataSourceVinsNatRuleListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(staticRoute.ID, 10))
|
||||
flattenStaticRouteData(d, staticRoute)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStaticRouteListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRouteList, err := utilityStaticRouteListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenStaticRouteList(staticRouteList))
|
||||
d.Set("entry_count", staticRouteList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceStaticRouteList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,672 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 vins
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
|
||||
)
|
||||
|
||||
func flattenVins(d *schema.ResourceData, vinsRecord *vins.RecordVINS) {
|
||||
d.Set("vnf_dev", flattenVinsVNFDev(vinsRecord.VNFDev))
|
||||
d.Set("account_id", vinsRecord.AccountID)
|
||||
d.Set("account_name", vinsRecord.AccountName)
|
||||
d.Set("created_by", vinsRecord.CreatedBy)
|
||||
d.Set("created_time", vinsRecord.CreatedTime)
|
||||
d.Set("default_gw", vinsRecord.DefaultGW)
|
||||
d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS))
|
||||
d.Set("deleted_by", vinsRecord.DeletedBy)
|
||||
d.Set("deleted_time", vinsRecord.DeletedTime)
|
||||
d.Set("description", vinsRecord.Description)
|
||||
d.Set("gid", vinsRecord.GID)
|
||||
d.Set("guid", vinsRecord.GUID)
|
||||
d.Set("vins_id", vinsRecord.ID)
|
||||
d.Set("lock_status", vinsRecord.LockStatus)
|
||||
d.Set("manager_id", vinsRecord.ManagerID)
|
||||
d.Set("manager_type", vinsRecord.ManagerType)
|
||||
d.Set("milestones", vinsRecord.Milestones)
|
||||
d.Set("name", vinsRecord.Name)
|
||||
d.Set("netmask", vinsRecord.NetMask)
|
||||
d.Set("network", vinsRecord.Network)
|
||||
d.Set("pre_reservations_num", vinsRecord.PreReservationsNum)
|
||||
d.Set("redundant", vinsRecord.Redundant)
|
||||
d.Set("rg_id", vinsRecord.RGID)
|
||||
d.Set("rg_name", vinsRecord.RGName)
|
||||
d.Set("sec_vnf_dev_id", vinsRecord.SecVNFDevID)
|
||||
d.Set("status", vinsRecord.Status)
|
||||
d.Set("updated_by", vinsRecord.UpdatedBy)
|
||||
d.Set("updated_time", vinsRecord.UpdatedTime)
|
||||
d.Set("user_managed", vinsRecord.UserManaged)
|
||||
d.Set("vnfs", flattenVinsRecordVNFs(vinsRecord.VNFs))
|
||||
d.Set("vxlan_id", vinsRecord.VXLANID)
|
||||
d.Set("nat_rule", flattenRuleBlock(vinsRecord.VNFs.NAT.Config.Rules))
|
||||
d.Set("computes", flattenComputes(vinsRecord.Computes))
|
||||
d.Set("zone_id", vinsRecord.ZoneID)
|
||||
}
|
||||
|
||||
func flattenVinsData(d *schema.ResourceData, vinsRecord *vins.RecordVINS) {
|
||||
log.Debugf("flattenVins: decoded ViNS name: %s, ID : %d, account ID %d, RG ID %d",
|
||||
vinsRecord.Name, vinsRecord.ID, vinsRecord.AccountID, vinsRecord.RGID)
|
||||
|
||||
d.Set("vnf_dev", flattenVinsVNFDev(vinsRecord.VNFDev))
|
||||
d.Set("account_id", vinsRecord.AccountID)
|
||||
d.Set("account_name", vinsRecord.AccountName)
|
||||
d.Set("created_by", vinsRecord.CreatedBy)
|
||||
d.Set("created_time", vinsRecord.CreatedTime)
|
||||
d.Set("default_gw", vinsRecord.DefaultGW)
|
||||
d.Set("default_qos", flattenVinsQOS(vinsRecord.DefaultQOS))
|
||||
d.Set("deleted_by", vinsRecord.DeletedBy)
|
||||
d.Set("deleted_time", vinsRecord.DeletedTime)
|
||||
d.Set("description", vinsRecord.Description)
|
||||
d.Set("gid", vinsRecord.GID)
|
||||
d.Set("guid", vinsRecord.GUID)
|
||||
d.Set("vins_id", vinsRecord.ID)
|
||||
d.Set("lock_status", vinsRecord.LockStatus)
|
||||
d.Set("manager_id", vinsRecord.ManagerID)
|
||||
d.Set("manager_type", vinsRecord.ManagerType)
|
||||
d.Set("milestones", vinsRecord.Milestones)
|
||||
d.Set("name", vinsRecord.Name)
|
||||
d.Set("netmask", vinsRecord.NetMask)
|
||||
d.Set("network", vinsRecord.Network)
|
||||
d.Set("pre_reservations_num", vinsRecord.PreReservationsNum)
|
||||
d.Set("redundant", vinsRecord.Redundant)
|
||||
d.Set("rg_id", vinsRecord.RGID)
|
||||
d.Set("rg_name", vinsRecord.RGName)
|
||||
d.Set("sec_vnf_dev_id", vinsRecord.SecVNFDevID)
|
||||
d.Set("status", vinsRecord.Status)
|
||||
d.Set("updated_by", vinsRecord.UpdatedBy)
|
||||
d.Set("updated_time", vinsRecord.UpdatedTime)
|
||||
d.Set("user_managed", vinsRecord.UserManaged)
|
||||
d.Set("vnfs", flattenVinsRecordVNFs(vinsRecord.VNFs))
|
||||
d.Set("vxlan_id", vinsRecord.VXLANID)
|
||||
d.Set("computes", flattenComputes(vinsRecord.Computes))
|
||||
d.Set("zone_id", vinsRecord.ZoneID)
|
||||
d.Set("enable_secgroups", vinsRecord.EnableSecGroups)
|
||||
|
||||
}
|
||||
|
||||
func flattenLibvirtSettings(libvirtSettings vins.LibvirtSettings) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"guid": libvirtSettings.GUID,
|
||||
"txmode": libvirtSettings.TXMode,
|
||||
"ioeventfd": libvirtSettings.IOEventFD,
|
||||
"event_idx": libvirtSettings.EventIDx,
|
||||
"queues": libvirtSettings.Queues,
|
||||
"rx_queue_size": libvirtSettings.RXQueueSize,
|
||||
"tx_queue_size": libvirtSettings.TXQueueSize,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsVNFDev(vd vins.VNFDev) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"ckey": vd.CKey,
|
||||
"meta": flattens.FlattenMeta(vd.Meta),
|
||||
"account_id": vd.AccountID,
|
||||
"capabilities": vd.Capabilities,
|
||||
"config": flattenVinsConfig(vd.Config),
|
||||
"config_saved": vd.ConfigSaved,
|
||||
"custom_precfg": vd.CustomPreConfig,
|
||||
"description": vd.Description,
|
||||
"gid": vd.GID,
|
||||
"guid": vd.GUID,
|
||||
"id": vd.ID,
|
||||
"interfaces": flattenVinsListInterfaces(vd.Interfaces),
|
||||
"live_migration_job_id": vd.LiveMigrationJobID,
|
||||
"lock_status": vd.LockStatus,
|
||||
"milestones": vd.Milestones,
|
||||
"name": vd.Name,
|
||||
"status": vd.Status,
|
||||
"tech_status": vd.TechStatus,
|
||||
"type": vd.Type,
|
||||
"vnc_password": vd.VNCPassword,
|
||||
"vins": vd.VINS,
|
||||
"zone_id": vd.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenComputes(computes []vins.Computes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(computes))
|
||||
for _, compute := range computes {
|
||||
tmp := map[string]interface{}{
|
||||
"id": compute.ID,
|
||||
"name": compute.Name,
|
||||
}
|
||||
res = append(res, tmp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsRecordVNFs(rv vins.RecordVNFs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"dhcp": flattenVinsRecordDHCP(rv.DHCP),
|
||||
"gw": flattenVinsRecordGW(rv.GW),
|
||||
"nat": flattenVinsRecordNAT(rv.NAT),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsRecordDHCP(rv vins.RecordDHCP) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"config": flattenVinsVNFsConfig(rv.Config),
|
||||
"ckey": rv.CKey,
|
||||
"meta": flattens.FlattenMeta(rv.Meta),
|
||||
"account_id": rv.AccountID,
|
||||
"created_time": rv.CreatedTime,
|
||||
"devices": flattenVinsPrimaryDevices(rv.Devices),
|
||||
"gid": rv.GID,
|
||||
"guid": rv.GUID,
|
||||
"id": rv.ID,
|
||||
"lock_status": rv.LockStatus,
|
||||
"milestones": rv.Milestones,
|
||||
"owner_id": rv.OwnerID,
|
||||
"owner_type": rv.OwnerType,
|
||||
"pure_virtual": rv.PureVirtual,
|
||||
"routes": flattenVinsRoutes(rv.Routes),
|
||||
"status": rv.Status,
|
||||
"tech_status": rv.TechStatus,
|
||||
"type": rv.Type,
|
||||
"zone_id": rv.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsRecordGW(rg vins.RecordGW) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"config": flattenVinsGWConfig(rg.Config),
|
||||
"ckey": rg.CKey,
|
||||
"meta": flattens.FlattenMeta(rg.Meta),
|
||||
"account_id": rg.AccountID,
|
||||
"created_time": rg.CreatedTime,
|
||||
"devices": flattenVinsPrimaryDevices(rg.Devices),
|
||||
"gid": rg.GID,
|
||||
"guid": rg.GUID,
|
||||
"id": rg.ID,
|
||||
"lock_status": rg.LockStatus,
|
||||
"milestones": rg.Milestones,
|
||||
"owner_id": rg.OwnerID,
|
||||
"owner_type": rg.OwnerType,
|
||||
"pure_virtual": rg.PureVirtual,
|
||||
"routes": flattenVinsRoutes(rg.Routes),
|
||||
"status": rg.Status,
|
||||
"tech_status": rg.TechStatus,
|
||||
"type": rg.Type,
|
||||
"zone_id": rg.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsRecordNAT(rn vins.RecordNAT) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"config": flattenVinsNATConfig(rn.Config),
|
||||
"ckey": rn.CKey,
|
||||
"meta": flattens.FlattenMeta(rn.Meta),
|
||||
"account_id": rn.AccountID,
|
||||
"created_time": rn.CreatedTime,
|
||||
"devices": flattenVinsPrimaryDevices(rn.Devices),
|
||||
"gid": rn.GID,
|
||||
"guid": rn.GUID,
|
||||
"id": rn.ID,
|
||||
"lock_status": rn.LockStatus,
|
||||
"milestones": rn.Milestones,
|
||||
"owner_id": rn.OwnerID,
|
||||
"owner_type": rn.OwnerType,
|
||||
"pure_virtual": rn.PureVirtual,
|
||||
"routes": flattenVinsRoutes(rn.Routes),
|
||||
"status": rn.Status,
|
||||
"tech_status": rn.TechStatus,
|
||||
"type": rn.Type,
|
||||
"zone_id": rn.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsVNFsConfig(vc vins.VNFsConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"default_gw": vc.DefaultGW,
|
||||
"dns": vc.DNS,
|
||||
"ip_end": vc.IPEnd,
|
||||
"ip_start": vc.IPStart,
|
||||
"lease": vc.Lease,
|
||||
"net_mask": vc.NetMask,
|
||||
"network": vc.Network,
|
||||
"reservations": flattenVinsListReservations(vc.Reservations),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsGWConfig(gc vins.GWConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"default_gw": gc.DefaultGW,
|
||||
"ext_net_id": gc.ExtNetID,
|
||||
"ext_net_ip": gc.ExtNetIP,
|
||||
"ext_netmask": gc.ExtNetMask,
|
||||
"qos": flattenVinsQOS(gc.QOS),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsNATConfig(nc vins.NATConfig) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"net_mask": nc.NetMask,
|
||||
"network": nc.Network,
|
||||
"rules": flattenRulesItem(nc.Rules),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRuleBlock(rules []vins.ItemNATRule) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
tmp := map[string]interface{}{
|
||||
"int_ip": rule.LocalIP,
|
||||
"int_port": rule.LocalPort,
|
||||
"ext_port_start": rule.PublicPortStart,
|
||||
"ext_port_end": rule.PublicPortEnd,
|
||||
"proto": rule.Protocol,
|
||||
"rule_id": rule.ID,
|
||||
}
|
||||
res = append(res, tmp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenRulesItem(rules []vins.ItemNATRule) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
tmp := map[string]interface{}{
|
||||
"rule_id": rule.ID,
|
||||
"local_ip": rule.LocalIP,
|
||||
"local_port": rule.LocalPort,
|
||||
"protocol": rule.Protocol,
|
||||
"public_port_end": rule.PublicPortEnd,
|
||||
"public_port_start": rule.PublicPortStart,
|
||||
"vm_id": rule.VMID,
|
||||
"vm_name": rule.VMName,
|
||||
}
|
||||
res = append(res, tmp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsPrimaryDevices(d vins.Devices) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"primary": flattenVinsDevices(d.Primary),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsDevices(d vins.Primary) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"dev_id": d.DevID,
|
||||
"iface01": d.IFace01,
|
||||
"iface02": d.IFace02,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsRoutes(r vins.ListRoutes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(r))
|
||||
for _, v := range r {
|
||||
temp := map[string]interface{}{
|
||||
"destination": v.Destination,
|
||||
"netmask": v.Netmask,
|
||||
"gateway": v.Gateway,
|
||||
"compute_ids": v.ComputeIds,
|
||||
"guid": v.GUID,
|
||||
"route_id": v.ID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsListReservations(li vins.ListReservations) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(li))
|
||||
for _, v := range li {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": v.AccountID,
|
||||
"ip": v.IP,
|
||||
"mac": v.MAC,
|
||||
"type": v.Type,
|
||||
"vm_id": v.VMID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsConfig(c vins.Config) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"mgmt": flattenVinsMGMT(c.MGMT),
|
||||
"resources": flattenVinsResources(c.Resources),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsMGMT(m vins.MGMT) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"ip_addr": m.IPAddress,
|
||||
"password": m.Password,
|
||||
"ssh_key": m.SSHKey,
|
||||
"user": m.User,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsResources(r vins.Resources) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"cpu": r.CPU,
|
||||
"ram": r.RAM,
|
||||
"node_id": r.NodeID,
|
||||
"uuid": r.UUID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsListInterfaces(i vins.ListInterfaces) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(i))
|
||||
for _, v := range i {
|
||||
temp := map[string]interface{}{
|
||||
"conn_id": v.ConnID,
|
||||
"conn_type": v.ConnType,
|
||||
"def_gw": v.DefGW,
|
||||
"enabled": v.Enabled,
|
||||
"enable_secgroups": v.EnableSecGroups,
|
||||
"flipgroup_id": v.FLIPGroupID,
|
||||
"guid": v.GUID,
|
||||
"ip_address": v.IPAddress,
|
||||
"listen_ssh": v.ListenSSH,
|
||||
"mac": v.MAC,
|
||||
"mtu": v.MTU,
|
||||
"name": v.Name,
|
||||
"net_id": v.NetID,
|
||||
"net_mask": v.NetMask,
|
||||
"net_type": v.NetType,
|
||||
"node_id": v.NodeID,
|
||||
"pci_slot": v.PCISlot,
|
||||
"bus_number": v.BusNumber,
|
||||
"qos": flattenVinsQOS(v.QOS),
|
||||
"security_groups": v.SecGroups,
|
||||
"sdn_interface_id": v.SDNInterfaceID,
|
||||
"target": v.Target,
|
||||
"type": v.Type,
|
||||
"vnfs": v.VNFs,
|
||||
"libvirt_settings": flattenLibvirtSettings(v.LibvirtSettings),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(vl.Data))
|
||||
for _, v := range vl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": v.AccountID,
|
||||
"account_name": v.AccountName,
|
||||
"created_by": v.CreatedBy,
|
||||
"created_time": v.CreatedTime,
|
||||
"default_gw": v.DefaultGW,
|
||||
"default_qos": flattenVinsQOS(v.DefaultQOS),
|
||||
"deleted_by": v.DeletedBy,
|
||||
"deleted_time": v.DeletedTime,
|
||||
"description": v.Description,
|
||||
"enable_secgroups": v.EnableSecGroups,
|
||||
"external_ip": v.ExternalIP,
|
||||
"extnet_id": v.ExtnetId,
|
||||
"free_ips": v.FreeIPs,
|
||||
"gid": v.GID,
|
||||
"guid": v.GUID,
|
||||
"vins_id": v.ID,
|
||||
"name": v.Name,
|
||||
"lock_status": v.LockStatus,
|
||||
"manager_id": v.ManagerID,
|
||||
"manager_type": v.ManagerType,
|
||||
"milestones": v.Milestones,
|
||||
"netmask": v.NetMask,
|
||||
"network": v.Network,
|
||||
"pre_reservations_num": v.PreReservationsNum,
|
||||
"pri_vnf_dev_id": v.PriVNFDevID,
|
||||
"redundant": v.Redundant,
|
||||
"rg_id": v.RGID,
|
||||
"rg_name": v.RGName,
|
||||
"sec_vnf_dev_id": v.SecVNFDevID,
|
||||
"status": v.Status,
|
||||
"updated_by": v.UpdatedBy,
|
||||
"updated_time": v.UpdatedTime,
|
||||
"user_managed": v.UserManaged,
|
||||
"vnfs": flattenVinsVNFs(v.VNFs),
|
||||
"vxlan_id": v.VXLANID,
|
||||
"zone_id": v.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsListDeleted(vl *vins.ListVINS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(vl.Data))
|
||||
for _, v := range vl.Data {
|
||||
temp := map[string]interface{}{
|
||||
"account_id": v.AccountID,
|
||||
"account_name": v.AccountName,
|
||||
"created_by": v.CreatedBy,
|
||||
"created_time": v.CreatedTime,
|
||||
"default_gw": v.DefaultGW,
|
||||
"default_qos": flattenVinsQOS(v.DefaultQOS),
|
||||
"deleted_by": v.DeletedBy,
|
||||
"deleted_time": v.DeletedTime,
|
||||
"description": v.Description,
|
||||
"external_ip": v.ExternalIP,
|
||||
"gid": v.GID,
|
||||
"guid": v.GUID,
|
||||
"vins_id": v.ID,
|
||||
"name": v.Name,
|
||||
"lock_status": v.LockStatus,
|
||||
"manager_id": v.ManagerID,
|
||||
"manager_type": v.ManagerType,
|
||||
"milestones": v.Milestones,
|
||||
"netmask": v.NetMask,
|
||||
"network": v.Network,
|
||||
"pre_reservations_num": v.PreReservationsNum,
|
||||
"pri_vnf_dev_id": v.PriVNFDevID,
|
||||
"redundant": v.Redundant,
|
||||
"rg_id": v.RGID,
|
||||
"rg_name": v.RGName,
|
||||
"sec_vnf_dev_id": v.SecVNFDevID,
|
||||
"status": v.Status,
|
||||
"updated_by": v.UpdatedBy,
|
||||
"updated_time": v.UpdatedTime,
|
||||
"user_managed": v.UserManaged,
|
||||
"vnfs": flattenVinsVNFs(v.VNFs),
|
||||
"vxlan_id": v.VXLANID,
|
||||
"zone_id": v.ZoneID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsVNFs(iv vins.ItemVNFs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"dhcp": iv.DHCP,
|
||||
"dns": iv.DNS,
|
||||
"fw": iv.FW,
|
||||
"gw": iv.GW,
|
||||
"nat": iv.NAT,
|
||||
"vpn": iv.VPN,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsQOS(dq vins.QOS) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"e_rate": dq.ERate,
|
||||
"guid": dq.GUID,
|
||||
"in_burst": dq.InBurst,
|
||||
"in_rate": dq.InRate,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsAudits(auidts vins.ListAudits) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(auidts))
|
||||
for _, audit := range auidts {
|
||||
temp := map[string]interface{}{
|
||||
"call": audit.Call,
|
||||
"response_time": audit.ResponseTime,
|
||||
"status_code": audit.StatusCode,
|
||||
"time_stamp": audit.Timestamp,
|
||||
"user": audit.User,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsExtNetList(extNetList *vins.ListExtNets) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(extNetList.Data))
|
||||
for _, extNet := range extNetList.Data {
|
||||
temp := map[string]interface{}{
|
||||
"default_gw": extNet.DefaultGW,
|
||||
"ext_net_id": extNet.ExtNetID,
|
||||
"ip": extNet.IP,
|
||||
"prefix_len": extNet.PrefixLen,
|
||||
"status": extNet.Status,
|
||||
"tech_status": extNet.TechStatus,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(natRules.Data))
|
||||
for _, natRule := range natRules.Data {
|
||||
temp := map[string]interface{}{
|
||||
"id": natRule.ID,
|
||||
"local_ip": natRule.LocalIP,
|
||||
"local_port": natRule.LocalPort,
|
||||
"protocol": natRule.Protocol,
|
||||
"public_port_end": natRule.PublicPortEnd,
|
||||
"public_port_start": natRule.PublicPortStart,
|
||||
"vm_id": natRule.VMID,
|
||||
"vm_name": natRule.VMName,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenVinsIpList(ips *vins.ListIPs) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(ips.Data))
|
||||
for _, ip := range ips.Data {
|
||||
temp := map[string]interface{}{
|
||||
"client_type": ip.ClientType,
|
||||
"domain_name": ip.DomainName,
|
||||
"host_name": ip.Hostname,
|
||||
"ip": ip.IP,
|
||||
"mac": ip.MAC,
|
||||
"type": ip.Type,
|
||||
"vm_id": ip.VMID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStaticRouteList(sr *vins.ListStaticRoutes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(sr.Data))
|
||||
for _, staticRoute := range sr.Data {
|
||||
temp := map[string]interface{}{
|
||||
"route_id": staticRoute.ID,
|
||||
"destination": staticRoute.Destination,
|
||||
"gateway": staticRoute.Gateway,
|
||||
"guid": staticRoute.GUID,
|
||||
"netmask": staticRoute.Netmask,
|
||||
"compute_ids": staticRoute.ComputeIds,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStaticRouteData(d *schema.ResourceData, route *vins.ItemRoutes) {
|
||||
d.Set("destination", route.Destination)
|
||||
d.Set("gateway", route.Gateway)
|
||||
d.Set("guid", route.GUID)
|
||||
d.Set("netmask", route.Netmask)
|
||||
d.Set("compute_ids", route.ComputeIds)
|
||||
d.Set("route_id", route.ID)
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func checkParamsExistenceCreateInAcc(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
|
||||
var errs []error
|
||||
|
||||
accountId := uint64(d.Get("account_id").(int))
|
||||
|
||||
if err := ic.ExistAccount(ctx, accountId, c); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
if gid, ok := d.GetOk("gid"); ok {
|
||||
if err := ic.ExistGID(ctx, uint64(gid.(int)), c); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
return dc.ErrorsToDiagnostics(errs)
|
||||
}
|
||||
|
||||
func checkParamsExistenceCreateInRG(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
|
||||
var errs []error
|
||||
|
||||
rgId := uint64(d.Get("rg_id").(int))
|
||||
|
||||
if err := ic.ExistGID(ctx, rgId, c); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
extNetID, ok := d.GetOk("ext_net_id")
|
||||
if ok {
|
||||
if err := ic.ExistExtNetInVins(ctx, extNetID.(int), c); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if extIP, ok := d.GetOk("ext_ip"); ok {
|
||||
if extNetID.(int) < 0 {
|
||||
errs = append(errs, fmt.Errorf("external IP is related only for extNetId >= 0: ext_ip %d, extNetId %d", extIP, extNetID))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkParamsExistenceUpdate(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
|
||||
var errs []error
|
||||
|
||||
if rgId, ok := d.GetOk("rg_id"); ok {
|
||||
err := ic.ExistRG(ctx, uint64(rgId.(int)), c)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if extNetId, ok := d.GetOk("ext_net_id"); ok {
|
||||
err := ic.ExistExtNetInVins(ctx, extNetId.(int), c)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
err := ic.ExistAccount(ctx, uint64(accountId.(int)), c)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if gid, ok := d.GetOk("gid"); ok {
|
||||
err := ic.ExistGID(ctx, uint64(gid.(int)), c)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
return dc.ErrorsToDiagnostics(errs)
|
||||
}
|
||||
|
||||
func checkParamsExistenceStaticRoute(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg) diag.Diagnostics {
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
if err := ic.ExistVins(ctx, vinsId, c); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func createVinsInAcc(ctx context.Context, d *schema.ResourceData, m interface{}, accID uint64) (vins.CreateInAccountRequest, diag.Diagnostics) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.CreateInAccountRequest{}
|
||||
|
||||
if diags := checkParamsExistenceCreateInAcc(ctx, d, c); diags != nil {
|
||||
return req, diags
|
||||
}
|
||||
|
||||
req.AccountID = accID
|
||||
req.Name = d.Get("name").(string)
|
||||
|
||||
if gid, ok := d.GetOk("gid"); ok {
|
||||
req.GID = uint64(gid.(int))
|
||||
}
|
||||
if IPCIDR, ok := d.GetOk("ipcidr"); ok {
|
||||
req.IPCIDR = IPCIDR.(string)
|
||||
}
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
req.Description = description.(string)
|
||||
}
|
||||
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
|
||||
req.PreReservationsNum = uint64(preReservationsNum.(int))
|
||||
}
|
||||
|
||||
if routesList, ok := d.GetOk("routes"); ok {
|
||||
var routes []vins.Route
|
||||
var route vins.Route
|
||||
for _, r := range routesList.([]map[string]interface{}) {
|
||||
route.Netmask = r["netmask"].(string)
|
||||
route.Destination = r["destination"].(string)
|
||||
route.Gateway = r["gateway"].(string)
|
||||
routes = append(routes, route)
|
||||
}
|
||||
req.Routes = routes
|
||||
}
|
||||
if dns, ok := d.GetOk("dns"); ok {
|
||||
dnsInterface := dns.(*schema.Set).List()
|
||||
req.DNSList = make([]string, 0, len(dnsInterface))
|
||||
for _, item := range dnsInterface {
|
||||
req.DNSList = append(req.DNSList, item.(string))
|
||||
}
|
||||
}
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func createVinsInRG(ctx context.Context, d *schema.ResourceData, m interface{}, RGID uint64) (vins.CreateInRGRequest, diag.Diagnostics) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.CreateInRGRequest{}
|
||||
|
||||
if diags := checkParamsExistenceCreateInRG(ctx, d, c); diags != nil {
|
||||
return req, diags
|
||||
}
|
||||
|
||||
req.RGID = RGID
|
||||
req.Name = d.Get("name").(string)
|
||||
|
||||
if IPCIDR, ok := d.GetOk("ipcidr"); ok {
|
||||
req.IPCIDR = IPCIDR.(string)
|
||||
}
|
||||
|
||||
if extNetID, ok := d.GetOk("ext_net_id"); ok {
|
||||
req.ExtNetID = int64(extNetID.(int))
|
||||
}
|
||||
|
||||
if extIP, ok := d.GetOk("ext_ip"); ok {
|
||||
req.ExtIP = extIP.(string)
|
||||
}
|
||||
if description, ok := d.GetOk("description"); ok {
|
||||
req.Description = description.(string)
|
||||
}
|
||||
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
|
||||
req.PreReservationsNum = uint64(preReservationsNum.(int))
|
||||
}
|
||||
|
||||
if routesList, ok := d.GetOk("routes"); ok {
|
||||
var routes []vins.Route
|
||||
var route vins.Route
|
||||
for _, r := range routesList.([]map[string]interface{}) {
|
||||
route.Netmask = r["netmask"].(string)
|
||||
route.Destination = r["destination"].(string)
|
||||
route.Gateway = r["gateway"].(string)
|
||||
routes = append(routes, route)
|
||||
}
|
||||
req.Routes = routes
|
||||
}
|
||||
if dns, ok := d.GetOk("dns"); ok {
|
||||
dnsInterface := dns.(*schema.Set).List()
|
||||
req.DNSList = make([]string, 0, len(dnsInterface))
|
||||
for _, item := range dnsInterface {
|
||||
req.DNSList = append(req.DNSList, item.(string))
|
||||
}
|
||||
}
|
||||
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func isContainsIp(els []interface{}, el interface{}) bool {
|
||||
elConv := el.(map[string]interface{})
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
if elOldConv["ip_addr"].(string) == elConv["ip_addr"].(string) &&
|
||||
elOldConv["type"].(string) == elConv["type"].(string) &&
|
||||
elOldConv["mac"].(string) == elConv["mac"].(string) &&
|
||||
elOldConv["compute_id"].(string) == elConv["compute_id"].(string) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isContainsNatRule(els []interface{}, el interface{}) bool {
|
||||
elConv := el.(map[string]interface{})
|
||||
for _, elOld := range els {
|
||||
elOldConv := elOld.(map[string]interface{})
|
||||
if elOldConv["int_ip"].(string) == elConv["int_ip"].(string) &&
|
||||
elOldConv["int_port"].(int) == elConv["int_port"].(int) &&
|
||||
elOldConv["ext_port_start"].(int) == elConv["ext_port_start"].(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1,826 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceVinsCreate: called for ViNS name %s, Account ID %d, RG ID %d",
|
||||
d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
RGID, rgOk := d.GetOk("rg_id")
|
||||
AccountID, accountIdOk := d.GetOk("account_id")
|
||||
|
||||
if !rgOk && !accountIdOk {
|
||||
return diag.Errorf("resourceVinsCreate: no valid accountId or resource group ID specified")
|
||||
}
|
||||
|
||||
if rgOk && accountIdOk {
|
||||
return diag.Errorf("resourceVinsCreate: either accountId or resource group ID should be specified")
|
||||
}
|
||||
|
||||
var vinsID uint64
|
||||
if accountIdOk {
|
||||
req, diags := createVinsInAcc(ctx, d, m, uint64(AccountID.(int)))
|
||||
if diags != nil {
|
||||
return diags
|
||||
}
|
||||
|
||||
apiResp, err := c.CloudBroker().VINS().CreateInAccount(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
vinsID = apiResp
|
||||
} else if rgOk {
|
||||
req, diags := createVinsInRG(ctx, d, m, uint64(RGID.(int)))
|
||||
if diags != nil {
|
||||
return diags
|
||||
}
|
||||
|
||||
apiResp, err := c.CloudBroker().VINS().CreateInRG(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
vinsID = apiResp
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(vinsID, 10))
|
||||
d.Set("vins_id", vinsID)
|
||||
|
||||
log.Debugf("resourceVinsCreate: new ViNS ID / name %d / %s creation sequence complete", vinsID, d.Get("name").(string))
|
||||
|
||||
warnings := dc.Warnings{}
|
||||
if _, ok := d.GetOk("ip"); ok {
|
||||
if errs := resourceVinsIpReserve(ctx, d, m, vinsID); len(errs) != 0 {
|
||||
for _, err := range errs {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := d.GetOk("nat_rule"); ok {
|
||||
if errs := resourceVinsNatRuleAdd(ctx, d, m, vinsID); len(errs) != 0 {
|
||||
for _, err := range errs {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceVinsRead: called for vins id %s, name %s",
|
||||
d.Id(), d.Get("name").(string))
|
||||
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
isEnabled := d.Get("enable").(bool)
|
||||
|
||||
hasChangeState := false
|
||||
|
||||
switch vinsData.Status {
|
||||
case status.Destroyed:
|
||||
d.Set("vins_id", 0)
|
||||
d.SetId("")
|
||||
return diag.Errorf("The resource cannot be read because it has been destroyed")
|
||||
// return resourceVinsCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
// hasChangeState = true
|
||||
|
||||
// req := vins.RestoreRequest{
|
||||
// VINSID: vinsData.ID,
|
||||
// }
|
||||
// if reason, ok := d.GetOk("reason"); ok {
|
||||
// req.Reason = reason.(string)
|
||||
// }
|
||||
|
||||
// _, err := c.CloudBroker().VINS().Restore(ctx, req)
|
||||
// if err != nil {
|
||||
// warnings.Add(err)
|
||||
// }
|
||||
case status.Modeled:
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vinsData.Status)
|
||||
case status.Created:
|
||||
case status.Enabled:
|
||||
if !isEnabled {
|
||||
hasChangeState = true
|
||||
if err := resourceVinsDisable(ctx, d, m, vinsData.ID); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
case status.Enabling:
|
||||
case status.Disabled:
|
||||
if isEnabled {
|
||||
hasChangeState = true
|
||||
if err := resourceVinsEnable(ctx, d, m, vinsData.ID); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
case status.Disabling:
|
||||
case status.Deleting:
|
||||
return diag.Errorf("ViNS are in progress with status: %s", vinsData.Status)
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
if vinsData == nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
flattenVins(d, vinsData)
|
||||
|
||||
log.Debugf("resourceVinsRead: after flattenVins: vins_id %s, name %s",
|
||||
d.Id(), d.Get("name").(string))
|
||||
|
||||
return warnings.Get()
|
||||
}
|
||||
|
||||
func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceVinsUpdate: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d",
|
||||
d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if diags := checkParamsExistenceUpdate(ctx, d, c); diags != nil {
|
||||
return diags
|
||||
}
|
||||
|
||||
vinsData, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
isEnabled := d.Get("enable").(bool)
|
||||
|
||||
hasChangeState := false
|
||||
|
||||
warnings := dc.Warnings{}
|
||||
switch vinsData.Status {
|
||||
case status.Destroyed:
|
||||
d.Set("vins_id", 0)
|
||||
d.SetId("")
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceVinsCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
|
||||
if err := resourceVinsRestore(ctx, d, m, vinsData.ID); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
case status.Modeled:
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vinsData.Status)
|
||||
case status.Created:
|
||||
case status.Enabled:
|
||||
if !isEnabled {
|
||||
hasChangeState = true
|
||||
if err := resourceVinsDisable(ctx, d, m, vinsData.ID); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
case status.Enabling:
|
||||
case status.Disabled:
|
||||
if isEnabled {
|
||||
hasChangeState = true
|
||||
if err := resourceVinsEnable(ctx, d, m, vinsData.ID); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
case status.Disabling:
|
||||
case status.Deleting:
|
||||
return diag.Errorf("ViNS are in progress with status: %s", vinsData.Status)
|
||||
}
|
||||
|
||||
if hasChangeState {
|
||||
vinsData, err = utilityVinsCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChanges("name", "desc", "enable_secgroups") {
|
||||
vinsID := uint64(d.Get("vins_id").(int))
|
||||
if err := utilityUpdateVINS(ctx, d, m, vinsID); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("enable") {
|
||||
if err := resourceVinsChangeEnabled(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("ext_net_id") {
|
||||
if err := resourceVinsChangeExtNetId(ctx, d, m); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("ip") {
|
||||
if errs := resourceVinsChangeIp(ctx, d, m); len(errs) != 0 {
|
||||
for _, err := range errs {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if d.HasChange("nat_rule") {
|
||||
if errs := resourceVinsChangeNatRule(ctx, d, m); len(errs) != 0 {
|
||||
for _, err := range errs {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("dns") {
|
||||
if err := resourceVinsChangeDNS(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("default_qos") {
|
||||
if err := resourceVinsChangeDefaultQos(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("vnfdev_redeploy") {
|
||||
if err := resourceVinsChangeVnfRedeploy(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("vnfdev_restart") {
|
||||
if err := resourceVinsChangeVnfRestart(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("vnfdev_reset") {
|
||||
if err := resourceVinsChangeVnfReset(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("vnfdev_start") {
|
||||
if err := resourceVinsChangeVnfStartStop(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("zone_id") {
|
||||
if err := resourceVinsChangeZoneID(ctx, d, m); err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), dataSourceVinsRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceVinsDelete: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d",
|
||||
d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsItem, err := utilityVinsCheckPresence(ctx, d, m)
|
||||
if vinsItem == nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := vins.DeleteRequest{VINSID: vinsItem.ID}
|
||||
|
||||
if force, ok := d.GetOk("force"); ok {
|
||||
req.Force = force.(bool)
|
||||
}
|
||||
if permanently, ok := d.GetOk("permanently"); ok {
|
||||
req.Permanently = permanently.(bool)
|
||||
}
|
||||
|
||||
if _, err := c.CloudBroker().VINS().Delete(ctx, req); err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVinsEnable(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := vins.EnableRequest{
|
||||
VINSID: vinsId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().Enable(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func resourceVinsDisable(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := vins.DisableRequest{
|
||||
VINSID: vinsId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().Disable(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func resourceVinsRestore(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := vins.RestoreRequest{
|
||||
VINSID: vinsId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().Restore(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func resourceVinsIpReserve(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) []error {
|
||||
var errs []error
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
ipRes := d.Get("ip")
|
||||
|
||||
ipsSlice := ipRes.([]interface{})
|
||||
for _, ipInterfase := range ipsSlice {
|
||||
ip := ipInterfase.(map[string]interface{})
|
||||
|
||||
req := vins.IPReserveRequest{
|
||||
VINSID: vinsId,
|
||||
Type: ip["type"].(string),
|
||||
}
|
||||
if ipAddr, ok := ip["ip_addr"]; ok {
|
||||
req.IPAddr = ipAddr.(string)
|
||||
}
|
||||
if macAddr, ok := ip["mac"]; ok {
|
||||
req.MAC = macAddr.(string)
|
||||
}
|
||||
if computeId, ok := ip["compute_id"]; ok {
|
||||
req.ComputeID = uint64(computeId.(int))
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().IPReserve(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
func resourceVinsNatRuleAdd(ctx context.Context, d *schema.ResourceData, m interface{}, vinsId uint64) []error {
|
||||
var errs []error
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
natRule := d.Get("nat_rule")
|
||||
|
||||
addedNatRules := natRule.([]interface{})
|
||||
if len(addedNatRules) > 0 {
|
||||
for _, natRuleInterface := range addedNatRules {
|
||||
natRule := natRuleInterface.(map[string]interface{})
|
||||
|
||||
req := vins.NATRuleAddRequest{
|
||||
VINSID: vinsId,
|
||||
IntIP: natRule["int_ip"].(string),
|
||||
ExtPortStart: uint64(natRule["ext_port_start"].(int)),
|
||||
}
|
||||
|
||||
if intPort, ok := natRule["int_port"]; ok {
|
||||
req.IntPort = uint64(intPort.(int))
|
||||
}
|
||||
if extPortEnd, ok := natRule["ext_port_end"]; ok {
|
||||
req.ExtPortEnd = uint64(extPortEnd.(int))
|
||||
}
|
||||
if proto, ok := natRule["proto"]; ok {
|
||||
req.Proto = proto.(string)
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().NATRuleAdd(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
func resourceVinsChangeEnabled(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
_, enableNew := d.GetChange("enable")
|
||||
if enableNew.(bool) {
|
||||
req := vins.EnableRequest{
|
||||
VINSID: vinsId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().Enable(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
req := vins.DisableRequest{
|
||||
VINSID: vinsId,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().Disable(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func resourceVinsChangeExtNetId(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
oldExtNetId, newExtNedId := d.GetChange("ext_net_id")
|
||||
log.Debugf("resourceVinsUpdate - resourceVinsChangeExtNetId: changing ViNS ID %s - ext_net_id %d -> %d", d.Id(), oldExtNetId.(int), newExtNedId.(int))
|
||||
|
||||
if oldExtNetId.(int) > 0 {
|
||||
// there was preexisting external net connection - disconnect ViNS
|
||||
req := vins.ExtNetDisconnectRequest{VINSID: vinsId}
|
||||
|
||||
_, err := c.CloudBroker().VINS().ExtNetDisconnect(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
if newExtNedId.(int) >= 0 {
|
||||
req := vins.ExtNetConnectRequest{
|
||||
VINSID: vinsId,
|
||||
NetID: uint64(newExtNedId.(int)),
|
||||
}
|
||||
if ip, ok := d.GetOk("ext_ip"); ok && ip != "" {
|
||||
req.IP = ip.(string)
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().ExtNetConnect(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVinsChangeIp(ctx context.Context, d *schema.ResourceData, m interface{}) []error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
var errs []error
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
deletedIps := make([]interface{}, 0)
|
||||
addedIps := make([]interface{}, 0)
|
||||
|
||||
oldIpInterface, newIpInterface := d.GetChange("ip")
|
||||
oldIpSlice := oldIpInterface.([]interface{})
|
||||
newIpSlice := newIpInterface.([]interface{})
|
||||
|
||||
for _, el := range oldIpSlice {
|
||||
if !isContainsIp(newIpSlice, el) {
|
||||
deletedIps = append(deletedIps, el)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newIpSlice {
|
||||
if !isContainsIp(oldIpSlice, el) {
|
||||
addedIps = append(addedIps, el)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedIps) > 0 {
|
||||
for _, ipInterface := range deletedIps {
|
||||
ip := ipInterface.(map[string]interface{})
|
||||
req := vins.IPReleaseRequest{VINSID: vinsId}
|
||||
|
||||
if ip["ip_addr"].(string) != "" {
|
||||
req.IPAddr = ip["ip_addr"].(string)
|
||||
}
|
||||
if ip["mac"].(string) != "" {
|
||||
req.MAC = ip["mac"].(string)
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().IPRelease(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedIps) > 0 {
|
||||
for _, ipInterface := range addedIps {
|
||||
ip := ipInterface.(map[string]interface{})
|
||||
req := vins.IPReserveRequest{
|
||||
VINSID: vinsId,
|
||||
Type: ip["type"].(string),
|
||||
}
|
||||
|
||||
if ip["ip_addr"].(string) != "" {
|
||||
req.IPAddr = ip["ip_addr"].(string)
|
||||
}
|
||||
if ip["mac"].(string) != "" {
|
||||
req.MAC = ip["mac"].(string)
|
||||
}
|
||||
if ip["compute_id"].(int) != 0 {
|
||||
req.ComputeID = uint64(ip["compute_id"].(int))
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().IPReserve(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func resourceVinsChangeNatRule(ctx context.Context, d *schema.ResourceData, m interface{}) []error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
var errs []error
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
deletedNatRules := make([]interface{}, 0)
|
||||
addedNatRules := make([]interface{}, 0)
|
||||
|
||||
oldNatRulesInterface, newNatRulesInterface := d.GetChange("nat_rule")
|
||||
oldNatRulesSlice := oldNatRulesInterface.([]interface{})
|
||||
newNatRulesSlice := newNatRulesInterface.([]interface{})
|
||||
|
||||
for _, el := range oldNatRulesSlice {
|
||||
if !isContainsNatRule(newNatRulesSlice, el) {
|
||||
deletedNatRules = append(deletedNatRules, el)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newNatRulesSlice {
|
||||
if !isContainsNatRule(oldNatRulesSlice, el) {
|
||||
addedNatRules = append(addedNatRules, el)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedNatRules) > 0 {
|
||||
for _, natRuleInterface := range deletedNatRules {
|
||||
natRule := natRuleInterface.(map[string]interface{})
|
||||
req := vins.NATRuleDelRequest{
|
||||
VINSID: vinsId,
|
||||
RuleID: int64(natRule["rule_id"].(int)),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().NATRuleDel(ctx, req)
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedNatRules) > 0 {
|
||||
for _, natRuleInterface := range addedNatRules {
|
||||
natRule := natRuleInterface.(map[string]interface{})
|
||||
req := vins.NATRuleAddRequest{
|
||||
VINSID: vinsId,
|
||||
IntIP: natRule["int_ip"].(string),
|
||||
ExtPortStart: uint64(natRule["ext_port_start"].(int)),
|
||||
}
|
||||
|
||||
if natRule["int_port"].(int) != 0 {
|
||||
req.IntPort = uint64(natRule["int_port"].(int))
|
||||
}
|
||||
if natRule["ext_port_end"].(int) != 0 {
|
||||
req.ExtPortEnd = uint64(natRule["ext_port_end"].(int))
|
||||
}
|
||||
if natRule["proto"].(string) != "" {
|
||||
req.Proto = natRule["proto"].(string)
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().NATRuleAdd(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func resourceVinsChangeDNS(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
// empty "dns" is allowed, it will update vnfs.dhcp.config.dns from current values to empty list
|
||||
dnsInterface := d.Get("dns").(*schema.Set).List()
|
||||
dnsList := make([]string, 0, len(dnsInterface))
|
||||
for _, item := range dnsInterface {
|
||||
dnsList = append(dnsList, item.(string))
|
||||
}
|
||||
|
||||
req := vins.DNSApplyRequest{
|
||||
VINSID: vinsId,
|
||||
DNSList: dnsList,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().DNSApply(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVinsChangeDefaultQos(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
defaultQosInterface := d.Get("default_qos").([]interface{})
|
||||
|
||||
if len(defaultQosInterface) > 0 {
|
||||
defaultQos := defaultQosInterface[0].(map[string]interface{})
|
||||
req := vins.DefaultQOSUpdateRequest{VINSID: vinsId}
|
||||
if inRate, ok := defaultQos["in_rate"]; ok {
|
||||
req.IngressRate = uint64(inRate.(int))
|
||||
}
|
||||
if inBurst, ok := defaultQos["in_burst"]; ok {
|
||||
req.IngressBirst = uint64(inBurst.(int))
|
||||
}
|
||||
if eRate, ok := defaultQos["e_rate"]; ok {
|
||||
req.EgressRate = uint64(eRate.(int))
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().DefaultQOSUpdate(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVinsChangeVnfRedeploy(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
_, newRedeploy := d.GetChange("vnfdev_redeploy")
|
||||
if newRedeploy.(bool) {
|
||||
req := vins.VNFDevRedeployRequest{VINSID: vinsId}
|
||||
|
||||
_, err := c.CloudBroker().VINS().VNFDevRedeploy(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVinsChangeVnfRestart(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
_, newRestart := d.GetChange("vnfdev_restart")
|
||||
if newRestart.(bool) {
|
||||
req := vins.VNFDevRestartRequest{VINSID: vinsId}
|
||||
|
||||
_, err := c.CloudBroker().VINS().VNFDevRestart(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVinsChangeVnfReset(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
_, newRestart := d.GetChange("vnfdev_reset")
|
||||
if newRestart.(bool) {
|
||||
req := vins.VNFDevResetRequest{VINSID: vinsId}
|
||||
|
||||
_, err := c.CloudBroker().VINS().VNFDevReset(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVinsChangeVnfStartStop(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
|
||||
_, newStart := d.GetChange("vnfdev_start")
|
||||
if newStart.(bool) {
|
||||
req := vins.VNFDevStartRequest{VINSID: vinsId}
|
||||
|
||||
_, err := c.CloudBroker().VINS().VNFDevStart(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
req := vins.VNFDevStopRequest{VINSID: vinsId}
|
||||
|
||||
_, err := c.CloudBroker().VINS().VNFDevStop(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func resourceVinsChangeZoneID(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
vinsId := uint64(d.Get("vins_id").(int))
|
||||
zoneID := uint64(d.Get("zone_id").(int))
|
||||
|
||||
req := vins.MigrateToZoneRequest{
|
||||
VINSID: vinsId,
|
||||
ZoneID: zoneID,
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().MigrateToZone(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func ResourceVins() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceVinsCreate,
|
||||
ReadContext: resourceVinsRead,
|
||||
UpdateContext: resourceVinsUpdate,
|
||||
DeleteContext: resourceVinsDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout20m,
|
||||
Read: &constants.Timeout600s,
|
||||
Update: &constants.Timeout20m,
|
||||
Delete: &constants.Timeout30m,
|
||||
Default: &constants.Timeout600s,
|
||||
},
|
||||
|
||||
Schema: resourceVinsSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"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/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceStaticRouteCreate: called for vins_id %s", d.Get("vins_id"))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if diags := checkParamsExistenceStaticRoute(ctx, d, c); diags != nil {
|
||||
return diags
|
||||
}
|
||||
|
||||
req := vins.StaticRouteAddRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
Destination: d.Get("destination").(string),
|
||||
Netmask: d.Get("netmask").(string),
|
||||
Gateway: d.Get("gateway").(string),
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().StaticRouteAdd(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
staticRouteData, err := getStaticRouteData(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(fmt.Sprintf("%d#%d", req.VINSID, staticRouteData.ID))
|
||||
|
||||
return resourceStaticRouteRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceStaticRouteRead: called for route_id %s", d.Id())
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenStaticRouteData(d, staticRouteData)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceStaticRouteDelete: called for static route id %s", d.Id())
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.StaticRouteDelRequest{}
|
||||
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return diag.Errorf("broken state id - %s", d.Id())
|
||||
}
|
||||
|
||||
req.VINSID, _ = strconv.ParseUint(arr[0], 10, 64)
|
||||
req.RouteId, _ = strconv.ParseUint(arr[1], 10, 64)
|
||||
|
||||
_, err := c.CloudBroker().VINS().StaticRouteDel(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func isContainsIds(els []interface{}, el interface{}) bool {
|
||||
convEl := el.(int)
|
||||
for _, elOld := range els {
|
||||
if convEl == elOld.(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ResourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceStaticRouteCreate,
|
||||
ReadContext: resourceStaticRouteRead,
|
||||
UpdateContext: resourceStaticRouteUpdate,
|
||||
DeleteContext: resourceStaticRouteDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout20m,
|
||||
Read: &constants.Timeout600s,
|
||||
Update: &constants.Timeout20m,
|
||||
Delete: &constants.Timeout600s,
|
||||
Default: &constants.Timeout600s,
|
||||
},
|
||||
|
||||
Schema: resourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.RecordVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
log.Debug("utilityVinsCheckPresence: locating ViNS by its ID")
|
||||
req := vins.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = id
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
vins, err := c.CloudBroker().VINS().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return vins, nil
|
||||
}
|
||||
|
||||
func utilityUpdateVINS(ctx context.Context, d *schema.ResourceData, m interface{}, vinsID uint64) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := vins.UpdateRequest{
|
||||
VINSID: vinsID,
|
||||
}
|
||||
|
||||
if d.HasChange("name") {
|
||||
req.Name = d.Get("name").(string)
|
||||
}
|
||||
if d.HasChange("desc") {
|
||||
req.Desc = d.Get("desc").(string)
|
||||
}
|
||||
if d.HasChange("enable_secgroups") {
|
||||
req.EnableSecGroups = d.Get("enable_secgroups").(bool)
|
||||
}
|
||||
|
||||
_, err := c.CloudBroker().VINS().Update(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Sergey Kisil, <svkisil@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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (vins.ListAudits, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := vins.AuditsRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = id
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
audits, err := c.CloudBroker().VINS().Audits(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return audits, nil
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListExtNets, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.ExtNetListRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = id
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
extNetList, err := c.CloudBroker().VINS().ExtNetList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return extNetList, nil
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListIPs, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.IPListRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = id
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
ips, err := c.CloudBroker().VINS().IPList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ips, nil
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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 vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.ListRequest{}
|
||||
|
||||
if byId, ok := d.GetOk("by_id"); ok {
|
||||
req.ByID = uint64(byId.(int))
|
||||
}
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
if accountId, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(accountId.(int))
|
||||
}
|
||||
if rgId, ok := d.GetOk("rg_id"); ok {
|
||||
req.RGID = uint64(rgId.(int))
|
||||
}
|
||||
if extIp, ok := d.GetOk("ext_ip"); ok {
|
||||
req.ExtIP = extIp.(string)
|
||||
}
|
||||
if VNFDevId, ok := d.GetOk("vnfdev_id"); ok {
|
||||
req.VNFDevID = uint64(VNFDevId.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
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))
|
||||
}
|
||||
if includeDeleted, ok := d.GetOk("include_deleted"); ok {
|
||||
req.IncludeDeleted = includeDeleted.(bool)
|
||||
}
|
||||
if zoneID, ok := d.GetOk("zone_id"); ok {
|
||||
req.ZoneID = uint64(zoneID.(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityVinsListCheckPresence")
|
||||
vinsList, err := c.CloudBroker().VINS().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return vinsList, nil
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsListDeletedCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListVINS, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.ListDeletedRequest{}
|
||||
|
||||
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 account_id, ok := d.GetOk("account_id"); ok {
|
||||
req.AccountID = uint64(account_id.(int))
|
||||
}
|
||||
if rg_id, ok := d.GetOk("rg_id"); ok {
|
||||
req.RGID = uint64(rg_id.(int))
|
||||
}
|
||||
if ext_ip, ok := d.GetOk("ext_ip"); ok {
|
||||
req.ExtIP = ext_ip.(string)
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(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))
|
||||
}
|
||||
if VNFDevId, ok := d.GetOk("vnfdev_id"); ok {
|
||||
req.VNFDevId = uint64(VNFDevId.(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityVinsListDeletedCheckPresence")
|
||||
vinsList, err := c.CloudBroker().VINS().ListDeleted(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return vinsList, nil
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListNATRules, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.NATRuleListRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
id, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = id
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
natRuleList, err := c.CloudBroker().VINS().NATRuleList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return natRuleList, nil
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityDataStaticRouteCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ItemRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.StaticRouteListRequest{}
|
||||
var routeId uint64
|
||||
|
||||
if d.Id() != "" {
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return nil, fmt.Errorf("broken state id")
|
||||
}
|
||||
|
||||
req.VINSID, _ = strconv.ParseUint(arr[0], 10, 64)
|
||||
routeId, _ = strconv.ParseUint(arr[1], 10, 64)
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
routeId = uint64(d.Get("route_id").(int))
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteCheckPresence, vins_id: %v", req.VINSID)
|
||||
staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("utilityStaticRouteCheckPresence: ROUTE ID %v", routeId)
|
||||
|
||||
staticRoute := &vins.ItemRoutes{}
|
||||
for _, route := range staticRouteList.Data {
|
||||
if routeId == route.ID {
|
||||
staticRoute = &route
|
||||
return staticRoute, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("static route not found")
|
||||
}
|
||||
|
||||
func getStaticRouteData(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ItemRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.StaticRouteListRequest{}
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
|
||||
staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
destination := d.Get("destination").(string)
|
||||
gateway := d.Get("gateway").(string)
|
||||
|
||||
staticRoute := &vins.ItemRoutes{}
|
||||
for _, route := range staticRouteList.Data {
|
||||
if destination == route.Destination && gateway == route.Gateway {
|
||||
staticRoute = &route
|
||||
return staticRoute, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("static route not found")
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func utilityStaticRouteListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*vins.ListStaticRoutes, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := vins.StaticRouteListRequest{}
|
||||
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
|
||||
log.Debugf("utilityStaticRouteListCheckPresence")
|
||||
staticRouteList, err := c.CloudBroker().VINS().StaticRouteList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return staticRouteList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user