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

Add AzureRM Service Bus Queue resource #14631

Closed

Conversation

iljaskevic
Copy link

This PR adds Azure RM - Service Bus Queue resource. Any ideas on how to improve this are welcome.

Copy link
Contributor

@stack72 stack72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @iljaskevic

Thanks for all the work here - I have left you some comments to think about

Thanks

Paul


"enable_batched_operations": {
Type: schema.TypeBool,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should provide a default here. We have a known bug in Terraform that if you specify a value of true then change back to false then terraform won't get that change

this is because of d.GetOk("false") believing that the value doesn't exist as the default value for a bool is false

},

"enable_express": {
Type: schema.TypeBool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same default value point


"enable_partitioning": {
Type: schema.TypeBool,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same default value point

},

"requires_duplicate_detection": {
Type: schema.TypeBool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same default value point

},

"support_ordering": {
Type: schema.TypeBool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same default value point

d.Set("namespace_name", namespaceName)
d.Set("location", azureRMNormalizeLocation(*resp.Location))

props := resp.QueueProperties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check that QueueProperties is not nil before trying to get values from it - otherwise this could panic

d.Set("auto_delete_on_idle", props.AutoDeleteOnIdle)
d.Set("default_message_ttl", props.DefaultMessageTimeToLive)

if props.DuplicateDetectionHistoryTimeWindow != nil && *props.DuplicateDetectionHistoryTimeWindow != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.Set will safely do this check for you

// if the queue is in a premium namespace and partitioning is enabled then the
// max size returned by the API will be 16 times greater than the value set
if *props.EnablePartitioning {
namespace, err := meta.(*ArmClient).serviceBusNamespacesClient.Get(resGroup, namespaceName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to make another Get request here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to retrieve the parent Namespace resource where the queue is running to get the size (Basic, Standard or Premium) to be able to re-calculate the max size property differently for Basic and Standard sizes than for Premium size, when getting the queue info from Azure.

In Azure Service Bus, if partitioning is enabled and maximum queue size is set to N megabytes, when getting the max size property of an existing queue we get N MB for Premium and N*16 MB for Basic and Standard. That is because Basic and Standard are running on shared resources and it creates 16 copies/partitions, which means that total max size is 16 times the value that was set. However, Premium runs on dedicated resources and partitioning is always enabled with 2 partitions with max size split between the them. This means that each partition has max size of N/2 MB and the total max size remains N MB.

So to avoid a problem of discrepancy between the value of the property we set when creating the queue and the value of that property we get when we retrieve it from Azure after it was created, it needs to divide the property value by 16 for queues running in Basic and Standard namespaces.

@stack72
Copy link
Contributor

stack72 commented May 24, 2017

The extra API call makes sense now - thanks for explaining that. Please can you just touch up the other points I made around d.Set and default values for bools and then we can get this merged

Thanks

Paul

@stack72
Copy link
Contributor

stack72 commented Jun 9, 2017

Hi @iljaskevic

The code LGTM to me, looks like there is a test failure:

% make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMServiceBusQueue'                                                ✭
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/06/09 16:57:53 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMServiceBusQueue -timeout 120m
=== RUN   TestAccAzureRMServiceBusQueue_importBasic
--- FAIL: TestAccAzureRMServiceBusQueue_importBasic (229.58s)
	testing.go:428: Step 0 error: After applying this step, the plan was not empty:

		DIFF:

		UPDATE: azurerm_servicebus_queue.test
		  duplicate_detection_history_time_window: "00:10:00" => ""

		STATE:

		azurerm_resource_group.test:
		  ID = /subscriptions/c0a607b2-6372-4ef3-abdb-dbe52a7b56ba/resourceGroups/acctestRG-6423544310546596076
		  location = westus
		  name = acctestRG-6423544310546596076
		  tags.% = 0
		azurerm_servicebus_namespace.test:
		  ID = /subscriptions/c0a607b2-6372-4ef3-abdb-dbe52a7b56ba/resourceGroups/acctestRG-6423544310546596076/providers/Microsoft.ServiceBus/namespaces/acctestservicebusnamespace-6423544310546596076
		  capacity = 1
		  default_primary_connection_string = Endpoint=sb://acctestservicebusnamespace-6423544310546596076.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=o1910MlqSDp7bECRiHm/EZhb0aPuWbt5qN4cry4JeRw=
		  default_primary_key = o1910MlqSDp7bECRiHm/EZhb0aPuWbt5qN4cry4JeRw=
		  default_secondary_connection_string = Endpoint=sb://acctestservicebusnamespace-6423544310546596076.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=IbP87TaRXjKDCPVYuuSj3wGefCSf11UZOcFCecWDBxI=
		  default_secondary_key = IbP87TaRXjKDCPVYuuSj3wGefCSf11UZOcFCecWDBxI=
		  location = westus
		  name = acctestservicebusnamespace-6423544310546596076
		  resource_group_name = acctestRG-6423544310546596076
		  sku = standard
		  tags.% = 0

		  Dependencies:
		    azurerm_resource_group.test
		azurerm_servicebus_queue.test:
		  ID = /subscriptions/c0a607b2-6372-4ef3-abdb-dbe52a7b56ba/resourceGroups/acctestRG-6423544310546596076/providers/Microsoft.ServiceBus/namespaces/acctestservicebusnamespace-6423544310546596076/queues/acctestservicebusqueue-6423544310546596076
		  auto_delete_on_idle = 10675199.02:48:05.4775807
		  default_message_ttl = 10675199.02:48:05.4775807
		  duplicate_detection_history_time_window = 00:10:00
		  enable_batched_operations = false
		  enable_express = false
		  enable_partitioning = false
		  location = westus
		  max_size_in_megabytes = 5120
		  name = acctestservicebusqueue-6423544310546596076
		  namespace_name = acctestservicebusnamespace-6423544310546596076
		  requires_duplicate_detection = false
		  resource_group_name = acctestRG-6423544310546596076
		  support_ordering = false

		  Dependencies:
		    azurerm_resource_group.test
		    azurerm_servicebus_namespace.test

Please can you look into the tests?

Thanks

Paul

@iljaskevic
Copy link
Author

Hi @stack72
Hmmm. That's interesting...
I've ran all the tests locally and they all passed. I'll take a look into why it's failing.
Thanks,

  • Igor

@tombuildsstuff tombuildsstuff self-assigned this Jul 4, 2017
tombuildsstuff added a commit to hashicorp/terraform-provider-azurerm that referenced this pull request Jul 4, 2017
tombuildsstuff pushed a commit to hashicorp/terraform-provider-azurerm that referenced this pull request Jul 4, 2017
tombuildsstuff pushed a commit to hashicorp/terraform-provider-azurerm that referenced this pull request Jul 4, 2017
@tombuildsstuff
Copy link
Contributor

Hey @iljaskevic

Since this PR was opened the AzureRM Provider has been moved out of this repository as part of the Provider Split in Terraform 0.10. Due to this the PR needed to be moved to the new split out repository - I hope you don't mind but I've gone ahead and done this (and retained your authorship for the original commit), and fixed the failing test that @stack72 identified and opened PR hashicorp/terraform-provider-azurerm#151

As such - I'm going to close this PR in favour of the split-out one - but I'd like to thank you for your contribution :)

Thanks!

stack72 pushed a commit to hashicorp/terraform-provider-azurerm that referenced this pull request Jul 5, 2017
* Importing the work from hashicorp/terraform#14631 by @iljaskevic

* Refactoring the tests

* Formatting

* Importing the docs

* Refactoring

* Making `duplicate_detection_history_time_window` computed

* Refactoring the tests

* Fixing the formatting
@ghost
Copy link

ghost commented Apr 8, 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 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants