This repository has been archived by the owner on Nov 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Fix bindings not being saved to state. #8
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ import ( | |
"log" | ||
"strings" | ||
|
||
"github.com/michaelklishin/rabbit-hole" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/michaelklishin/rabbit-hole" | ||
"net/url" | ||
) | ||
|
||
func resourceBinding() *schema.Resource { | ||
|
@@ -44,12 +44,6 @@ func resourceBinding() *schema.Resource { | |
ForceNew: true, | ||
}, | ||
|
||
"properties_key": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than removing "properties_key": &schema.Schema{
Type: schema.TypeString,
Computed: true,
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do, thanks for the tip. |
||
|
||
"routing_key": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -74,14 +68,16 @@ func CreateBinding(d *schema.ResourceData, meta interface{}) error { | |
Destination: d.Get("destination").(string), | ||
DestinationType: d.Get("destination_type").(string), | ||
RoutingKey: d.Get("routing_key").(string), | ||
PropertiesKey: d.Get("properties_key").(string), | ||
Arguments: d.Get("arguments").(map[string]interface{}), | ||
} | ||
|
||
if err := declareBinding(rmqc, vhost, bindingInfo); err != nil { | ||
propertiesKey, err := declareBinding(rmqc, vhost, bindingInfo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] RabbitMQ: Binding properties key: %s", propertiesKey) | ||
bindingInfo.PropertiesKey = propertiesKey | ||
name := fmt.Sprintf("%s/%s/%s/%s/%s", vhost, bindingInfo.Source, bindingInfo.Destination, bindingInfo.DestinationType, bindingInfo.PropertiesKey) | ||
d.SetId(name) | ||
|
||
|
@@ -177,19 +173,26 @@ func DeleteBinding(d *schema.ResourceData, meta interface{}) error { | |
return nil | ||
} | ||
|
||
func declareBinding(rmqc *rabbithole.Client, vhost string, bindingInfo rabbithole.BindingInfo) error { | ||
log.Printf("[DEBUG] RabbitMQ: Attempting to declare binding for %s/%s/%s/%s/%s", | ||
vhost, bindingInfo.Source, bindingInfo.Destination, bindingInfo.DestinationType, bindingInfo.PropertiesKey) | ||
func declareBinding(rmqc *rabbithole.Client, vhost string, bindingInfo rabbithole.BindingInfo) (string, error) { | ||
log.Printf("[DEBUG] RabbitMQ: Attempting to declare binding for %s/%s/%s/%s", | ||
vhost, bindingInfo.Source, bindingInfo.Destination, bindingInfo.DestinationType) | ||
|
||
resp, err := rmqc.DeclareBinding(vhost, bindingInfo) | ||
log.Printf("[DEBUG] RabbitMQ: Binding declare response: %#v", resp) | ||
if err != nil { | ||
return err | ||
return "", err | ||
} | ||
|
||
if resp.StatusCode >= 400 { | ||
return fmt.Errorf("Error declaring RabbitMQ binding: %s", resp.Status) | ||
return "", fmt.Errorf("Error declaring RabbitMQ binding: %s", resp.Status) | ||
} | ||
|
||
return nil | ||
location := strings.Split(resp.Header.Get("Location"), "/") | ||
propertiesKey, err := url.PathUnescape(location[len(location)-1]) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return propertiesKey, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,6 @@ resource "rabbitmq_binding" "test" { | |
destination = "${rabbitmq_queue.test.name}" | ||
destination_type = "queue" | ||
routing_key = "#" | ||
properties_key = "%23" | ||
} | ||
``` | ||
|
||
|
@@ -72,8 +71,6 @@ The following arguments are supported: | |
|
||
* `destination_type` - (Required) The type of destination (queue or exchange). | ||
|
||
* `properties_key` - (Required) A unique key to refer to the binding. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of being removed, this should be moved to the |
||
|
||
* `routing_key` - (Optional) A routing key for the binding. | ||
|
||
* `arguments` - (Optional) Additional key/value arguments for the binding. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
net/url
should be inbetweenlog
andstrings
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, for some reason intellij reorged it to the bottom like that, just alpha order is expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ordering is usually something like: first standard packages, blank space, external packages. See the other files for an example.