@@ -33,27 +33,32 @@ async function startEc2Instance(label, githubRegistrationToken) {
33
33
34
34
const userData = buildUserDataScript ( githubRegistrationToken , label ) ;
35
35
36
- const params = {
37
- ImageId : config . input . ec2ImageId ,
38
- InstanceType : config . input . ec2InstanceType ,
39
- MinCount : 1 ,
40
- MaxCount : 1 ,
41
- UserData : Buffer . from ( userData . join ( '\n' ) ) . toString ( 'base64' ) ,
42
- SubnetId : config . input . subnetId ,
43
- SecurityGroupIds : [ config . input . securityGroupId ] ,
44
- IamInstanceProfile : { Name : config . input . iamRoleName } ,
45
- TagSpecifications : config . tagSpecifications ,
46
- } ;
36
+ const subnetId = config . input . subnetId ;
37
+ const subnets = subnetId ? subnetId . replace ( / \s / g, '' ) . split ( ',' ) : [ null ] ;
47
38
48
- try {
49
- const result = await ec2 . runInstances ( params ) . promise ( ) ;
50
- const ec2InstanceId = result . Instances [ 0 ] . InstanceId ;
51
- core . info ( `AWS EC2 instance ${ ec2InstanceId } is started` ) ;
52
- return ec2InstanceId ;
53
- } catch ( error ) {
54
- core . error ( 'AWS EC2 instance starting error' ) ;
55
- throw error ;
39
+ for ( const subnet of subnets ) {
40
+ const params = {
41
+ ImageId : config . input . ec2ImageId ,
42
+ InstanceType : config . input . ec2InstanceType ,
43
+ MinCount : 1 ,
44
+ MaxCount : 1 ,
45
+ UserData : Buffer . from ( userData . join ( '\n' ) ) . toString ( 'base64' ) ,
46
+ SubnetId : subnet ,
47
+ SecurityGroupIds : [ config . input . securityGroupId ] ,
48
+ IamInstanceProfile : { Name : config . input . iamRoleName } ,
49
+ TagSpecifications : config . tagSpecifications ,
50
+ } ;
51
+ try {
52
+ const result = await ec2 . runInstances ( params ) . promise ( ) ;
53
+ const ec2InstanceId = result . Instances [ 0 ] . InstanceId ;
54
+ core . info ( `AWS EC2 instance ${ ec2InstanceId } is started` ) ;
55
+ return ec2InstanceId ;
56
+ } catch ( error ) {
57
+ core . warning ( 'AWS EC2 instance starting error' ) ;
58
+ core . warning ( error ) ;
59
+ }
56
60
}
61
+ core . setFailed ( `Failed to launch instance after trying in ${ subnets . length } subnets.` ) ;
57
62
}
58
63
59
64
async function terminateEc2Instance ( ) {
0 commit comments