Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rabbitmq: bindings not being stored in state #12782

Closed
jason-archidera opened this issue Mar 16, 2017 · 12 comments
Closed

rabbitmq: bindings not being stored in state #12782

jason-archidera opened this issue Mar 16, 2017 · 12 comments

Comments

@jason-archidera
Copy link

jason-archidera commented Mar 16, 2017

I seem to have an issue and it seems to be in saving state.
Version: 0.9
Resource: rabbitmq_binding

I've setup my project with a main.tf:

terraform {
    required_version = ">= 0.9"
    backend "consul" {
      address = "XXXXXXXX"
      path    = "tfstate/vhost/xxxxx-development"
  }
}

#######VARIABLES########
variable "endpoint" {
  default = "http://127.0.0.1:15672"
}

variable "username" {
  default = "XXXXX"
}

variable "password" {
  default = "XXXXXX"
}

variable "usersuffix" {
  default = "DEVELOPMENT"
}

variable "vhost" {
  default = "XXXX-DEVELOPMENT-TF"
}

# Configure the RabbitMQ provider
provider "rabbitmq" {
  endpoint = "${var.endpoint}"
  username = "${var.username}"
  password = "${var.password}"
  insecure = true
}

########GET MODULES########
module "create-all" {
    source="./../modules"
    vhost = "${var.vhost}"
    usersuffix = "${var.usersuffix}"
}

#######OUTPUT FOR CONSOLE#######
output "endpoint" {
  value = "${var.endpoint}"
}

output "vhost" {
  value = "${var.vhost}"
}

output "usersuffix" {
  value = "${var.usersuffix}"
}

My modules folder has several tf files and all is well except for any binding with a routing key that isn't "#". For example:

resource "rabbitmq_binding" "xxxx_to_zzzz" {
    depends_on = ["rabbitmq_exchange.xxxx", "rabbitmq_queue.zzzzz"]
    source = "XXXX.XXXX"
    vhost = "${rabbitmq_vhost.vhost.name}"
    destination = "XXXX.ZZZZ.Queue"
    destination_type = "queue"
    routing_key = "ZZ.#"
    #routing_key = "#"
    properties_key = "%23"
}

I run the commands, everything seems to work, except for the bindings with anything other than "#" are not stored in the remote state (Consul). This causes each time I run plan or apply, it thinks these bindings are new.

- terraform init -get=true -backend=true

- terraform plan

- terraform apply

It's either a bug in the RabbitMQ provider or perhaps in state? The interesting part is that the bindings are created in RabbitMQ, but the state is not saved.

@jbardin
Copy link
Member

jbardin commented Mar 16, 2017

Hi @jason-archidera,

I'm working on a condensed reproduction for this, but could you confirm that this does not happen with local state? Remote state backends just store a binary blob, so it seems strange that it could return a partial state.

@jbardin jbardin added the waiting-response An issue/pull request is waiting for a response from the community label Mar 16, 2017
@jason-archidera
Copy link
Author

@jbardin, thanks for looking into this. I'll test that out today and post and update.

@jason-archidera
Copy link
Author

@jbardin, I did the same config with local state and the same behavior occurs.

@jbardin
Copy link
Member

jbardin commented Mar 17, 2017

@jason-archidera,

Thanks for the update. I'll tag this to look into the provider first, since it's likely not storing the state correctly in the first place.

@jbardin jbardin added bug provider/rabbitmq and removed waiting-response An issue/pull request is waiting for a response from the community labels Mar 17, 2017
@jbardin jbardin changed the title backend - consul - storing rabbitmq state rabbitmq: bindings not being stored in state Mar 17, 2017
@jason-archidera
Copy link
Author

jason-archidera commented Mar 17, 2017

@jbardin, I did a simple test and can reproduce with this. BTW, I'm using RabbitMQ v3.6.6.

# Configure the RabbitMQ provider
provider "rabbitmq" {
  endpoint = "http://127.0.0.1:15672"
  username = "XXXX"
  password = "XXXXX"
  insecure = true
}

