Day 95 of DevOps, Day 45 of Azure. Both tasks printed an empty array, and the two mean opposite things. One is true, documented, and the reason the thing I built would not work. The other is false, and the resource it denied was running at the time.
One Terraform task, one Azure task. A security group, then a private AKS cluster. The tasks come from the KodeKloud Engineer platform.
Task 1: A security group in Terraform
Named xfusion-sg, described as "Security group for Nautilus App Servers", with inbound TCP 22 and TCP 80.
Step 1: The configuration
resource "aws_security_group" "xfusion_sg" {
name = "xfusion-sg"
description = "Security group for Nautilus App Servers"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
Step 2: Apply and read it back
Both ingress rules are present, and both the requested ports, name and description are exact. The task is done correctly.
And then this, in the same response:
"IpPermissionsEgress": [],
Step 3: Finding out why
That is not "the default is implied and not shown". It is genuinely empty, and it is the documented behaviour of the resource:
By default, AWS creates an
ALLOW ALLegress rule when creating a new Security Group inside of a VPC.When creating a new Security Group inside a VPC, Terraform will remove this default rule and require you to specifically re-create it if you desire that rule.
So AWS adds allow-all egress to every new security group, and the provider takes it away again unless the configuration asks for it back. A configuration with ingress blocks and no egress block does not mean leave egress alone. It means egress is exactly this list, and the list is empty.
The consequence is not subtle. An EC2 instance whose only group is this one cannot open an outbound connection to anything at all: no package installs, no DNS to the VPC resolver, no SSM agent registration, no AWS API calls.
The part that makes it nasty is that the instance still looks reachable. Security groups are stateful, so the response traffic to an allowed inbound flow is permitted regardless of egress rules. SSH in on port 22 works fine. Everything the machine tries to do from there times out.
The fix is one block, and being explicit about it is the whole point:
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
What the docs recommend
Two more things from the same page, both of which change what my next Terraform task should look like.
The provider recommends against the syntax this task uses: "Avoid using the ingress and egress arguments of the aws_security_group resource to configure in-line rules." The current recommendation is one rule per resource with aws_vpc_security_group_ingress_rule and aws_vpc_security_group_egress_rule, one CIDR block each. And the two styles must not be mixed, because "Doing so may cause rule conflicts, perpetual differences, and result in rules being overwritten."
The reason inline rules cause trouble is the same reason my egress list is empty: they are authoritative for the whole list. Anything that adds a rule outside Terraform gets removed on the next apply.
The other thing is where this group ended up. I set no vpc_id, and the docs say what that means: "VPC ID. Defaults to the region's default VPC." Which is fine here, but a security group's VPC is not cosmetic. A group can only attach to instances in its own VPC, so building the group in the default VPC and the workload in a custom one produces an error at attach time rather than at create time.
One thing I want to flag about my own file
cidr_blocks = ["0.0.0.0/0"] # Replace with your IP or CIDR range
The comment says to replace the range. I did not replace the range. SSH is open to the entire internet.
The task specified both rules that way, and nothing real is exposed in a mock environment, so this is not a mistake so much as a habit worth not forming. A comment telling a future reader to change something is a much weaker control than simply not writing the permissive value. A variable with no default fails the plan until somebody supplies an answer:
variable "ssh_cidr" {
description = "CIDR allowed to reach SSH"
type = string
}
Task 2: A private AKS cluster
Kubernetes 1.36.x in Central US, Standard tier, private API server, one node pool called agentpool autoscaling 1 to 2, all monitoring off, ready for workloads.
Step 1: Choosing the version deliberately
1.37 ['1.37.0']
1.36 ['1.36.0', '1.36.1', '1.36.2', '1.36.3', '1.36.4'] default
1.37.0 exists, so any logic reaching for "latest" produces a version that fails the requirement. The minors also come back unordered, with 1.37 listed above 1.36, so taking the first entry would be wrong too.
The patch list is lexically unsafe as well. On 1.34 it returns ['1.34.0', '1.34.1', '1.34.10', '1.34.11', '1.34.2', ...], because '10' sorts before '2' as a string. For 1.36 the highest patch is 4 so sorted()[-1] happens to work, and on 1.34 the same code picks 1.34.9 over 1.34.11.
max(cands, key=lambda s: tuple(int(x) for x in s.split('.')))
Step 2: The empty list
=== node pools ===
[]
=== pool count ===
0
NAME STATUS ROLES AGE VERSION
aks-agentpool-30092218-vmss000000 Ready <none> 21m v1.36.4
az aks nodepool list returned an empty array with exit 0, next to a running node whose name contains the pool it belongs to. AKS names nodes aks-<poolname>-<hash>-vmss<ordinal>, so that node name is proof a pool called agentpool exists and is healthy.
I did not find out why. The unfiltered list and az aks nodepool show -n agentpool were queued when the lab expired, so the candidates stay candidates: an API version mismatch on the sub-resource, a read denial swallowed into an empty list, or a CLI defect.
What is certain is that the cluster is fine and the command is wrong. az aks show --query agentPoolProfiles reads the pool off the cluster object, which is the GET that demonstrably works and what the portal displays.
Step 3: Why I noticed at all
I had two independent views of the same fact. One ARM query and one kubectl listing disagreed, and the disagreement is the entire signal. Reading only the ARM side would have produced the confident and wrong conclusion that the cluster had no node pool, followed by creating a second one.
Which is why I wanted these two tasks in the same post. IpPermissionsEgress: [] and nodepool list returning [] are the same shape in a terminal, and they could not be more different. The first is true and is the reason an instance in that group would have no outbound connectivity. The second is false and the pool was serving at the time.
Nothing about the empty array tells you which kind you have. The only thing that separated them was a second source: the provider documentation on one side, and a disagreeing command on the other.
What the docs recommend
Three notes, one of which corrects something I wrote earlier.
The cluster came back with both a private and a public FQDN populated, which looks like the private setting failed. It did not, and this is documented: "When you create a private AKS cluster, AKS creates both private and public fully qualified domain names (FQDNs) with corresponding DNS zones by default", and the public one "is only a publicly resolvable DNS name, while API communication for private clusters still occurs through the private endpoint."
My earlier note went a step further and said the public record resolves to the private IP. That is not on the page. What is documented is that it is publicly resolvable and that it "doesn't create a public API endpoint or remove the requirement for network connectivity to the private endpoint". What the record actually points at is left unstated, so I am marking that claim unverified rather than repeating it. The conclusion it supported survives on the documented wording anyway: no public endpoint, only public resolution.
Second, az aks command invoke is documented as the answer to exactly the problem a private cluster creates: "If you don't have direct network connectivity, use the az aks command invoke command to run commands through the Azure API." AKS schedules a short-lived pod inside the cluster, runs the command, and returns output over ARM. EKS has no equivalent, which is why the comparable EKS task could only report ACTIVE while this one could demonstrate a Ready node.
Its output format is worth recognising: the leading integer is the command's exit code, and the ARM operation reports Succeeded even when the command inside the cluster failed. Two success signals in one line, and only the first is about kubectl.
Third, sku.name and sku.tier are different fields. The cluster reports skuName: Base and skuTier: Standard, which reads like a contradiction and is not: the name is the product, Base or Automatic, and the tier is the control plane SLA. Checking "Standard" against the wrong one reports a failure that is not one.
What I learned
Terraform removes the AWS default allow-all egress rule from every security group it creates. No egress block means no egress at all, and the instance still answers inbound SSH while being unable to reach anything.
The provider recommends against inline ingress and egress blocks, and against mixing them with the separate rule resources.
vpc_id defaults to the region's default VPC, and a group only attaches to instances in its own VPC.
An empty list with exit 0 is not evidence of absence. Only a second, independent view tells a true empty from a false one.
AKS node names encode their pool, so a node name proves a pool name.
null is the pass condition for "monitoring disabled", and monitoring hides in three places, one of which is a different resource provider that never shows up on the cluster object at all.
Check for newer minors before taking "latest", and sort version patches numerically.
So here is the Day 95 question. The last time something returned you an empty list, what was your second source? I had one by accident on the Azure side, and by reading the documentation on the Terraform side, and without either, I would have believed both of them.
Day 95 down. Five to go.
Top comments (0)