Skip to content

Commit 809e6f2

Browse files
committed
Add IAM Configuration to branch sandboxing blog
1 parent b69c908 commit 809e6f2

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

  • adminforth/documentation/blog/2026-06-01-branch-sandboxing-k3s

adminforth/documentation/blog/2026-06-01-branch-sandboxing-k3s/index.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ terraform {
106106
}
107107
}
108108
```
109+
After this you need to run
110+
111+
```bash
112+
terraform init -migrate-state
113+
```
114+
in terraform directory
109115

110116
Also, we need to output the values we need for the sandbox deployment. In the same directory add (or edit) the `outputs.tf` file:
111117

@@ -166,6 +172,59 @@ output "instance_type" {
166172
}
167173
```
168174

175+
Also you need to attach IAM policy to the instance profile created in the main deployment. This is required for the cluster autoscaler to be able to manage the Auto Scaling Group. Also we attach role for ECR repository pull only to the node role. So the autoscaled node instances can pull images from ECR.
176+
177+
```hcl title="[deploy/terraform/resvpc.tf]"
178+
resource "aws_iam_role_policy_attachment" "ecr_access_policy" {
179+
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPullOnly"
180+
role = aws_iam_role.node_role.name
181+
}
182+
183+
resource "aws_iam_role_policy" "cluster_autoscaler_policy" {
184+
name = "${local.app_name}-cluster-autoscaler-policy"
185+
role = aws_iam_role.node_role.id
186+
187+
policy = jsonencode({
188+
Version = "2012-10-17"
189+
Statement = [
190+
{
191+
Effect = "Allow"
192+
Action = [
193+
"autoscaling:DescribeAutoScalingGroups",
194+
"autoscaling:DescribeAutoScalingInstances",
195+
"autoscaling:DescribeLaunchConfigurations",
196+
"autoscaling:DescribeTags",
197+
"ec2:DescribeInstanceTypes",
198+
"ec2:DescribeLaunchTemplateVersions"
199+
]
200+
Resource = ["*"]
201+
},
202+
{
203+
Effect = "Allow"
204+
Action = [
205+
"autoscaling:SetDesiredCapacity",
206+
"autoscaling:TerminateInstanceInAutoScalingGroup",
207+
"autoscaling:UpdateAutoScalingGroup"
208+
]
209+
Resource = ["*"]
210+
Condition = {
211+
StringEquals = {
212+
"autoscaling:ResourceTag/k8s.io/cluster-autoscaler/enabled" = "true"
213+
}
214+
}
215+
}
216+
]
217+
})
218+
}
219+
```
220+
221+
Make sure you attach the policies to the node role created in the main deployment. If you didn't create the node role in the main deployment, you should create it now. We attach it to the node role, because we create node instances using Auto Scaling Group. So the autoscaled node instances can pull images from ECR. Also you need to add cluster autoscaler deployment to the cluster.
222+
223+
```bash
224+
terraform apply --auto-approve
225+
```
226+
in terraform directory
227+
169228
Make sure, that you're using the same values as in the main deployment, so if you're using different `ECR` repository name, `subnet_id`, `security_group_id`, `iam_instance_profile`, `key_name` or `instance_type` in your main deployment, you should use the same values in the sandbox deployment.
170229

171230
### Terraform Sandbox Configuration

0 commit comments

Comments
 (0)