#CREATE THE VHOST
resource "rabbitmq_vhost" "vhost" {
    name = "BINDING-TEST-DEVELOPMENT"
}

resource "rabbitmq_permissions" "admin_builtin" {
    user = "admin"
    vhost = "BINDING-TEST-DEVELOPMENT"
    permissions {
        configure = ".*"
        write = ".*"
        read = ".*"
    }
}

#CREATE EXCHANGES
resource "rabbitmq_exchange" "test_exchange" {
    depends_on = ["rabbitmq_permissions.admin_builtin"]
    name = "Test"
    vhost = "BINDING-TEST-DEVELOPMENT"
    settings {
        type = "topic"
        durable = true
        auto_delete = false
    }
}

#CREATE QUEUES
resource "rabbitmq_queue" "test_queue" {
    depends_on = ["rabbitmq_permissions.admin_builtin"]
    name = "Test.Queue"
    vhost = "BINDING-TEST-DEVELOPMENT"
    settings {
        durable = true
        auto_delete = false
    }
}


#CREATE BINDINGS
resource "rabbitmq_binding" "test_exchange_to_test_queue" {
    source = "Test"
    vhost = "BINDING-TEST-DEVELOPMENT"
    destination = "Test.Queue"
    destination_type = "queue"
    routing_key = "ANYTHING.#"
    properties_key = "%23"
}

routing_key = "ANYTHING.#" doesn't store in state.
routing_key="#" does store in state.

Let me know if you need anything else.

@lmayorga1980
Copy link

@jbardin,
Something that can be done for 0.9.3_1 release?

@jason-archidera
Copy link
Author

jason-archidera commented Apr 18, 2017

@lmayorga1980, I tested this again with 0.9.3 and it is still not working. bindings with routing_key="#" works fine. Anything other than that and it doesn't store in state.

@jason-archidera
Copy link
Author

Spent a little time looking at this.

On line 113, it's failing the '... && binding.PropertiesKey == propertiesKey' check.
https://github.com/hashicorp/terraform/blob/master/builtin/providers/rabbitmq/resource_binding.go

If I change the binding declaration to below, it works. Basically, the url encoding is goofing things up with the properties_key. Maybe this is an easy fix somewhere in the chain?

#CREATE BINDINGS
resource "rabbitmq_binding" "test_exchange_to_test_queue" {
source = "Test"
vhost = "BINDING-TEST-DEVELOPMENT"
destination = "Test.Queue"
destination_type = "queue"
routing_key = "ANYTHING.#"
properties_key = "ANYTHING.%23"
}

@jason-archidera
Copy link
Author

A little more commentary, this is probably a 'rabbitmq-ism' since any binding I create modifies the properties key by changing the "#" to "%23". This doesn't seem to be a code change at all, but perhaps some instructions/notes in the RabbitMQ provider documentation. It wasn't apparent and I did not find it documented anywhere, even the RabbitMQ documentation.

@jtopjian
Copy link
Contributor

@jason-archidera I believe you are correct. This looks to be a rabbitmq-ism. I found the following mailing list thread which sounds exactly like your scenario:

http://rabbitmq.1065348.n5.nabble.com/Query-for-Binding-with-similar-topic-routing-keys-returns-all-similar-vs-the-one-matching-td6396.html

To confirm: when you change your properties_key to ANYTHING.%23, everything works and the binding is correctly stored in state? Or is the state issue still a problem?

@jason-archidera
Copy link
Author

I have confirmed the following works for my stack (Terraform 0.9.3 and RabbitMq 3.6.6):
If routing_key="#", then properties_key="%23" works
If routing_key="ANYTHING", then properties_key="ANYTHING" works
If routing_key="ANYTHING.#", then properties_key="ANYTHING.%23" works

It seems the logic is that the binding's properties_key needs to be unique for each queue so based on how a developer is handling routing_keys, it should be verified to ensure it's unique. My config is pretty large so it would be easy to goof it up.

@ghost
Copy link

ghost commented Apr 9, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants