Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block for primary nic in VM #379

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {
outscale-toa marked this conversation as resolved.
Show resolved Hide resolved
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
Loading