rabbitmq 通过Terraform将定义文件导入Amazon MQ

unguejic  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(1)|浏览(196)

我已经使用Terraform创建了一个Amazon MQ代理(引擎类型为RabbitMQ)。现在我想导入一个XML定义文件。这可以很容易地手动完成,我只需要导出定义文件并手动将其导入到AWS MQ。但我需要使用Terraform自动化此过程。任何建议都将受到欢迎。这是我的terraform代码:

resource "aws_mq_broker" "rabbitmq_broker" {
broker_name         = "mq_test"
engine_type         = var.mq_engine_type
engine_version      = var.mq_engine_version
host_instance_type  = var.mq_instance_type
deployment_mode     = var.mq_deployment_mode
security_groups     = [aws_security_group.ecs_private.id]
apply_immediately   = "true"
publicly_accessible = "false"
subnet_ids          = [aws_subnet.private.id]

user {
console_access = "true"
username       = var.mq_username
password       = "password"
}
tags = {
env         = "${terraform.workspace}",
 }
}
bhmjp9jg

bhmjp9jg1#

首先,需要创建一个MQ Configuration,它是XML文件传递到的对象,然后将配置传递给代理。

resource "aws_mq_configuration" "rabbitmq_broker_config" {
  name           = "My Broker Configuration"
  description    = "My RabbitMQ Broker Configuration"
  engine_type    = var.mq_engine_type
  engine_version = var.mq_engine_version

  data = file("${path.module}/broker-config.xml")
}

resource "aws_mq_broker" "rabbitmq_broker" {
  # All your attributes here

  configuration {
    id       = aws_mq_configuration.rabbitmq_broker_config.id
    revision = aws_mq_configuration.rabbitmq_broker_config.latest_revision
  }
}

相关问题