-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update README and add apprunner folder
- Loading branch information
Chandra Reddy
authored and
Chandra Reddy
committed
Aug 16, 2024
1 parent
d1ac37a
commit 675b203
Showing
6 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "5.62.0" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = "us-east-1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
variable "applications" { | ||
type = list(string) | ||
default = ["announcements"] | ||
} | ||
|
||
variable "environments" { | ||
type = list(string) | ||
default = ["dev", "qa", "prod"] | ||
} | ||
|
||
locals { | ||
app_env_combinations = [ | ||
for app in var.applications : [ | ||
for env in var.environments : { | ||
app = app | ||
env = env | ||
} | ||
] | ||
] | ||
|
||
app_env_list = flatten(local.app_env_combinations) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
resource "aws_apprunner_service" "app_services" { | ||
for_each = { for combo in local.app_env_list : "${combo.app}-${combo.env}" => combo } | ||
|
||
service_name = "${each.value.app}-${each.value.env}-service" | ||
|
||
source_configuration { | ||
image_repository { | ||
image_configuration { | ||
port = "8000" | ||
} | ||
image_identifier = "654654512735.dkr.ecr.us-east-1.amazonaws.com/${each.value.app}-${each.value.env}:latest" | ||
image_repository_type = "ECR" | ||
} | ||
|
||
authentication_configuration { | ||
access_role_arn = aws_iam_role.apprunner_role.arn | ||
} | ||
} | ||
|
||
instance_configuration { | ||
cpu = "1024" | ||
memory = "2048" | ||
} | ||
|
||
auto_scaling_configuration_arn = aws_apprunner_auto_scaling_configuration_version.app_scaling.arn | ||
|
||
tags = { | ||
Environment = each.value.env | ||
Application = each.value.app | ||
} | ||
|
||
} | ||
|
||
resource "aws_iam_role" "apprunner_role" { | ||
name = "apprunner-access-role" | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "build.apprunner.amazonaws.com" | ||
}, | ||
Action = "sts:AssumeRole" | ||
}, | ||
] | ||
}) | ||
} | ||
|
||
|
||
resource "aws_iam_policy" "ecr_access_policy" { | ||
name = "apprunner-ecr-access-policy" | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Action = [ | ||
"ecr:GetDownloadUrlForLayer", | ||
"ecr:BatchGetImage", | ||
"ecr:BatchCheckLayerAvailability" | ||
], | ||
Resource = "*" | ||
}, | ||
{ | ||
Effect = "Allow", | ||
Action = "ecr:GetAuthorizationToken", | ||
Resource = "*" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "apprunner_ecr_policy_attach" { | ||
role = aws_iam_role.apprunner_role.name | ||
policy_arn = aws_iam_policy.ecr_access_policy.arn | ||
} | ||
|
||
resource "aws_apprunner_auto_scaling_configuration_version" "app_scaling" { | ||
auto_scaling_configuration_name = "app-scaling-config" | ||
|
||
max_concurrency = 100 | ||
max_size = 3 | ||
min_size = 1 | ||
} | ||
|