How do I create a custom Event Bus in AWS Event Bridge?

烈酒焚心 提交于 2021-02-08 05:44:23

问题


I can't find the documentation or an example Terraform module online.

How do I create a custom Event Bus in AWS Event Bridge?


回答1:


As of this writing, creating an EventBridge Event Bus isn't supported by the Terraform Provider for AWS yet.

We had to use the default Event Bus or create it with the AWS CLI or Console.

Caveats: EventBridge has a couple of serious IAM gaps right now: you can't restrict what buses an IAM principal can publish events too and it uses a Service principal instead of a Service Linked Role principal to access things like KMS keys used to encrypt the buses.

You can use a null_resource provisioner as a workaround for the missing provider resource (this assumes you are using environment variables or an IAM instance profile to authenticate your AWS provider):

resource "null_resource" "custom_event_bus" {
  triggers = {
    event_bus_name = var.event_bus_name
  }

  provisioner "local-exec" {
    command = "aws events create-event-bus --name ${var.event_bus_name}'"
  }
}

If you are using a named AWS configuration profile instead of environment variables, you'll need to specify that with --profile profile_name the same as you would if you ran it at your shell.




回答2:


With a recent update to the AWS Terraform Provider, the EOF template_body style mentioned in another answer is no longer the preferred way of specifying a CloudFormation stack. Here is an example snippet of code using the new STACK declaration style that accomplishes the same thing (provisions a custom EventBridge bus):

resource "aws_cloudformation_stack" "eventbridge_bus" {
  name = "eventbridge-bus"

  template_body = <<STACK
{
  "Resources" : {
    "bus" : {
      "Type" : "AWS::Events::EventBus",
      "Properties" : {
        "Name": "bus-name"
      }
    }
  }
}
STACK
}



回答3:


There is a ticket refering to the non support of event bridge in terraform: https://github.com/terraform-providers/terraform-provider-aws/issues/9330

By quoting github user https://github.com/mwarkentin who deserves the credit for the following snippet, there is a cloudformation in terraform hack to enable the declaration of an event bridge in terraform :

resource "aws_cloudformation_stack" "eventbridge_bus" {   
  name = "eventbridge-bus"
  template_body = <<EOF 
Resources:
  EventBus:
    Type: AWS::Events::EventBus
    Properties:
      Name: bus-name
EOF
}


来源:https://stackoverflow.com/questions/61711215/how-do-i-create-a-custom-event-bus-in-aws-event-bridge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!