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

New Resource r/azurerm_servicebus_namespace_virtual_network_rule #6453

Closed
wants to merge 1 commit into from

Conversation

aristosvo
Copy link
Collaborator

@aristosvo aristosvo commented Apr 13, 2020

Fixes #2255

@tombuildsstuff I changed the resource name to azurerm_servicebus_namespace_virtual_network_rule compared to the proposed name of azurerm_servicebus_subscription_virtual_network_rule, as it seems a child resource of azurerm_servicebus_namespace at this moment.

--- PASS: TestAccAzureRMServiceBusNamespaceVirtualNetworkRule_requiresImport (560.76s)
--- PASS: TestAccAzureRMServiceBusNamespaceVirtualNetworkRule_create (816.97s)

@ghost ghost added the size/XL label Apr 13, 2020
@ghost ghost added the documentation label Apr 13, 2020
@aristosvo aristosvo force-pushed the servicebusvnetrule branch 3 times, most recently from 0eee18d to e8f50da Compare April 13, 2020 19:59
@ArcturusZhang
Copy link
Contributor

Hi @aristosvo thanks for this PR.
But this looks like this PR collides with PR #6379
Based on my previous experiments, the API CreateOrUpdateVirtualNetworkRule will eventually modify the NetworkRules of the namespace, which could also be modified by calling the API CreateOrUpdateNetworkRuleSet.

You can run the following program:

func main() {
	if authorizer, err := auth.NewAuthorizerFromCLI(); err != nil {
		panic(err)
	} else {
		listVirtualNetworkRule(authorizer)
		if err := associateSBNamespaceWithVNet(authorizer); err != nil {
			panic(err)
		}
		listVirtualNetworkRule(authorizer)
	}
}

func listVirtualNetworkRule(authorizer autorest.Authorizer) {
	client := servicebus.NewNamespacesClient(subsID)
	client.Authorizer = authorizer
	for it, err := client.ListVirtualNetworkRulesComplete(ctx, resGroup, namespaceName);
	it.NotDone(); err = it.NextWithContext(ctx) {
		if err != nil {
			panic(err)
		}

		v := it.Value()
		b, _ := json.MarshalIndent(v, "", "  ")
		fmt.Println(string(b))
	}
}

// associate a service bus namespace with a virtual network
func associateSBNamespaceWithVNet(authorizer autorest.Authorizer) error {
	client := servicebus.NewNamespacesClient(subsID)
	client.Authorizer = authorizer
	rules := servicebus.NetworkRuleSet{
		NetworkRuleSetProperties: &servicebus.NetworkRuleSetProperties{
			DefaultAction:       servicebus.Deny,
			VirtualNetworkRules: &[]servicebus.NWRuleSetVirtualNetworkRules{
				{
					Subnet: &servicebus.Subnet{
						ID:to.StringPtr(subnetID),
					},
				},
			},
			IPRules:             nil,
		},
	}
	_, err := client.CreateOrUpdateNetworkRuleSet(ctx, resGroup, namespaceName, rules)
	return err
}

This little program first list all the "VirtualNetworkRule"s, and then call CreateOrUpdateNetworkRuleSet API to modify the NetworkRuleSet of the namespace, and finally list the VirtualNetworkRule again.
The result is that the second call of list will have the rule that added by CreateOrUpdateNetworkRuleSet.

@aristosvo
Copy link
Collaborator Author

aristosvo commented Apr 14, 2020

@ArcturusZhang Haha, I didn't noticed your pull request!🤣 Thanks for pointing out, I’ll close this one as it is just confusing to have both.

@aristosvo aristosvo closed this Apr 14, 2020
@ghost
Copy link

ghost commented May 14, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators May 14, 2020
@aristosvo aristosvo deleted the servicebusvnetrule branch May 14, 2020 16:11
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.

New Resource: azurerm_servicebus_subscription_virtual_network_rule
2 participants