From 1d4db86b6a33c9a9781030e1f763aed4416ca950 Mon Sep 17 00:00:00 2001 From: XxxKMSxxX Date: Sun, 28 Jul 2024 17:06:35 +0900 Subject: [PATCH] =?UTF-8?q?ECS=E3=82=BF=E3=82=B9=E3=82=AF=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/{apply.yml => cd.yml} | 4 +- .github/workflows/{plan.yml => ci.yml} | 2 +- README.md | 4 +- environments/prod/tokyo/collects.yaml | 38 +++++++++---------- environments/prod/tokyo/ecs/terragrunt.hcl | 2 + .../prod/tokyo/firehose/terragrunt.hcl | 19 ++++++++++ modules/ecs/main.tf | 4 ++ modules/ecs/variables.tf | 13 ++++++- modules/firehose/main.tf | 10 +++++ modules/firehose/outputs.tf | 7 ++++ modules/firehose/variables.tf | 26 +++++++++++++ 11 files changed, 104 insertions(+), 25 deletions(-) rename .github/workflows/{apply.yml => cd.yml} (98%) rename .github/workflows/{plan.yml => ci.yml} (99%) create mode 100644 environments/prod/tokyo/firehose/terragrunt.hcl create mode 100644 modules/firehose/main.tf create mode 100644 modules/firehose/outputs.tf create mode 100644 modules/firehose/variables.tf diff --git a/.github/workflows/apply.yml b/.github/workflows/cd.yml similarity index 98% rename from .github/workflows/apply.yml rename to .github/workflows/cd.yml index 5b2a9fe..f10b5e7 100644 --- a/.github/workflows/apply.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,4 @@ -name: apply +name: CD on: pull_request: @@ -17,7 +17,7 @@ permissions: contents: read jobs: - apply: + CD: runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/.github/workflows/plan.yml b/.github/workflows/ci.yml similarity index 99% rename from .github/workflows/plan.yml rename to .github/workflows/ci.yml index 6592299..8d2e2e7 100644 --- a/.github/workflows/plan.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: plan +name: CI on: push: diff --git a/README.md b/README.md index bb41f80..ed2b58b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Cryptra-Infra -[![plan](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/plan.yml/badge.svg)](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/plan.yml) -[![apply](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/apply.yml/badge.svg)](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/apply.yml) +[![CI](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/ci.yml/badge.svg)](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/ci.yml) +[![CD](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/cd.yml/badge.svg)](https://github.com/XxxKMSxxX/Cryptra-Infra/actions/workflows/cd.yml) ## References diff --git a/environments/prod/tokyo/collects.yaml b/environments/prod/tokyo/collects.yaml index b9a05aa..07d215a 100644 --- a/environments/prod/tokyo/collects.yaml +++ b/environments/prod/tokyo/collects.yaml @@ -1,26 +1,26 @@ collects: { # binance: { - # # spot: [ - # # "btcjpy", - # # "btcusdt", - # # "ethjpy", - # # "ethusdt", - # # "soljpy" - # # "solusdt", - # # ], + # spot: [ + # "btcjpy", + # "btcusdt", + # "ethjpy", + # "ethusdt", + # "soljpy" + # "solusdt", + # ], # usdt_perpetual: [ - # # "btcusdt", - # # "ethusdt", + # "btcusdt", + # "ethusdt", # "solusdt" # ], # }, - # bitflyer: { - # spot: [ - # "BTC_JPY", - # "ETH_JPY" - # ], - # fx: [ - # "FX_BTC_JPY" - # ], - # } + bitflyer: { + # spot: [ + # "BTC_JPY", + # "ETH_JPY" + # ], + fx: [ + "FX_BTC_JPY" + ], + } } \ No newline at end of file diff --git a/environments/prod/tokyo/ecs/terragrunt.hcl b/environments/prod/tokyo/ecs/terragrunt.hcl index 0e6c22f..27c3d10 100644 --- a/environments/prod/tokyo/ecs/terragrunt.hcl +++ b/environments/prod/tokyo/ecs/terragrunt.hcl @@ -22,8 +22,10 @@ inputs = { project_name = include.root.locals.conf.project_name collects = include.root.locals.conf.collects aws_region = include.root.locals.conf.region + aws_role_arn = "arn:aws:iam::${local.aws_account_id}:role/${include.root.locals.conf.project_name}-collector-role" instance_type = local.instance_type vpc_id = local.vpc_id subnet_ids = local.subnet_ids ecr_registry = "${local.aws_account_id}.dkr.ecr.ap-northeast-1.amazonaws.com/${include.root.locals.conf.project_name}-collector" + tags = include.root.locals.tags } diff --git a/environments/prod/tokyo/firehose/terragrunt.hcl b/environments/prod/tokyo/firehose/terragrunt.hcl new file mode 100644 index 0000000..3debcb5 --- /dev/null +++ b/environments/prod/tokyo/firehose/terragrunt.hcl @@ -0,0 +1,19 @@ +include "root" { + path = find_in_parent_folders() + expose = true + merge_strategy = "deep" +} + +terraform { + source = "../../../../modules/firehose" +} + +inputs = { + project_name = include.root.locals.conf.project_name + stream_name = "${include.root.locals.conf.project_name}-collector" + role_arn = "arn:aws:iam::123456789012:role/FirehoseDeliveryRole" + bucket_arn = "arn:aws:s3:::${include.root.locals.conf.project_name}-collector" + s3_prefix = "firehose" + environment = "prod" + tags = include.root.locals.tags +} \ No newline at end of file diff --git a/modules/ecs/main.tf b/modules/ecs/main.tf index f522c28..4446ba8 100644 --- a/modules/ecs/main.tf +++ b/modules/ecs/main.tf @@ -102,6 +102,10 @@ resource "aws_ecs_task_definition" "ecs_task_definitions" { name = "SYMBOL" value = each.value.symbol }, + { + name = "AWS_ROLE_ARN" + value = var.aws_role_arn + }, { name = "AWS_REGION" value = var.aws_region diff --git a/modules/ecs/variables.tf b/modules/ecs/variables.tf index 9be2c05..bc74b51 100644 --- a/modules/ecs/variables.tf +++ b/modules/ecs/variables.tf @@ -13,6 +13,11 @@ variable "aws_region" { type = string } +variable "aws_role_arn" { + description = "AWS role arn" + type = string +} + variable "instance_type" { description = "The EC2 instance type" type = string @@ -32,4 +37,10 @@ variable "subnet_ids" { variable "ecr_registry" { description = "ECR registry URI" type = string -} \ No newline at end of file +} + +variable "tags" { + description = "A map of tags to assign to the repository" + type = map(string) + default = {} +} diff --git a/modules/firehose/main.tf b/modules/firehose/main.tf new file mode 100644 index 0000000..fe19247 --- /dev/null +++ b/modules/firehose/main.tf @@ -0,0 +1,10 @@ +resource "aws_kinesis_firehose_delivery_stream" "this" { + name = var.stream_name + destination = "s3" + + s3_configuration { + role_arn = var.role_arn + bucket_arn = var.bucket_arn + prefix = var.s3_prefix + } +} diff --git a/modules/firehose/outputs.tf b/modules/firehose/outputs.tf new file mode 100644 index 0000000..4eb51d3 --- /dev/null +++ b/modules/firehose/outputs.tf @@ -0,0 +1,7 @@ +output "firehose_arn" { + value = aws_kinesis_firehose_delivery_stream.this.arn +} + +output "firehose_name" { + value = aws_kinesis_firehose_delivery_stream.this.name +} diff --git a/modules/firehose/variables.tf b/modules/firehose/variables.tf new file mode 100644 index 0000000..b765b81 --- /dev/null +++ b/modules/firehose/variables.tf @@ -0,0 +1,26 @@ +variable "stream_name" { + description = "The name of the Firehose stream" + type = string +} + +variable "role_arn" { + description = "The ARN of the IAM role for Firehose" + type = string +} + +variable "bucket_arn" { + description = "The ARN of the S3 bucket for Firehose to deliver data" + type = string +} + +variable "s3_prefix" { + description = "The prefix for the S3 bucket" + type = string + default = "" +} + +variable "tags" { + description = "A map of tags to assign to the repository" + type = map(string) + default = {} +}