Skip to content

Commit ac66b2c

Browse files
committed
Add gitpod.io/network-check tag to ec2 instances and security groups
1 parent 2703ad4 commit ac66b2c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

gitpod-network-check/cmd/checks.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,17 @@ func launchInstanceInSubnet(ctx context.Context, ec2Client *ec2.Client, subnetID
302302
IamInstanceProfile: &types.IamInstanceProfileSpecification{
303303
Arn: instanceProfileName,
304304
},
305+
TagSpecifications: []types.TagSpecification{
306+
{
307+
ResourceType: types.ResourceTypeInstance,
308+
Tags: []types.Tag{
309+
{
310+
Key: aws.String("gitpod.io/network-check"),
311+
Value: aws.String("true"),
312+
},
313+
},
314+
},
315+
},
305316
}
306317

307318
var result *ec2.RunInstancesOutput
@@ -440,6 +451,17 @@ func createSecurityGroups(ctx context.Context, svc *ec2.Client, subnetID string)
440451
Description: aws.String("EC2 security group allowing all HTTPS outgoing traffic"),
441452
GroupName: aws.String(fmt.Sprintf("EC2-security-group-nc-%s", subnetID)),
442453
VpcId: vpcID,
454+
TagSpecifications: []types.TagSpecification{
455+
{
456+
ResourceType: types.ResourceTypeInstance,
457+
Tags: []types.Tag{
458+
{
459+
Key: aws.String("gitpod.io/network-check"),
460+
Value: aws.String("true"),
461+
},
462+
},
463+
},
464+
},
443465
}
444466

445467
createSGOutput, err := svc.CreateSecurityGroup(ctx, createSGInput)

gitpod-network-check/cmd/common.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ func cleanup(ctx context.Context, svc *ec2.Client, iamsvc *iam.Client) {
4848
})
4949
if err != nil {
5050
log.WithError(err).Warn("Failed to list instances, please cleanup manually")
51+
} else if len(instances.Reservations) == 0 {
52+
log.Info("No instances found.")
5153
}
5254

53-
for _, i := range instances.Reservations[0].Instances {
54-
InstanceIds = append(InstanceIds, *i.InstanceId)
55+
for _, r := range instances.Reservations {
56+
for _, i := range r.Instances {
57+
InstanceIds = append(InstanceIds, *i.InstanceId)
58+
}
5559
}
5660
}
5761

@@ -72,6 +76,8 @@ func cleanup(ctx context.Context, svc *ec2.Client, iamsvc *iam.Client) {
7276
})
7377
if err != nil {
7478
log.WithError(err).Warn("Failed to list roles, please cleanup manually")
79+
} else if len(roles.Roles) == 0 {
80+
log.Info("No roles found.")
7581
}
7682

7783
for _, role := range roles.Roles {
@@ -139,6 +145,8 @@ func cleanup(ctx context.Context, svc *ec2.Client, iamsvc *iam.Client) {
139145

140146
if err != nil {
141147
log.WithError(err).Error("Failed to list security groups, please cleanup manually")
148+
} else if len(securityGroups.SecurityGroups) == 0 {
149+
log.Info("No security groups found.")
142150
}
143151

144152
for _, sg := range securityGroups.SecurityGroups {

0 commit comments

Comments
 (0)