Skip to content

Commit 059f54b

Browse files
committed
fix: app runner deployment.
1 parent bacdd2c commit 059f54b

File tree

2 files changed

+68
-24
lines changed

2 files changed

+68
-24
lines changed

terraform/app_runner.tf

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
1-
resource "aws_apprunner_vpc_connector" "connector" {
2-
vpc_connector_name = "app-runner-connector"
3-
subnets = aws_subnet.private[*].id
4-
security_groups = [aws_security_group.app_runner.id]
5-
}
6-
71
resource "aws_apprunner_service" "service" {
82
for_each = var.environments
93

104
service_name = "openresume-${each.key}"
115

126
source_configuration {
13-
authentication_configuration {
14-
access_role_arn = aws_iam_role.app_runner_service_role.arn
15-
}
7+
auto_deployments_enabled = true
168

179
image_repository {
1810
image_configuration {
19-
port = "3000" # Adjust based on your application
11+
port = "3000"
2012
runtime_environment_variables = {
2113
NODE_ENV = each.key
2214
DB_SECRET_ID = aws_secretsmanager_secret.db_secrets[each.key].arn
2315
}
2416
}
25-
image_identifier = "public.ecr.aws/docker/library/hello-world:latest" # Placeholder image
17+
image_identifier = "public.ecr.aws/docker/library/hello-world:latest"
2618
image_repository_type = "ECR_PUBLIC"
2719
}
2820
}
2921

3022
instance_configuration {
31-
cpu = "1024"
32-
memory = "2048"
23+
cpu = "1024"
24+
memory = "2048"
25+
instance_role_arn = aws_iam_role.app_runner_instance_role.arn
3326
}
3427

3528
network_configuration {
@@ -40,7 +33,7 @@ resource "aws_apprunner_service" "service" {
4033
}
4134

4235
health_check_configuration {
43-
path = "/health" # Adjust based on your application
36+
path = "/health"
4437
protocol = "HTTP"
4538
}
4639

terraform/iam.tf

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,70 @@
1-
data "aws_iam_policy_document" "app_runner_assume_role" {
2-
statement {
3-
actions = ["sts:AssumeRole"]
4-
principals {
5-
type = "Service"
6-
identifiers = ["build.apprunner.amazonaws.com", "tasks.apprunner.amazonaws.com"]
7-
}
8-
}
1+
# Instance Role
2+
resource "aws_iam_role" "app_runner_instance_role" {
3+
name = "app-runner-instance-role"
4+
5+
assume_role_policy = jsonencode({
6+
Version = "2012-10-17"
7+
Statement = [
8+
{
9+
Action = "sts:AssumeRole"
10+
Effect = "Allow"
11+
Principal = {
12+
Service = "tasks.apprunner.amazonaws.com"
13+
}
14+
}
15+
]
16+
})
917
}
1018

19+
# Service Role
1120
resource "aws_iam_role" "app_runner_service_role" {
12-
name = "app-runner-service-role"
13-
assume_role_policy = data.aws_iam_policy_document.app_runner_assume_role.json
21+
name = "app-runner-service-role"
22+
23+
assume_role_policy = jsonencode({
24+
Version = "2012-10-17"
25+
Statement = [
26+
{
27+
Action = "sts:AssumeRole"
28+
Effect = "Allow"
29+
Principal = {
30+
Service = "build.apprunner.amazonaws.com"
31+
}
32+
}
33+
]
34+
})
35+
}
36+
37+
# Attach policies to the instance role
38+
resource "aws_iam_role_policy_attachment" "app_runner_instance_policy" {
39+
role = aws_iam_role.app_runner_instance_role.name
40+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSAppRunnerServicePolicyForECRAccess"
1441
}
1542

43+
# Attach policies to the service role
1644
resource "aws_iam_role_policy_attachment" "app_runner_service_policy" {
1745
role = aws_iam_role.app_runner_service_role.name
1846
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSAppRunnerServicePolicyForECRAccess"
1947
}
48+
49+
# Add SecretsManager access policy for the instance role
50+
resource "aws_iam_role_policy" "secrets_access" {
51+
name = "secrets-access"
52+
role = aws_iam_role.app_runner_instance_role.id
53+
54+
policy = jsonencode({
55+
Version = "2012-10-17"
56+
Statement = [
57+
{
58+
Effect = "Allow"
59+
Action = [
60+
"secretsmanager:GetSecretValue",
61+
"secretsmanager:DescribeSecret"
62+
]
63+
Resource = [
64+
aws_secretsmanager_secret.db_secrets["test"].arn,
65+
aws_secretsmanager_secret.db_secrets["prod"].arn
66+
]
67+
}
68+
]
69+
})
70+
}

0 commit comments

Comments
 (0)