Skip to content

Commit 69f400c

Browse files
yagreutnikpivkin
andauthored
feat(misconf): add agentpools to azure container schema (#9714)
Signed-off-by: nikpivkin <[email protected]> Co-authored-by: nikpivkin <[email protected]>
1 parent 6fb3fde commit 69f400c

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

pkg/iac/adapters/terraform/azure/container/adapt.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func adaptCluster(resource *terraform.Block) container.KubernetesCluster {
3535
APIServerAuthorizedIPRanges: nil,
3636
AzurePolicyEnabled: iacTypes.BoolDefault(false, resource.GetMetadata()),
3737
DiskEncryptionSetID: iacTypes.StringDefault("", resource.GetMetadata()),
38+
AgentPools: []container.AgentPool{},
3839
RoleBasedAccessControl: container.RoleBasedAccessControl{
3940
Metadata: resource.GetMetadata(),
4041
Enabled: iacTypes.BoolDefault(false, resource.GetMetadata()),
@@ -119,10 +120,29 @@ func adaptCluster(resource *terraform.Block) container.KubernetesCluster {
119120
cluster.AzurePolicyEnabled = azurePolicyEnabledAttr.AsBoolValueOrDefault(false, resource)
120121
}
121122

122-
// disk encryption set ID
123123
if diskEncryptionSetIDAttr := resource.GetAttribute("disk_encryption_set_id"); diskEncryptionSetIDAttr.IsNotNil() {
124124
cluster.DiskEncryptionSetID = diskEncryptionSetIDAttr.AsStringValueOrDefault("", resource)
125125
}
126126

127+
cluster.AgentPools = adaptAgentPools(resource)
128+
127129
return cluster
128130
}
131+
132+
func adaptAgentPools(resource *terraform.Block) []container.AgentPool {
133+
var pools []container.AgentPool
134+
135+
if defaultNodePoolBlock := resource.GetBlock("default_node_pool"); defaultNodePoolBlock.IsNotNil() {
136+
pools = append(pools, adaptAgentPool(defaultNodePoolBlock))
137+
}
138+
139+
return pools
140+
}
141+
142+
func adaptAgentPool(block *terraform.Block) container.AgentPool {
143+
return container.AgentPool{
144+
Metadata: block.GetMetadata(),
145+
DiskEncryptionSetID: block.GetAttribute("disk_encryption_set_id").AsStringValueOrDefault("", block),
146+
NodeType: block.GetAttribute("type").AsStringValueOrDefault("VirtualMachineScaleSets", block),
147+
}
148+
}

pkg/iac/adapters/terraform/azure/container/adapt_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,52 @@ resource "azurerm_kubernetes_cluster" "misreporting_example" {
281281
},
282282
},
283283
},
284+
{
285+
name: "with default_node_pool",
286+
terraform: `
287+
resource "azurerm_kubernetes_cluster" "example" {
288+
default_node_pool {
289+
name = "default"
290+
node_count = 1
291+
vm_size = "Standard_DS2_v2"
292+
type = "VirtualMachineScaleSets"
293+
disk_encryption_set_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Compute/diskEncryptionSets/node-pool-des"
294+
}
295+
}
296+
`,
297+
expected: container.KubernetesCluster{
298+
Metadata: iacTypes.NewTestMetadata(),
299+
NetworkProfile: container.NetworkProfile{
300+
Metadata: iacTypes.NewTestMetadata(),
301+
NetworkPolicy: iacTypes.String("", iacTypes.NewTestMetadata()),
302+
},
303+
EnablePrivateCluster: iacTypes.Bool(false, iacTypes.NewTestMetadata()),
304+
AzurePolicyEnabled: iacTypes.Bool(false, iacTypes.NewTestMetadata()),
305+
DiskEncryptionSetID: iacTypes.String("", iacTypes.NewTestMetadata()),
306+
AgentPools: []container.AgentPool{
307+
{
308+
Metadata: iacTypes.NewTestMetadata(),
309+
DiskEncryptionSetID: iacTypes.String("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Compute/diskEncryptionSets/node-pool-des", iacTypes.NewTestMetadata()),
310+
NodeType: iacTypes.String("VirtualMachineScaleSets", iacTypes.NewTestMetadata()),
311+
},
312+
},
313+
AddonProfile: container.AddonProfile{
314+
Metadata: iacTypes.NewTestMetadata(),
315+
OMSAgent: container.OMSAgent{
316+
Metadata: iacTypes.NewTestMetadata(),
317+
Enabled: iacTypes.Bool(false, iacTypes.NewTestMetadata()),
318+
},
319+
AzurePolicy: container.AzurePolicy{
320+
Metadata: iacTypes.NewTestMetadata(),
321+
Enabled: iacTypes.Bool(false, iacTypes.NewTestMetadata()),
322+
},
323+
},
324+
RoleBasedAccessControl: container.RoleBasedAccessControl{
325+
Metadata: iacTypes.NewTestMetadata(),
326+
Enabled: iacTypes.Bool(false, iacTypes.NewTestMetadata()),
327+
},
328+
},
329+
},
284330
}
285331

