@@ -12,49 +12,83 @@ func getClusters(ctx parser.FileContext) (clusters []eks.Cluster) {
12
12
13
13
for _ , r := range clusterResources {
14
14
cluster := eks.Cluster {
15
- Metadata : r .Metadata (),
16
- // Logging not supported for cloudformation https://github.com/aws/containers-roadmap/issues/242
17
- // TODO: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eks-cluster.html#cfn-eks-cluster-logging
18
- Logging : eks.Logging {
19
- Metadata : r .Metadata (),
20
- API : iacTypes .BoolUnresolvable (r .Metadata ()),
21
- Audit : iacTypes .BoolUnresolvable (r .Metadata ()),
22
- Authenticator : iacTypes .BoolUnresolvable (r .Metadata ()),
23
- ControllerManager : iacTypes .BoolUnresolvable (r .Metadata ()),
24
- Scheduler : iacTypes .BoolUnresolvable (r .Metadata ()),
25
- },
26
- Encryption : getEncryptionConfig (r ),
27
- // endpoint protection not supported - https://github.com/aws/containers-roadmap/issues/242
28
- // TODO: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eks-cluster.html#cfn-eks-cluster-resourcesvpcconfig
29
- PublicAccessEnabled : iacTypes .BoolUnresolvable (r .Metadata ()),
30
- PublicAccessCIDRs : nil ,
15
+ Metadata : r .Metadata (),
16
+ Logging : getLogging (r ),
17
+ Encryption : getEncryptionConfig (r ),
18
+ PublicAccessEnabled : r .GetBoolProperty ("ResourcesVpcConfig.EndpointPublicAccess" ),
19
+ PublicAccessCIDRs : getPublicCIDRs (r ),
31
20
}
32
21
33
22
clusters = append (clusters , cluster )
34
23
}
35
24
return clusters
36
25
}
37
26
27
+ func getPublicCIDRs (r * parser.Resource ) []iacTypes.StringValue {
28
+ publicAccessCidrs := r .GetProperty ("ResourcesVpcConfig.PublicAccessCidrs" )
29
+ if publicAccessCidrs .IsNotList () {
30
+ return nil
31
+ }
32
+
33
+ var cidrs []iacTypes.StringValue
34
+ for _ , el := range publicAccessCidrs .AsList () {
35
+ cidrs = append (cidrs , el .AsStringValue ())
36
+ }
37
+
38
+ return cidrs
39
+ }
40
+
38
41
func getEncryptionConfig (r * parser.Resource ) eks.Encryption {
39
42
40
- encryption := eks.Encryption {
43
+ encryptionConfigs := r .GetProperty ("EncryptionConfig" )
44
+ if encryptionConfigs .IsNotList () {
45
+ return eks.Encryption {
46
+ Metadata : r .Metadata (),
47
+ }
48
+ }
49
+
50
+ for _ , encryptionConfig := range encryptionConfigs .AsList () {
51
+ resources := encryptionConfig .GetProperty ("Resources" )
52
+ hasSecrets := resources .IsList () && resources .Contains ("secrets" )
53
+ return eks.Encryption {
54
+ Metadata : encryptionConfig .Metadata (),
55
+ KMSKeyID : encryptionConfig .GetStringProperty ("Provider.KeyArn" ),
56
+ Secrets : iacTypes .Bool (hasSecrets , resources .Metadata ()),
57
+ }
58
+ }
59
+
60
+ return eks.Encryption {
41
61
Metadata : r .Metadata (),
42
- Secrets : iacTypes .BoolDefault (false , r .Metadata ()),
43
- KMSKeyID : iacTypes .StringDefault ("" , r .Metadata ()),
44
- }
45
-
46
- // TODO: EncryptionConfig is a list
47
- // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eks-cluster.html#cfn-eks-cluster-encryptionconfig
48
- if encProp := r .GetProperty ("EncryptionConfig" ); encProp .IsNotNil () {
49
- encryption .Metadata = encProp .Metadata ()
50
- encryption .KMSKeyID = encProp .GetStringProperty ("Provider.KeyArn" )
51
- resourcesProp := encProp .GetProperty ("Resources" )
52
- if resourcesProp .IsList () {
53
- if resourcesProp .Contains ("secrets" ) {
54
- encryption .Secrets = iacTypes .Bool (true , resourcesProp .Metadata ())
55
- }
62
+ }
63
+ }
64
+
65
+ func getLogging (r * parser.Resource ) eks.Logging {
66
+ enabledTypes := r .GetProperty ("Logging.ClusterLogging.EnabledTypes" )
67
+ if enabledTypes .IsNotList () {
68
+ return eks.Logging {
69
+ Metadata : r .Metadata (),
56
70
}
57
71
}
58
72
59
- return encryption
73
+ logging := eks.Logging {
74
+ Metadata : enabledTypes .Metadata (),
75
+ }
76
+
77
+ for _ , typeConf := range enabledTypes .AsList () {
78
+ switch typ := typeConf .GetProperty ("Type" ); typ .AsString () {
79
+ case "api" :
80
+ logging .API = iacTypes .Bool (true , typ .Metadata ())
81
+ case "audit" :
82
+ logging .Audit = iacTypes .Bool (true , typ .Metadata ())
83
+ case "authenticator" :
84
+ logging .Authenticator = iacTypes .Bool (true , typ .Metadata ())
85
+ case "controllerManager" :
86
+ logging .ControllerManager = iacTypes .Bool (true , typ .Metadata ())
87
+ case "scheduler" :
88
+ logging .Scheduler = iacTypes .Bool (true , typ .Metadata ())
89
+ }
90
+
91
+ }
92
+
93
+ return logging
60
94
}
0 commit comments