Skip to content

Commit

Permalink
restructure folders to serperate IAM from services
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandra Reddy authored and Chandra Reddy committed Aug 16, 2024
1 parent e6570e9 commit 1dda6ad
Show file tree
Hide file tree
Showing 10 changed files with 479 additions and 445 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ Replace the URL in the middle with the proper endpoint of your database and repl

10. Go to the apprunner folder (`cd ../apprunner`)

11. Run `tofu init` and then `tofu apply` to set up the App Runner services
11. Run `tofu init` and then `tofu apply` to set up the App Runner IAM

12. Go to the service sub-folder (`cd /service`)

13. Run 'tofu init' and then 'tofu apply' to set up the App Runner services
47 changes: 47 additions & 0 deletions apprunner/03_iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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
}

12 changes: 12 additions & 0 deletions apprunner/service/01_provider.tf
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"
}
22 changes: 22 additions & 0 deletions apprunner/service/02_applicationlist.tf
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)
}
47 changes: 0 additions & 47 deletions apprunner/03_apprunner.tf → apprunner/service/03_apprunner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,53 +31,6 @@ resource "aws_apprunner_service" "app_services" {

}

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"

Expand Down
9 changes: 9 additions & 0 deletions apprunner/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 4,
"terraform_version": "1.7.2",
"serial": 5,
"lineage": "8ebc2ad4-09a6-559d-169e-e7f1af71737f",
"outputs": {},
"resources": [],
"check_results": null
}
Loading

0 comments on commit 1dda6ad

Please sign in to comment.