Skip to content

Commit 71b4c31

Browse files
committed
fix: SSM 연결을 위한 누락 설정 추가
- K8S 노드에 SSM Agent 설치 user_data 추가 (Ubuntu 24.04 미포함) - K8S 노드 IAM Role에 S3 버킷 권한 추가 (aws_ssm 파일 전송용)
1 parent 1d8e164 commit 71b4c31

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

IaC/3-v3/aws/modules/iam/main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,27 @@ resource "aws_iam_role_policy_attachment" "ssm" {
8383
role = aws_iam_role.k8s_node.name
8484
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
8585
}
86+
87+
# --- S3 for Ansible SSM file transfer ---
88+
89+
resource "aws_iam_role_policy" "ssm_s3" {
90+
name = "ssm-s3-transfer"
91+
role = aws_iam_role.k8s_node.id
92+
93+
policy = jsonencode({
94+
Version = "2012-10-17"
95+
Statement = [{
96+
Effect = "Allow"
97+
Action = [
98+
"s3:GetObject",
99+
"s3:PutObject",
100+
"s3:DeleteObject",
101+
"s3:GetBucketLocation"
102+
]
103+
Resource = [
104+
"arn:aws:s3:::dojangkok-v3-ansible-ssm",
105+
"arn:aws:s3:::dojangkok-v3-ansible-ssm/*"
106+
]
107+
}]
108+
})
109+
}

IaC/3-v3/aws/modules/k8s-nodes/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ resource "aws_instance" "control_plane" {
3535
vpc_security_group_ids = var.cp_security_group_ids
3636
iam_instance_profile = var.iam_instance_profile
3737
source_dest_check = false
38+
user_data = local.ssm_user_data
3839

3940
metadata_options {
4041
http_endpoint = "enabled"
@@ -63,6 +64,13 @@ resource "aws_instance" "control_plane" {
6364
# --- Worker Nodes ---
6465

6566
locals {
67+
ssm_user_data = <<-EOF
68+
#!/bin/bash
69+
snap install amazon-ssm-agent --classic
70+
systemctl enable snap.amazon-ssm-agent.amazon-ssm-agent.service
71+
systemctl start snap.amazon-ssm-agent.amazon-ssm-agent.service
72+
EOF
73+
6674
# workers_per_az × 3 AZ → 플랫 맵 생성
6775
# e.g. workers_per_az=1 → { "w-2a-1"={az="a",...}, "w-2b-1"={...}, "w-2c-1"={...} }
6876
# e.g. workers_per_az=2 → { "w-2a-1"={...}, "w-2a-2"={...}, "w-2b-1"={...}, ... }
@@ -87,6 +95,7 @@ resource "aws_instance" "workers" {
8795
vpc_security_group_ids = var.worker_security_group_ids
8896
iam_instance_profile = var.iam_instance_profile
8997
source_dest_check = false
98+
user_data = local.ssm_user_data
9099

91100
metadata_options {
92101
http_endpoint = "enabled"

0 commit comments

Comments
 (0)