Skip to content

Commit

Permalink
Check for nil VpcId and SubnetId before use (#1254)
Browse files Browse the repository at this point in the history
Fixes #1250

Co-authored-by: Azanul Haque <[email protected]>
  • Loading branch information
codekoala and Azanul authored Dec 1, 2023
1 parent e49a149 commit cd97d33
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions providers/aws/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ func Instances(ctx context.Context, client providers.ProviderClient) ([]models.R
}

func getEC2Relations(inst *etype.Instance, resourceArn string) []models.Link {

var rel []models.Link
// Get associated security groups
// Get associated security groups
for _, sgrp := range inst.SecurityGroups {
rel = append(rel, models.Link{
ResourceID: *sgrp.GroupId,
Expand All @@ -197,21 +197,25 @@ func getEC2Relations(inst *etype.Instance, resourceArn string) []models.Link {
})
}

// Get associated VPC
rel = append(rel, models.Link{
ResourceID: fmt.Sprintf("%s:vpc/%s", resourceArn, *inst.VpcId),
Type: "VPC",
Name: *inst.VpcId,
Relation: "USES",
})

// Get associated Subnet
rel = append(rel, models.Link{
ResourceID: fmt.Sprintf("%s:subnet/%s", resourceArn, *inst.SubnetId),
Name: *inst.SubnetId,
Type: "Subnet",
Relation: "USES",
})
if inst.VpcId != nil {
// Get associated VPC
rel = append(rel, models.Link{
ResourceID: fmt.Sprintf("%s:vpc/%s", resourceArn, *inst.VpcId),
Type: "VPC",
Name: *inst.VpcId,
Relation: "USES",
})
}

if inst.SubnetId != nil {
// Get associated Subnet
rel = append(rel, models.Link{
ResourceID: fmt.Sprintf("%s:subnet/%s", resourceArn, *inst.SubnetId),
Name: *inst.SubnetId,
Type: "Subnet",
Relation: "USES",
})
}

// Get associated Keypair
if inst.KeyName != nil {
Expand Down

0 comments on commit cd97d33

Please sign in to comment.