This commit is contained in:
2025-11-18 16:20:26 +03:00
parent 4b3f21d9be
commit e42fbcef39
397 changed files with 17560 additions and 1501 deletions

View File

@@ -0,0 +1,87 @@
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(),
}
}

View File

@@ -0,0 +1,40 @@
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(),
}
}

View File

@@ -0,0 +1,39 @@
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(),
}
}

View File

@@ -0,0 +1,140 @@
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
}

View File

@@ -0,0 +1,276 @@
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(),
}
}

View File

@@ -0,0 +1,389 @@
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",
},
"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
}

View File

@@ -0,0 +1,43 @@
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
}

View File

@@ -0,0 +1,52 @@
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)
}
log.Debugf("utilityAccessGroupListCheckPresence")
accessGroupList, err := c.SDN().AccessGroups().List(ctx, req)
if err != nil {
return nil, err
}
return accessGroupList, nil
}

View File

@@ -0,0 +1,74 @@
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
}

View File

@@ -0,0 +1,40 @@
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(),
}
}

View File

@@ -0,0 +1,130 @@
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
}

View File

@@ -0,0 +1,369 @@
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
}

View File

@@ -0,0 +1,40 @@
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
}

View File

@@ -0,0 +1,36 @@
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(),
}
}

View File

@@ -0,0 +1,35 @@
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(),
}
}

View File

@@ -0,0 +1,39 @@
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(),
}
}

View File

@@ -0,0 +1,114 @@
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("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("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,
"live_migration_target_hv": v.LiveMigrationTargetHV,
"status": flattenStatus(v.Status),
"unique_identifier": v.UniqueIdentifier,
"version_id": v.VersionID,
"bindings": flattenBindings(v.Bindings),
"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("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("created_at", logicalPort.CreatedAt)
d.Set("updated_at", logicalPort.UpdatedAt)
}
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,
"is_excluded_from_firewall": bindings.IsExcludedFromFirewall,
"version_id": bindings.VersionID,
"created_at": bindings.CreatedAt,
"updated_at": bindings.UpdatedAt,
}
res = append(res, temp)
return res
}
func flattenStatus(status logicalports.Status) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
temp := map[string]interface{}{
"common": status.Common,
"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{}{
"status": v.Status,
"name": v.Name,
"display_name": v.DisplayName,
"hypervisor_status": v.HypervisorStatus,
"synced_at": v.SyncedAt,
}
res = append(res, temp)
}
return res
}

View File

@@ -0,0 +1,226 @@
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),
IsExcludedFromFirewall: d.Get("is_excluded_from_firewall").(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 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_address"]; 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)
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),
Hypervisor: d.Get("hypervisor").(string),
PortSecurity: d.Get("port_security").(bool),
IsExcludedFromFirewall: d.Get("is_excluded_from_firewall").(bool),
SegmentID: d.Get("segment_id").(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_address"]; 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_address"]; ok {
logicalPortAddress.MAC = mac.(string)
}
newAddressesMap[logicalPortAddress.IP] = logicalPortAddress
}
for addressIP, _ := range oldAddressesMap {
removeAddresses := make([]string, 0)
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)
}
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(),
}
}

View File

