4.5.2
This commit is contained in:
@@ -1,107 +1,108 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(staticRoute.ID, 10))
|
||||
flattenStaticRouteData(d, staticRoute)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the ViNS",
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the static route",
|
||||
},
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
func DataSourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRoute, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(staticRoute.ID, 10))
|
||||
flattenStaticRouteData(d, staticRoute)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := map[string]*schema.Schema{
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the ViNS",
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the static route",
|
||||
},
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return rets
|
||||
}
|
||||
|
||||
func DataSourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,121 +1,122 @@
|
||||
/*
|
||||
Copyright (c) 2019-2022 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
||||
Authors:
|
||||
Petr Krutov, <petr.krutov@digitalenergy.online>
|
||||
Stanislav Solovev, <spsolovev@digitalenergy.online>
|
||||
Kasim Baybikov, <kmbaybikov@basistech.ru>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
|
||||
Orchestration Technology) with Terraform by Hashicorp.
|
||||
|
||||
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
|
||||
|
||||
Please see README.md to learn where to place source code so that it
|
||||
builds seamlessly.
|
||||
|
||||
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
|
||||
*/
|
||||
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
)
|
||||
|
||||
func dataSourceStaticRouteListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
staticRouteList, err := utilityStaticRouteListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenStaticRouteList(staticRouteList))
|
||||
d.Set("entry_count", staticRouteList.EntryCount)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceStaticRouteListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of VINS",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceStaticRouteList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteListSchemaMake(),
|
||||
}
|
||||
}
|
||||
/*
|
||||
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 dataSourceStaticRouteListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"vins_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "ID of VINS",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceStaticRouteList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceStaticRouteListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceStaticRouteListSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,10 @@ func vnfInterfaceSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"flipgroup_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
@@ -486,6 +490,13 @@ func dhcpSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: routesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -501,6 +512,39 @@ func dhcpSchemaMake() map[string]*schema.Schema {
|
||||
}
|
||||
}
|
||||
|
||||
func routesSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"route_id": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
Description: "Unique ID of the static route",
|
||||
},
|
||||
"compute_ids": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
},
|
||||
"destination": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"guid": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"netmask": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func gwConfigSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"default_gw": {
|
||||
@@ -589,6 +633,13 @@ func gwSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: routesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
@@ -721,6 +772,13 @@ func natSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"routes": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: routesSchemaMake(),
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
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()
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
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()
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
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()
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import (
|
||||
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()
|
||||
|
||||
@@ -90,6 +90,7 @@ func flattenInterfaces(interfaces []vins.ItemVNFInterface) []map[string]interfac
|
||||
"conn_id": vnfInterface.ConnID,
|
||||
"conn_type": vnfInterface.ConnType,
|
||||
"def_gw": vnfInterface.DefGW,
|
||||
"enabled": vnfInterface.Enabled,
|
||||
"flipgroup_id": vnfInterface.FLIPGroupID,
|
||||
"guid": vnfInterface.GUID,
|
||||
"ip_address": vnfInterface.IPAddress,
|
||||
@@ -226,6 +227,7 @@ func flattenDHCP(dhcp vins.RecordDHCP) []map[string]interface{} {
|
||||
"owner_id": dhcp.OwnerID,
|
||||
"owner_type": dhcp.OwnerType,
|
||||
"pure_virtual": dhcp.PureVirtual,
|
||||
"routes": flattenStaticRoute(dhcp.Routes),
|
||||
"status": dhcp.Status,
|
||||
"tech_status": dhcp.TechStatus,
|
||||
"type": dhcp.Type,
|
||||
@@ -265,6 +267,7 @@ func flattenGW(gw vins.RecordGW) []map[string]interface{} {
|
||||
"owner_id": gw.OwnerID,
|
||||
"owner_type": gw.OwnerType,
|
||||
"pure_virtual": gw.PureVirtual,
|
||||
"routes": flattenStaticRoute(gw.Routes),
|
||||
"status": gw.Status,
|
||||
"tech_status": gw.TechStatus,
|
||||
"type": gw.Type,
|
||||
@@ -321,6 +324,7 @@ func flattenNAT(nat vins.RecordNAT) []map[string]interface{} {
|
||||
"owner_id": nat.OwnerID,
|
||||
"owner_type": nat.OwnerType,
|
||||
"pure_virtual": nat.PureVirtual,
|
||||
"routes": flattenStaticRoute(nat.Routes),
|
||||
"status": nat.Status,
|
||||
"tech_status": nat.TechStatus,
|
||||
"type": nat.Type,
|
||||
@@ -508,7 +512,7 @@ func flattenVinsList(vl *vins.ListVINS) []map[string]interface{} {
|
||||
|
||||
// /4.4.0
|
||||
func flattenStaticRouteList(sr *vins.ListStaticRoutes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
res := make([]map[string]interface{}, 0, len(sr.Data))
|
||||
for _, staticRoute := range sr.Data {
|
||||
temp := map[string]interface{}{
|
||||
"route_id": staticRoute.ID,
|
||||
@@ -533,6 +537,22 @@ func flattenStaticRouteData(d *schema.ResourceData, route *vins.ItemRoutes) {
|
||||
d.Set("route_id", route.ID)
|
||||
}
|
||||
|
||||
func flattenStaticRoute(sr vins.ListRoutes) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(sr))
|
||||
for _, staticRoute := range sr {
|
||||
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 flattenVinsNatRuleList(natRules *vins.ListNATRules) []map[string]interface{} {
|
||||
|
||||
@@ -1,276 +1,277 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if _, ok := d.GetOk("vins_id"); ok {
|
||||
haveVinsID, err := existVinsID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveVinsID {
|
||||
return diag.Errorf("resourceStaticRouteCreate: can't create Static Route because Vins ID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
||||
}
|
||||
}
|
||||
|
||||
req := vins.StaticRouteAddRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
Destination: d.Get("destination").(string),
|
||||
Netmask: d.Get("netmask").(string),
|
||||
Gateway: d.Get("gateway").(string),
|
||||
}
|
||||
|
||||
if computesIDS, ok := d.GetOk("compute_ids"); ok {
|
||||
ids := computesIDS.([]interface{})
|
||||
|
||||
res := make([]uint64, 10)
|
||||
|
||||
for _, id := range ids {
|
||||
computeId := uint64(id.(int))
|
||||
res = append(res, computeId)
|
||||
}
|
||||
|
||||
req.ComputeIds = res
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteAdd(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
staticRouteData, err := getStaticRouteData(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(fmt.Sprintf("%d#%d", req.VINSID, staticRouteData.ID))
|
||||
|
||||
return resourceStaticRouteRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenStaticRouteData(d, staticRouteData)
|
||||
|
||||
return warnings.Get()
|
||||
}
|
||||
|
||||
func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
if _, ok := d.GetOk("vins_id"); ok {
|
||||
haveVinsID, err := existVinsID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveVinsID {
|
||||
return diag.Errorf("resourceVinsUpdate: can't update Static Route because VinsID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
||||
}
|
||||
}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if d.HasChange("compute_ids") {
|
||||
deletedIds := make([]uint64, 0)
|
||||
addedIds := make([]uint64, 0)
|
||||
|
||||
oldComputeIds, newComputeIds := d.GetChange("compute_ids")
|
||||
oldComputeIdsSlice := oldComputeIds.([]interface{})
|
||||
newComputeIdsSlice := newComputeIds.([]interface{})
|
||||
|
||||
for _, el := range oldComputeIdsSlice {
|
||||
if !isContainsIds(newComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
deletedIds = append(deletedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newComputeIdsSlice {
|
||||
if !isContainsIds(oldComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
addedIds = append(addedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedIds) > 0 {
|
||||
req := vins.StaticRouteAccessRevokeRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: deletedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteAccessRevoke(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedIds) > 0 {
|
||||
req := vins.StaticRouteAccessGrantRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: addedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteAccessGrant(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceStaticRouteRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return diag.FromErr(fmt.Errorf("broken state id"))
|
||||
}
|
||||
|
||||
vinsId, _ := strconv.ParseUint(arr[0], 10, 64)
|
||||
routeId, _ := strconv.ParseUint(arr[1], 10, 64)
|
||||
|
||||
req := vins.StaticRouteDelRequest{
|
||||
VINSID: vinsId,
|
||||
RouteId: routeId,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteDel(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := dataSourceStaticRouteSchemaMake()
|
||||
rets["route_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
}
|
||||
rets["compute_ids"] = &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
}
|
||||
rets["destination"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
rets["gateway"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
rets["netmask"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func isContainsIds(els []interface{}, el interface{}) bool {
|
||||
convEl := el.(int)
|
||||
for _, elOld := range els {
|
||||
if convEl == elOld.(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ResourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceStaticRouteCreate,
|
||||
ReadContext: resourceStaticRouteRead,
|
||||
UpdateContext: resourceStaticRouteUpdate,
|
||||
DeleteContext: resourceStaticRouteDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout20m,
|
||||
Read: &constants.Timeout600s,
|
||||
Update: &constants.Timeout20m,
|
||||
Delete: &constants.Timeout600s,
|
||||
Default: &constants.Timeout600s,
|
||||
},
|
||||
|
||||
Schema: resourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
/*
|
||||
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"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func resourceStaticRouteCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
if _, ok := d.GetOk("vins_id"); ok {
|
||||
haveVinsID, err := existVinsID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveVinsID {
|
||||
return diag.Errorf("resourceStaticRouteCreate: can't create Static Route because Vins ID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
||||
}
|
||||
}
|
||||
|
||||
req := vins.StaticRouteAddRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
Destination: d.Get("destination").(string),
|
||||
Netmask: d.Get("netmask").(string),
|
||||
Gateway: d.Get("gateway").(string),
|
||||
}
|
||||
|
||||
if computesIDS, ok := d.GetOk("compute_ids"); ok {
|
||||
ids := computesIDS.([]interface{})
|
||||
|
||||
res := make([]uint64, 10)
|
||||
|
||||
for _, id := range ids {
|
||||
computeId := uint64(id.(int))
|
||||
res = append(res, computeId)
|
||||
}
|
||||
|
||||
req.ComputeIds = res
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteAdd(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
staticRouteData, err := getStaticRouteData(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(fmt.Sprintf("%d#%d", req.VINSID, staticRouteData.ID))
|
||||
|
||||
return resourceStaticRouteRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceStaticRouteRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenStaticRouteData(d, staticRouteData)
|
||||
|
||||
return warnings.Get()
|
||||
}
|
||||
|
||||
func resourceStaticRouteUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
warnings := dc.Warnings{}
|
||||
|
||||
if _, ok := d.GetOk("vins_id"); ok {
|
||||
haveVinsID, err := existVinsID(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if !haveVinsID {
|
||||
return diag.Errorf("resourceVinsUpdate: can't update Static Route because VinsID %d is not allowed or does not exist", d.Get("vins_id").(int))
|
||||
}
|
||||
}
|
||||
|
||||
staticRouteData, err := utilityDataStaticRouteCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if d.HasChange("compute_ids") {
|
||||
deletedIds := make([]uint64, 0)
|
||||
addedIds := make([]uint64, 0)
|
||||
|
||||
oldComputeIds, newComputeIds := d.GetChange("compute_ids")
|
||||
oldComputeIdsSlice := oldComputeIds.([]interface{})
|
||||
newComputeIdsSlice := newComputeIds.([]interface{})
|
||||
|
||||
for _, el := range oldComputeIdsSlice {
|
||||
if !isContainsIds(newComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
deletedIds = append(deletedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newComputeIdsSlice {
|
||||
if !isContainsIds(oldComputeIdsSlice, el) {
|
||||
convertedEl := uint64(el.(int))
|
||||
addedIds = append(addedIds, convertedEl)
|
||||
}
|
||||
}
|
||||
|
||||
if len(deletedIds) > 0 {
|
||||
req := vins.StaticRouteAccessRevokeRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: deletedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteAccessRevoke(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedIds) > 0 {
|
||||
req := vins.StaticRouteAccessGrantRequest{
|
||||
VINSID: uint64(d.Get("vins_id").(int)),
|
||||
RouteId: staticRouteData.ID,
|
||||
ComputeIds: addedIds,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteAccessGrant(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append(warnings.Get(), resourceStaticRouteRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceStaticRouteDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
arr := strings.Split(d.Id(), "#")
|
||||
if len(arr) != 2 {
|
||||
return diag.FromErr(fmt.Errorf("broken state id"))
|
||||
}
|
||||
|
||||
vinsId, _ := strconv.ParseUint(arr[0], 10, 64)
|
||||
routeId, _ := strconv.ParseUint(arr[1], 10, 64)
|
||||
|
||||
req := vins.StaticRouteDelRequest{
|
||||
VINSID: vinsId,
|
||||
RouteId: routeId,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().StaticRouteDel(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceStaticRouteSchemaMake() map[string]*schema.Schema {
|
||||
rets := dataSourceStaticRouteSchemaMake()
|
||||
rets["route_id"] = &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
}
|
||||
rets["compute_ids"] = &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
},
|
||||
}
|
||||
rets["destination"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
rets["gateway"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
rets["netmask"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
}
|
||||
|
||||
return rets
|
||||
}
|
||||
|
||||
func isContainsIds(els []interface{}, el interface{}) bool {
|
||||
convEl := el.(int)
|
||||
for _, elOld := range els {
|
||||
if convEl == elOld.(int) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ResourceStaticRoute() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceStaticRouteCreate,
|
||||
ReadContext: resourceStaticRouteRead,
|
||||
UpdateContext: resourceStaticRouteUpdate,
|
||||
DeleteContext: resourceStaticRouteDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout20m,
|
||||
Read: &constants.Timeout600s,
|
||||
Update: &constants.Timeout20m,
|
||||
Delete: &constants.Timeout600s,
|
||||
Default: &constants.Timeout600s,
|
||||
},
|
||||
|
||||
Schema: resourceStaticRouteSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,17 +132,18 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
|
||||
req.PreReservationsNum = uint64(preReservationsNum.(int))
|
||||
}
|
||||
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInRG(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(id, 10))
|
||||
} else if accountIdOk {
|
||||
req := vins.CreateInAccountRequest{
|
||||
Name: d.Get("name").(string),
|
||||
AccountID: uint64(accountId.(int)),
|
||||
Name: d.Get("name").(string),
|
||||
AccountID: uint64(accountId.(int)),
|
||||
}
|
||||
|
||||
if gid, ok := d.GetOk("gid"); ok {
|
||||
@@ -157,9 +158,10 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
if preReservationsNum, ok := d.GetOk("pre_reservations_num"); ok {
|
||||
req.PreReservationsNum = uint64(preReservationsNum.(int))
|
||||
}
|
||||
|
||||
|
||||
id, err := c.CloudAPI().VINS().CreateInAccount(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
@@ -218,7 +220,6 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
@@ -387,22 +388,22 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
return diag.Errorf("The resource cannot be updated because it has been destroyed")
|
||||
// return resourceVinsCreate(ctx, d, m)
|
||||
case status.Deleted:
|
||||
hasChangeState = true
|
||||
if restore, ok := d.GetOk("restore"); ok && restore.(bool) {
|
||||
req := vins.RestoreRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
req := vins.RestoreRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().Restore(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
_, err := c.CloudAPI().VINS().Restore(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
hasChangeState = true
|
||||
}
|
||||
case status.Modeled:
|
||||
return diag.Errorf("ViNS are in status: %s, please, contact support for more information", vinsData.Status)
|
||||
case status.Created:
|
||||
case status.Enabled:
|
||||
if !isEnabled {
|
||||
hasChangeState = true
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
@@ -411,11 +412,11 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
hasChangeState = true
|
||||
}
|
||||
case status.Enabling:
|
||||
case status.Disabled:
|
||||
if isEnabled {
|
||||
hasChangeState = true
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
@@ -424,6 +425,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
hasChangeState = true
|
||||
}
|
||||
case status.Disabling:
|
||||
case status.Deleting:
|
||||
@@ -438,62 +440,64 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
enableOld, enableNew := d.GetChange("enable")
|
||||
if enableOld.(bool) && !enableNew.(bool) {
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().Disable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
} else if !enableOld.(bool) && enableNew.(bool) {
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().Enable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
//extnet v1
|
||||
oldExtNetId, newExtNedId := d.GetChange("ext_net_id")
|
||||
if oldExtNetId.(int) != newExtNedId.(int) {
|
||||
log.Debugf("resourceVinsUpdate: 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: vinsData.ID}
|
||||
|
||||
_, err := c.CloudAPI().VINS().ExtNetDisconnect(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if newExtNedId.(int) > 0 {
|
||||
// new external network connection requested - connect ViNS
|
||||
req := vins.ExtNetConnectRequest{
|
||||
if d.HasChange("enable") {
|
||||
enableOld, enableNew := d.GetChange("enable")
|
||||
if enableOld.(bool) && !enableNew.(bool) {
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
NetID: uint64(newExtNedId.(int)),
|
||||
IP: "",
|
||||
}
|
||||
|
||||
extNetIp, ok := d.GetOk("ext_net_ip")
|
||||
if ok && extNetIp.(string) != "" {
|
||||
req.IP = extNetIp.(string)
|
||||
_, err := c.CloudAPI().VINS().Disable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
} else if !enableOld.(bool) && enableNew.(bool) {
|
||||
req := vins.DisableEnableRequest{
|
||||
VINSID: vinsData.ID,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().ExtNetConnect(ctx, req)
|
||||
_, err := c.CloudAPI().VINS().Enable(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if d.HasChange("ext_net_id") {
|
||||
//extnet v1
|
||||
oldExtNetId, newExtNedId := d.GetChange("ext_net_id")
|
||||
if oldExtNetId.(int) != newExtNedId.(int) {
|
||||
log.Debugf("resourceVinsUpdate: 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: vinsData.ID}
|
||||
|
||||
_, err := c.CloudAPI().VINS().ExtNetDisconnect(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
|
||||
if newExtNedId.(int) > 0 {
|
||||
// new external network connection requested - connect ViNS
|
||||
req := vins.ExtNetConnectRequest{
|
||||
VINSID: vinsData.ID,
|
||||
NetID: uint64(newExtNedId.(int)),
|
||||
IP: "",
|
||||
}
|
||||
|
||||
extNetIp, ok := d.GetOk("ext_net_ip")
|
||||
if ok && extNetIp.(string) != "" {
|
||||
req.IP = extNetIp.(string)
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().VINS().ExtNetConnect(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if d.HasChange("ip") {
|
||||
deletedIps := make([]interface{}, 0)
|
||||
addedIps := make([]interface{}, 0)
|
||||
@@ -619,25 +623,27 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
||||
}
|
||||
}
|
||||
|
||||
if oldRestart, newRestart := d.GetChange("vnfdev_restart"); oldRestart == false && newRestart == true {
|
||||
req := vins.VNFDevRestartRequest{VINSID: vinsData.ID}
|
||||
if d.HasChange("vnfdev_restart") {
|
||||
if oldRestart, newRestart := d.GetChange("vnfdev_restart"); oldRestart == false && newRestart == true {
|
||||
req := vins.VNFDevRestartRequest{VINSID: vinsData.ID}
|
||||
|
||||
_, err := c.CloudAPI().VINS().VNFDevRestart(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
_, err := c.CloudAPI().VINS().VNFDevRestart(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if d.HasChange("vnfdev_redeploy") {
|
||||
if oldRedeploy, newRedeploy := d.GetChange("vnfdev_redeploy"); oldRedeploy == false && newRedeploy == true {
|
||||
req := vins.VNFDevRedeployRequest{VINSID: vinsData.ID}
|
||||
|
||||
if oldRedeploy, newRedeploy := d.GetChange("vnfdev_redeploy"); oldRedeploy == false && newRedeploy == true {
|
||||
req := vins.VNFDevRedeployRequest{VINSID: vinsData.ID}
|
||||
|
||||
_, err := c.CloudAPI().VINS().VNFDevRedeploy(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
_, err := c.CloudAPI().VINS().VNFDevRedeploy(ctx, req)
|
||||
if err != nil {
|
||||
warnings.Add(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append (warnings.Get(), resourceVinsRead(ctx, d, m)...)
|
||||
return append(warnings.Get(), resourceVinsRead(ctx, d, m)...)
|
||||
}
|
||||
|
||||
func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
@@ -677,9 +683,9 @@ func extNetSchemaMake() map[string]*schema.Schema {
|
||||
func ipSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string {"DHCP", "VIP", "EXCLUDE"}, false),
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"DHCP", "VIP", "EXCLUDE"}, false),
|
||||
},
|
||||
"ip_addr": {
|
||||
Type: schema.TypeString,
|
||||
|
||||
@@ -47,8 +47,8 @@ func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m
|
||||
req := vins.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = vinsId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
@@ -60,4 +60,3 @@ func utilityDataVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m
|
||||
|
||||
return vins, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ func utilityVinsAuditsCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
req := vins.AuditsRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = vinsId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ func utilityVinsExtNetListCheckPresence(ctx context.Context, d *schema.ResourceD
|
||||
}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = vinsId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ func utilityVinsIpListCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
req := vins.IPListRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = vinsId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ func utilityVinsNatRuleListCheckPresence(ctx context.Context, d *schema.Resource
|
||||
req := vins.NATRuleListRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
rgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = rgId
|
||||
vinsId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
req.VINSID = vinsId
|
||||
} else {
|
||||
req.VINSID = uint64(d.Get("vins_id").(int))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user