286332
for _, test := range tests {

pkg/iac/providers/azure/container/container.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type KubernetesCluster struct {
1717
RoleBasedAccessControl RoleBasedAccessControl
1818
AzurePolicyEnabled iacTypes.BoolValue
1919
DiskEncryptionSetID iacTypes.StringValue
20+
AgentPools []AgentPool
2021
}
2122

2223
type RoleBasedAccessControl struct {
@@ -44,3 +45,9 @@ type NetworkProfile struct {
4445
Metadata iacTypes.Metadata
4546
NetworkPolicy iacTypes.StringValue // "", "calico", "azure"
4647
}
48+
49+
type AgentPool struct {
50+
Metadata iacTypes.Metadata
51+
DiskEncryptionSetID iacTypes.StringValue
52+
NodeType iacTypes.StringValue // "VirtualMachineScaleSets" or others
53+
}

pkg/iac/rego/schemas/cloud.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,6 +4812,23 @@
48124812
}
48134813
}
48144814
},
4815+
"fd.axjsq.dpdns.org.aquasecurity.trivy.pkg.iac.providers.azure.container.AgentPool": {
4816+
"type": "object",
4817+
"properties": {
4818+
"__defsec_metadata": {
4819+
"type": "object",
4820+
"$ref": "#/definitions/fd.axjsq.dpdns.org.aquasecurity.trivy.pkg.iac.types.Metadata"
4821+
},
4822+
"diskencryptionsetid": {
4823+
"type": "object",
4824+
"$ref": "#/definitions/fd.axjsq.dpdns.org.aquasecurity.trivy.pkg.iac.types.StringValue"
4825+
},
4826+
"nodetype": {
4827+
"type": "object",
4828+
"$ref": "#/definitions/fd.axjsq.dpdns.org.aquasecurity.trivy.pkg.iac.types.StringValue"
4829+
}
4830+
}
4831+
},
48154832
"fd.axjsq.dpdns.org.aquasecurity.trivy.pkg.iac.providers.azure.container.AzurePolicy": {
48164833
"type": "object",
48174834
"properties": {
@@ -4848,6 +4865,13 @@
48484865
"type": "object",
48494866
"$ref": "#/definitions/fd.axjsq.dpdns.org.aquasecurity.trivy.pkg.iac.providers.azure.container.AddonProfile"
48504867
},
4868+
"agentpools": {
4869+
"type": "array",
4870+
"items": {
4871+
"type": "object",
4872+
"$ref": "#/definitions/fd.axjsq.dpdns.org.aquasecurity.trivy.pkg.iac.providers.azure.container.AgentPool"
4873+
}
4874+
},
48514875
"apiserverauthorizedipranges": {
48524876
"type": "array",
48534877
"items": {

0 commit comments

Comments
 (0)