@@ -22,14 +22,15 @@ use sles4sap::sap_deployment_automation_framework::deployment_connector qw(find_
2222Library with common functions for Microsoft SDAF deployment automation that help with preparation of
2323'WORKLOAD-ZONE' tfvars file.
2424Generated file is following example template:
25- https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/SYSTEM /LAB-SECE-SAP04-L00 /LAB-SECE-SAP04-L00 .tfvars
25+ https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/LANDSCAPE /LAB-SECE-SAP04-INFRASTRUCTURE /LAB-SECE-SAP04-INFRASTRUCTURE .tfvars
2626
2727=cut
2828
2929our @EXPORT = qw(
3030 create_workload_tfvars
3131 write_tfvars_file
3232 get_tags_entry
33+ define_vm_images
3334) ;
3435
3536=head2 write_tfvars_file
@@ -137,6 +138,8 @@ Content is generated in perl and transformed into tfvars format. File is uploade
137138
138139=item * B<workload_vnet_code > : Workload zone VNET code
139140
141+ =item * B<os_image > : BYOS or PAYG image ID. For example: 'suse:sles-sap-15-sp7:gen2:latest'
142+
140143=back
141144
142145=cut
@@ -149,14 +152,14 @@ sub create_workload_tfvars {
149152 my $vnet_code = get_required_var(' SDAF_DEPLOYER_VNET_CODE' );
150153
151154 # Mandatory arguments
152- for my $arg (' network_data' , ' workload_vnet_code' ) {
155+ for my $arg (' network_data' , ' workload_vnet_code' , ' os_image ' ) {
153156 croak(" Missing mandatory argument \$ args{$arg }" ) unless $args {$arg };
154157 }
155158
156159 # Generate tfvars file data
157160 my $tfvars_file = get_os_variable(' workload_zone_parameter_file' );
158161 my %tfvars_data ;
159- $tfvars_data {file_header } = " ### File was generated by OpenQA automation according to template:\n ### https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/SYSTEM /LAB-SECE-SAP04-L00 /LAB-SECE-SAP04-L00 .tfvars\n " ;
162+ $tfvars_data {file_header } = " ### File was generated by OpenQA automation according to template:\n ### https://github.com/Azure/SAP-automation-samples/blob/main/Terraform/WORKSPACES/LANDSCAPE /LAB-SECE-SAP04-INFRASTRUCTURE /LAB-SECE-SAP04-INFRASTRUCTURE .tfvars\n " ;
160163 $tfvars_data {env_definitions } = define_workload_environment(
161164 environment => $env_code ,
162165 location => $location ,
@@ -176,6 +179,8 @@ sub create_workload_tfvars {
176179 workload_vnet_code => $args {workload_vnet_code });
177180 $tfvars_data {iscsi_devices } = define_iscsi_devices();
178181 $tfvars_data {storage_account } = define_storage_account();
182+ # Defines the Virtual Machine image for the iSCSI devices
183+ $tfvars_data {iscsi_image } = define_vm_images(os_image => $args {os_image }, deployment_type => ' workload_zone' );
179184
180185 # Write file and upload to OpenQA logs
181186 write_tfvars_file(tfvars_data => \%tfvars_data , tfvars_file => $tfvars_file );
@@ -422,3 +427,66 @@ sub define_storage_account {
422427
423428 return (\%result );
424429}
430+
431+ =head2 define_vm_images
432+
433+ define_vm_images(os_image=>'suse:sles-sap-15-sp5:gen2:latest');
434+
435+ VM OS image tfvars setting definition. Currently all VMs use the same OS image. Both BYOS and PAYG images can be used.
436+ B<Example: > {source_image_id : '"suse:sles-sap-15-sp5:gen2:latest"', publisher : '"SUSE"' ... }
437+ Pay attention to double quoting strings. They are very important in resulting file.
438+
439+ =over
440+
441+ =item * B<os_image > : BYOS or PAYG image ID.
442+
443+ =item * B<deployment_type > : deployment type: optional argument; 'workload_zone' or 'sap_system'; default is 'sap_system'.
444+
445+ =back
446+
447+ =cut
448+
449+ sub define_vm_images {
450+ my (%args ) = @_ ;
451+ $args {deployment_type } //= ' sap_system' ;
452+ croak ' Missing mandatory argument $args{os_image}' unless $args {os_image };
453+ my $type ;
454+ my $publisher ;
455+ my $offer ;
456+ my $sku ;
457+ my $version ;
458+
459+ # This regex targets the general Azure Gallery image naming patterns,
460+ # excluding part of the name that are related to PC library.
461+ if ($args {os_image } =~ / ^\/ subscriptions\/ .*\/ galleries\/ .*/ ) {
462+ $type = ' custom' ;
463+ ($publisher , $offer , $sku , $version ) = (' ' , ' ' , ' ' , ' ' ); # Those can't be undef
464+ }
465+ else {
466+ # Parse image ID supplied by OpenQA parameter 'PUBLIC_CLOUD_IMAGE_ID'
467+ ($publisher , $offer , $sku , $version ) = split (' :' , $args {os_image });
468+ $type = ' marketplace' ;
469+ }
470+
471+ my %result = (
472+ header => ' ### VM images ###'
473+ );
474+ my @components = (' database_vm_image' , ' scs_server_image' , ' application_server_image' );
475+ @components = (' iscsi_image' ) if ($args {deployment_type } eq ' workload_zone' );
476+ for my $component (@components ) {
477+ $result {$component } = <<"END" ;
478+ { os_type = "LINUX",
479+ source_image_id = "$args {os_image}",
480+ publisher = "$publisher ",
481+ offer = "$offer ",
482+ sku = "$sku ",
483+ version = "$version ",
484+ type = "$type "
485+ }
486+ END
487+ }
488+
489+ return (\%result );
490+ }
491+
492+ 1;
0 commit comments