Skip to content

Commit

Permalink
Add block for primary nic in VM
Browse files Browse the repository at this point in the history
To avoid confict nic inside VM with link_nic resouces we add
a new block 'primary_nic' in VM for only nic with device number 0
  • Loading branch information
outscale-toa committed Sep 21, 2023
1 parent 4b55210 commit d94f520
Show file tree
Hide file tree
Showing 48 changed files with 1,161 additions and 180 deletions.
174 changes: 173 additions & 1 deletion outscale/data_source_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func oapiVMDescriptionAttributes(set AttributeSetter, vm *oscgo.Vm) error {
if err := set("nested_virtualization", vm.GetNestedVirtualization()); err != nil {
return err
}
if err := set("nics", getOAPIVMNetworkInterfaceLightSet(vm.GetNics())); err != nil {
prNic, secNic := getOAPIVMNetworkInterfaceLightSet(vm.GetNics())
if err := set("primary_nic", prNic); err != nil {
return err
}
if err := set("nics", secNic); err != nil {
return err
}
if err := set("os_family", vm.GetOsFamily()); err != nil {
Expand Down Expand Up @@ -383,6 +387,174 @@ func getOApiVMAttributesSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"primary_nic": {
Type: schema.TypeSet,
Computed: true,
Set: func(v interface{}) int {
return v.(map[string]interface{})["device_number"].(int)
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"delete_on_vm_deletion": {
Type: schema.TypeBool,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"device_number": {
Type: schema.TypeInt,
Computed: true,
},
"nic_id": {
Type: schema.TypeString,
Computed: true,
},
"private_ips": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"is_primary": {
Type: schema.TypeBool,
Computed: true,
},
"link_public_ip": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"public_dns_name": {
Type: schema.TypeString,
Computed: true,
},
"public_ip": {
Type: schema.TypeString,
Computed: true,
},
"public_ip_account_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"private_dns_name": {
Type: schema.TypeString,
Computed: true,
},
"private_ip": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"secondary_private_ip_count": {
Type: schema.TypeInt,
Computed: true,
},
"account_id": {
Type: schema.TypeString,
Computed: true,
},

"is_source_dest_checked": {
Type: schema.TypeBool,
Computed: true,
},

"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"link_nic": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"delete_on_vm_deletion": {
Type: schema.TypeBool,
Computed: true,
},
"device_number": {
Type: schema.TypeString,
Computed: true,
},
"link_nic_id": {
Type: schema.TypeString,
Computed: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"link_public_ip": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"public_dns_name": {
Type: schema.TypeString,
Computed: true,
},
"public_ip": {
Type: schema.TypeString,
Computed: true,
},
"public_ip_account_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"mac_address": {
Type: schema.TypeString,
Computed: true,
},
"net_id": {
Type: schema.TypeString,
Computed: true,
},

"private_dns_name": {
Type: schema.TypeString,
Computed: true,
},
"security_group_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"security_groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"security_group_id": {
Type: schema.TypeString,
Computed: true,
},
"security_group_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"state": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"nics": {
Type: schema.TypeList,
Optional: true,
Expand Down
8 changes: 5 additions & 3 deletions outscale/instance_set_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func getOAPIPrivateIPs(privateIPs []oscgo.PrivateIp) (res []map[string]interface
return
}

func getOAPIVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (res []map[string]interface{}) {
func getOAPIVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (primaryNic []map[string]interface{}, secondaryNic []map[string]interface{}) {
for _, nic := range nics {
securityGroups, securityGroupIds := getOAPISecurityGroups(nic.GetSecurityGroups())

Expand Down Expand Up @@ -143,8 +143,10 @@ func getOAPIVMNetworkInterfaceLightSet(nics []oscgo.NicLight) (res []map[string]
if nic.HasLinkNic() {
nicMap["link_nic"] = getOAPILinkNicLight(nic.GetLinkNic())
}

res = append(res, nicMap)
if nic.LinkNic.GetDeviceNumber() == 0 {
primaryNic = append(primaryNic, nicMap)
}
secondaryNic = append(secondaryNic, nicMap)
}
return
}
Expand Down
Loading

0 comments on commit d94f520

Please sign in to comment.