@@ -0,0 +1,858 @@
package logicalports
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceLogicalPortSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"access_group_id": {
Type: schema.TypeString,
Required: true,
Description: "Access Group ID",
},
"description": {
Type: schema.TypeString,
Required: true,
Description: "Description",
},
"display_name": {
Type: schema.TypeString,
Required: true,
Description: "Display Name",
},
"enabled": {
Type: schema.TypeBool,
Required: true,
Description: "Whether the logical port should be enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Required: true,
},
"hypervisor": {
Type: schema.TypeString,
Required: true,
Description: "Hypervisor",
},
"port_security": {
Type: schema.TypeBool,
Required: true,
Description: "Whether the port security is enabled",
},
"segment_id": {
Type: schema.TypeString,
Required: true,
Description: "Segment ID",
},
"adapter_mac": {
Type: schema.TypeString,
Optional: true,
Description: "Adapter MAC address",
},
"unique_identifier": {
Type: schema.TypeString,
Optional: true,
Description: "Unique identifier of the logical port",
},
"force": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"logical_port_addresses": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip": {
Type: schema.TypeString,
Required: true,
Description: "IP address of the logical port",
},
"ip_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"IPv4", "IPv6"}, false),
},
"is_primary": {
Type: schema.TypeBool,
Required: true,
},
"is_discovered": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"mac": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the logical port",
},
"access_group_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the access group",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"external_network_id": {
Type: schema.TypeString,
Computed: true,
},
"hypervisor_display_name": {
Type: schema.TypeString,
Computed: true,
},
"live_migration_target_hv": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the hypervisor",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the hypervisor",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"synced_at": {
Type: schema.TypeString,
Computed: true,
Description: "Sync time of the hypervisor",
},
},
},
},
},
},
},
"bindings": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the binding",
},
"segment_id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the segment",
},
"segment_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the segment",
},
"port_security": {
Type: schema.TypeBool,
Computed: true,
Description: "If the port is secured",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the binding",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the binding",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time of the binding",
},
},
},
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the logical port",
},
}
return res
}
func dataSourceLogicalPortListSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"access_group_id": {
Type: schema.TypeString,
Optional: true,
Description: "Access Group ID",
},
"segment_id": {
Type: schema.TypeString,
Optional: true,
Description: "Segment ID",
},
"segment_display_name": {
Type: schema.TypeString,
Optional: true,
Description: "Segment display name",
},
"external_network_id": {
Type: schema.TypeString,
Optional: true,
Description: "External Network ID",
},
"unique_identifier": {
Type: schema.TypeString,
Optional: true,
Description: "Unique identifier",
},
"display_name": {
Type: schema.TypeString,
Optional: true,
Description: "Display name",
},
"adapter_mac": {
Type: schema.TypeString,
Optional: true,
Description: "Adapter mac",
},
"hypervisor": {
Type: schema.TypeString,
Optional: true,
Description: "Hypervisor",
},
"hypervisor_display_name": {
Type: schema.TypeString,
Optional: true,
Description: "Hypervisor display name",
},
"live_migration_target_hv": {
Type: schema.TypeString,
Optional: true,
Description: "Live migration target HV",
},
"port_security": {
Type: schema.TypeBool,
Optional: true,
},
"address_detection": {
Type: schema.TypeBool,
Optional: true,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
},
"created_from": {
Type: schema.TypeString,
Optional: true,
},
"created_to": {
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,
ValidateFunc: validation.StringInSlice([]string{"display_name", "created_at", "updated_at",
"deleted_at", "segment_id", "hypervisor",
"port_security", "segment_display_name", "primary_address",
"hypervisor_display_name"}, false),
},
"sort_order": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"asc", "dec"}, false),
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the logical port to use",
},
"access_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the access group",
},
"access_group_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the access group",
},
"adapter_mac": {
Type: schema.TypeString,
Computed: true,
Description: "MAC address of the adapter",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
Description: "If the adapter address detection is enabled",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of the logical port",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the logical port",
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "If the logical port is enabled",
},
"hypervisor": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the hypervisor",
},
"hypervisor_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the hypervisor",
},
"live_migration_target_hv": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the hypervisor",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the hypervisor",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"synced_at": {
Type: schema.TypeString,
Computed: true,
Description: "Sync time of the hypervisor",
},
},
},
},
},
},
},
"unique_identifier": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the logical port",
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the logical port",
},
"bindings": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the binding",
},
"segment_id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the segment",
},
"segment_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the segment",
},
"port_security": {
Type: schema.TypeBool,
Computed: true,
Description: "If the port is secured",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the binding",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the binding",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time of the binding",
},
},
},
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the logical port",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time the logical port",
},
},
},
},
}
return res
}
func dataSourceLogicalPortByUniqueIDSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"unique_identifier": {
Type: schema.TypeString,
Required: true,
Description: "Unique ID of the logical port to use",
},
"access_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the access group",
},
"access_group_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the access group",
},
"adapter_mac": {
Type: schema.TypeString,
Computed: true,
Description: "MAC address of the adapter",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
Description: "If the adapter address detection is enabled",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of the logical port",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the logical port",
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "If the logical port is enabled",
},
"hypervisor": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the hypervisor",
},
"hypervisor_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the hypervisor",
},
"live_migration_target_hv": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the hypervisor",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the hypervisor",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"synced_at": {
Type: schema.TypeString,
Computed: true,
Description: "Sync time of the hypervisor",
},
},
},
},
},
},
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the logical port",
},
"bindings": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the binding",
},
"segment_id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the segment",
},
"segment_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the segment",
},
"port_security": {
Type: schema.TypeBool,
Computed: true,
Description: "If the port is secured",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the binding",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the binding",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time of the binding",
},
},
},
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the logical port",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time the logical port",
},
}
return res
}
func dataSourceLogicalPortSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"logical_port_id": {
Type: schema.TypeString,
Required: true,
Description: "ID of the logical port to use",
},
"access_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the access group",
},
"access_group_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the access group",
},
"adapter_mac": {
Type: schema.TypeString,
Computed: true,
Description: "MAC address of the adapter",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
Description: "If the adapter address detection is enabled",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of the logical port",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the logical port",
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "If the logical port is enabled",
},
"hypervisor": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the hypervisor",
},
"hypervisor_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the hypervisor",
},
"live_migration_target_hv": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common": {
Type: schema.TypeString,
Computed: true,
Description: "Common status",
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the hypervisor",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the hypervisor",
},
"hypervisor_status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the hypervisor",
},
"synced_at": {
Type: schema.TypeString,
Computed: true,
Description: "Sync time of the hypervisor",
},
},
},
},
},
},
},
"unique_identifier": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the logical port",
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the logical port",
},
"bindings": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the binding",
},
"segment_id": {
Type: schema.TypeString,
Computed: true,
Description: "Unique identifier of the segment",
},
"segment_display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Display name of the segment",
},
"port_security": {
Type: schema.TypeBool,
Computed: true,
Description: "If the port is secured",
},
"address_detection": {
Type: schema.TypeBool,
Computed: true,
Description: "If the adapter address detection is enabled",
},
"is_excluded_from_firewall": {
Type: schema.TypeBool,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Version ID of the binding",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the binding",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time of the binding",
},
},
},
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the logical port",
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
Description: "Update time the logical port",
},
}
return res
}

