Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 2bd22d5

Browse files
authored
Improve listing of cloudcontrol resources (#1096)
1 parent 5560ce3 commit 2bd22d5

File tree

1 file changed

+62
-55
lines changed

1 file changed

+62
-55
lines changed

dev/list-cloudcontrol/main.go

+62-55
Original file line numberDiff line numberDiff line change
@@ -34,67 +34,74 @@ func main() {
3434
mapping := resources.GetCloudControlMapping()
3535

3636
in := &cloudformation.ListTypesInput{
37-
Type: aws.String(cloudformation.RegistryTypeResource),
38-
Visibility: aws.String(cloudformation.VisibilityPublic),
39-
ProvisioningType: aws.String(cloudformation.ProvisioningTypeFullyMutable),
40-
}
37+
Type: aws.String(cloudformation.RegistryTypeResource),
38+
Visibility: aws.String(cloudformation.VisibilityPublic),
4139

42-
err = cf.ListTypesPagesWithContext(ctx, in, func(out *cloudformation.ListTypesOutput, _ bool) bool {
43-
if out == nil {
44-
return true
45-
}
46-
47-
for _, summary := range out.TypeSummaries {
48-
if summary == nil {
49-
continue
50-
}
51-
52-
typeName := aws.StringValue(summary.TypeName)
53-
color.New(color.Bold).Printf("%-55s", typeName)
54-
if !strings.HasPrefix(typeName, "AWS::") {
55-
color.HiBlack("does not have a valid prefix")
56-
continue
57-
}
58-
59-
describe, err := cf.DescribeType(&cloudformation.DescribeTypeInput{
60-
Type: aws.String(cloudformation.RegistryTypeResource),
61-
TypeName: aws.String(typeName),
62-
})
63-
if err != nil {
64-
color.New(color.FgRed).Println(err)
65-
continue
66-
}
67-
68-
var schema CFTypeSchema
69-
err = json.Unmarshal([]byte(aws.StringValue(describe.Schema)), &schema)
70-
if err != nil {
71-
color.New(color.FgRed).Println(err)
72-
continue
73-
}
40+
Filters: &cloudformation.TypeFilters{
41+
TypeNamePrefix: aws.String("AWS::"),
42+
},
43+
}
7444

75-
_, canList := schema.Handlers["list"]
76-
if !canList {
77-
color.New(color.FgHiBlack).Println("does not support list")
78-
continue
45+
// Immutable objects don't have an `update` option, but can still be removed
46+
for _, provisioningType := range []string{cloudformation.ProvisioningTypeFullyMutable, cloudformation.ProvisioningTypeImmutable} {
47+
in.ProvisioningType = &provisioningType
48+
err = cf.ListTypesPagesWithContext(ctx, in, func(out *cloudformation.ListTypesOutput, _ bool) bool {
49+
if out == nil {
50+
return true
7951
}
8052

81-
resourceName, exists := mapping[typeName]
82-
if exists && resourceName == typeName {
83-
fmt.Print("is only covered by ")
84-
color.New(color.FgGreen, color.Bold).Println(resourceName)
85-
continue
86-
} else if exists {
87-
fmt.Print("is also covered by ")
88-
color.New(color.FgBlue, color.Bold).Println(resourceName)
89-
continue
53+
for _, summary := range out.TypeSummaries {
54+
if summary == nil {
55+
continue
56+
}
57+
58+
typeName := aws.StringValue(summary.TypeName)
59+
color.New(color.Bold).Printf("%-55s", typeName)
60+
if !strings.HasPrefix(typeName, "AWS::") {
61+
color.HiBlack("does not have a valid prefix")
62+
continue
63+
}
64+
65+
describe, err := cf.DescribeType(&cloudformation.DescribeTypeInput{
66+
Type: aws.String(cloudformation.RegistryTypeResource),
67+
TypeName: aws.String(typeName),
68+
})
69+
if err != nil {
70+
color.New(color.FgRed).Println(err)
71+
continue
72+
}
73+
74+
var schema CFTypeSchema
75+
err = json.Unmarshal([]byte(aws.StringValue(describe.Schema)), &schema)
76+
if err != nil {
77+
color.New(color.FgRed).Println(err)
78+
continue
79+
}
80+
81+
_, canList := schema.Handlers["list"]
82+
if !canList {
83+
color.New(color.FgHiBlack).Println("does not support list")
84+
continue
85+
}
86+
87+
resourceName, exists := mapping[typeName]
88+
if exists && resourceName == typeName {
89+
fmt.Print("is only covered by ")
90+
color.New(color.FgGreen, color.Bold).Println(resourceName)
91+
continue
92+
} else if exists {
93+
fmt.Print("is also covered by ")
94+
color.New(color.FgBlue, color.Bold).Println(resourceName)
95+
continue
96+
}
97+
98+
color.New(color.FgYellow).Println("is not configured")
9099
}
91100

92-
color.New(color.FgYellow).Println("is not configured")
101+
return true
102+
})
103+
if err != nil {
104+
logrus.Fatal(err)
93105
}
94-
95-
return true
96-
})
97-
if err != nil {
98-
logrus.Fatal(err)
99106
}
100107
}

0 commit comments

Comments
 (0)