@@ -938,14 +938,12 @@ public void DefaultExecuteCmdlet()
938938 && this . VM . StorageProfile ? . ImageReference ? . SharedGalleryImageId == null ) //had to add this
939939 {
940940 defaultTrustedLaunchAndUefi ( ) ;
941-
942941 setTrustedLaunchImage ( ) ;
943942 }
944-
945943 // Disk attached scenario for TL defaulting
946944 // Determines if the disk has SecurityType enabled.
947945 // If so, turns on TrustedLaunch for this VM.
948- if ( this . VM . SecurityProfile ? . SecurityType == null
946+ else if ( this . VM . SecurityProfile ? . SecurityType == null
949947 && this . VM . StorageProfile ? . OsDisk ? . ManagedDisk ? . Id != null )
950948 {
951949 var mDiskId = this . VM . StorageProfile ? . OsDisk ? . ManagedDisk . Id . ToString ( ) ;
@@ -959,33 +957,14 @@ public void DefaultExecuteCmdlet()
959957 defaultTrustedLaunchAndUefi ( ) ;
960958 }
961959 }
962-
963- // Guest Attestation extension defaulting scenario check.
964- // And SecureBootEnabled and VtpmEnabled defaulting scenario.
965- if ( this . VM . SecurityProfile ? . SecurityType != null
966- && ( this . VM . SecurityProfile ? . SecurityType ? . ToLower ( ) == ConstantValues . TrustedLaunchSecurityType
967- || this . VM . SecurityProfile ? . SecurityType ? . ToLower ( ) == ConstantValues . ConfidentialVMSecurityType ) )
968- {
969- if ( this . VM ? . SecurityProfile ? . UefiSettings != null )
970- {
971- this . VM . SecurityProfile . UefiSettings . SecureBootEnabled = this . VM . SecurityProfile . UefiSettings . SecureBootEnabled ?? true ;
972- this . VM . SecurityProfile . UefiSettings . VTpmEnabled = this . VM . SecurityProfile . UefiSettings . VTpmEnabled ?? true ;
973- }
974- else
975- {
976- this . VM . SecurityProfile . UefiSettings = new UefiSettings ( true , true ) ;
977- }
978- }
979-
980-
981960 // ImageReference provided, TL defaulting occurs if image is Gen2.
982961 // This will handle when the Id is provided in a URI format and
983962 // when the image segments are provided individually.
984- if ( this . VM . SecurityProfile ? . SecurityType == null
963+ else if ( this . VM . SecurityProfile ? . SecurityType == null
985964 && this . VM . StorageProfile ? . ImageReference != null )
986965 {
987966 if ( this . VM . StorageProfile ? . ImageReference ? . Id != null )
988- {
967+ {
989968 string imageRefString = this . VM . StorageProfile . ImageReference . Id . ToString ( ) ;
990969
991970 string galleryImgIdPattern = @"/subscriptions/(?<subscriptionId>[^/]+)/resourceGroups/(?<resourceGroup>[^/]+)/providers/Microsoft.Compute/galleries/(?<gallery>[^/]+)/images/(?<image>[^/]+)" ;
@@ -1001,7 +980,7 @@ public void DefaultExecuteCmdlet()
1001980 // Default Image Id
1002981 Regex defaultImageRgx = new Regex ( defaultExistingImagePattern , RegexOptions . IgnoreCase ) ;
1003982 Match defaultImageMatch = defaultImageRgx . Match ( imageRefString ) ;
1004-
983+
1005984 if ( defaultImageMatch . Success )
1006985 {
1007986 var parts = imageRefString . Split ( new char [ ] { '/' } , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -1045,16 +1024,31 @@ public void DefaultExecuteCmdlet()
10451024 setHyperVGenForImageCheckAndTLDefaulting ( specificImageRespone ) ;
10461025 }
10471026 }
1048-
1049- if ( this . VM . SecurityProfile ? . SecurityType == ConstantValues . TrustedLaunchSecurityType
1027+ else if ( this . VM . SecurityProfile ? . SecurityType == ConstantValues . TrustedLaunchSecurityType
10501028 && this . VM . StorageProfile ? . ImageReference == null
10511029 && this . VM . StorageProfile ? . OsDisk ? . ManagedDisk ? . Id == null //had to add this
1052- && this . VM . StorageProfile ? . ImageReference ? . SharedGalleryImageId == null )
1030+ && this . VM . StorageProfile ? . ImageReference ? . SharedGalleryImageId == null )
10531031 {
10541032 defaultTrustedLaunchAndUefi ( ) ;
10551033 setTrustedLaunchImage ( ) ;
10561034 }
10571035
1036+ // SecureBootEnabled and VtpmEnabled defaulting scenario.
1037+ if ( this . VM . SecurityProfile ? . SecurityType != null
1038+ && ( this . VM . SecurityProfile ? . SecurityType ? . ToLower ( ) == ConstantValues . TrustedLaunchSecurityType
1039+ || this . VM . SecurityProfile ? . SecurityType ? . ToLower ( ) == ConstantValues . ConfidentialVMSecurityType ) )
1040+ {
1041+ if ( this . VM ? . SecurityProfile ? . UefiSettings != null )
1042+ {
1043+ this . VM . SecurityProfile . UefiSettings . SecureBootEnabled = this . VM . SecurityProfile . UefiSettings . SecureBootEnabled ?? true ;
1044+ this . VM . SecurityProfile . UefiSettings . VTpmEnabled = this . VM . SecurityProfile . UefiSettings . VTpmEnabled ?? true ;
1045+ }
1046+ else
1047+ {
1048+ this . VM . SecurityProfile . UefiSettings = new UefiSettings ( true , true ) ;
1049+ }
1050+ }
1051+
10581052 // Standard security type removing value since API does not support it yet.
10591053 if ( this . VM . SecurityProfile ? . SecurityType != null
10601054 && this . VM . SecurityProfile ? . SecurityType ? . ToString ( ) . ToLower ( ) == ConstantValues . StandardSecurityType )
0 commit comments