-
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.
Data source azurerm servicebus namespace authorization rule (#4294)
- Loading branch information
Showing
5 changed files
with
271 additions
and
88 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
azurerm/data_source_servicebus_namespace_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,86 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmServiceBusNamespaceAuthorizationRule() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmServiceBusNamespaceAuthorizationRuleRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: azure.ValidateServiceBusNamespaceName(), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"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 dataSourceArmServiceBusNamespaceAuthorizationRuleRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).servicebus.NamespacesClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
namespaceName := d.Get("namespace_name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("ServiceBus Namespace Authorization Rule %q was not found in Resource Group %q", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error retrieving ServiceBus Namespace Authorization Rule %q (Resource Group %q, Namespace %q): %s", name, resourceGroup, namespaceName, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
keysResp, err := client.ListKeys(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making Read request on Azure ServiceBus Namespace 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 | ||
} |
47 changes: 47 additions & 0 deletions
47
azurerm/data_source_servicebus_namespace_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,47 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMServiceBusNamespaceRule_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_servicebus_namespace_authorization_rule.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMServiceBusNamespaceAuthorizationRuleDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAzureRMServiceBusNamespaceAuthorizationRule_basic(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMServiceBusNamespaceExists(dataSourceName), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "primary_connection_string"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "primary_key"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "secondary_connection_string"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "secondary_key"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMServiceBusNamespaceAuthorizationRule_basic(rInt int, location string) string { | ||
template := testAccAzureRMServiceBusNamespaceAuthorizationRule_base(rInt, location, true, true, true) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_servicebus_namespace_authorization_rule" "test" { | ||
name = "${azurerm_servicebus_namespace_authorization_rule.test.name}" | ||
namespace_name = "${azurerm_servicebus_namespace.test.name}" | ||
resource_group_name = "${azurerm_resource_group.test.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
Oops, something went wrong.