@@ -21,13 +21,15 @@ import (
2121 "crypto/rand"
2222 "crypto/rsa"
2323 "encoding/base64"
24+ "fmt"
2425
2526 "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
2627 "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
2728 "github.com/Azure/go-autorest/autorest/to"
2829 "github.com/pkg/errors"
2930 "golang.org/x/crypto/ssh"
3031 "k8s.io/klog"
32+ "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1"
3133 "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure"
3234 "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/services/networkinterfaces"
3335)
@@ -37,6 +39,9 @@ type Spec struct {
3739 Name string
3840 NICName string
3941 SSHKeyData string
42+ Size string
43+ Image v1alpha1.Image
44+ OSDisk v1alpha1.OSDisk
4045}
4146
4247// Get provides information about a virtual network.
@@ -101,29 +106,34 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
101106 Location : to .StringPtr (s .Scope .ClusterConfig .Location ),
102107 VirtualMachineProperties : & compute.VirtualMachineProperties {
103108 HardwareProfile : & compute.HardwareProfile {
104- VMSize : compute .VirtualMachineSizeTypes ("Standard_DS2_v2" ),
109+ VMSize : compute .VirtualMachineSizeTypes (vmSpec . Size ),
105110 },
106111 StorageProfile : & compute.StorageProfile {
107112 ImageReference : & compute.ImageReference {
108- Publisher : to .StringPtr ("Canonical" ),
109- Offer : to .StringPtr ("UbuntuServer" ),
110- Sku : to .StringPtr ("18.04-LTS" ),
111- Version : to .StringPtr ("latest" ),
113+ Publisher : to .StringPtr (vmSpec . Image . Publisher ),
114+ Offer : to .StringPtr (vmSpec . Image . Offer ),
115+ Sku : to .StringPtr (vmSpec . Image . SKU ),
116+ Version : to .StringPtr (vmSpec . Image . Version ),
112117 },
113118 OsDisk : & compute.OSDisk {
119+ Name : to .StringPtr (fmt .Sprintf ("%s_OSDisk" , vmSpec .Name )),
120+ OsType : compute .OperatingSystemTypes (vmSpec .OSDisk .OSType ),
114121 CreateOption : compute .DiskCreateOptionTypesFromImage ,
115- DiskSizeGB : to .Int32Ptr (64 ),
122+ DiskSizeGB : to .Int32Ptr (vmSpec .OSDisk .DiskSizeGB ),
123+ ManagedDisk : & compute.ManagedDiskParameters {
124+ StorageAccountType : compute .StorageAccountTypes (vmSpec .OSDisk .ManagedDisk .StorageAccountType ),
125+ },
116126 },
117127 },
118128 OsProfile : & compute.OSProfile {
119129 ComputerName : to .StringPtr (vmSpec .Name ),
120- AdminUsername : to .StringPtr ("azureuser" ),
130+ AdminUsername : to .StringPtr (azure . DefaultUserName ),
121131 AdminPassword : to .StringPtr (randomPassword ),
122132 LinuxConfiguration : & compute.LinuxConfiguration {
123133 SSH : & compute.SSHConfiguration {
124134 PublicKeys : & []compute.SSHPublicKey {
125135 {
126- Path : to .StringPtr ("/home/azureuser /.ssh/authorized_keys" ),
136+ Path : to .StringPtr (fmt . Sprintf ( "/home/%s /.ssh/authorized_keys" , azure . DefaultUserName ) ),
127137 KeyData : to .StringPtr (sshKeyData ),
128138 },
129139 },
0 commit comments