🐰

Terraformを使ってEventBridgePipeを作成する

2024/01/10に公開

概要

  • Terraformを使ってEventBridgePipeを作成する
  • やりたいこと
    • SQSにメッセージが登録されると、ECSタスクをEventBridgePipeを介して起動させる
  • 今回はFilteringEnrichmentは設定しない
  • EventBridgePipe用のRoleは事前に作成
  • EventBridgePipeから起動させるtask-definitionは事前に作成

コード

terraform {
        awscc = {
            source  = "hashicorp/awscc"
        }
    }
}

provider "awscc" {
    region = "ap-northeast-1"
}

resource "awscc_pipes_pipe" "pipe" {
    name     = "terraform-test-eventbridgepipes"
    role_arn = "arn:aws:iam::XXXXXXXXXXX:role/service-role/test-eventbridgepipes-role"

    source = "arn:aws:sqs:ap-northeast-1:XXXXXXXXXXX:test-eventbridgepipes-sqs"

    source_parameters = {
        sqs = {
            sqs_queue_parameters = {
                batch_size = 10
            }
        }
    }

    target = "arn:aws:ecs:ap-northeast-1:XXXXXXXXXXX:cluster/default"
    target_parameters = {
        ecs_task_parameters = {
            task_definition_arn = "arn:aws:ecs:ap-northeast-1:XXXXXXXXXXX:task-definition/test-eventbridgepipes-task"
            launch_type = "FARGATE"
            task_count = "1"
            network_configuration = {
                awsvpc_configuration = {
                    assign_public_ip = "DISABLED"
                    subnets = [
                        "subnet-0XXXXXXXXXXXXXXXX",
                        "subnet-0XXXXXXXXXXXXXXXX",
                        "subnet-0XXXXXXXXXXXXXXXX"
                    ]
                }
            }
        }
    }
}

詳細

  • 現時点(2023/04/10)でhashicorp/awsはEventBridgePipeに未対応なので、hashicorp/awscc利用する
  • 公開されているスキーマに沿って記載

参考

https://towardsaws.com/eventbridge-pipes-using-terraform-ae3abe6266cc

https://registry.terraform.io/providers/hashicorp/awscc/latest/docs/resources/pipes_pipe

Discussion