Skip to content

Commit

Permalink
fix errors when running with new services
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Carter committed Nov 12, 2020
1 parent 20ea0e1 commit 21b4fbd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lister/cloudformation_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (l AWSCloudFormationStack) List(cfg option.AWSetsConfig) (*resource.Group,
if rt == resource.Unnecessary {
continue
}
if rsum.PhysicalResourceId == nil {
// If stack is in certain statuses (like DELETE_FAILED) the physical id may be nil as this
// particular resource may have been deleted
continue
}
resourceId := *rsum.PhysicalResourceId
if strings.Contains(resourceId, "arn:") {
resourceArn := arn.Parse(resourceId)
Expand Down
4 changes: 4 additions & 0 deletions lister/ec2_vpcendpointservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (l AWSEc2VpcEndpointService) List(cfg option.AWSetsConfig) (*resource.Group
return nil, err
}
for _, v := range res.ServiceDetails {
if v.ServiceId == nil {
// some Amazon owned vpc service endpoints have null IDs
continue
}
r := resource.New(cfg, resource.Ec2VpcEndpointService, v.ServiceId, v.ServiceName, v)

configs := make([]*types.ServiceConfiguration, 0)
Expand Down
2 changes: 1 addition & 1 deletion lister/glue_crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (l AWSGlueCrawler) List(cfg option.AWSetsConfig) (*resource.Group, error) {
}
for _, v := range res.Crawlers {
r := resource.NewVersion(cfg, resource.GlueCrawler, v.Name, v.Name, v.Version, v)
r.AddARNRelation(resource.IamRole, v.Role)
r.AddRelation(resource.IamRole, v.Role, "")
r.AddRelation(resource.GlueDatabase, v.DatabaseName, "")
// TODO: review relationships to s3, ddb, jdbc

Expand Down
11 changes: 6 additions & 5 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resource
import (
"encoding/json"
"fmt"
"os"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -74,8 +75,8 @@ func makeResource(account, region string, kind ResourceType, iId, iName, iVersio
Attributes: asMap,
Tags: make(map[string]string),
}
if strings.Contains(id, "arn:") {
fmt.Printf("new resource contains arn: %s - %s\n", kind.String(), id)
if strings.Contains(id, "arn:") && kind != SsmPatchBaseline {
fmt.Fprintf(os.Stderr, "new resource contains arn: %s - %s\n", kind.String(), id)
}
if tags, ok := asMap["Tags"]; ok {
switch t := tags.(type) {
Expand All @@ -97,7 +98,7 @@ func makeResource(account, region string, kind ResourceType, iId, iName, iVersio
case nil:
// no op
default:
fmt.Printf("Unknown tag type: %T\n", t)
fmt.Fprintf(os.Stderr, "Unknown tag type: %T\n", t)
}
}
return resource
Expand Down Expand Up @@ -127,7 +128,7 @@ func (r *Resource) AddARNRelation(kind ResourceType, iArn interface{}) {
}
if !strings.Contains(sArn, "arn:") {
// TODO: remove printing
fmt.Printf("resource %+v tried adding relationsip that was not an ARN: %s-%s", r.Identifier, kind.String(), sArn)
fmt.Fprintf(os.Stderr, "resource %+v tried adding relationsip that was not an ARN: %s - %s\n", r.Identifier, kind.String(), sArn)
return
}
parsedArn := arn.Parse(sArn)
Expand Down Expand Up @@ -156,7 +157,7 @@ func (r *Resource) addRelation(account string, region string, kind ResourceType,

if strings.Contains(id, "arn:") {
// TODO: remove printing
fmt.Printf("new relation with %s has arn: %s - %s\n", r.Type.String(), kind.String(), id)
fmt.Fprintf(os.Stderr, "new relation with %s has arn: %s - %s\n", r.Type.String(), kind.String(), id)
}
if strings.HasPrefix(kind.String(), "iam/") ||
strings.HasPrefix(kind.String(), "route53/") ||
Expand Down

0 comments on commit 21b4fbd

Please sign in to comment.