git test
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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 dataSourceAccessGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
accessGroup, err := utilityAccessGroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenAccessGroupDataSource(d, accessGroup)
|
||||
d.SetId(accessGroup.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceAccessGroupSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "The unique access group ID",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"comment": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Comment description",
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Creation timestamp",
|
||||
},
|
||||
"net_object_access_group": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Net object access group configuration",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Access group ID",
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Unique identifier",
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Version identifier",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func DataSourceAccessGroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceAccessGroupRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceAccessGroupSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
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 dataSourceAccessGroupListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
accessGroupList, err := utilityAccessGroupListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccessGroupList(accessGroupList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceAccessGroupList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceAccessGroupListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceAccessGroupListSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
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 dataSourceAccessGroupUserListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
userList, err := utilityAccessGroupUserListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenAccessGroupUserList(userList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceAccessGroupUserList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceAccessGroupUserListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceAccessGroupUserListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/acsgroups"
|
||||
)
|
||||
|
||||
func flattenAccessGroupDataSource(d *schema.ResourceData, accessGroupRecord *acsgroups.AccessGroup) {
|
||||
d.Set("display_name", accessGroupRecord.DisplayName)
|
||||
d.Set("comment", accessGroupRecord.Comment)
|
||||
d.Set("created_at", accessGroupRecord.CreatedAt)
|
||||
d.Set("net_object_access_group", flattenNetObjectAccessGroup(accessGroupRecord.NetObjectAccessGroup))
|
||||
}
|
||||
|
||||
func flattenAccessGroupResource(d *schema.ResourceData, accessGroupRecord *acsgroups.AccessGroup, userList *acsgroups.UsersList) {
|
||||
d.Set("display_name", accessGroupRecord.DisplayName)
|
||||
d.Set("comment", accessGroupRecord.Comment)
|
||||
d.Set("created_at", accessGroupRecord.CreatedAt)
|
||||
d.Set("net_object_access_group", flattenNetObjectAccessGroup(accessGroupRecord.NetObjectAccessGroup))
|
||||
|
||||
defaultSecurityPolicy := accessGroupRecord.DefaultSecurityPolicy
|
||||
if defaultSecurityPolicy.ID != "" {
|
||||
flattenedDefaultSecPolicy := map[string]interface{}{
|
||||
"display_name": defaultSecurityPolicy.DisplayName,
|
||||
"id": defaultSecurityPolicy.ID,
|
||||
"description": defaultSecurityPolicy.Description,
|
||||
"version_id": int(defaultSecurityPolicy.VersionID),
|
||||
"access_group_id": defaultSecurityPolicy.AccessGroupID,
|
||||
"default_open_session_drop": defaultSecurityPolicy.DefaultOpenSessionDrop,
|
||||
}
|
||||
|
||||
if defaultSecPolicy, ok := d.GetOk("default_security_policy"); ok {
|
||||
defaultSecPolicyList := defaultSecPolicy.([]interface{})
|
||||
if len(defaultSecPolicyList) > 0 {
|
||||
defaultSecPolicyMap := defaultSecPolicyList[0].(map[string]interface{})
|
||||
|
||||
if defaultAclDrop, ok := defaultSecPolicyMap["default_acl_drop"].(string); ok && defaultAclDrop != "" {
|
||||
flattenedDefaultSecPolicy["default_acl_drop"] = defaultAclDrop
|
||||
} else if defaultSecurityPolicy.DefaultAclDrop != "" {
|
||||
flattenedDefaultSecPolicy["default_acl_drop"] = defaultSecurityPolicy.DefaultAclDrop
|
||||
}
|
||||
|
||||
if defaultOpenSessionDrop, ok := defaultSecPolicyMap["default_open_session_drop"].(bool); ok {
|
||||
flattenedDefaultSecPolicy["default_open_session_drop"] = defaultOpenSessionDrop
|
||||
}
|
||||
} else {
|
||||
if defaultSecurityPolicy.DefaultAclDrop != "" {
|
||||
flattenedDefaultSecPolicy["default_acl_drop"] = defaultSecurityPolicy.DefaultAclDrop
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if defaultSecurityPolicy.DefaultAclDrop != "" {
|
||||
flattenedDefaultSecPolicy["default_acl_drop"] = defaultSecurityPolicy.DefaultAclDrop
|
||||
}
|
||||
}
|
||||
|
||||
d.Set("default_security_policy", []map[string]interface{}{flattenedDefaultSecPolicy})
|
||||
}
|
||||
|
||||
if userList != nil {
|
||||
d.Set("users", flattenAccessGroupUsers(userList))
|
||||
}
|
||||
}
|
||||
|
||||
func flattenNetObjectAccessGroup(noag acsgroups.NetObjectAccessGroup) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"access_group_id": noag.AccessGroupID,
|
||||
"id": noag.ID,
|
||||
"version_id": noag.VersionID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDefaultSecurityPolicy(dsp acsgroups.DefaultSecurityPolicy) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"display_name": dsp.DisplayName,
|
||||
"id": dsp.ID,
|
||||
"description": dsp.Description,
|
||||
"version_id": dsp.VersionID,
|
||||
"access_group_id": dsp.AccessGroupID,
|
||||
"default_acl_drop": dsp.DefaultAclDrop,
|
||||
"default_open_session_drop": dsp.DefaultOpenSessionDrop,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccessGroupList(agList *acsgroups.AccessGroupList) []map[string]interface{} {
|
||||
if agList == nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
res := make([]map[string]interface{}, 0, len(agList.AccessGroups))
|
||||
for _, v := range agList.AccessGroups {
|
||||
temp := map[string]interface{}{
|
||||
"id": v.ID,
|
||||
"display_name": v.DisplayName,
|
||||
"comment": v.Comment,
|
||||
"created_at": v.CreatedAt,
|
||||
"net_object_access_group": flattenNetObjectAccessGroup(v.NetObjectAccessGroup),
|
||||
"default_security_policy": flattenDefaultSecurityPolicy(v.DefaultSecurityPolicy),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccessGroupUserList(userList *acsgroups.UsersList) []map[string]interface{} {
|
||||
if userList == nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
res := make([]map[string]interface{}, 0, len(userList.Users))
|
||||
for _, v := range userList.Users {
|
||||
temp := map[string]interface{}{
|
||||
"id": v.ID,
|
||||
"display_name": v.Name,
|
||||
"role_id": v.RoleID,
|
||||
"login": v.Login,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAccessGroupUsers(userList *acsgroups.UsersList) []map[string]interface{} {
|
||||
if userList == nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
res := make([]map[string]interface{}, 0, len(userList.Users))
|
||||
for _, v := range userList.Users {
|
||||
temp := map[string]interface{}{
|
||||
"user_id": v.ID,
|
||||
"access_group_role_id": v.RoleID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/sdn/acsgroups"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/defsecpolicies"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceAccessGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceAccessGroupCreate: called access group with name %s",
|
||||
d.Get("display_name").(string))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := acsgroups.CreateRequest{
|
||||
DisplayName: d.Get("display_name").(string),
|
||||
Comment: d.Get("comment").(string),
|
||||
}
|
||||
|
||||
accessGroup, err := c.SDN().AccessGroups().Create(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(accessGroup.ID)
|
||||
|
||||
if users, ok := d.GetOk("users"); ok {
|
||||
usersList := users.([]interface{})
|
||||
for _, userRaw := range usersList {
|
||||
userMap := userRaw.(map[string]interface{})
|
||||
userReq := acsgroups.UserAddRequest{
|
||||
GroupID: accessGroup.ID,
|
||||
UserID: userMap["user_id"].(string),
|
||||
AccessGroupRoleID: userMap["access_group_role_id"].(string),
|
||||
}
|
||||
_, err := c.SDN().AccessGroups().UserAdd(ctx, userReq)
|
||||
if err != nil {
|
||||
log.Warnf("resourceAccessGroupRead: failed to add users for access group %s: %v", d.Id(), err)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if defaultSecPolicy, ok := d.GetOk("default_security_policy"); ok {
|
||||
defaultSecPolicyList := defaultSecPolicy.([]interface{})
|
||||
if len(defaultSecPolicyList) > 0 {
|
||||
defaultSecPolicyMap := defaultSecPolicyList[0].(map[string]interface{})
|
||||
|
||||
getReq := acsgroups.GetGroupRequest{
|
||||
GroupID: accessGroup.ID,
|
||||
}
|
||||
fullAccessGroup, err := c.SDN().AccessGroups().Get(ctx, getReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if fullAccessGroup.DefaultSecurityPolicy.ID == "" {
|
||||
return diag.Errorf("default security policy not found for access group %s", accessGroup.ID)
|
||||
}
|
||||
|
||||
updateReq := defsecpolicies.UpdateRequest{
|
||||
AccessGroupID: accessGroup.ID,
|
||||
VersionID: uint64(fullAccessGroup.DefaultSecurityPolicy.VersionID),
|
||||
}
|
||||
|
||||
if defaultAclDrop, ok := defaultSecPolicyMap["default_acl_drop"].(string); ok && defaultAclDrop != "" {
|
||||
updateReq.DefaultACLDrop = defaultAclDrop
|
||||
}
|
||||
|
||||
if defaultOpenSessionDrop, ok := defaultSecPolicyMap["default_open_session_drop"].(bool); ok {
|
||||
updateReq.DefaultOpenSessionDrop = defaultOpenSessionDrop
|
||||
}
|
||||
|
||||
_, err = c.SDN().DefaultSecurityPolicies().Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resourceAccessGroupRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceAccessGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceAccessGroupRead: called access group with id %s", d.Id())
|
||||
|
||||
accessGroup, err := utilityAccessGroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
userList, err := utilityAccessGroupUsersGet(ctx, accessGroup.ID, m)
|
||||
if err != nil {
|
||||
log.Warnf("resourceAccessGroupRead: failed to get users for access group %s: %v", d.Id(), err)
|
||||
userList = nil
|
||||
}
|
||||
|
||||
flattenAccessGroupResource(d, accessGroup, userList)
|
||||
d.SetId(accessGroup.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceAccessGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceAccessGroupUpdate: called access group with id %s", d.Id())
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := acsgroups.UpdateRequest{
|
||||
AccessGroupID: d.Id(),
|
||||
}
|
||||
|
||||
needUpdate := false
|
||||
|
||||
if d.HasChange("display_name") {
|
||||
req.DisplayName = d.Get("display_name").(string)
|
||||
needUpdate = true
|
||||
}
|
||||
|
||||
if d.HasChange("comment") {
|
||||
req.Comment = d.Get("comment").(string)
|
||||
needUpdate = true
|
||||
}
|
||||
|
||||
var err error
|
||||
if needUpdate {
|
||||
_, err = c.SDN().AccessGroups().Update(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("users") {
|
||||
oldUsers, newUsers := d.GetChange("users")
|
||||
oldUsersList := oldUsers.([]interface{})
|
||||
newUsersList := newUsers.([]interface{})
|
||||
|
||||
oldUsersMap := make(map[string]string)
|
||||
for _, userRaw := range oldUsersList {
|
||||
userMap := userRaw.(map[string]interface{})
|
||||
userID := userMap["user_id"].(string)
|
||||
oldUsersMap[userID] = userMap["access_group_role_id"].(string)
|
||||
}
|
||||
|
||||
newUsersMap := make(map[string]string)
|
||||
for _, userRaw := range newUsersList {
|
||||
userMap := userRaw.(map[string]interface{})
|
||||
userID := userMap["user_id"].(string)
|
||||
newUsersMap[userID] = userMap["access_group_role_id"].(string)
|
||||
}
|
||||
|
||||
for userID := range oldUsersMap {
|
||||
if _, exists := newUsersMap[userID]; !exists {
|
||||
userDeleteReq := acsgroups.UserDeleteRequest{
|
||||
GroupID: d.Id(),
|
||||
UserID: userID,
|
||||
}
|
||||
_, err := c.SDN().AccessGroups().UserDelete(ctx, userDeleteReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for userID, roleID := range newUsersMap {
|
||||
if oldRoleID, exists := oldUsersMap[userID]; !exists || oldRoleID != roleID {
|
||||
if !exists {
|
||||
userAddReq := acsgroups.UserAddRequest{
|
||||
GroupID: d.Id(),
|
||||
UserID: userID,
|
||||
AccessGroupRoleID: roleID,
|
||||
}
|
||||
_, err := c.SDN().AccessGroups().UserAdd(ctx, userAddReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
} else if oldRoleID != roleID {
|
||||
userUpdateRoleReq := acsgroups.UserUpdateRoleRequest{
|
||||
GroupID: d.Id(),
|
||||
UserID: userID,
|
||||
AccessGroupRoleID: roleID,
|
||||
}
|
||||
_, err := c.SDN().AccessGroups().UserUpdateRole(ctx, userUpdateRoleReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("default_security_policy") {
|
||||
defaultSecPolicy, ok := d.GetOk("default_security_policy")
|
||||
if ok {
|
||||
defaultSecPolicyList := defaultSecPolicy.([]interface{})
|
||||
if len(defaultSecPolicyList) > 0 {
|
||||
defaultSecPolicyMap := defaultSecPolicyList[0].(map[string]interface{})
|
||||
|
||||
versionID, ok := defaultSecPolicyMap["version_id"].(int)
|
||||
if !ok || versionID == 0 {
|
||||
return diag.Errorf("version_id not found in default_security_policy for access group %s", d.Id())
|
||||
}
|
||||
|
||||
updateReq := defsecpolicies.UpdateRequest{
|
||||
AccessGroupID: d.Id(),
|
||||
VersionID: uint64(versionID),
|
||||
}
|
||||
|
||||
if defaultAclDrop, ok := defaultSecPolicyMap["default_acl_drop"].(string); ok && defaultAclDrop != "" {
|
||||
updateReq.DefaultACLDrop = defaultAclDrop
|
||||
}
|
||||
|
||||
if defaultOpenSessionDrop, ok := defaultSecPolicyMap["default_open_session_drop"].(bool); ok {
|
||||
updateReq.DefaultOpenSessionDrop = defaultOpenSessionDrop
|
||||
}
|
||||
|
||||
_, err = c.SDN().DefaultSecurityPolicies().Update(ctx, updateReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resourceAccessGroupRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceAccessGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceAccessGroupDelete: called access group with id %s", d.Id())
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := acsgroups.DeleteRequest{
|
||||
GroupID: d.Id(),
|
||||
}
|
||||
|
||||
_, err := c.SDN().AccessGroups().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResourceAccessGroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceAccessGroupCreate,
|
||||
ReadContext: resourceAccessGroupRead,
|
||||
UpdateContext: resourceAccessGroupUpdate,
|
||||
DeleteContext: resourceAccessGroupDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout600s,
|
||||
Delete: &constants.Timeout300s,
|
||||
Default: &constants.Timeout300s,
|
||||
},
|
||||
|
||||
Schema: resourceAccessGroupSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,393 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
)
|
||||
|
||||
func dataSourceAccessGroupListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Page number",
|
||||
},
|
||||
"per_page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Items per page",
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"display_name", "created_at", "updated_at", "deleted_at", "owner_login"}, false),
|
||||
Description: "sort by one of supported fields",
|
||||
},
|
||||
"sort_order": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"asc", "desc"}, false),
|
||||
Description: "sort order",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "filter by enabled/disabled group",
|
||||
},
|
||||
"deleted": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "filter by deleted/not deleted group",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by display name",
|
||||
},
|
||||
"created_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by the lower limit of the creation date",
|
||||
},
|
||||
"created_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by the upper limit of the creation date",
|
||||
},
|
||||
"owner_display_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "List of access groups",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The unique identifier",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"comment": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Comment description",
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Creation timestamp",
|
||||
},
|
||||
"net_object_access_group": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Net object access group configuration",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Access group ID",
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Unique identifier",
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Version identifier",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"default_security_policy": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Default security policy configuration",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy display name",
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy unique identifier",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy description",
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Policy version identifier",
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy access group ID",
|
||||
},
|
||||
"default_acl_drop": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Default ACL drop action",
|
||||
},
|
||||
"default_open_session_drop": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Default open session drop flag",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceAccessGroupUserListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "filter by access group id",
|
||||
},
|
||||
"global_role": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by global role",
|
||||
},
|
||||
"access_group_role": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by access group role",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "filter by inclusion",
|
||||
},
|
||||
"deleted": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "delete filter",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by display name",
|
||||
},
|
||||
"login": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by user login",
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "who created the user",
|
||||
},
|
||||
"deleted_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "who deleted the user",
|
||||
},
|
||||
"disabled_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "who disabled the user",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "result page number",
|
||||
},
|
||||
"per_page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "number of results per page",
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"display_name", "email", "phone", "created_at", "updated_at", "deleted_at"}, false),
|
||||
Description: "sort by one of supported fields",
|
||||
},
|
||||
"sort_order": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"asc", "desc"}, false),
|
||||
Description: "sorting order",
|
||||
},
|
||||
"created_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by the lower limit of the creation date",
|
||||
},
|
||||
"created_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "filter by the upper limit of the creation date",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "List of users",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "The unique identifier",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"role_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Role identifier",
|
||||
},
|
||||
"login": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Login",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func resourceAccessGroupSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "group name",
|
||||
},
|
||||
"comment": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "description (comment) of the group",
|
||||
},
|
||||
"users": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Description: "managing users who are part of a group",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_role_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "id of the assigned role",
|
||||
},
|
||||
"user_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Description: "user ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"default_security_policy": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Description: "Default security policy configuration",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"default_acl_drop": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Default ACL drop action",
|
||||
},
|
||||
"default_open_session_drop": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "Default open session drop flag",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy display name",
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy unique identifier",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy description",
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Policy version identifier",
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Policy access group ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// Computed fields
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Creation timestamp",
|
||||
},
|
||||
"net_object_access_group": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Net object access group configuration",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Access group ID",
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Unique identifier",
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Version identifier",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/acsgroups"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityAccessGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*acsgroups.AccessGroup, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := acsgroups.GetGroupRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
req.GroupID = d.Id()
|
||||
} else {
|
||||
req.GroupID = d.Get("access_group_id").(string)
|
||||
}
|
||||
|
||||
accessGroup, err := c.SDN().AccessGroups().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accessGroup, nil
|
||||
}
|
||||
|
||||
func utilityAccessGroupUsersGet(ctx context.Context, groupID string, m interface{}) (*acsgroups.UsersList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := acsgroups.UsersListRequest{
|
||||
AccessGroupID: groupID,
|
||||
}
|
||||
|
||||
userList, err := c.SDN().AccessGroups().UsersList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return userList, nil
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/acsgroups"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityAccessGroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*acsgroups.AccessGroupList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := acsgroups.ListGroupsRequest{}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if perPage, ok := d.GetOk("per_page"); ok {
|
||||
req.PerPage = uint64(perPage.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
if sortOrder, ok := d.GetOk("sort_order"); ok {
|
||||
req.SortOrder = sortOrder.(string)
|
||||
}
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
req.Enabled = enabled.(bool)
|
||||
}
|
||||
if deleted, ok := d.GetOk("deleted"); ok {
|
||||
req.Deleted = deleted.(bool)
|
||||
}
|
||||
if displayName, ok := d.GetOk("display_name"); ok {
|
||||
req.DisplayName = displayName.(string)
|
||||
}
|
||||
if createdFrom, ok := d.GetOk("created_from"); ok {
|
||||
req.CreatedFrom = createdFrom.(string)
|
||||
}
|
||||
if createdTo, ok := d.GetOk("created_to"); ok {
|
||||
req.CreatedTo = createdTo.(string)
|
||||
}
|
||||
if ownerDisplayName, ok := d.GetOk("owner_display_name"); ok {
|
||||
req.OwnerDisplayName = ownerDisplayName.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccessGroupListCheckPresence")
|
||||
accessGroupList, err := c.SDN().AccessGroups().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return accessGroupList, nil
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package accessgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/acsgroups"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityAccessGroupUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*acsgroups.UsersList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := acsgroups.UsersListRequest{}
|
||||
|
||||
req.AccessGroupID = d.Get("access_group_id").(string)
|
||||
|
||||
if globalRole, ok := d.GetOk("global_role"); ok {
|
||||
req.GlobalRole = globalRole.(string)
|
||||
}
|
||||
if accessGroupRole, ok := d.GetOk("access_group_role"); ok {
|
||||
req.AccessGroupRole = accessGroupRole.(string)
|
||||
}
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
req.Enabled = enabled.(bool)
|
||||
}
|
||||
if deleted, ok := d.GetOk("deleted"); ok {
|
||||
req.Deleted = deleted.(bool)
|
||||
}
|
||||
if displayName, ok := d.GetOk("display_name"); ok {
|
||||
req.DisplayName = displayName.(string)
|
||||
}
|
||||
if login, ok := d.GetOk("login"); ok {
|
||||
req.Login = login.(string)
|
||||
}
|
||||
if createdBy, ok := d.GetOk("created_by"); ok {
|
||||
req.CreatedBy = createdBy.(string)
|
||||
}
|
||||
if updatedBy, ok := d.GetOk("updated_by"); ok {
|
||||
req.UpdatedBy = updatedBy.(string)
|
||||
}
|
||||
if deletedBy, ok := d.GetOk("deleted_by"); ok {
|
||||
req.DeletedBy = deletedBy.(string)
|
||||
}
|
||||
if disabledBy, ok := d.GetOk("disabled_by"); ok {
|
||||
req.DisabledBy = disabledBy.(string)
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if perPage, ok := d.GetOk("per_page"); ok {
|
||||
req.PerPage = uint64(perPage.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
if sortOrder, ok := d.GetOk("sort_order"); ok {
|
||||
req.SortOrder = sortOrder.(string)
|
||||
}
|
||||
if createdFrom, ok := d.GetOk("created_from"); ok {
|
||||
req.CreatedFrom = createdFrom.(string)
|
||||
}
|
||||
if createdTo, ok := d.GetOk("created_to"); ok {
|
||||
req.CreatedTo = createdTo.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityAccessGroupUserListCheckPresence")
|
||||
userList, err := c.SDN().AccessGroups().UsersList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return userList, nil
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package defaultsecuritypolicy
|
||||
|
||||
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 dataSourceDefaultSecurityPolicyListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
defaultSecurityPolicyList, err := utilityDefaultSecurityPolicyListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenDefaultSecurityPolicyList(defaultSecurityPolicyList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceDefaultSecurityPolicyList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceDefaultSecurityPolicyListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceDefaultSecurityPolicyListSchemaMake(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package defaultsecuritypolicy
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/defsecpolicies"
|
||||
)
|
||||
|
||||
func flattenDefaultSecurityPolicyList(policyList *defsecpolicies.SecurityPoliciesList) []map[string]interface{} {
|
||||
if policyList == nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
res := make([]map[string]interface{}, 0, len(policyList.Policies))
|
||||
for _, v := range policyList.Policies {
|
||||
temp := map[string]interface{}{
|
||||
"access_group_id": v.AccessGroupID,
|
||||
"created_at": v.CreatedAt,
|
||||
"default_acl_drop": v.DefaultACLDrop,
|
||||
"default_open_session_drop": v.DefaultOpenSessionDrop,
|
||||
"description": v.Description,
|
||||
"display_name": v.DisplayName,
|
||||
"id": v.ID,
|
||||
"security_rules": flattenSecurityRules(v.SecurityRules),
|
||||
"locked_at": v.LockedAt,
|
||||
"status": flattenStatus(v.Status),
|
||||
"version_id": int(v.VersionID),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSecurityRules(rules []defsecpolicies.SecurityRule) []map[string]interface{} {
|
||||
if rules == nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
res := make([]map[string]interface{}, 0, len(rules))
|
||||
for _, v := range rules {
|
||||
temp := map[string]interface{}{
|
||||
"access_group_id": v.AccessGroupID,
|
||||
"action": v.Action,
|
||||
"description": v.Description,
|
||||
"destination_net_object": flattenNetObject(v.DestinationNetObject),
|
||||
"direction": v.Direction,
|
||||
"display_name": v.DisplayName,
|
||||
"enabled": v.Enabled,
|
||||
"filter": flattenFilter(v.Filter),
|
||||
"id": v.ID,
|
||||
"log_enabled": v.LogEnabled,
|
||||
"log_name": v.LogName,
|
||||
"log_severity": v.LogSeverity,
|
||||
"priority": v.Priority,
|
||||
"security_policy_id": v.SecurityPolicyID,
|
||||
"source_net_object": flattenNetObject(v.SourceNetObject),
|
||||
"statistics_enabled": v.StatisticsEnabled,
|
||||
"version_id": int(v.VersionID),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNetObject(netObj defsecpolicies.NetObject) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"display_name": netObj.DisplayName,
|
||||
"net_address_pool_id": netObj.NetAddressPoolID,
|
||||
"net_object_group_id": netObj.NetObjectGroupID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenFilter(filter defsecpolicies.Filter) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"filters": flattenFilterParams(filter.Filters),
|
||||
"name": filter.Name,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenFilterParams(params defsecpolicies.FilterParams) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"all": params.All,
|
||||
"arp": params.ARP,
|
||||
"dhcp": params.DHCP,
|
||||
"expression": params.Expression,
|
||||
"icmp": params.ICMP,
|
||||
"ip": params.IP,
|
||||
"ip_v4": params.IPv4,
|
||||
"ip_v6": params.IPv6,
|
||||
"keep_opened_sessions": params.KeepOpenedSessions,
|
||||
"nd": params.ND,
|
||||
"tcp": params.TCP,
|
||||
"tcp_dst_ports": params.TCPDstPorts,
|
||||
"udp": params.UDP,
|
||||
"udp_dst_ports": params.UDPDstPorts,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStatus(status defsecpolicies.Status) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"common": status.Common,
|
||||
"hypervisors": flattenHypervisorStatuses(status.Hypervisors),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenHypervisorStatuses(hypervisors []defsecpolicies.HypervisorStatus) []map[string]interface{} {
|
||||
if hypervisors == nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
res := make([]map[string]interface{}, 0, len(hypervisors))
|
||||
for _, v := range hypervisors {
|
||||
temp := map[string]interface{}{
|
||||
"status": v.Status,
|
||||
"name": v.Name,
|
||||
"display_name": v.DisplayName,
|
||||
"hypervisor_status": v.HypervisorStatus,
|
||||
"synced_at": v.SyncedAt,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,369 +0,0 @@
|
||||
package defaultsecuritypolicy
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
)
|
||||
|
||||
func dataSourceDefaultSecurityPolicyListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "id of the access group",
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "result page number",
|
||||
},
|
||||
"per_page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "number of results per page",
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"created_at", "updated_at"}, false),
|
||||
Description: "sort by one of the supported fields",
|
||||
},
|
||||
"sort_order": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"asc", "desc"}, false),
|
||||
Description: "sorting order",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "List of default security policies",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Access group ID",
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Creation timestamp",
|
||||
},
|
||||
"default_acl_drop": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Default ACL drop action",
|
||||
},
|
||||
"default_open_session_drop": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Default open session drop flag",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Description",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Unique identifier",
|
||||
},
|
||||
"security_rules": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Security rules",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Access group ID",
|
||||
},
|
||||
"action": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Action",
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Description",
|
||||
},
|
||||
"destination_net_object": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Destination network object",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"net_address_pool_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Network address pool ID",
|
||||
},
|
||||
"net_object_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Network object group ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"direction": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Direction",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Enabled flag",
|
||||
},
|
||||
"filter": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Filter configuration",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"filters": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Filter parameters",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"all": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "All protocols flag",
|
||||
},
|
||||
"arp": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "ARP protocol flag",
|
||||
},
|
||||
"dhcp": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "DHCP protocol flag",
|
||||
},
|
||||
"expression": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Filter expression",
|
||||
},
|
||||
"icmp": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "ICMP protocol flag",
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "IP protocol flag",
|
||||
},
|
||||
"ip_v4": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "IPv4 protocol flag",
|
||||
},
|
||||
"ip_v6": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "IPv6 protocol flag",
|
||||
},
|
||||
"keep_opened_sessions": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Keep opened sessions flag",
|
||||
},
|
||||
"nd": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "ND protocol flag",
|
||||
},
|
||||
"tcp": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "TCP protocol flag",
|
||||
},
|
||||
"tcp_dst_ports": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "TCP destination ports",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"udp": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "UDP protocol flag",
|
||||
},
|
||||
"udp_dst_ports": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "UDP destination ports",
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Filter name",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Unique identifier",
|
||||
},
|
||||
"log_enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Log enabled flag",
|
||||
},
|
||||
"log_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Log name",
|
||||
},
|
||||
"log_severity": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Log severity",
|
||||
},
|
||||
"priority": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Priority",
|
||||
},
|
||||
"security_policy_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Security policy ID",
|
||||
},
|
||||
"source_net_object": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Source network object",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"net_address_pool_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Network address pool ID",
|
||||
},
|
||||
"net_object_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Network object group ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"statistics_enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
Description: "Statistics enabled flag",
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Version ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"locked_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Locked timestamp",
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Status information",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"common": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Common status",
|
||||
},
|
||||
"hypervisors": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "Hypervisor statuses",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Status",
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Name",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Display name",
|
||||
},
|
||||
"hypervisor_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Hypervisor status",
|
||||
},
|
||||
"synced_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Description: "Last sync timestamp",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "Version ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package defaultsecuritypolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/defsecpolicies"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityDefaultSecurityPolicyListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*defsecpolicies.SecurityPoliciesList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := defsecpolicies.ListRequest{}
|
||||
|
||||
if accessGroupID, ok := d.GetOk("access_group_id"); ok {
|
||||
req.AccessGroupID = accessGroupID.(string)
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if perPage, ok := d.GetOk("per_page"); ok {
|
||||
req.PerPage = uint64(perPage.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
if sortOrder, ok := d.GetOk("sort_order"); ok {
|
||||
req.SortOrder = sortOrder.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityDefaultSecurityPolicyListCheckPresence")
|
||||
defaultSecurityPolicyList, err := c.SDN().DefaultSecurityPolicies().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return defaultSecurityPolicyList, nil
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package hypervisors
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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 dataSourceHypervisorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
hypervisor, err := utilityHypervisorCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenHypervisorDataSource(d, hypervisor)
|
||||
d.SetId(hypervisor.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceHypervisor() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceHypervisorRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceHypervisorSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package hypervisors
|
||||
|
||||
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 dataSourceHypervisorListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
hypervisorList, err := utilityHypervisorListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenHypervisorListDataSource(hypervisorList))
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceHypervisorList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceHypervisorListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceHypervisorListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package hypervisors
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/hypervisors"
|
||||
)
|
||||
|
||||
func flattenHypervisorResource(d *schema.ResourceData, hypervisor *hypervisors.RecordHypervisor) {
|
||||
d.Set("display_name", hypervisor.DisplayName)
|
||||
d.Set("hostname", hypervisor.Hostname)
|
||||
d.Set("ip", hypervisor.IP)
|
||||
d.Set("name", hypervisor.Name)
|
||||
d.Set("ports", flattenPorts(hypervisor.Ports))
|
||||
d.Set("status", hypervisor.Status)
|
||||
d.Set("created_at", hypervisor.CreatedAt)
|
||||
d.Set("synced_at", hypervisor.SyncedAt)
|
||||
}
|
||||
|
||||
func flattenHypervisorListDataSource(hypervisorList hypervisors.HypervisorsList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(hypervisorList))
|
||||
for _, v := range hypervisorList {
|
||||
temp := map[string]interface{}{
|
||||
"display_name": v.DisplayName,
|
||||
"hostname": v.Hostname,
|
||||
"ip": v.IP,
|
||||
"name": v.Name,
|
||||
"ports": flattenPorts(v.Ports),
|
||||
"status": v.Status,
|
||||
"created_at": v.CreatedAt,
|
||||
"synced_at": v.SyncedAt,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenHypervisorDataSource(d *schema.ResourceData, hypervisor *hypervisors.RecordHypervisor) {
|
||||
d.Set("display_name", hypervisor.DisplayName)
|
||||
d.Set("hostname", hypervisor.Hostname)
|
||||
d.Set("ip", hypervisor.IP)
|
||||
d.Set("name", hypervisor.Name)
|
||||
d.Set("ports", flattenPorts(hypervisor.Ports))
|
||||
d.Set("status", hypervisor.Status)
|
||||
d.Set("created_at", hypervisor.CreatedAt)
|
||||
d.Set("synced_at", hypervisor.SyncedAt)
|
||||
}
|
||||
|
||||
func flattenPorts(ports hypervisors.Ports) []map[string]interface{} {
|
||||
final := make([]map[string]interface{}, 0)
|
||||
|
||||
res := map[string]interface{}{}
|
||||
|
||||
data := make([]map[string]interface{}, 0)
|
||||
info := map[string]interface{}{}
|
||||
|
||||
for _, v := range ports.Data {
|
||||
temp := map[string]interface{}{
|
||||
"id": v.ID,
|
||||
"unique_identifier": v.UniqueIdentifier,
|
||||
"display_name": v.DisplayName,
|
||||
"up": v.UP,
|
||||
}
|
||||
data = append(data, temp)
|
||||
}
|
||||
|
||||
info["active_ports"] = ports.Info.ActivePorts
|
||||
info["total_ports"] = ports.Info.TotalPorts
|
||||
|
||||
res["data"] = data
|
||||
res["info"] = []interface{}{info}
|
||||
|
||||
final = append(final, res)
|
||||
|
||||
return final
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package hypervisors
|
||||
|
||||
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/sdn/hypervisors"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceHypervisorCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
return diag.Errorf(
|
||||
"It's impossible to create a hypervisor from terraform")
|
||||
}
|
||||
|
||||
func resourceHypervisorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
hypervisor, err := utilityHypervisorCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenHypervisorResource(d, hypervisor)
|
||||
d.SetId(hypervisor.Name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceHypervisorUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := hypervisors.UpdateDisplayNameRequest{
|
||||
Name: d.Get("name").(string),
|
||||
DisplayName: d.Get("display_name").(string),
|
||||
}
|
||||
|
||||
_, err := c.SDN().Hypervisors().UpdateDisplayName(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
return resourceHypervisorRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceHypervisorDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := hypervisors.DeleteRequest{
|
||||
Name: d.Get("name").(string),
|
||||
}
|
||||
|
||||
_, err := c.SDN().Hypervisors().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResourceHypervisor() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceHypervisorCreate,
|
||||
ReadContext: resourceHypervisorRead,
|
||||
UpdateContext: resourceHypervisorUpdate,
|
||||
DeleteContext: resourceHypervisorDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout600s,
|
||||
Delete: &constants.Timeout300s,
|
||||
Default: &constants.Timeout300s,
|
||||
},
|
||||
|
||||
Schema: resourceHypervisorSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
package hypervisors
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
)
|
||||
|
||||
func resourceHypervisorSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"hostname": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ports": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"data": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"unique_identifier": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"up": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"active_ports": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"total_ports": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"synced_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceHypervisorListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"per_page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"name", "hostname", "last_sync",
|
||||
"display_name", "ip", "created_at", "updated_at"}, false),
|
||||
},
|
||||
"sort_order": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"asc", "desc"}, false),
|
||||
},
|
||||
"port_info": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"detailed", "general"}, false),
|
||||
},
|
||||
"hostname": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"created_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"created_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"updated_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"updated_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Description: "List of hypervisors",
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hostname": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ports": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"data": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"unique_identifier": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"up": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"active_ports": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"total_ports": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"synced_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func dataSourceHypervisorSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"port_info": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"detailed", "general"}, false),
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hostname": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ports": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"data": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"unique_identifier": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"up": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"active_ports": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"total_ports": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"synced_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package hypervisors
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/hypervisors"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityHypervisorCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*hypervisors.RecordHypervisor, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := hypervisors.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
req.Name = d.Id()
|
||||
} else {
|
||||
req.Name = d.Get("name").(string)
|
||||
}
|
||||
|
||||
if portInfo, ok := d.GetOk("port_info"); ok {
|
||||
req.PortInfo = portInfo.(string)
|
||||
}
|
||||
|
||||
hypervisor, err := c.SDN().Hypervisors().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return hypervisor, nil
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package hypervisors
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/hypervisors"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityHypervisorListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (hypervisors.HypervisorsList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := hypervisors.ListRequest{}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
|
||||
if perPage, ok := d.GetOk("per_page"); ok {
|
||||
req.PerPage = uint64(perPage.(int))
|
||||
}
|
||||
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
|
||||
if sortOrder, ok := d.GetOk("sort_order"); ok {
|
||||
req.SortOrder = sortOrder.(string)
|
||||
}
|
||||
|
||||
if portInfo, ok := d.GetOk("port_info"); ok {
|
||||
req.PortInfo = portInfo.(string)
|
||||
}
|
||||
|
||||
if hostname, ok := d.GetOk("hostname"); ok {
|
||||
req.Hostname = hostname.(string)
|
||||
}
|
||||
|
||||
if displayName, ok := d.GetOk("display_name"); ok {
|
||||
req.DisplayName = displayName.(string)
|
||||
}
|
||||
|
||||
if ip, ok := d.GetOk("ip"); ok {
|
||||
req.IP = ip.(string)
|
||||
}
|
||||
|
||||
if createdFrom, ok := d.GetOk("created_from"); ok {
|
||||
req.CreatedFrom = createdFrom.(string)
|
||||
}
|
||||
|
||||
if createdTo, ok := d.GetOk("created_to"); ok {
|
||||
req.CreatedTo = createdTo.(string)
|
||||
}
|
||||
|
||||
if updatedFrom, ok := d.GetOk("updated_from"); ok {
|
||||
req.UpdatedFrom = updatedFrom.(string)
|
||||
}
|
||||
|
||||
if updatedTo, ok := d.GetOk("updated_to"); ok {
|
||||
req.UpdatedTo = updatedTo.(string)
|
||||
}
|
||||
|
||||
hypervisorList, err := c.SDN().Hypervisors().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return hypervisorList, nil
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceLogicalPortRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
logicalPort, err := utilityLogicalPortCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenLogicalPort(d, logicalPort)
|
||||
d.SetId(logicalPort.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceLogicalPort() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceLogicalPortRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: dataSourceLogicalPortSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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 dataSourceLogicalPortByUniqueIDRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
logicalPort, err := utilityLogicalPortByUniqueIDCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenLogicalPort(d, logicalPort)
|
||||
d.SetId(logicalPort.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceLogicalPortByUniqueID() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceLogicalPortByUniqueIDRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: dataSourceLogicalPortByUniqueIDSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
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 dataSourceLogicalPortListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
logicalPortList, err := utilityLogicalPortListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenLogicalPortList(logicalPortList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceLogicalPortList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceLogicalPortListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceLogicalPortListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/logicalports"
|
||||
)
|
||||
|
||||
func flattenLogicalPortResource(d *schema.ResourceData, logicalPort *logicalports.LogicalPort) {
|
||||
d.Set("id", logicalPort.ID)
|
||||
d.Set("access_group_id", logicalPort.AccessGroupID)
|
||||
d.Set("access_group_name", logicalPort.AccessGroupName)
|
||||
d.Set("adapter_mac", logicalPort.AdapterMAC)
|
||||
d.Set("address_detection", logicalPort.AddressDetection)
|
||||
d.Set("description", logicalPort.Description)
|
||||
d.Set("display_name", logicalPort.DisplayName)
|
||||
d.Set("enabled", logicalPort.Enabled)
|
||||
d.Set("external_network_id", logicalPort.ExternalNetworkID)
|
||||
d.Set("hypervisor", logicalPort.Hypervisor)
|
||||
d.Set("hypervisor_display_name", logicalPort.HypervisorDisplayName)
|
||||
d.Set("live_migration_target_hv", logicalPort.LiveMigrationTargetHV)
|
||||
d.Set("status", flattenStatus(logicalPort.Status))
|
||||
d.Set("unique_identifier", logicalPort.UniqueIdentifier)
|
||||
d.Set("version_id", logicalPort.VersionID)
|
||||
d.Set("bindings", flattenBindings(logicalPort.Bindings))
|
||||
d.Set("labels", flattenLabels(logicalPort.Labels))
|
||||
d.Set("created_at", logicalPort.CreatedAt)
|
||||
}
|
||||
|
||||
func flattenLogicalPortList(lpl *logicalports.LogicalPortsList) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(lpl.Ports))
|
||||
for _, v := range lpl.Ports {
|
||||
temp := map[string]interface{}{
|
||||
"id": v.ID,
|
||||
"access_group_id": v.AccessGroupID,
|
||||
"access_group_name": v.AccessGroupName,
|
||||
"adapter_mac": v.AdapterMAC,
|
||||
"address_detection": v.AddressDetection,
|
||||
"description": v.Description,
|
||||
"display_name": v.DisplayName,
|
||||
"enabled": v.Enabled,
|
||||
"hypervisor": v.Hypervisor,
|
||||
"hypervisor_display_name": v.HypervisorDisplayName,
|
||||
"external_network_id": v.ExternalNetworkID,
|
||||
"live_migration_target_hv": v.LiveMigrationTargetHV,
|
||||
"status": flattenStatus(v.Status),
|
||||
"unique_identifier": v.UniqueIdentifier,
|
||||
"version_id": v.VersionID,
|
||||
"bindings": flattenBindings(v.Bindings),
|
||||
"labels": flattenLabels(v.Labels),
|
||||
"created_at": v.CreatedAt,
|
||||
"updated_at": v.UpdatedAt,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenLogicalPort(d *schema.ResourceData, logicalPort *logicalports.LogicalPort) {
|
||||
d.Set("id", logicalPort.ID)
|
||||
d.Set("access_group_id", logicalPort.AccessGroupID)
|
||||
d.Set("access_group_name", logicalPort.AccessGroupName)
|
||||
d.Set("adapter_mac", logicalPort.AdapterMAC)
|
||||
d.Set("address_detection", logicalPort.AddressDetection)
|
||||
d.Set("description", logicalPort.Description)
|
||||
d.Set("display_name", logicalPort.DisplayName)
|
||||
d.Set("enabled", logicalPort.Enabled)
|
||||
d.Set("external_network_id", logicalPort.ExternalNetworkID)
|
||||
d.Set("hypervisor", logicalPort.Hypervisor)
|
||||
d.Set("hypervisor_display_name", logicalPort.HypervisorDisplayName)
|
||||
d.Set("live_migration_target_hv", logicalPort.LiveMigrationTargetHV)
|
||||
d.Set("status", flattenStatus(logicalPort.Status))
|
||||
d.Set("unique_identifier", logicalPort.UniqueIdentifier)
|
||||
d.Set("version_id", logicalPort.VersionID)
|
||||
d.Set("bindings", flattenBindings(logicalPort.Bindings))
|
||||
d.Set("labels", flattenLabels(logicalPort.Labels))
|
||||
d.Set("created_at", logicalPort.CreatedAt)
|
||||
d.Set("updated_at", logicalPort.UpdatedAt)
|
||||
}
|
||||
|
||||
func flattenLabels(labels logicalports.Labels) []map[string]interface{} {
|
||||
if labels.VMID == "" && labels.VMName == "" {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"vm_id": labels.VMID,
|
||||
"vm_name": labels.VMName,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenBindings(bindings logicalports.Bindings) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"id": bindings.ID,
|
||||
"segment_id": bindings.SegmentID,
|
||||
"segment_display_name": bindings.SegmentDisplayName,
|
||||
"port_security": bindings.PortSecurity,
|
||||
"address_detection": bindings.AddressDetection,
|
||||
"version_id": bindings.VersionID,
|
||||
"created_at": bindings.CreatedAt,
|
||||
"updated_at": bindings.UpdatedAt,
|
||||
"logical_port_addresses": flattenLogicalPortAddresses(bindings.LogicalPortAddresses),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenLogicalPortAddresses(addrs []logicalports.LogicalPortAddress) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(addrs))
|
||||
for _, a := range addrs {
|
||||
res = append(res, map[string]interface{}{
|
||||
"ip": a.IP,
|
||||
"ip_type": a.IPType,
|
||||
"mac": a.MAC,
|
||||
"id": a.ID,
|
||||
"logical_port_id": a.LogicalPortID,
|
||||
"assigned_at": a.AssignedAt,
|
||||
"is_discovered": a.IsDiscovered,
|
||||
"is_primary": a.IsPrimary,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenStatus(status logicalports.Status) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"operation_status": status.OperationStatus,
|
||||
"hypervisor_status": status.HypervisorStatus,
|
||||
"hypervisors": flattenHypervisors(status.Hypervisors),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenHypervisors(hv []logicalports.HypervisorStatus) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(hv))
|
||||
for _, v := range hv {
|
||||
temp := map[string]interface{}{
|
||||
"operation_status": v.OperationStatus,
|
||||
"name": v.Name,
|
||||
"display_name": v.DisplayName,
|
||||
"hypervisor_status": v.HypervisorStatus,
|
||||
"synced_at": v.SyncedAt,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/sdn/logicalports"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceLogicalPortCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLogicalPortCreate: called logical port with name %s",
|
||||
d.Get("display_name").(string))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := logicalports.CreateRequest{
|
||||
AccessGroupID: d.Get("access_group_id").(string),
|
||||
Description: d.Get("description").(string),
|
||||
DisplayName: d.Get("display_name").(string),
|
||||
Enabled: d.Get("enabled").(bool),
|
||||
Hypervisor: d.Get("hypervisor").(string),
|
||||
PortSecurity: d.Get("port_security").(bool),
|
||||
SegmentID: d.Get("segment_id").(string),
|
||||
}
|
||||
|
||||
if adapterMAC, ok := d.GetOk("adapter_mac"); ok {
|
||||
req.AdapterMAC = adapterMAC.(string)
|
||||
}
|
||||
if uniqueID, ok := d.GetOk("unique_identifier"); ok {
|
||||
req.UniqueIdentifier = uniqueID.(string)
|
||||
}
|
||||
if labelsRaw, ok := d.GetOk("labels"); ok {
|
||||
labelsList := labelsRaw.([]interface{})
|
||||
if len(labelsList) > 0 {
|
||||
labelsMap := labelsList[0].(map[string]interface{})
|
||||
req.Labels = logicalports.CreateLabels{
|
||||
VMID: labelsMap["vm_id"].(string),
|
||||
VMName: labelsMap["vm_name"].(string),
|
||||
}
|
||||
}
|
||||
}
|
||||
if logicalPortAddresses, ok := d.GetOk("logical_port_addresses"); ok {
|
||||
logicalPortAddressesList := logicalPortAddresses.([]interface{})
|
||||
logicalPortsAddressesArr := make([]logicalports.LogicalPortAddress, 0)
|
||||
for _, logicalPortAddressRaw := range logicalPortAddressesList {
|
||||
logicalPortAddressMap := logicalPortAddressRaw.(map[string]interface{})
|
||||
logicalPortAddress := logicalports.LogicalPortAddress{
|
||||
IP: logicalPortAddressMap["ip"].(string),
|
||||
IPType: logicalPortAddressMap["ip_type"].(string),
|
||||
IsPrimary: logicalPortAddressMap["is_primary"].(bool),
|
||||
}
|
||||
if isDiscovered, ok := logicalPortAddressMap["is_discovered"]; ok {
|
||||
logicalPortAddress.IsDiscovered = isDiscovered.(bool)
|
||||
}
|
||||
if mac, ok := logicalPortAddressMap["mac"]; ok {
|
||||
logicalPortAddress.MAC = mac.(string)
|
||||
}
|
||||
logicalPortsAddressesArr = append(logicalPortsAddressesArr, logicalPortAddress)
|
||||
}
|
||||
req.LogicalPortAddresses = logicalPortsAddressesArr
|
||||
}
|
||||
|
||||
logicalPort, err := c.SDN().LogicalPorts().Create(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(logicalPort.ID)
|
||||
|
||||
return resourceLogicalPortRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceLogicalPortRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLogicalPortRead: called logical port with id %s", d.Id())
|
||||
|
||||
logicalPort, err := utilityLogicalPortCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenLogicalPortResource(d, logicalPort)
|
||||
d.SetId(logicalPort.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceLogicalPortUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLogicalPortUpdate: called logical port with id %s", d.Id())
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
migrate := d.Get("migrate").(bool)
|
||||
|
||||
req := logicalports.UpdateRequest{
|
||||
LogicalPortID: d.Id(),
|
||||
VersionID: uint64(d.Get("version_id").(int)),
|
||||
AdapterMAC: d.Get("adapter_mac").(string),
|
||||
Description: d.Get("description").(string),
|
||||
DisplayName: d.Get("display_name").(string),
|
||||
Enabled: d.Get("enabled").(bool),
|
||||
PortSecurity: d.Get("port_security").(bool),
|
||||
SegmentID: d.Get("segment_id").(string),
|
||||
}
|
||||
|
||||
if !migrate {
|
||||
req.Hypervisor = d.Get("hypervisor").(string)
|
||||
} else {
|
||||
old, _ := d.GetChange("hypervisor")
|
||||
req.Hypervisor = old.(string)
|
||||
}
|
||||
|
||||
if d.HasChange("labels") {
|
||||
if labelsRaw, ok := d.GetOk("labels"); ok {
|
||||
labelsList := labelsRaw.([]interface{})
|
||||
if len(labelsList) > 0 {
|
||||
labelsMap := labelsList[0].(map[string]interface{})
|
||||
req.Labels = logicalports.UpdateLabels{
|
||||
VMID: labelsMap["vm_id"].(string),
|
||||
VMName: labelsMap["vm_name"].(string),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("logical_port_addresses") {
|
||||
oldAddresses, newAddresses := d.GetChange("logical_port_addresses")
|
||||
oldAddressesList := oldAddresses.([]interface{})
|
||||
newAddressesList := newAddresses.([]interface{})
|
||||
oldAddressesMap := make(map[string]logicalports.LogicalPortAddress)
|
||||
for _, oldAddressRaw := range oldAddressesList {
|
||||
logicalPortAddressMap := oldAddressRaw.(map[string]interface{})
|
||||
logicalPortAddress := logicalports.LogicalPortAddress{
|
||||
IP: logicalPortAddressMap["ip"].(string),
|
||||
IPType: logicalPortAddressMap["ip_type"].(string),
|
||||
IsPrimary: logicalPortAddressMap["is_primary"].(bool),
|
||||
}
|
||||
if isDiscovered, ok := logicalPortAddressMap["is_discovered"]; ok {
|
||||
logicalPortAddress.IsDiscovered = isDiscovered.(bool)
|
||||
}
|
||||
if mac, ok := logicalPortAddressMap["mac"]; ok {
|
||||
logicalPortAddress.MAC = mac.(string)
|
||||
}
|
||||
oldAddressesMap[logicalPortAddress.IP] = logicalPortAddress
|
||||
}
|
||||
newAddressesMap := make(map[string]logicalports.LogicalPortAddress)
|
||||
for _, newAddressRaw := range newAddressesList {
|
||||
logicalPortAddressMap := newAddressRaw.(map[string]interface{})
|
||||
logicalPortAddress := logicalports.LogicalPortAddress{
|
||||
IP: logicalPortAddressMap["ip"].(string),
|
||||
IPType: logicalPortAddressMap["ip_type"].(string),
|
||||
IsPrimary: logicalPortAddressMap["is_primary"].(bool),
|
||||
}
|
||||
if isDiscovered, ok := logicalPortAddressMap["is_discovered"]; ok {
|
||||
logicalPortAddress.IsDiscovered = isDiscovered.(bool)
|
||||
}
|
||||
if mac, ok := logicalPortAddressMap["mac"]; ok {
|
||||
logicalPortAddress.MAC = mac.(string)
|
||||
}
|
||||
newAddressesMap[logicalPortAddress.IP] = logicalPortAddress
|
||||
}
|
||||
|
||||
removeAddresses := make([]string, 0)
|
||||
for addressIP := range oldAddressesMap {
|
||||
if _, exists := newAddressesMap[addressIP]; !exists {
|
||||
removeAddresses = append(removeAddresses, addressIP)
|
||||
}
|
||||
}
|
||||
req.RemoveAddresses = removeAddresses
|
||||
|
||||
for addressIP, address := range newAddressesMap {
|
||||
if oldAddressIP, exists := oldAddressesMap[addressIP]; !exists || address != oldAddressIP {
|
||||
if !exists {
|
||||
logicalPortAddress := logicalports.AddAddress{
|
||||
IP: address.IP,
|
||||
IPType: address.IPType,
|
||||
IsPrimary: address.IsPrimary,
|
||||
IsDiscovered: address.IsDiscovered,
|
||||
MAC: address.MAC,
|
||||
}
|
||||
req.AddAddresses = append(req.AddAddresses, logicalPortAddress)
|
||||
} else if address != oldAddressIP {
|
||||
logicalPortAddress := logicalports.UpdateAddress{
|
||||
IP: address.IP,
|
||||
IPType: address.IPType,
|
||||
IsPrimary: address.IsPrimary,
|
||||
IsDiscovered: address.IsDiscovered,
|
||||
MAC: address.MAC,
|
||||
}
|
||||
req.UpdateAddresses = append(req.UpdateAddresses, logicalPortAddress)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_, err := c.SDN().LogicalPorts().Update(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
if migrate {
|
||||
if targetHV, ok := d.GetOk("hypervisor"); ok {
|
||||
// Re-read version_id
|
||||
lp, err := utilityLogicalPortCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
migrateReq := logicalports.MigrateStartRequest{
|
||||
LogicalPortID: d.Id(),
|
||||
VersionID: lp.VersionID,
|
||||
TargetHypervisor: targetHV.(string),
|
||||
}
|
||||
|
||||
_, err = c.SDN().LogicalPorts().StartMigrate(ctx, migrateReq)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
// to prevent drift on the next plan
|
||||
diags := resourceLogicalPortRead(ctx, d, m)
|
||||
if diags.HasError() {
|
||||
return diags
|
||||
}
|
||||
d.Set("hypervisor", targetHV.(string))
|
||||
return diags
|
||||
}
|
||||
}
|
||||
|
||||
return resourceLogicalPortRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceLogicalPortDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceLogicalPortDelete: called logical port with id %s", d.Id())
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := logicalports.DeleteRequest{
|
||||
ID: d.Id(),
|
||||
Version: uint64(d.Get("version_id").(int)),
|
||||
}
|
||||
|
||||
if force, ok := d.GetOk("force"); ok {
|
||||
req.Force = force.(bool)
|
||||
}
|
||||
|
||||
_, err := c.SDN().LogicalPorts().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResourceLogicalPort() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceLogicalPortCreate,
|
||||
ReadContext: resourceLogicalPortRead,
|
||||
UpdateContext: resourceLogicalPortUpdate,
|
||||
DeleteContext: resourceLogicalPortDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout600s,
|
||||
Delete: &constants.Timeout300s,
|
||||
Default: &constants.Timeout300s,
|
||||
},
|
||||
|
||||
Schema: resourceLogicalPortSchemaMake(),
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,30 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/logicalports"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityLogicalPortCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*logicalports.LogicalPort, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := logicalports.GetRequest{
|
||||
ID: d.Id(),
|
||||
}
|
||||
|
||||
if d.Id() != "" {
|
||||
req.ID = d.Id()
|
||||
} else {
|
||||
req.ID = d.Get("logical_port_id").(string)
|
||||
}
|
||||
|
||||
logicalPort, err := c.SDN().LogicalPorts().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return logicalPort, nil
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/logicalports"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityLogicalPortByUniqueIDCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*logicalports.LogicalPort, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := logicalports.GetByUniqueIdentifierRequest{
|
||||
ID: d.Id(),
|
||||
}
|
||||
|
||||
if d.Id() != "" {
|
||||
req.ID = d.Id()
|
||||
} else {
|
||||
req.ID = d.Get("unique_identifier").(string)
|
||||
}
|
||||
|
||||
logicalPort, err := c.SDN().LogicalPorts().GetByUniqueIdentifier(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return logicalPort, nil
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/logicalports"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityLogicalPortListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*logicalports.LogicalPortsList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := logicalports.ListRequest{}
|
||||
|
||||
if accessGroupID, ok := d.GetOk("access_group_id"); ok {
|
||||
req.AccessGroupID = accessGroupID.(string)
|
||||
}
|
||||
if segmentID, ok := d.GetOk("segment_id"); ok {
|
||||
req.SegmentID = segmentID.(string)
|
||||
}
|
||||
if segmentDisplayName, ok := d.GetOk("segment_display_name"); ok {
|
||||
req.SegmentDisplayName = segmentDisplayName.(string)
|
||||
}
|
||||
if externalNetworkID, ok := d.GetOk("external_network_id"); ok {
|
||||
req.ExternalNetworkID = externalNetworkID.(string)
|
||||
}
|
||||
if uniqueID, ok := d.GetOk("unique_identifier"); ok {
|
||||
req.UniqueIdentifier = uniqueID.(string)
|
||||
}
|
||||
if displayName, ok := d.GetOk("display_name"); ok {
|
||||
req.DisplayName = displayName.(string)
|
||||
}
|
||||
if adapterMAC, ok := d.GetOk("adapter_mac"); ok {
|
||||
req.AdapterMAC = adapterMAC.(string)
|
||||
}
|
||||
if hypervisor, ok := d.GetOk("hypervisor"); ok {
|
||||
req.Hypervisor = hypervisor.(string)
|
||||
}
|
||||
if hypervisorDisplayName, ok := d.GetOk("hypervisor_display_name"); ok {
|
||||
req.HypervisorDisplayName = hypervisorDisplayName.(string)
|
||||
}
|
||||
if liveMigrationTargetHV, ok := d.GetOk("live_migration_target_hv"); ok {
|
||||
req.LiveMigrationTargetHv = liveMigrationTargetHV.(string)
|
||||
}
|
||||
if portSecurity, ok := d.GetOk("port_security"); ok {
|
||||
req.PortSecurity = portSecurity.(bool)
|
||||
}
|
||||
if addressDetection, ok := d.GetOk("address_detection"); ok {
|
||||
req.AddressDetection = addressDetection.(bool)
|
||||
}
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
req.Enabled = enabled.(bool)
|
||||
}
|
||||
if createdFrom, ok := d.GetOk("created_from"); ok {
|
||||
req.CreatedFrom = createdFrom.(string)
|
||||
}
|
||||
if createdTo, ok := d.GetOk("created_to"); ok {
|
||||
req.CreatedTo = createdTo.(string)
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if perPage, ok := d.GetOk("per_page"); ok {
|
||||
req.PerPage = uint64(perPage.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
if sortOrder, ok := d.GetOk("sort_order"); ok {
|
||||
req.SortOrder = sortOrder.(string)
|
||||
}
|
||||
if operationStatus, ok := d.GetOk("operation_status"); ok {
|
||||
req.OperationStatus = operationStatus.(string)
|
||||
}
|
||||
if hypervisorStatus, ok := d.GetOk("hypervisor_status"); ok {
|
||||
req.HypervisorStatus = hypervisorStatus.(string)
|
||||
}
|
||||
|
||||
logicalPortList, err := c.SDN().LogicalPorts().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return logicalPortList, nil
|
||||
}
|
||||
@@ -1,572 +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 netobjgroups
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func hypervisorsInfoComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {Type: schema.TypeString, Computed: true},
|
||||
"name": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"hypervisor_status": {Type: schema.TypeString, Computed: true},
|
||||
"synced_at": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func statusComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {Type: schema.TypeString, Computed: true},
|
||||
"hypervisor_status": {Type: schema.TypeString, Computed: true},
|
||||
"hypervisors": hypervisorsInfoComputedSchema(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func logicalPortAddressesComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"ip": {Type: schema.TypeString, Computed: true},
|
||||
"ip_type": {Type: schema.TypeString, Computed: true},
|
||||
"is_discovered": {Type: schema.TypeBool, Computed: true},
|
||||
"is_primary": {Type: schema.TypeBool, Computed: true},
|
||||
"mac": {Type: schema.TypeString, Computed: true},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"logical_port_id": {Type: schema.TypeString, Computed: true},
|
||||
"assigned_at": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func bindingsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"segment_display_name": {Type: schema.TypeString, Computed: true},
|
||||
"segment_id": {Type: schema.TypeString, Computed: true},
|
||||
"port_security": {Type: schema.TypeBool, Computed: true},
|
||||
"address_detection": {Type: schema.TypeBool, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"logical_port_addresses": logicalPortAddressesComputedSchema(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func excludeFirewallComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"exclusion_reason": {Type: schema.TypeString, Computed: true},
|
||||
"logical_port_addresses_excluded": {Type: schema.TypeBool, Computed: true},
|
||||
"logical_port_excluded": {Type: schema.TypeBool, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func labelsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"vm_id": {Type: schema.TypeString, Computed: true},
|
||||
"vm_name": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func ipv6ConfigComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address_mode": {Type: schema.TypeString, Computed: true},
|
||||
"enable_periodic_ra": {Type: schema.TypeBool, Computed: true},
|
||||
"interval_ra": {Type: schema.TypeInt, Computed: true},
|
||||
"router_preference": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func routerGatewayPortComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"router_display_name": {Type: schema.TypeString, Computed: true},
|
||||
"router_id": {Type: schema.TypeString, Computed: true},
|
||||
"snat_enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func logicalPortSchemaFields() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_name": {Type: schema.TypeString, Computed: true},
|
||||
"adapter_mac": {Type: schema.TypeString, Computed: true},
|
||||
"address_detection": {Type: schema.TypeBool, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"exclude_firewall": excludeFirewallComputedSchema(),
|
||||
"external_network_id": {Type: schema.TypeString, Computed: true},
|
||||
"hypervisor": {Type: schema.TypeString, Computed: true},
|
||||
"hypervisor_display_name": {Type: schema.TypeString, Computed: true},
|
||||
"labels": labelsComputedSchema(),
|
||||
"live_migration_target_hv": {Type: schema.TypeString, Computed: true},
|
||||
"status": statusComputedSchema(),
|
||||
"bindings": bindingsComputedSchema(),
|
||||
"unique_identifier": {Type: schema.TypeString, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
}
|
||||
}
|
||||
|
||||
func logicalPortsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: logicalPortSchemaFields(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func l2ExternalNetworkComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"bridge_network_name": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"hypervisors": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
"vlan_tag": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func l2ConnectionPortsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
"l2_external_network": l2ExternalNetworkComputedSchema(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func appliedNetObjectGroupsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"name": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func securityRuleNetObjectComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"net_address_pool_id": {Type: schema.TypeString, Computed: true},
|
||||
"net_object_group_id": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func securityRuleFiltersComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"all": {Type: schema.TypeBool, Computed: true},
|
||||
"arp": {Type: schema.TypeBool, Computed: true},
|
||||
"dhcp": {Type: schema.TypeBool, Computed: true},
|
||||
"expression": {Type: schema.TypeString, Computed: true},
|
||||
"icmp": {Type: schema.TypeBool, Computed: true},
|
||||
"ip": {Type: schema.TypeBool, Computed: true},
|
||||
"ip_v4": {Type: schema.TypeBool, Computed: true},
|
||||
"ip_v6": {Type: schema.TypeBool, Computed: true},
|
||||
"keep_opened_sessions": {Type: schema.TypeBool, Computed: true},
|
||||
"nd": {Type: schema.TypeBool, Computed: true},
|
||||
"tcp": {Type: schema.TypeBool, Computed: true},
|
||||
"tcp_dst_ports": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
"udp": {Type: schema.TypeBool, Computed: true},
|
||||
"udp_dst_ports": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func securityRuleFilterComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {Type: schema.TypeString, Computed: true},
|
||||
"filters": securityRuleFiltersComputedSchema(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func securityRulesComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"action": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"destination_net_object": securityRuleNetObjectComputedSchema(),
|
||||
"direction": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"filter": securityRuleFilterComputedSchema(),
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"log_enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"log_name": {Type: schema.TypeString, Computed: true},
|
||||
"log_severity": {Type: schema.TypeString, Computed: true},
|
||||
"priority": {Type: schema.TypeInt, Computed: true},
|
||||
"security_policy_id": {Type: schema.TypeString, Computed: true},
|
||||
"source_net_object": securityRuleNetObjectComputedSchema(),
|
||||
"statistics_enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"type": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func securityPoliciesComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_name": {Type: schema.TypeString, Computed: true},
|
||||
"applied_net_object_groups": appliedNetObjectGroupsComputedSchema(),
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"end_priority": {Type: schema.TypeInt, Computed: true},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"security_rules": securityRulesComputedSchema(),
|
||||
"start_priority": {Type: schema.TypeInt, Computed: true},
|
||||
"status": statusComputedSchema(),
|
||||
"type": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func gateawayPortsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"external_l4_port_max": {Type: schema.TypeInt, Computed: true},
|
||||
"external_l4_port_min": {Type: schema.TypeInt, Computed: true},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"snat_enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"status": statusComputedSchema(),
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func policiesComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"action": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"match": {Type: schema.TypeString, Computed: true},
|
||||
"next_ipv4_address": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
"next_ipv6_address": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
"priority": {Type: schema.TypeInt, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func segmentComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_name": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"subnet_v4": {Type: schema.TypeString, Computed: true},
|
||||
"subnet_v6": {Type: schema.TypeString, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func routerPortsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"ipv4_address": {Type: schema.TypeString, Computed: true},
|
||||
"ipv6_address": {Type: schema.TypeString, Computed: true},
|
||||
"ipv6_config": ipv6ConfigComputedSchema(),
|
||||
"mac": {Type: schema.TypeString, Computed: true},
|
||||
"segment_id": {Type: schema.TypeString, Computed: true},
|
||||
"segment": segmentComputedSchema(),
|
||||
"status": statusComputedSchema(),
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func routerComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_name": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"gateaway_ports": gateawayPortsComputedSchema(),
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"policies": policiesComputedSchema(),
|
||||
"ports": routerPortsComputedSchema(),
|
||||
"status": statusComputedSchema(),
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func floatingIPComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_name": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
"logical_port": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: logicalPortSchemaFields(),
|
||||
},
|
||||
},
|
||||
"router": routerComputedSchema(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func externalNetworkPortFieldsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_name": {Type: schema.TypeString, Computed: true},
|
||||
"comment": {Type: schema.TypeString, Computed: true},
|
||||
"display_name": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"ipv4": {Type: schema.TypeString, Computed: true},
|
||||
"ipv6": {Type: schema.TypeString, Computed: true},
|
||||
"ipv6_config": ipv6ConfigComputedSchema(),
|
||||
"mac": {Type: schema.TypeString, Computed: true},
|
||||
"router_gateaway_port": routerGatewayPortComputedSchema(),
|
||||
"floating_ip": floatingIPComputedSchema(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func externalNetworkPortsComputedSchema() *schema.Schema {
|
||||
return &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_id": {Type: schema.TypeString, Computed: true},
|
||||
"access_group_name": {Type: schema.TypeString, Computed: true},
|
||||
"bridge_network_name": {Type: schema.TypeString, Computed: true},
|
||||
"comment": {Type: schema.TypeString, Computed: true},
|
||||
"default_gateway_ipv4": {Type: schema.TypeString, Computed: true},
|
||||
"default_gateway_ipv6": {Type: schema.TypeString, Computed: true},
|
||||
"description": {Type: schema.TypeString, Computed: true},
|
||||
"enabled": {Type: schema.TypeBool, Computed: true},
|
||||
"external_network_ports": externalNetworkPortFieldsComputedSchema(),
|
||||
"hypervisors": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
"ipv4": {Type: schema.TypeString, Computed: true},
|
||||
"status": statusComputedSchema(),
|
||||
"version_id": {Type: schema.TypeInt, Computed: true},
|
||||
"subnet_v4": {Type: schema.TypeString, Computed: true},
|
||||
"subnet_v6": {Type: schema.TypeString, Computed: true},
|
||||
"created_at": {Type: schema.TypeString, Computed: true},
|
||||
"updated_at": {Type: schema.TypeString, Computed: true},
|
||||
"vlan_tag": {Type: schema.TypeInt, Computed: true},
|
||||
"mac": {Type: schema.TypeString, Computed: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,178 +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 netobjgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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 dataSourceNetworkObjectGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
rec, err := utilityNetworkObjectGroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenNetworkObjectGroupDataSource(d, rec)
|
||||
d.SetId(rec.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceNetworkObjectGroupSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"net_object_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"purpose": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"addresses": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"net_address_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_addr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_addr_range_end": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_prefix": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"mac_addr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"counters": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"addresses_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"l2_connection_ports_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"logical_ports_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"security_policies_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"security_rules_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"l2_connection_ports": l2ConnectionPortsComputedSchema(),
|
||||
"logical_ports": logicalPortsComputedSchema(),
|
||||
"external_network_ports": externalNetworkPortsComputedSchema(),
|
||||
"security_policies": securityPoliciesComputedSchema(),
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceNetworkObjectGroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceNetworkObjectGroupRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceNetworkObjectGroupSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,233 +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 netobjgroups
|
||||
|
||||
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 dataSourceNetworkObjectGroupListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
list, err := utilityNetworkObjectGroupListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenNetworkObjectGroupList(list))
|
||||
d.Set("entry_count", len(list.Objects))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func dataSourceNetworkObjectGroupListSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"per_page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"sort_order": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"created_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"created_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"updated_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"updated_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"purpose": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"addresses": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"net_address_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_addr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_addr_range_end": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_prefix": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"mac_addr": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"counters": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"addresses_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"l2_connection_ports_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"logical_ports_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"security_policies_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"security_rules_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"l2_connection_ports": l2ConnectionPortsComputedSchema(),
|
||||
"logical_ports": logicalPortsComputedSchema(),
|
||||
"external_network_ports": externalNetworkPortsComputedSchema(),
|
||||
"security_policies": securityPoliciesComputedSchema(),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DataSourceNetworkObjectGroupList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceNetworkObjectGroupListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceNetworkObjectGroupListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,581 +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 netobjgroups
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/netobjgroups"
|
||||
)
|
||||
|
||||
func flattenNetworkObjectGroupResource(d *schema.ResourceData, rec *netobjgroups.RecordNetObjGroup) {
|
||||
d.Set("name", rec.Name)
|
||||
d.Set("access_group_id", rec.AccessGroupID)
|
||||
d.Set("access_group_name", rec.AccessGroupName)
|
||||
d.Set("description", rec.Description)
|
||||
d.Set("type", rec.Type)
|
||||
d.Set("purpose", rec.Purpose)
|
||||
d.Set("version_id", int(rec.VersionID))
|
||||
d.Set("addresses", flattenAddresses(rec.Addresses))
|
||||
d.Set("counters", flattenCounters(rec.Counters))
|
||||
d.Set("l2_connection_ports", flattenL2ConnectionPorts(rec.L2ConnectionPorts))
|
||||
d.Set("logical_ports", flattenLogicalPorts(rec.LogicalPorts))
|
||||
d.Set("external_network_ports", flattenExternalNetworkPorts(rec.ExternalNetworkPorts))
|
||||
d.Set("security_policies", flattenSecurityPolicies(rec.SecurityPolicies))
|
||||
}
|
||||
|
||||
func flattenNetworkObjectGroupDataSource(d *schema.ResourceData, rec *netobjgroups.RecordNetObjGroup) {
|
||||
d.Set("name", rec.Name)
|
||||
d.Set("access_group_id", rec.AccessGroupID)
|
||||
d.Set("access_group_name", rec.AccessGroupName)
|
||||
d.Set("description", rec.Description)
|
||||
d.Set("type", rec.Type)
|
||||
d.Set("purpose", rec.Purpose)
|
||||
d.Set("version_id", int(rec.VersionID))
|
||||
d.Set("created_at", rec.CreatedAt)
|
||||
d.Set("updated_at", rec.UpdatedAt)
|
||||
d.Set("addresses", flattenAddresses(rec.Addresses))
|
||||
d.Set("counters", flattenCounters(rec.Counters))
|
||||
d.Set("l2_connection_ports", flattenL2ConnectionPorts(rec.L2ConnectionPorts))
|
||||
d.Set("logical_ports", flattenLogicalPorts(rec.LogicalPorts))
|
||||
d.Set("external_network_ports", flattenExternalNetworkPorts(rec.ExternalNetworkPorts))
|
||||
d.Set("security_policies", flattenSecurityPolicies(rec.SecurityPolicies))
|
||||
}
|
||||
|
||||
func flattenAddresses(addrs netobjgroups.NetAddresses) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(addrs))
|
||||
for _, a := range addrs {
|
||||
res = append(res, map[string]interface{}{
|
||||
"id": a.ID,
|
||||
"net_address_type": a.NetAddressType,
|
||||
"ip_addr": a.IPAddr,
|
||||
"ip_addr_range_end": a.IPAddrRangeEnd,
|
||||
"ip_prefix": a.IPPrefix,
|
||||
"mac_addr": a.MACAddr,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenCounters(c netobjgroups.Counter) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"addresses_count": int(c.AddressesCount),
|
||||
"l2_connection_ports_count": int(c.L2ConnectionPortsCount),
|
||||
"logical_ports_count": int(c.LogicalPortsCount),
|
||||
"security_policies_count": int(c.SecurityPoliciesCount),
|
||||
"security_rules_count": int(c.SecurityRulesCount),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenStatus(s netobjgroups.Status) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"operation_status": s.OperationStatus,
|
||||
"hypervisor_status": s.HypervisorStatus,
|
||||
"hypervisors": flattenHypervisorsInfo(s.Hypervisors),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenHypervisorsInfo(hvs netobjgroups.HypervisorsInfo) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(hvs))
|
||||
for _, hv := range hvs {
|
||||
res = append(res, map[string]interface{}{
|
||||
"operation_status": hv.OperationStatus,
|
||||
"name": hv.Name,
|
||||
"display_name": hv.DisplayName,
|
||||
"hypervisor_status": hv.HypervisorStatus,
|
||||
"synced_at": hv.SyncedAt,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenLogicalPortAddresses(addrs netobjgroups.LogicalPortAddresses) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(addrs))
|
||||
for _, a := range addrs {
|
||||
res = append(res, map[string]interface{}{
|
||||
"ip": a.IP,
|
||||
"ip_type": a.IPType,
|
||||
"is_discovered": a.IsDiscovered,
|
||||
"is_primary": a.IsPrimary,
|
||||
"mac": a.MAC,
|
||||
"id": a.ID,
|
||||
"logical_port_id": a.LogicalPortID,
|
||||
"assigned_at": a.AssignedAt,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenBindings(b netobjgroups.Bindings) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"id": b.ID,
|
||||
"segment_display_name": b.SegmentDisplayName,
|
||||
"segment_id": b.SegmentID,
|
||||
"port_security": b.PortSecurity,
|
||||
"address_detection": b.AddressDetection,
|
||||
"version_id": int(b.VersionID),
|
||||
"created_at": b.CreatedAt,
|
||||
"updated_at": b.UpdatedAt,
|
||||
"logical_port_addresses": flattenLogicalPortAddresses(b.LogicalPortAddresses),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenExcludeFirewall(e netobjgroups.ExcludeFirewall) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"exclusion_reason": e.ExclusionReason,
|
||||
"logical_port_addresses_excluded": e.LogicalPortAddressesExcluded,
|
||||
"logical_port_excluded": e.LogicalPortExcluded,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenLabels(l netobjgroups.Labels) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"vm_id": l.VMID,
|
||||
"vm_name": l.VMName,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenLogicalPort(lp netobjgroups.LogicalPort) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": lp.ID,
|
||||
"access_group_id": lp.AccessGroupID,
|
||||
"access_group_name": lp.AccessGroupName,
|
||||
"adapter_mac": lp.AdapterMAC,
|
||||
"address_detection": lp.AddressDetection,
|
||||
"description": lp.Description,
|
||||
"created_at": lp.CreatedAt,
|
||||
"display_name": lp.DisplayName,
|
||||
"enabled": lp.Enabled,
|
||||
"exclude_firewall": flattenExcludeFirewall(lp.ExcludeFirewall),
|
||||
"external_network_id": lp.ExternalNetworkID,
|
||||
"hypervisor": lp.Hypervisor,
|
||||
"hypervisor_display_name": lp.HypervisorDisplayName,
|
||||
"labels": flattenLabels(lp.Labels),
|
||||
"live_migration_target_hv": lp.LiveMigrationTargetHV,
|
||||
"status": flattenStatus(lp.Status),
|
||||
"bindings": flattenBindings(lp.Bindings),
|
||||
"unique_identifier": lp.UniqueIdentifier,
|
||||
"updated_at": lp.UpdatedAt,
|
||||
"version_id": int(lp.VersionID),
|
||||
}
|
||||
}
|
||||
|
||||
func flattenLogicalPorts(ports netobjgroups.LogicalPorts) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(ports))
|
||||
for _, lp := range ports {
|
||||
res = append(res, flattenLogicalPort(lp))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenL2ExternalNetwork(n netobjgroups.L2ExternalNetwork) []map[string]interface{} {
|
||||
hypervisors := make([]interface{}, 0, len(n.Hypervisors))
|
||||
for _, h := range n.Hypervisors {
|
||||
hypervisors = append(hypervisors, h)
|
||||
}
|
||||
vlanTag := 0
|
||||
if n.VLANTag != nil {
|
||||
vlanTag = *n.VLANTag
|
||||
}
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"bridge_network_name": n.BridgeNetworkName,
|
||||
"created_at": n.CreatedAt,
|
||||
"description": n.Description,
|
||||
"display_name": n.DisplayName,
|
||||
"hypervisors": hypervisors,
|
||||
"id": n.ID,
|
||||
"updated_at": n.UpdatedAt,
|
||||
"version_id": int(n.VersionID),
|
||||
"vlan_tag": vlanTag,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenL2ConnectionPorts(ports netobjgroups.L2ConnectionPorts) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(ports))
|
||||
for _, p := range ports {
|
||||
res = append(res, map[string]interface{}{
|
||||
"id": p.ID,
|
||||
"access_group_id": p.AccessGroupID,
|
||||
"created_at": p.CreatedAt,
|
||||
"updated_at": p.UpdatedAt,
|
||||
"version_id": int(p.VersionID),
|
||||
"l2_external_network": flattenL2ExternalNetwork(p.L2ExternalNetwork),
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenIPv6Config(c netobjgroups.IPv6Config) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"address_mode": c.AddressMode,
|
||||
"enable_periodic_ra": c.EnablePeriodicRA,
|
||||
"interval_ra": int(c.IntervalRA),
|
||||
"router_preference": c.RouterPreference,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenRouterGatewayPort(r netobjgroups.RouterGateawayPort) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"created_at": r.CreatedAt,
|
||||
"description": r.Description,
|
||||
"id": r.ID,
|
||||
"router_display_name": r.RouterDisplayName,
|
||||
"router_id": r.RouterID,
|
||||
"snat_enabled": r.SNATEnabled,
|
||||
"updated_at": r.UpdatedAt,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenSegment(s netobjgroups.Segment) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"access_group_id": s.AccessGroupID,
|
||||
"access_group_name": s.AccessGroupName,
|
||||
"created_at": s.CreatedAt,
|
||||
"description": s.Description,
|
||||
"display_name": s.DisplayName,
|
||||
"enabled": s.Enabled,
|
||||
"id": s.ID,
|
||||
"subnet_v4": s.SubnetV4,
|
||||
"subnet_v6": s.SubnetV6,
|
||||
"updated_at": s.UpdatedAt,
|
||||
"version_id": int(s.VersionID),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenRouter(r netobjgroups.Router) []map[string]interface{} {
|
||||
gateawayPorts := make([]map[string]interface{}, 0, len(r.GateawayPorts))
|
||||
for _, gp := range r.GateawayPorts {
|
||||
gateawayPorts = append(gateawayPorts, map[string]interface{}{
|
||||
"created_at": gp.CreatedAt,
|
||||
"description": gp.Description,
|
||||
"external_l4_port_max": int(gp.ExternalL4PortMax),
|
||||
"external_l4_port_min": int(gp.ExternalL4PortMin),
|
||||
"id": gp.ID,
|
||||
"snat_enabled": gp.SNATEnabled,
|
||||
"status": flattenStatus(gp.Status),
|
||||
"updated_at": gp.UpdatedAt,
|
||||
"version_id": int(gp.VersionID),
|
||||
})
|
||||
}
|
||||
|
||||
policies := make([]map[string]interface{}, 0, len(r.Policies))
|
||||
for _, pol := range r.Policies {
|
||||
nextIPv4 := make([]interface{}, 0, len(pol.NextIPv4Address))
|
||||
for _, ip := range pol.NextIPv4Address {
|
||||
nextIPv4 = append(nextIPv4, ip)
|
||||
}
|
||||
nextIPv6 := make([]interface{}, 0, len(pol.NextIPv6Address))
|
||||
for _, ip := range pol.NextIPv6Address {
|
||||
nextIPv6 = append(nextIPv6, ip)
|
||||
}
|
||||
policies = append(policies, map[string]interface{}{
|
||||
"action": pol.Action,
|
||||
"created_at": pol.CreatedAt,
|
||||
"display_name": pol.DisplayName,
|
||||
"enabled": pol.Enabled,
|
||||
"id": pol.ID,
|
||||
"match": pol.Match,
|
||||
"next_ipv4_address": nextIPv4,
|
||||
"next_ipv6_address": nextIPv6,
|
||||
"priority": pol.Priority,
|
||||
"updated_at": pol.UpdatedAt,
|
||||
"version_id": int(pol.VersionID),
|
||||
})
|
||||
}
|
||||
|
||||
ports := make([]map[string]interface{}, 0, len(r.Port))
|
||||
for _, port := range r.Port {
|
||||
ports = append(ports, map[string]interface{}{
|
||||
"created_at": port.CreatedAt,
|
||||
"description": port.Description,
|
||||
"enabled": port.Enabled,
|
||||
"id": port.ID,
|
||||
"ipv4_address": port.IPv4Address,
|
||||
"ipv6_address": port.IPv6Address,
|
||||
"ipv6_config": flattenIPv6Config(port.IPv6Config),
|
||||
"mac": port.MAC,
|
||||
"segment_id": port.SegmentID,
|
||||
"segment": flattenSegment(port.Segment),
|
||||
"status": flattenStatus(port.Status),
|
||||
"updated_at": port.UpdatedAt,
|
||||
"version_id": int(port.VersionID),
|
||||
})
|
||||
}
|
||||
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"access_group_id": r.AccessGroupID,
|
||||
"access_group_name": r.AccessGroupName,
|
||||
"created_at": r.CreatedAt,
|
||||
"description": r.Description,
|
||||
"display_name": r.DisplayName,
|
||||
"enabled": r.Enabled,
|
||||
"gateaway_ports": gateawayPorts,
|
||||
"id": r.ID,
|
||||
"policies": policies,
|
||||
"ports": ports,
|
||||
"status": flattenStatus(r.Status),
|
||||
"updated_at": r.UpdatedAt,
|
||||
"version_id": int(r.VersionID),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenFloatingIP(f netobjgroups.FloatingIP) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"access_group_id": f.AccessGroupID,
|
||||
"access_group_name": f.AccessGroupName,
|
||||
"created_at": f.CreatedAt,
|
||||
"updated_at": f.UpdatedAt,
|
||||
"version_id": int(f.VersionID),
|
||||
"logical_port": []map[string]interface{}{flattenLogicalPort(f.LogicalPort)},
|
||||
"router": flattenRouter(f.Router),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenExternalNetworkPortFields(ports netobjgroups.ExternalNetworkPortsField) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(ports))
|
||||
for _, p := range ports {
|
||||
res = append(res, map[string]interface{}{
|
||||
"access_group_id": p.AccessGroupID,
|
||||
"access_group_name": p.AccessGroupName,
|
||||
"comment": p.Comment,
|
||||
"display_name": p.DisplayName,
|
||||
"enabled": p.Enabled,
|
||||
"ipv4": p.IPv4,
|
||||
"ipv6": p.IPv6,
|
||||
"ipv6_config": flattenIPv6Config(p.IPv6Config),
|
||||
"mac": p.MAC,
|
||||
"router_gateaway_port": flattenRouterGatewayPort(p.RouterGateawayPort),
|
||||
"floating_ip": flattenFloatingIP(p.FloatingIP),
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenExternalNetworkPorts(ports netobjgroups.ExternalNetworkPorts) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(ports))
|
||||
for _, p := range ports {
|
||||
hypervisors := make([]interface{}, 0, len(p.Hypervisors))
|
||||
for _, h := range p.Hypervisors {
|
||||
hypervisors = append(hypervisors, h)
|
||||
}
|
||||
res = append(res, map[string]interface{}{
|
||||
"id": p.ID,
|
||||
"access_group_id": p.AccessGroupID,
|
||||
"access_group_name": p.AccessGroupName,
|
||||
"bridge_network_name": p.BridgeNetworkName,
|
||||
"comment": p.Comment,
|
||||
"default_gateway_ipv4": p.DefaultGatewayIPv4,
|
||||
"default_gateway_ipv6": p.DefaultGatewayIPv6,
|
||||
"description": p.Description,
|
||||
"enabled": p.Enabled,
|
||||
"external_network_ports": flattenExternalNetworkPortFields(p.ExternalNetworkPorts),
|
||||
"hypervisors": hypervisors,
|
||||
"ipv4": p.IPv4,
|
||||
"status": flattenStatus(p.Status),
|
||||
"version_id": int(p.VersionID),
|
||||
"subnet_v4": p.SubnetV4,
|
||||
"subnet_v6": p.SubnetV6,
|
||||
"created_at": p.CreatedAt,
|
||||
"updated_at": p.UpdatedAt,
|
||||
"vlan_tag": p.VLANTag,
|
||||
"mac": p.MAC,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenAppliedNetObjectGroups(groups netobjgroups.AppliedNetObjectGroups) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(groups))
|
||||
for _, g := range groups {
|
||||
res = append(res, map[string]interface{}{
|
||||
"id": g.ID,
|
||||
"name": g.Name,
|
||||
"version_id": int(g.VersionID),
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSecurityRules(rules netobjgroups.SecurityRules) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(rules))
|
||||
for _, r := range rules {
|
||||
srcNetObj := []map[string]interface{}{}
|
||||
if r.SourceNetObject != nil {
|
||||
srcNetObj = []map[string]interface{}{
|
||||
{
|
||||
"display_name": r.SourceNetObject.DisplayName,
|
||||
"net_address_pool_id": r.SourceNetObject.NetAddressPoolID,
|
||||
"net_object_group_id": r.SourceNetObject.NetObjectGroupID,
|
||||
},
|
||||
}
|
||||
}
|
||||
dstNetObj := []map[string]interface{}{}
|
||||
if r.DestinationNetObject != nil {
|
||||
dstNetObj = []map[string]interface{}{
|
||||
{
|
||||
"display_name": r.DestinationNetObject.DisplayName,
|
||||
"net_address_pool_id": r.DestinationNetObject.NetAddressPoolID,
|
||||
"net_object_group_id": r.DestinationNetObject.NetObjectGroupID,
|
||||
},
|
||||
}
|
||||
}
|
||||
filter := []map[string]interface{}{}
|
||||
if r.Filter != nil {
|
||||
tcpDstPorts := make([]interface{}, 0, len(r.Filter.Filters.TCPDstPorts))
|
||||
for _, p := range r.Filter.Filters.TCPDstPorts {
|
||||
tcpDstPorts = append(tcpDstPorts, p)
|
||||
}
|
||||
udpDstPorts := make([]interface{}, 0, len(r.Filter.Filters.UDPDstPorts))
|
||||
for _, p := range r.Filter.Filters.UDPDstPorts {
|
||||
udpDstPorts = append(udpDstPorts, p)
|
||||
}
|
||||
filter = []map[string]interface{}{
|
||||
{
|
||||
"name": r.Filter.Name,
|
||||
"filters": []map[string]interface{}{
|
||||
{
|
||||
"all": r.Filter.Filters.All,
|
||||
"arp": r.Filter.Filters.ARP,
|
||||
"dhcp": r.Filter.Filters.DHCP,
|
||||
"expression": r.Filter.Filters.Expression,
|
||||
"icmp": r.Filter.Filters.ICMP,
|
||||
"ip": r.Filter.Filters.IP,
|
||||
"ip_v4": r.Filter.Filters.IPv4,
|
||||
"ip_v6": r.Filter.Filters.IPv6,
|
||||
"keep_opened_sessions": r.Filter.Filters.KeepOpenedSessions,
|
||||
"nd": r.Filter.Filters.ND,
|
||||
"tcp": r.Filter.Filters.TCP,
|
||||
"tcp_dst_ports": tcpDstPorts,
|
||||
"udp": r.Filter.Filters.UDP,
|
||||
"udp_dst_ports": udpDstPorts,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
res = append(res, map[string]interface{}{
|
||||
"access_group_id": r.AccessGroupID,
|
||||
"action": r.Action,
|
||||
"description": r.Description,
|
||||
"destination_net_object": dstNetObj,
|
||||
"direction": r.Direction,
|
||||
"display_name": r.DisplayName,
|
||||
"enabled": r.Enabled,
|
||||
"filter": filter,
|
||||
"id": r.ID,
|
||||
"log_enabled": r.LogEnabled,
|
||||
"log_name": r.LogName,
|
||||
"log_severity": r.LogSeverity,
|
||||
"priority": r.Priority,
|
||||
"security_policy_id": r.SecurityPolicyID,
|
||||
"source_net_object": srcNetObj,
|
||||
"statistics_enabled": r.StatisticsEnabled,
|
||||
"type": r.Type,
|
||||
"version_id": int(r.VersionID),
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenSecurityPolicies(policies netobjgroups.SecurityPolicies) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(policies))
|
||||
for _, p := range policies {
|
||||
res = append(res, map[string]interface{}{
|
||||
"access_group_id": p.AccessGroupID,
|
||||
"access_group_name": p.AccessGroupName,
|
||||
"applied_net_object_groups": flattenAppliedNetObjectGroups(p.AppliedNetObjectGroups),
|
||||
"created_at": p.CreatedAt,
|
||||
"description": p.Description,
|
||||
"display_name": p.DisplayName,
|
||||
"enabled": p.Enabled,
|
||||
"end_priority": int(p.EndPriority),
|
||||
"id": p.ID,
|
||||
"security_rules": flattenSecurityRules(p.SecurityRules),
|
||||
"start_priority": int(p.StartPriority),
|
||||
"status": flattenStatus(p.Status),
|
||||
"type": p.Type,
|
||||
"version_id": int(p.VersionID),
|
||||
"updated_at": p.UpdatedAt,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenNetworkObjectGroupList(list *netobjgroups.NetObjGroupList) []map[string]interface{} {
|
||||
if list == nil {
|
||||
return []map[string]interface{}{}
|
||||
}
|
||||
res := make([]map[string]interface{}, 0, len(list.Objects))
|
||||
for _, v := range list.Objects {
|
||||
res = append(res, map[string]interface{}{
|
||||
"id": v.ID,
|
||||
"name": v.Name,
|
||||
"access_group_id": v.AccessGroupID,
|
||||
"access_group_name": v.AccessGroupName,
|
||||
"description": v.Description,
|
||||
"type": v.Type,
|
||||
"purpose": v.Purpose,
|
||||
"version_id": int(v.VersionID),
|
||||
"created_at": v.CreatedAt,
|
||||
"updated_at": v.UpdatedAt,
|
||||
"addresses": flattenAddresses(v.Addresses),
|
||||
"counters": flattenCounters(v.Counters),
|
||||
"l2_connection_ports": flattenL2ConnectionPorts(v.L2ConnectionPorts),
|
||||
"logical_ports": flattenLogicalPorts(v.LogicalPorts),
|
||||
"external_network_ports": flattenExternalNetworkPorts(v.ExternalNetworkPorts),
|
||||
"security_policies": flattenSecurityPolicies(v.SecurityPolicies),
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,322 +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 netobjgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/sdn/netobjgroups"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceNetworkObjectGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceNetworkObjectGroupCreate: called with name %s", d.Get("name").(string))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := netobjgroups.CreateRequest{
|
||||
AccessGroupID: d.Get("access_group_id").(string),
|
||||
Description: d.Get("description").(string),
|
||||
Name: d.Get("name").(string),
|
||||
}
|
||||
|
||||
if addrRaw, ok := d.GetOk("addresses"); ok {
|
||||
req.Addresses = buildAddressesRequest(addrRaw.([]interface{}))
|
||||
}
|
||||
|
||||
if l2Raw, ok := d.GetOk("l2_connection_ports_bindings"); ok {
|
||||
req.L2ConnectionPortsBindings = buildL2PortsBindingsRequest(l2Raw.([]interface{}))
|
||||
}
|
||||
|
||||
rec, err := c.SDN().NetworkObjectGroups().Create(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(rec.ID)
|
||||
|
||||
return resourceNetworkObjectGroupRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceNetworkObjectGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceNetworkObjectGroupRead: called with id %s", d.Id())
|
||||
|
||||
rec, err := utilityNetworkObjectGroupCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenNetworkObjectGroupResource(d, rec)
|
||||
d.SetId(rec.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceNetworkObjectGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceNetworkObjectGroupUpdate: called with id %s", d.Id())
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := netobjgroups.UpdateRequest{
|
||||
ObjectGroupID: d.Id(),
|
||||
VersionID: uint64(d.Get("version_id").(int)),
|
||||
AccessGroupID: d.Get("access_group_id").(string),
|
||||
Description: d.Get("description").(string),
|
||||
Name: d.Get("name").(string),
|
||||
}
|
||||
|
||||
if addrRaw, ok := d.GetOk("addresses"); ok {
|
||||
req.Addresses = buildAddressesRequest(addrRaw.([]interface{}))
|
||||
}
|
||||
|
||||
rec, err := c.SDN().NetworkObjectGroups().Update(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(rec.ID)
|
||||
|
||||
return resourceNetworkObjectGroupRead(ctx, d, m)
|
||||
}
|
||||
|
||||
func resourceNetworkObjectGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceNetworkObjectGroupDelete: called with id %s", d.Id())
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := netobjgroups.DeleteRequest{
|
||||
ObjectGroupID: d.Id(),
|
||||
VersionID: uint64(d.Get("version_id").(int)),
|
||||
}
|
||||
|
||||
_, err := c.SDN().NetworkObjectGroups().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildL2PortsBindingsRequest(raw []interface{}) []netobjgroups.LogicalPortsBindings {
|
||||
result := make([]netobjgroups.LogicalPortsBindings, 0, len(raw))
|
||||
for _, item := range raw {
|
||||
m := item.(map[string]interface{})
|
||||
result = append(result, netobjgroups.LogicalPortsBindings{
|
||||
PortID: m["port_id"].(string),
|
||||
PortVersion: uint64(m["port_version"].(int)),
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func buildAddressesRequest(raw []interface{}) []netobjgroups.NetAddressRequest {
|
||||
result := make([]netobjgroups.NetAddressRequest, 0, len(raw))
|
||||
for _, item := range raw {
|
||||
addrMap := item.(map[string]interface{})
|
||||
addr := netobjgroups.NetAddressRequest{
|
||||
NetAddressType: addrMap["net_address_type"].(string),
|
||||
}
|
||||
if v, ok := addrMap["ip_addr"].(string); ok && v != "" {
|
||||
addr.IPAddr = v
|
||||
}
|
||||
if v, ok := addrMap["ip_addr_range_end"].(string); ok && v != "" {
|
||||
addr.IPAddrRangeEnd = v
|
||||
}
|
||||
if v, ok := addrMap["ip_prefix"].(string); ok && v != "" {
|
||||
addr.IPPrefix = v
|
||||
}
|
||||
if v, ok := addrMap["mac_addr"].(string); ok && v != "" {
|
||||
addr.MACAddr = v
|
||||
}
|
||||
result = append(result, addr)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func resourceNetworkObjectGroupSchemaMake() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"addresses": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"net_address_type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"ip_addr": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_addr_range_end": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"ip_prefix": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"mac_addr": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"l2_connection_ports_bindings": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"port_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"port_version": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"access_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"purpose": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"counters": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"addresses_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"l2_connection_ports_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"logical_ports_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"security_policies_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"security_rules_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"l2_connection_ports": l2ConnectionPortsComputedSchema(),
|
||||
"logical_ports": logicalPortsComputedSchema(),
|
||||
"external_network_ports": externalNetworkPortsComputedSchema(),
|
||||
"security_policies": securityPoliciesComputedSchema(),
|
||||
}
|
||||
}
|
||||
|
||||
func ResourceNetworkObjectGroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceNetworkObjectGroupCreate,
|
||||
ReadContext: resourceNetworkObjectGroupRead,
|
||||
UpdateContext: resourceNetworkObjectGroupUpdate,
|
||||
DeleteContext: resourceNetworkObjectGroupDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
|
||||
changedKeys := diff.GetChangedKeysPrefix("")
|
||||
if len(changedKeys) > 0 {
|
||||
diff.SetNewComputed("version_id")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout600s,
|
||||
Delete: &constants.Timeout300s,
|
||||
Default: &constants.Timeout300s,
|
||||
},
|
||||
|
||||
Schema: resourceNetworkObjectGroupSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,60 +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 netobjgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/netobjgroups"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityNetworkObjectGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*netobjgroups.RecordNetObjGroup, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := netobjgroups.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
req.NetObjGroupID = d.Id()
|
||||
} else {
|
||||
req.NetObjGroupID = d.Get("net_object_group_id").(string)
|
||||
}
|
||||
|
||||
netObjGroup, err := c.SDN().NetworkObjectGroups().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return netObjGroup, nil
|
||||
}
|
||||
@@ -1,87 +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 netobjgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/netobjgroups"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilityNetworkObjectGroupListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*netobjgroups.NetObjGroupList, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := netobjgroups.ListRequest{}
|
||||
|
||||
if name, ok := d.GetOk("name"); ok {
|
||||
req.Name = name.(string)
|
||||
}
|
||||
if accessGroupID, ok := d.GetOk("access_group_id"); ok {
|
||||
req.AccessGroupID = accessGroupID.(string)
|
||||
}
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if perPage, ok := d.GetOk("per_page"); ok {
|
||||
req.PerPage = uint64(perPage.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
if sortOrder, ok := d.GetOk("sort_order"); ok {
|
||||
req.SortOrder = sortOrder.(string)
|
||||
}
|
||||
if createdFrom, ok := d.GetOk("created_from"); ok {
|
||||
req.CreatedFrom = createdFrom.(string)
|
||||
}
|
||||
if createdTo, ok := d.GetOk("created_to"); ok {
|
||||
req.CreatedTo = createdTo.(string)
|
||||
}
|
||||
if updatedFrom, ok := d.GetOk("updated_from"); ok {
|
||||
req.UpdatedFrom = updatedFrom.(string)
|
||||
}
|
||||
if updatedTo, ok := d.GetOk("updated_to"); ok {
|
||||
req.UpdatedTo = updatedTo.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilityNetworkObjectGroupListCheckPresence")
|
||||
list, err := c.SDN().NetworkObjectGroups().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
@@ -1,67 +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>
|
||||
|
||||
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 segments
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceSegmentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
segment, err := utilitySegmentCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenSegment(d, segment)
|
||||
d.SetId(segment.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceSegment() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceSegmentRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
Schema: dataSourceSegmentSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
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 segments
|
||||
|
||||
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 dataSourceSegmentListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
segmentList, err := utilitySegmentListCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
d.SetId(id.String())
|
||||
d.Set("items", flattenSegmentList(segmentList))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DataSourceSegmentList() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
ReadContext: dataSourceSegmentListRead,
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Read: &constants.Timeout30s,
|
||||
Default: &constants.Timeout60s,
|
||||
},
|
||||
|
||||
Schema: dataSourceSegmentListSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
package segments
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/segments"
|
||||
)
|
||||
|
||||
func flattenSegment(d *schema.ResourceData, segmentRecord *segments.SegmentResponse) {
|
||||
d.Set("access_group_id", segmentRecord.AccessGroupID)
|
||||
d.Set("access_group_name", segmentRecord.AccessGroupName)
|
||||
d.Set("created_at", segmentRecord.CreatedAt.String())
|
||||
d.Set("description", segmentRecord.Description)
|
||||
d.Set("dhcp_v4", flattenDHCPv4(segmentRecord.DHCPv4))
|
||||
d.Set("dhcp_v6", flattenDHCPv6(segmentRecord.DHCPv6))
|
||||
d.Set("display_name", segmentRecord.DisplayName)
|
||||
d.Set("enabled", segmentRecord.Enabled)
|
||||
d.Set("l2_connection_port", flattenL2ConnectionPort(segmentRecord.L2ConnectionPort))
|
||||
d.Set("logical_ports_info", flattenEntity(segmentRecord.LogicalPortsInfo))
|
||||
d.Set("routers_info", flattenEntity(segmentRecord.RoutersInfo))
|
||||
d.Set("status", flattenStatus(segmentRecord.Status))
|
||||
d.Set("subnet_v4", segmentRecord.SubnetV4)
|
||||
d.Set("subnet_v6", segmentRecord.SubnetV6)
|
||||
d.Set("type", segmentRecord.Type)
|
||||
d.Set("updated_at", segmentRecord.UpdatedAt.String())
|
||||
d.Set("version_id", segmentRecord.VersionID)
|
||||
}
|
||||
|
||||
func flattenStatus(s segments.Status) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"operation_status": s.OperationStatus,
|
||||
"hypervisors": flattenHypervisors(s.Hypervisors),
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenHypervisors(hv []segments.HypervisorStatus) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(hv))
|
||||
for _, v := range hv {
|
||||
temp := map[string]interface{}{
|
||||
"operation_status": v.OperationStatus,
|
||||
"name": v.Name,
|
||||
"display_name": v.DisplayName,
|
||||
"hypervisor_status": v.HypervisorStatus,
|
||||
"synced_at": v.SyncedAt.String(),
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenEntity(ei []segments.EntityInfo) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(ei))
|
||||
for _, v := range ei {
|
||||
temp := map[string]interface{}{
|
||||
"display_name": v.DisplayName,
|
||||
"id": v.ID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDHCPv4(dchp segments.DHCPv4Config) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"dns": dchp.DNS,
|
||||
"excluded_address_ranges": dchp.ExcludedAddressRanges,
|
||||
"gateway": dchp.Gateway,
|
||||
"id": dchp.ID,
|
||||
"lease_time": dchp.LeaseTime,
|
||||
"server_ip": dchp.ServerIP,
|
||||
"server_mac": dchp.ServerMAC,
|
||||
"enabled": dchp.Enabled,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenDHCPv6(dchp segments.DHCPv6Config) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0)
|
||||
temp := map[string]interface{}{
|
||||
"dns": dchp.DNS,
|
||||
"address_prefix": dchp.AddressPrefix,
|
||||
"id": dchp.ID,
|
||||
"lease_time": dchp.LeaseTime,
|
||||
"server_mac": dchp.ServerMAC,
|
||||
"enabled": dchp.Enabled,
|
||||
}
|
||||
res = append(res, temp)
|
||||
return res
|
||||
}
|
||||
|
||||
func flattenL2ExternalNetwork(net segments.L2ExternalNetwork) []map[string]interface{} {
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"id": net.ID,
|
||||
"display_name": net.DisplayName,
|
||||
"description": net.Description,
|
||||
"bridge_network_name": net.BridgeNetworkName,
|
||||
"hypervisors": net.Hypervisors,
|
||||
"vlan_tag": net.VLANTag,
|
||||
"version_id": net.VersionID,
|
||||
"created_at": net.CreatedAt.String(),
|
||||
"created_by": net.CreatedBy,
|
||||
"updated_at": net.UpdatedAt.String(),
|
||||
"updated_by": net.UpdatedBy,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenL2ConnectionPort(port *segments.L2ConnectionPort) []map[string]interface{} {
|
||||
if port == nil {
|
||||
return nil
|
||||
}
|
||||
return []map[string]interface{}{
|
||||
{
|
||||
"id": port.ID,
|
||||
"access_group_id": port.AccessGroupID,
|
||||
"version_id": port.VersionID,
|
||||
"created_at": port.CreatedAt.String(),
|
||||
"created_by": port.CreatedBy,
|
||||
"updated_at": port.UpdatedAt.String(),
|
||||
"updated_by": port.UpdatedBy,
|
||||
"l2_external_network": flattenL2ExternalNetwork(port.L2ExternalNetwork),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func flattenSegmentList(sl *segments.ListSegment) []map[string]interface{} {
|
||||
res := make([]map[string]interface{}, 0, len(*sl))
|
||||
for _, v := range *sl {
|
||||
temp := map[string]interface{}{
|
||||
"access_group_id": v.AccessGroupID,
|
||||
"access_group_name": v.AccessGroupName,
|
||||
"created_at": v.CreatedAt.String(),
|
||||
"description": v.Description,
|
||||
"dhcp_v4": flattenDHCPv4(v.DHCPv4),
|
||||
"dhcp_v6": flattenDHCPv6(v.DHCPv6),
|
||||
"display_name": v.DisplayName,
|
||||
"enabled": v.Enabled,
|
||||
"l2_connection_port": flattenL2ConnectionPort(v.L2ConnectionPort),
|
||||
"logical_ports_info": flattenEntity(v.LogicalPortsInfo),
|
||||
"routers_info": flattenEntity(v.RoutersInfo),
|
||||
"status": flattenStatus(v.Status),
|
||||
"id": v.ID,
|
||||
"subnet_v4": v.SubnetV4,
|
||||
"subnet_v6": v.SubnetV6,
|
||||
"type": v.Type,
|
||||
"updated_at": v.UpdatedAt.String(),
|
||||
"version_id": v.VersionID,
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,365 +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>
|
||||
|
||||
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 segments
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/sdn/segments"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func resourceSegmentCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceSegmentCreate: called segment with name %s",
|
||||
d.Get("display_name").(string))
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
subnetV4, v4ok := d.GetOk("subnet_v4")
|
||||
subnetV6, v6ok := d.GetOk("subnet_v6")
|
||||
|
||||
if !v4ok && !v6ok {
|
||||
return diag.Errorf("resourceSegmentCreate: either subnet_v4 or subnet_v6 must be specified")
|
||||
}
|
||||
|
||||
req := segments.CreateRequest{
|
||||
AccessGroupID: d.Get("access_group_id").(string),
|
||||
Description: d.Get("description").(string),
|
||||
DisplayName: d.Get("display_name").(string),
|
||||
Enabled: d.Get("enabled").(bool),
|
||||
}
|
||||
|
||||
if t, ok := d.GetOk("type"); ok {
|
||||
req.Type = t.(string)
|
||||
}
|
||||
|
||||
if v4ok {
|
||||
req.SubnetV4 = subnetV4.(string)
|
||||
}
|
||||
|
||||
if v6ok {
|
||||
req.SubnetV6 = subnetV6.(string)
|
||||
}
|
||||
|
||||
if dhcpV4, ok := d.GetOk("dhcp_v4"); ok {
|
||||
dhcpV4 := dhcpV4.([]interface{})[0]
|
||||
dhcpV4Map := dhcpV4.(map[string]interface{})
|
||||
dhcpReq := segments.DHCPv4ConfigRequest{
|
||||
Gateway: dhcpV4Map["gateway"].(string),
|
||||
ServerIP: dhcpV4Map["server_ip"].(string),
|
||||
Enabled: dhcpV4Map["enabled"].(bool),
|
||||
}
|
||||
serverMAC, sMAC := dhcpV4Map["server_mac"]
|
||||
if sMAC {
|
||||
dhcpReq.ServerMAC = serverMAC.(string)
|
||||
}
|
||||
|
||||
leaseTime, lTime := dhcpV4Map["lease_time"]
|
||||
if lTime {
|
||||
dhcpReq.LeaseTime = uint64(leaseTime.(int))
|
||||
}
|
||||
|
||||
dns, dnsOk := dhcpV4Map["dns"]
|
||||
if dnsOk {
|
||||
dnsArr := make([]string, 0)
|
||||
for _, v := range dns.([]interface{}) {
|
||||
dnsArr = append(dnsArr, v.(string))
|
||||
}
|
||||
dhcpReq.DNS = dnsArr
|
||||
}
|
||||
|
||||
adrRanges, earOK := dhcpV4Map["excluded_address_ranges"]
|
||||
if earOK {
|
||||
earArr := make([]string, 0)
|
||||
for _, v := range adrRanges.([]interface{}) {
|
||||
earArr = append(earArr, v.(string))
|
||||
}
|
||||
dhcpReq.ExcludedAddressRanges = earArr
|
||||
}
|
||||
req.DHCPv4 = &dhcpReq
|
||||
}
|
||||
|
||||
if dhcpV6, ok := d.GetOk("dhcp_v6"); ok {
|
||||
dhcpV6 := dhcpV6.([]interface{})[0]
|
||||
dhcpV6Map := dhcpV6.(map[string]interface{})
|
||||
dhcpReq := segments.DHCPv6ConfigRequest{
|
||||
AddressPrefix: dhcpV6Map["address_prefix"].(string),
|
||||
Enabled: dhcpV6Map["enabled"].(bool),
|
||||
}
|
||||
serverMAC, sMAC := dhcpV6Map["server_mac"]
|
||||
if sMAC {
|
||||
dhcpReq.ServerMAC = serverMAC.(string)
|
||||
}
|
||||
|
||||
leaseTime, lTime := dhcpV6Map["lease_time"]
|
||||
if lTime {
|
||||
dhcpReq.LeaseTime = uint64(leaseTime.(int))
|
||||
}
|
||||
|
||||
dns, dnsOk := dhcpV6Map["dns"]
|
||||
if dnsOk {
|
||||
dnsArr := make([]string, 0)
|
||||
for _, v := range dns.([]interface{}) {
|
||||
dnsArr = append(dnsArr, v.(string))
|
||||
}
|
||||
dhcpReq.DNS = dnsArr
|
||||
}
|
||||
req.DHCPv6 = &dhcpReq
|
||||
}
|
||||
|
||||
segmentData, err := c.SDN().Segments().Create(ctx, req)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(segmentData.ID)
|
||||
d.Set("segment_id", segmentData.ID)
|
||||
|
||||
return append(resourceSegmentRead(ctx, d, m))
|
||||
}
|
||||
|
||||
func resourceSegmentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceSegmentRead: called segment with name %s",
|
||||
d.Get("display_name").(string))
|
||||
|
||||
segmentData, err := utilitySegmentCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
flattenSegment(d, segmentData)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceSegmentUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceSegmentUpdate: called segment with name %s",
|
||||
d.Get("display_name").(string))
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
segmentData, err := utilitySegmentCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
subnetV4, v4ok := d.GetOk("subnet_v4")
|
||||
subnetV6, v6ok := d.GetOk("subnet_v6")
|
||||
|
||||
if !v4ok && !v6ok {
|
||||
return diag.Errorf("resourceSegmentCreate: either subnet_v4 or subnet_v6 must be specified")
|
||||
}
|
||||
|
||||
needUpdate := false
|
||||
|
||||
req := segments.UpdateRequest{
|
||||
SegmentID: segmentData.ID,
|
||||
VersionID: segmentData.VersionID,
|
||||
AccessGroupID: d.Get("access_group_id").(string),
|
||||
Description: d.Get("description").(string),
|
||||
DisplayName: d.Get("display_name").(string),
|
||||
Enabled: d.Get("enabled").(bool),
|
||||
}
|
||||
|
||||
if d.HasChanges("access_group_id", "description", "display_name", "enabled", "type") {
|
||||
needUpdate = true
|
||||
}
|
||||
|
||||
if t, ok := d.GetOk("type"); ok {
|
||||
req.Type = t.(string)
|
||||
}
|
||||
|
||||
if v4ok {
|
||||
req.SubnetV4 = subnetV4.(string)
|
||||
}
|
||||
|
||||
if v6ok {
|
||||
req.SubnetV6 = subnetV6.(string)
|
||||
}
|
||||
|
||||
if d.HasChange("dhcp_v4") {
|
||||
if dhcpV4, ok := d.GetOk("dhcp_v4"); ok {
|
||||
dhcpV4 := dhcpV4.([]interface{})[0]
|
||||
dhcpV4Map := dhcpV4.(map[string]interface{})
|
||||
dhcpReq := segments.DHCPv4ConfigRequest{
|
||||
Gateway: dhcpV4Map["gateway"].(string),
|
||||
ServerIP: dhcpV4Map["server_ip"].(string),
|
||||
Enabled: dhcpV4Map["enabled"].(bool),
|
||||
}
|
||||
serverMAC, sMAC := dhcpV4Map["server_mac"]
|
||||
if sMAC {
|
||||
dhcpReq.ServerMAC = serverMAC.(string)
|
||||
}
|
||||
|
||||
leaseTime, lTime := dhcpV4Map["lease_time"]
|
||||
if lTime {
|
||||
dhcpReq.LeaseTime = uint64(leaseTime.(int))
|
||||
}
|
||||
|
||||
dns, dnsOk := dhcpV4Map["dns"]
|
||||
if dnsOk {
|
||||
dnsArr := make([]string, 0)
|
||||
for _, v := range dns.([]interface{}) {
|
||||
dnsArr = append(dnsArr, v.(string))
|
||||
}
|
||||
dhcpReq.DNS = dnsArr
|
||||
}
|
||||
|
||||
adrRanges, earOK := dhcpV4Map["excluded_address_ranges"]
|
||||
if earOK {
|
||||
earArr := make([]string, 0)
|
||||
for _, v := range adrRanges.([]interface{}) {
|
||||
earArr = append(earArr, v.(string))
|
||||
}
|
||||
dhcpReq.ExcludedAddressRanges = earArr
|
||||
}
|
||||
req.DHCPv4 = &dhcpReq
|
||||
}
|
||||
|
||||
needUpdate = true
|
||||
}
|
||||
|
||||
if d.HasChange("dhcp_v6") {
|
||||
if dhcpV6, ok := d.GetOk("dhcp_v6"); ok {
|
||||
dhcpV6 := dhcpV6.([]interface{})[0]
|
||||
dhcpV6Map := dhcpV6.(map[string]interface{})
|
||||
dhcpReq := segments.DHCPv6ConfigRequest{
|
||||
AddressPrefix: dhcpV6Map["address_prefix"].(string),
|
||||
Enabled: dhcpV6Map["enabled"].(bool),
|
||||
}
|
||||
serverMAC, sMAC := dhcpV6Map["server_mac"]
|
||||
if sMAC {
|
||||
dhcpReq.ServerMAC = serverMAC.(string)
|
||||
}
|
||||
|
||||
leaseTime, lTime := dhcpV6Map["lease_time"]
|
||||
if lTime {
|
||||
dhcpReq.LeaseTime = uint64(leaseTime.(int))
|
||||
}
|
||||
|
||||
dns, dnsOk := dhcpV6Map["dns"]
|
||||
if dnsOk {
|
||||
dnsArr := make([]string, 0)
|
||||
for _, v := range dns.([]interface{}) {
|
||||
dnsArr = append(dnsArr, v.(string))
|
||||
}
|
||||
dhcpReq.DNS = dnsArr
|
||||
}
|
||||
req.DHCPv6 = &dhcpReq
|
||||
}
|
||||
needUpdate = true
|
||||
}
|
||||
|
||||
if needUpdate {
|
||||
segmentData, err = c.SDN().Segments().Update(ctx, req)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(segmentData.ID)
|
||||
d.Set("segment_id", segmentData.ID)
|
||||
|
||||
return append(resourceSegmentRead(ctx, d, m))
|
||||
}
|
||||
|
||||
func resourceSegmentDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
log.Debugf("resourceSegmentUpdate: called segment with name %s",
|
||||
d.Get("display_name").(string))
|
||||
|
||||
segmentData, err := utilitySegmentCheckPresence(ctx, d, m)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
req := segments.DeleteRequest{
|
||||
SegmentID: segmentData.ID,
|
||||
VersionID: segmentData.VersionID,
|
||||
}
|
||||
|
||||
if force, ok := d.GetOk("force"); ok {
|
||||
req.Force = force.(bool)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
err = c.SDN().Segments().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ResourceSegment() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
SchemaVersion: 1,
|
||||
|
||||
CreateContext: resourceSegmentCreate,
|
||||
ReadContext: resourceSegmentRead,
|
||||
UpdateContext: resourceSegmentUpdate,
|
||||
DeleteContext: resourceSegmentDelete,
|
||||
|
||||
Importer: &schema.ResourceImporter{
|
||||
StateContext: schema.ImportStatePassthroughContext,
|
||||
},
|
||||
|
||||
CustomizeDiff: func(ctx context.Context, diff *schema.ResourceDiff, i interface{}) error {
|
||||
changedKeys := diff.GetChangedKeysPrefix("")
|
||||
if len(changedKeys) > 0 {
|
||||
diff.SetNewComputed("updated_at")
|
||||
diff.SetNewComputed("version_id")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
Timeouts: &schema.ResourceTimeout{
|
||||
Create: &constants.Timeout600s,
|
||||
Read: &constants.Timeout300s,
|
||||
Update: &constants.Timeout600s,
|
||||
Delete: &constants.Timeout900s,
|
||||
Default: &constants.Timeout300s,
|
||||
},
|
||||
|
||||
Schema: resourceSegmentSchemaMake(),
|
||||
}
|
||||
}
|
||||
@@ -1,841 +0,0 @@
|
||||
package segments
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
)
|
||||
|
||||
func l2ExternalNetworkSchema() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"bridge_network_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hypervisors": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"vlan_tag": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func l2ConnectionPortSchema() map[string]*schema.Schema {
|
||||
return map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_by": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"l2_external_network": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: l2ExternalNetworkSchema(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceSegmentSchemaMake() map[string]*schema.Schema {
|
||||
sch := map[string]*schema.Schema{
|
||||
"segment_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dhcp_v4": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"dns": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"excluded_address_ranges": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"lease_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"server_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"server_mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"dhcp_v6": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address_prefix": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dns": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"lease_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"server_mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"l2_connection_port": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: l2ConnectionPortSchema(),
|
||||
},
|
||||
},
|
||||
"logical_ports_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"routers_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hypervisors": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hypervisor_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"synced_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"subnet_v4": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"subnet_v6": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return sch
|
||||
}
|
||||
|
||||
func dataSourceSegmentListSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Page number",
|
||||
},
|
||||
"per_page": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Description: "Items per page",
|
||||
},
|
||||
"sort_by": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"display_name", "subnet", "created_at", "updated_at"}, false),
|
||||
Description: "sort by one of supported fields",
|
||||
},
|
||||
"sort_order": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"asc", "dec"}, false),
|
||||
Description: "sort order",
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "find by enabled status",
|
||||
},
|
||||
"is_synced": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Description: "does core currently believe that its data is synchronized with the data in the OVN?",
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "find by display name",
|
||||
},
|
||||
"subnet": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "IPv4 or IPv6 subnet for the current segment",
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "find by access group id",
|
||||
},
|
||||
"created_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "find by created date",
|
||||
},
|
||||
"created_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "find by created date",
|
||||
},
|
||||
"updated_from": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "find by updated date",
|
||||
},
|
||||
"updated_to": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Description: "find by updated date",
|
||||
},
|
||||
"operation_status": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ValidateFunc: validation.StringInSlice([]string{"Idle", "SynchronizingAtCore", "SynchronizingAtOVN", "Synchronized", "NoHypervisorAtOVN", "FailedAtCore", "TemporaryFailedAtCore"}, false),
|
||||
Description: "filter by operation status",
|
||||
},
|
||||
"items": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"access_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dhcp_v4": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"dns": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"excluded_address_ranges": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"lease_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"server_ip": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"server_mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"dhcp_v6": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address_prefix": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"dns": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"lease_time": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
"server_mac": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"l2_connection_port": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: l2ConnectionPortSchema(),
|
||||
},
|
||||
},
|
||||
"logical_ports_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"routers_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hypervisors": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hypervisor_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"synced_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"subnet_v4": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"subnet_v6": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"entry_count": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
Description: "entry count",
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func resourceSegmentSchemaMake() map[string]*schema.Schema {
|
||||
res := map[string]*schema.Schema{
|
||||
"access_group_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"description": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Required: true,
|
||||
},
|
||||
"force": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
},
|
||||
"subnet_v4": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"subnet_v6": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"dhcp_v4": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"dns": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"excluded_address_ranges": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"gateway": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"lease_time": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"server_ip": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"server_mac": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"dhcp_v6": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"address_prefix": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"dns": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"lease_time": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"server_mac": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"enabled": {
|
||||
Type: schema.TypeBool,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"access_group_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"created_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"l2_connection_port": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: l2ConnectionPortSchema(),
|
||||
},
|
||||
},
|
||||
"logical_ports_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"routers_info": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"status": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hypervisors": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"operation_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"hypervisor_status": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"synced_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
"updated_at": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"version_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package segments
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/segments"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilitySegmentCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*segments.SegmentResponse, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := segments.GetRequest{}
|
||||
|
||||
if d.Id() != "" {
|
||||
req.SegmentID = d.Id()
|
||||
} else {
|
||||
req.SegmentID = d.Get("segment_id").(string)
|
||||
}
|
||||
|
||||
segment, err := c.SDN().Segments().Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return segment, nil
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package segments
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/segments"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
func utilitySegmentListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*segments.ListSegment, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := segments.ListRequest{}
|
||||
|
||||
if page, ok := d.GetOk("page"); ok {
|
||||
req.Page = uint64(page.(int))
|
||||
}
|
||||
if perPage, ok := d.GetOk("per_page"); ok {
|
||||
req.PerPage = uint64(perPage.(int))
|
||||
}
|
||||
if sortBy, ok := d.GetOk("sort_by"); ok {
|
||||
req.SortBy = sortBy.(string)
|
||||
}
|
||||
if sortOrder, ok := d.GetOk("sort_order"); ok {
|
||||
req.SortOrder = sortOrder.(string)
|
||||
}
|
||||
if enabled, ok := d.GetOk("enabled"); ok {
|
||||
req.Enabled = enabled.(bool)
|
||||
}
|
||||
if isSynced, ok := d.GetOk("is_synced"); ok {
|
||||
req.IsSynced = isSynced.(bool)
|
||||
}
|
||||
if displayName, ok := d.GetOk("display_name"); ok {
|
||||
req.DisplayName = displayName.(string)
|
||||
}
|
||||
if subnet, ok := d.GetOk("subnet"); ok {
|
||||
req.Subnet = subnet.(string)
|
||||
}
|
||||
if accessGroupID, ok := d.GetOk("access_group_id"); ok {
|
||||
req.AccessGroupID = accessGroupID.(string)
|
||||
}
|
||||
if createdFrom, ok := d.GetOk("created_from"); ok {
|
||||
req.CreatedFrom = createdFrom.(string)
|
||||
}
|
||||
if createdTo, ok := d.GetOk("created_to"); ok {
|
||||
req.CreatedTo = createdTo.(string)
|
||||
}
|
||||
if updatedFrom, ok := d.GetOk("updated_from"); ok {
|
||||
req.UpdatedFrom = updatedFrom.(string)
|
||||
}
|
||||
if updatedTo, ok := d.GetOk("updated_to"); ok {
|
||||
req.UpdatedTo = updatedTo.(string)
|
||||
}
|
||||
if operationStatus, ok := d.GetOk("operation_status"); ok {
|
||||
req.OperationStatus = operationStatus.(string)
|
||||
}
|
||||
|
||||
log.Debugf("utilitySegmentListCheckPresence")
|
||||
segmentList, err := c.SDN().Segments().List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &segmentList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user