@@ -61,35 +61,39 @@ public final class AwsEc2Image {
61
61
private final transient InstanceType type ;
62
62
63
63
/**
64
- * Ctor.
65
- * @param api AwsEc2 api client
66
- * @param image Ec2 instance ami_id
64
+ * EC2 security group.
67
65
*/
68
- public AwsEc2Image (final AwsEc2 api , final String image ) {
69
- this (api , image , "t2.nano" );
70
- }
66
+ private final String sgroup ;
71
67
72
68
/**
73
69
* Ctor.
74
70
* @param api AwsEc2 api client
75
71
* @param image Ec2 instance ami_id
76
72
* @param type Instance type
73
+ * @param grp Security group
74
+ * @checkstyle ParameterNumberCheck (5 lines)
77
75
*/
78
76
public AwsEc2Image (final AwsEc2 api , final String image ,
79
- final String type ) {
77
+ final String type , final String grp ) {
78
+ this .api = api ;
80
79
if (image .isEmpty ()) {
81
80
throw new IllegalArgumentException (
82
81
"Machine image id is mandatory"
83
82
);
84
83
}
84
+ this .image = image ;
85
85
if (type .isEmpty ()) {
86
86
throw new IllegalArgumentException (
87
87
"Machine type is mandatory"
88
88
);
89
89
}
90
- this .api = api ;
91
- this .image = image ;
92
90
this .type = InstanceType .fromValue (type );
91
+ if (grp .isEmpty ()) {
92
+ throw new IllegalArgumentException (
93
+ "Security group is mandatory"
94
+ );
95
+ }
96
+ this .sgroup = grp ;
93
97
}
94
98
95
99
/**
@@ -98,6 +102,7 @@ public AwsEc2Image(final AwsEc2 api, final String image,
98
102
*/
99
103
public AwsEc2Instance run () {
100
104
final RunInstancesRequest request = new RunInstancesRequest ()
105
+ .withSecurityGroups (this .sgroup )
101
106
.withImageId (this .image )
102
107
.withInstanceType (this .type )
103
108
.withMaxCount (1 )
0 commit comments