-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new data source `azurerm_servicebus_topic_authorization_r… (#6017)
Fixes #5988
- Loading branch information
1 parent
1c09b63
commit 3d7691c
Showing
8 changed files
with
254 additions
and
8 deletions.
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
131 changes: 131 additions & 0 deletions
131
azurerm/internal/services/servicebus/data_source_servicebus_topic_authorization_rule.go
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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package servicebus | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmServiceBusTopicAuthorizationRule() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmServiceBusTopicAuthorizationRuleRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateServiceBusAuthorizationRuleName(), | ||
}, | ||
|
||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateServiceBusNamespaceName(), | ||
}, | ||
|
||
"topic_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateServiceBusTopicName(), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupName(), | ||
|
||
"listen": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"send": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"manage": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"primary_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"primary_connection_string": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"secondary_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
|
||
"secondary_connection_string": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmServiceBusTopicAuthorizationRuleRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*clients.Client).ServiceBus.TopicsClient | ||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||
defer cancel() | ||
|
||
name := d.Get("name").(string) | ||
namespaceName := d.Get("namespace_name").(string) | ||
topicName := d.Get("topic_name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, topicName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("ServiceBus Topic Authorization Rule %q (Resource Group %q / Namespace Name %q) was not found", name, resourceGroup, namespaceName) | ||
} | ||
return fmt.Errorf("Error making Read request on Azure ServiceBus Topic Authorization Rule %s: %+v", name, err) | ||
} | ||
|
||
d.Set("name", name) | ||
d.Set("topic_name", topicName) | ||
d.Set("namespace_name", namespaceName) | ||
d.Set("resource_group_name", resourceGroup) | ||
|
||
if properties := resp.SBAuthorizationRuleProperties; properties != nil { | ||
listen, send, manage := azure.FlattenServiceBusAuthorizationRuleRights(properties.Rights) | ||
d.Set("listen", listen) | ||
d.Set("send", send) | ||
d.Set("manage", manage) | ||
} | ||
|
||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("API returned a nil/empty id for ServiceBus Topic Authorization Rule %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
d.SetId(*resp.ID) | ||
|
||
keysResp, err := client.ListKeys(ctx, resourceGroup, namespaceName, topicName, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making Read request on Azure ServiceBus Topic Authorization Rule List Keys %s: %+v", name, err) | ||
} | ||
|
||
d.Set("primary_key", keysResp.PrimaryKey) | ||
d.Set("primary_connection_string", keysResp.PrimaryConnectionString) | ||
d.Set("secondary_key", keysResp.SecondaryKey) | ||
d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) | ||
|
||
return 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
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
48 changes: 48 additions & 0 deletions
48
...nternal/services/servicebus/tests/data_source_servicebus_topic_authorization_rule_test.go
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" | ||
) | ||
|
||
func TestAccDataSourceAzureRMServiceBusTopicAuthorizationRule_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_servicebus_topic_authorization_rule", "test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acceptance.PreCheck(t) }, | ||
Providers: acceptance.SupportedProviders, | ||
CheckDestroy: testCheckAzureRMServiceBusTopicAuthorizationRuleDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAzureRMServiceBusTopicAuthorizationRule_basic(data), | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMServiceBusTopicAuthorizationRuleExists(data.ResourceName), | ||
resource.TestCheckResourceAttrSet(data.ResourceName, "id"), | ||
resource.TestCheckResourceAttrSet(data.ResourceName, "name"), | ||
resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), | ||
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), | ||
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), | ||
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), | ||
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMServiceBusTopicAuthorizationRule_basic(data acceptance.TestData) string { | ||
template := testAccAzureRMServiceBusTopicAuthorizationRule_base(data, true, true, true) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_servicebus_topic_authorization_rule" "test" { | ||
name = azurerm_servicebus_topic_authorization_rule.test.name | ||
namespace_name = azurerm_servicebus_topic_authorization_rule.test.namespace_name | ||
resource_group_name = azurerm_servicebus_topic_authorization_rule.test.resource_group_name | ||
topic_name = azurerm_servicebus_topic_authorization_rule.test.topic_name | ||
} | ||
`, template) | ||
} |
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
59 changes: 59 additions & 0 deletions
59
website/docs/d/servicebus_topic_authorization_rule.html.markdown
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
subcategory: "Messaging" | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_servicebus_topic_authorization_rule" | ||
description: |- | ||
Gets information about a ServiceBus Topic authorization Rule within a ServiceBus Topic. | ||
--- | ||
|
||
# Data Source: azurerm_servicebus_topic_authorization_rule | ||
|
||
Use this data source to access information about a ServiceBus Topic Authorization Rule within a ServiceBus Topic. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_servicebus_topic_authorization_rule" "example" { | ||
name = "example-tfex_name" | ||
resource_group_name = "example-resources" | ||
namespace_name = "example-namespace" | ||
topic_name = "example-servicebus_topic" | ||
} | ||
output "servicebus_authorization_rule_id" { | ||
value = "${data.azurem_servicebus_topic_authorization_rule.example.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - The name of the ServiceBus Topic Authorization Rule resource. | ||
|
||
* `resource_group_name` - The name of the resource group in which the ServiceBus Namespace exists. | ||
|
||
* `namespace_name` - The name of the ServiceBus Namespace. | ||
|
||
* `topic_name` - The name of the ServiceBus Topic. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The ServiceBus Topic ID. | ||
|
||
* `primary_key` - The Primary Key for the ServiceBus Topic authorization Rule. | ||
|
||
* `primary_connection_string` - The Primary Connection String for the ServiceBus Topic authorization Rule. | ||
|
||
* `secondary_key` - The Secondary Key for the ServiceBus Topic authorization Rule. | ||
|
||
* `secondary_connection_string` - The Secondary Connection String for the ServiceBus Topic authorization Rule. | ||
|
||
## Timeouts | ||
|
||
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: | ||
|
||
* `read` - (Defaults to 5 minutes) Used when retrieving the ServiceBus Topic Authorization Rule. |