View File

@@ -0,0 +1,30 @@
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
}

View File

@@ -0,0 +1,30 @@
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
}

View File

@@ -0,0 +1,79 @@
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)
}
logicalPortList, err := c.SDN().LogicalPorts().List(ctx, req)
if err != nil {
return nil, err
}
return logicalPortList, nil
}

View File

@@ -0,0 +1,70 @@
/*
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 dataSourceSegmentGetStatusRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
status, err := utilitySegmentGetStatusCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
if d.Id() == "" {
d.SetId(d.Get("segment_id").(string))
}
d.Set("status", status)
return nil
}
func DataSourceSegmentGetStatus() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceSegmentGetStatusRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceSegmentGetStatusSchemaMake(),
}
}

View File

@@ -0,0 +1,67 @@
/*
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(),
}
}

View File

@@ -0,0 +1,70 @@
/*
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(),
}
}

View File

@@ -0,0 +1,117 @@
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("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("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{}{
"common": s.Common,
"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{}{
"status": v.Status,
"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 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,
"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,
"updated_at": v.UpdatedAt.String(),
"version_id": v.VersionID,
}
res = append(res, temp)
}
return res
}

View File

@@ -0,0 +1,357 @@
/*
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 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") {
needUpdate = true
}
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(),
}
}

View File

@@ -0,0 +1,731 @@
package segments
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
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,
},
"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{
"common": {
Type: schema.TypeString,
Computed: true,
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"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,
},
"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",
},
"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,
},
"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{
"common": {
Type: schema.TypeString,
Computed: true,
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"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,
},
"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 dataSourceSegmentGetStatusSchemaMake() map[string]*schema.Schema {
res := map[string]*schema.Schema{
"segment_id": {
Type: schema.TypeString,
Required: true,
},
"version_id": {
Type: schema.TypeInt,
Optional: true,
},
"detailed": {
Type: schema.TypeBool,
Optional: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
}
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,
},
"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{
"common": {
Type: schema.TypeString,
Computed: true,
},
"hypervisors": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"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,
},
},
},
},
},
},
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
"version_id": {
Type: schema.TypeInt,
Computed: true,
},
}
return res
}

View File

@@ -0,0 +1,28 @@
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
}

View File

@@ -0,0 +1,36 @@
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 utilitySegmentGetStatusCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
c := m.(*controller.ControllerCfg)
req := segments.GetStatusRequest{}
if d.Id() != "" {
req.SegmentID = d.Id()
} else {
req.SegmentID = d.Get("segment_id").(string)
}
if version, ok := d.GetOk("version"); ok {
req.VersionID = uint64(version.(int))
}
if detailed, ok := d.GetOk("detailed"); ok {
req.Detailed = detailed.(bool)
}
segment, err := c.SDN().Segments().GetStatus(ctx, req)
if err != nil {
return "", err
}
return segment, nil
}

View File

@@ -0,0 +1,63 @@
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.Enabled = 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.UpdatedTo = updatedFrom.(string)
}
if updatedTo, ok := d.GetOk("updated_to"); ok {
req.UpdatedTo = updatedTo.(string)
}
log.Debugf("utilitySegmentListCheckPresence")
segmentList, err := c.SDN().Segments().List(ctx, req)
if err != nil {
return nil, err
}
return &segmentList, nil
}