Skip to content

Commit 9531516

Browse files
committed
Remove hard code region
1 parent 7d9a24a commit 9531516

15 files changed

+26
-14
lines changed

terraform/prod/access_logs_bucket.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "random_pet" "access_logs" {
33
}
44

55
resource "aws_s3_bucket" "access_logs" {
6-
bucket = "access-logs-${random_pet.access_logs.id}"
6+
bucket = "${local.env}-access-logs-${random_pet.access_logs.id}"
77
acl = "private"
88
force_destroy = true # to make it easier to destroy at this repository example
99
}
@@ -13,15 +13,18 @@ resource "aws_s3_bucket_policy" "access_logs" {
1313
policy = data.aws_iam_policy_document.access_logs.json
1414
}
1515

16+
data "aws_elb_service_account" "main" {}
17+
1618
data "aws_iam_policy_document" "access_logs" {
17-
# Allow from Elastic Load Balancing account in ap-northeast-1
19+
# Allow from Elastic Load Balancing account
20+
# ref: https://docs.aws.amazon.com/ja_jp/elasticloadbalancing/latest/application/load-balancer-access-logs.html
1821
statement {
1922
actions = ["s3:PutObject"]
2023
resources = ["${aws_s3_bucket.access_logs.arn}/*"]
2124

2225
principals {
2326
type = "AWS"
24-
identifiers = ["arn:aws:iam::582318560864:root"]
27+
identifiers = [data.aws_elb_service_account.main.arn]
2528
}
2629
}
27-
}
30+
}

terraform/prod/codepipeline.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ resource "aws_codepipeline" "codepipeline" {
3838
configuration = {
3939
Owner = dirname(data.github_repository.repo.full_name)
4040
Repo = data.github_repository.repo.name
41-
Branch = "master"
41+
Branch = var.target_branch
4242
PollForSourceChanges = false
4343
}
4444
}

terraform/prod/ecs_scheduled_task_export.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ resource "aws_ecs_task_definition" "export" {
1616
image = data.terraform_remote_state.common.outputs.ecr_rails_blog_example_repository_url
1717
awslogs_group = aws_cloudwatch_log_group.export.name
1818
awslogs_region = data.aws_region.current.name
19+
aws_region = data.aws_region.current.name
1920
database_url_arn = aws_ssm_parameter.database_url.arn
2021
secret_key_base_arn = aws_ssm_parameter.secret_key_base.arn
2122
})

terraform/prod/ecs_service_api.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ resource "aws_s3_bucket_object" "api_task_definition" {
2323
execution_role_arn = module.ecs_task_execution_iam.service_role_arn
2424
awslogs_group = aws_cloudwatch_log_group.api.name
2525
awslogs_region = data.aws_region.current.name
26+
aws_region = data.aws_region.current.name
2627
memory = 512
2728
task_role_arn = module.ecs_task_execution_iam.service_role_arn
2829
family = aws_ecs_task_definition.api.family

terraform/prod/ecs_service_web.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ resource "aws_s3_bucket_object" "web_task_definition" {
2323
execution_role_arn = module.ecs_task_execution_iam.service_role_arn
2424
awslogs_group = aws_cloudwatch_log_group.web.name
2525
awslogs_region = data.aws_region.current.name
26+
aws_region = data.aws_region.current.name
2627
memory = 512
2728
task_role_arn = module.ecs_task_execution_iam.service_role_arn
2829
family = aws_ecs_task_definition.web.family

terraform/prod/templates/api/taskdef.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"environment": [
1919
{
2020
"name": "AWS_REGION",
21-
"value": "ap-northeast-1"
21+
"value": "${aws_region}"
2222
},
2323
{
2424
"name": "RAILS_LOG_TO_STDOUT",

terraform/prod/templates/export/container_definitions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"environment": [
1212
{
1313
"name": "AWS_REGION",
14-
"value": "ap-northeast-1"
14+
"value": "${aws_region}"
1515
},
1616
{
1717
"name": "RAILS_LOG_TO_STDOUT",

terraform/prod/templates/web/taskdef.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"environment": [
2121
{
2222
"name": "AWS_REGION",
23-
"value": "ap-northeast-1"
23+
"value": "${aws_region}"
2424
},
2525
{
2626
"name": "RAILS_LOG_TO_STDOUT",

terraform/stg/access_logs_bucket.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ resource "aws_s3_bucket_policy" "access_logs" {
1313
policy = data.aws_iam_policy_document.access_logs.json
1414
}
1515

16+
data "aws_elb_service_account" "main" {}
17+
1618
data "aws_iam_policy_document" "access_logs" {
17-
# Allow from Elastic Load Balancing account in ap-northeast-1
19+
# Allow from Elastic Load Balancing account
20+
# ref: https://docs.aws.amazon.com/ja_jp/elasticloadbalancing/latest/application/load-balancer-access-logs.html
1821
statement {
1922
actions = ["s3:PutObject"]
2023
resources = ["${aws_s3_bucket.access_logs.arn}/*"]
2124

2225
principals {
2326
type = "AWS"
24-
identifiers = ["arn:aws:iam::582318560864:root"]
27+
identifiers = [data.aws_elb_service_account.main.arn]
2528
}
2629
}
27-
}
30+
}

terraform/stg/ecs_scheduled_task_export.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ resource "aws_ecs_task_definition" "export" {
1616
image = data.terraform_remote_state.common.outputs.ecr_rails_blog_example_repository_url
1717
awslogs_group = aws_cloudwatch_log_group.export.name
1818
awslogs_region = data.aws_region.current.name
19+
aws_region = data.aws_region.current.name
1920
database_url_arn = aws_ssm_parameter.database_url.arn
2021
secret_key_base_arn = aws_ssm_parameter.secret_key_base.arn
2122
})

0 commit comments

Comments
 (0)