We config services roles and policies through json files, making roles and policies management more easily. Below is a list of services to be configured:
templates\policies\ecstask_role.json
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
templates\policies\ecstask_policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:*",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ssmmessages:*",
"ssm:*",
"ecs:*"
],
"Resource": "*"
}
]
}
templates\policies\codebuild_role.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "codebuild.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Json Policies path: templates\policies\codebuild_policy.json
Grant AWS CodeBuild the necessary permissions to access S3, CloudWatch Logs, CodeBuild, Secrets Manager, ECR, and ECS for essential build and deployment tasks:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"codebuild:BatchGetBuilds",
"codebuild:StartBuild",
"codebuild:UpdateProject",
"codebuild:StopBuild",
"secretsmanager:GetSecretValue",
"ecr:*",
"ecs:DescribeCluster",
"ecs:DescribeServices",
"ecs:UpdateService"
],
"Resource": "*"
}
]
}
templates\policies\codedeploy_role.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "codedeploy.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Json Policies path: templates\policies\codedeploy_policy.json
AWS CodeDeploy with the necessary permissions to manage ECS deployments, access logging and monitoring services, and interact with S3 and Elastic Load Balancing:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:DescribeClusters",
"ecs:DescribeServices",
"ecs:DescribeTaskDefinition",
"ecs:UpdateService",
"ecs:ListTasks",
"ecs:DescribeTasks",
"ecs:CreateTaskSet",
"ecs:DeleteTaskSet",
"ecs:UpdateServicePrimaryTaskSet",
"iam:PassRole",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"cloudwatch:PutMetricData",
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket",
"elasticloadbalancing:*"
],
"Resource": "*"
}
]
}
templates\policies\codepipeline_role.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "codepipeline.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Json Policies path: templates\policies\codepipeline_policy.json
AWS CodePipeline the permissions are needed for orchestrating and managing end-to-end CI/CD pipelines:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ecs:UpdateService",
"codestar:*",
"codestar-connections:*",
"codebuild:*",
"codedeploy:*"
],
"Resource": "*"
}
]
}
templates\policies\app_autoscale_role.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "application-autoscaling.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Finally, we completely set up necessary variables and environment for Terraform. Please save it and go to next step.