RabbitMQ - Create Update or Delete User using Terraform

This assumes you have setup Terraform as described in RabbitMQ - Getting Started with Terraform. Let's say you have the following files on your Terraform server.



Add the following to your users.tf file. This will create user john.doe with the management tag.

resource "rabbitmq_vhost" "user1" {
  name = "john.doe"
  password = "itsasecret"
  tags = ["management"]


The terraform init command can be used so that Terraform can communicate with RabbitMQ.

terraform init


The terraform plan command can be used to see what Terraform will try to do.

terraform plan


By default, the terraform.tfstate file should be found in your root module directory (/usr/local/terraform/rabbitmq in this example).

  • If the user does not exist and the terraform.tfstate file does not contain the user, Terraform will create the user.
  • If the user exists and the terraform.tfstate file contains the user and a difference is found between the users.tf file and the terraform.tfstate file, Terraform will update the user.
  • If the user exists and the terraform.tfstate file contains the user and the user is removed from the users.tf file, Terraform will destroy (delete) the user.


The terraform apply command from your root module directory (/usr/local/terraform/rabbitmq in this example) can be used to create, update or destory the shovel.

terraform apply


Something like this should be displayed, and you will be prompted to enter yes.

Terraform will perform the following actions:

  # rabbitmq_user.user1 will be created
  + resource "rabbitmq_vhost" "user1" {
      + id   = (known after apply)
      + name = "john.doe"
      + password = (sensitive value)
      + tags = [
          + "management",

Plan: 1 to add, 0 to change, 0 to destroy.


After entering yes, the following should be displayed.

rabbitmq_user.user1: Creation complete after 0s [id=foo]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter a5239 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |