@@ -348,21 +348,21 @@ func (m *MachineScope) InstanceNetworkInterfaceSpec() *compute.NetworkInterface
348348 return networkInterface
349349}
350350
351- // InstanceServiceAccountsSpec returns service-account spec.
352- func ( m * MachineScope ) InstanceServiceAccountsSpec ( ) * compute.ServiceAccount {
353- serviceAccount := & compute.ServiceAccount {
351+ // instanceServiceAccountsSpec returns service-account spec.
352+ func instanceServiceAccountsSpec ( serviceAccount * infrav1. ServiceAccount ) * compute.ServiceAccount {
353+ out := & compute.ServiceAccount {
354354 Email : "default" ,
355355 Scopes : []string {
356356 compute .CloudPlatformScope ,
357357 },
358358 }
359359
360- if m . GCPMachine . Spec . ServiceAccount != nil {
361- serviceAccount .Email = m . GCPMachine . Spec . ServiceAccount .Email
362- serviceAccount .Scopes = m . GCPMachine . Spec . ServiceAccount .Scopes
360+ if serviceAccount != nil {
361+ out .Email = serviceAccount .Email
362+ out .Scopes = serviceAccount .Scopes
363363 }
364364
365- return serviceAccount
365+ return out
366366}
367367
368368// InstanceAdditionalMetadataSpec returns additional metadata spec.
@@ -486,7 +486,7 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
486486 instance .Disks = append (instance .Disks , m .InstanceImageSpec ())
487487 instance .Disks = append (instance .Disks , instanceAdditionalDiskSpec (ctx , m .GCPMachine .Spec .AdditionalDisks , m .GCPMachine .Spec .RootDiskEncryptionKey , m .Zone (), m .ResourceManagerTags ())... )
488488 instance .Metadata = m .InstanceAdditionalMetadataSpec ()
489- instance .ServiceAccounts = append (instance .ServiceAccounts , m . InstanceServiceAccountsSpec ( ))
489+ instance .ServiceAccounts = append (instance .ServiceAccounts , instanceServiceAccountsSpec ( m . GCPMachine . Spec . ServiceAccount ))
490490 instance .NetworkInterfaces = append (instance .NetworkInterfaces , m .InstanceNetworkInterfaceSpec ())
491491 instance .GuestAccelerators = m .InstanceGuestAcceleratorsSpec ()
492492 if len (instance .GuestAccelerators ) > 0 {
0 commit comments