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