@@ -636,3 +636,63 @@ func (v VaultSecretConverter) ConvertToMultyResource(resourceId string, m proto.
636636 ImplicitlyCreated : false ,
637637 }, nil
638638}
639+
640+ type VirtualMachineConverter struct {
641+ }
642+
643+ func (v VirtualMachineConverter ) NewArg () proto.Message {
644+ return & resources.CloudSpecificVirtualMachineArgs {}
645+ }
646+
647+ func (v VirtualMachineConverter ) ConvertToMultyResource (resourceId string , m proto.Message , otherResources map [string ]common_resources.CloudSpecificResource ) (common_resources.CloudSpecificResource , error ) {
648+ arg := m .(* resources.CloudSpecificVirtualMachineArgs )
649+ c := cloud_providers .CloudProvider (strings .ToLower (arg .CommonParameters .CloudProvider .String ()))
650+ vm := types.VirtualMachine {
651+ CommonResourceParams : & common_resources.CommonResourceParams {
652+ ResourceId : resourceId ,
653+ ResourceGroupId : arg .CommonParameters .ResourceGroupId ,
654+ Location : strings .ToLower (arg .CommonParameters .Location .String ()),
655+ Clouds : []string {string (c )},
656+ },
657+ Name : arg .Name ,
658+ OperatingSystem : strings .ToLower (arg .OperatingSystem .String ()),
659+ Size : strings .ToLower (arg .VmSize .String ()),
660+ UserData : arg .UserData ,
661+ SshKey : arg .PublicSshKey ,
662+ PublicIp : arg .GeneratePublicIp ,
663+ }
664+
665+ if pid , ok := otherResources [common_resources .GetResourceIdForCloud (arg .PublicIpId , c )]; ok {
666+ vm .PublicIpId = pid .Resource .(* types.PublicIp )
667+ } else {
668+ return common_resources.CloudSpecificResource {}, fmt .Errorf ("public ip with id %s not found in %s" , arg .PublicIpId , c )
669+ }
670+
671+ if subnet , ok := otherResources [common_resources .GetResourceIdForCloud (arg .SubnetId , c )]; ok {
672+ vm .SubnetId = subnet .Resource .(* types.Subnet )
673+ } else {
674+ return common_resources.CloudSpecificResource {}, fmt .Errorf ("subnet with id %s not found in %s" , arg .SubnetId , c )
675+ }
676+
677+ for _ , niId := range arg .NetworkInterfaceIds {
678+ if ni , ok := otherResources [common_resources .GetResourceIdForCloud (niId , c )]; ok {
679+ vm .NetworkInterfaceIds = append (vm .NetworkInterfaceIds , ni .Resource .(* types.NetworkInterface ))
680+ } else {
681+ return common_resources.CloudSpecificResource {}, fmt .Errorf ("network interface with id %s not found in %s" , niId , c )
682+ }
683+ }
684+
685+ for _ , nsgId := range arg .NetworkInterfaceIds {
686+ if nsg , ok := otherResources [common_resources .GetResourceIdForCloud (nsgId , c )]; ok {
687+ vm .NetworkSecurityGroupIds = append (vm .NetworkSecurityGroupIds , nsg .Resource .(* types.NetworkSecurityGroup ))
688+ } else {
689+ return common_resources.CloudSpecificResource {}, fmt .Errorf ("network security group with id %s not found in %s" , nsgId , c )
690+ }
691+ }
692+
693+ return common_resources.CloudSpecificResource {
694+ Cloud : c ,
695+ Resource : & vm ,
696+ ImplicitlyCreated : false ,
697+ }, nil
698+ }
0 commit comments