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: azurerm_eventhub_namespace_disaster_recovery_config #4425

Merged
merged 11 commits into from
Sep 27, 2019
2 changes: 1 addition & 1 deletion azurerm/helpers/azure/sku.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ func MinCapacitySkuNameInSlice(valid []string, minCapacity int32, ignoreCase boo
}

for _, str := range valid {
if name == str || (ignoreCase && strings.ToLower(name) == strings.ToLower(str)) {
if name == str || (ignoreCase && strings.EqualFold(name, str)) {
if capacity < minCapacity {
es = append(es, fmt.Errorf("expected %s capacity value to be greater that %d, got %d", k, minCapacity, capacity))
}
17 changes: 11 additions & 6 deletions azurerm/internal/services/eventhub/client.go
Original file line number Diff line number Diff line change
@@ -6,24 +6,29 @@ import (
)

type Client struct {
ConsumerGroupClient *eventhub.ConsumerGroupsClient
EventHubsClient *eventhub.EventHubsClient
NamespacesClient *eventhub.NamespacesClient
ConsumerGroupClient *eventhub.ConsumerGroupsClient
DisasterRecoveryConfigsClient *eventhub.DisasterRecoveryConfigsClient
EventHubsClient *eventhub.EventHubsClient
NamespacesClient *eventhub.NamespacesClient
}

func BuildClient(o *common.ClientOptions) *Client {
EventHubsClient := eventhub.NewEventHubsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&EventHubsClient.Client, o.ResourceManagerAuthorizer)

DisasterRecoveryConfigsClient := eventhub.NewDisasterRecoveryConfigsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&DisasterRecoveryConfigsClient.Client, o.ResourceManagerAuthorizer)

ConsumerGroupClient := eventhub.NewConsumerGroupsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ConsumerGroupClient.Client, o.ResourceManagerAuthorizer)

NamespacesClient := eventhub.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&NamespacesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
ConsumerGroupClient: &ConsumerGroupClient,
EventHubsClient: &EventHubsClient,
NamespacesClient: &NamespacesClient,
ConsumerGroupClient: &ConsumerGroupClient,
DisasterRecoveryConfigsClient: &DisasterRecoveryConfigsClient,
EventHubsClient: &EventHubsClient,
NamespacesClient: &NamespacesClient,
}
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
@@ -256,6 +256,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(),
"azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(),
"azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(),
"azurerm_eventhub_namespace_disaster_recovery_config": resourceArmEventHubNamespaceDisasterRecoveryConfig(),
"azurerm_eventhub_namespace": resourceArmEventHubNamespace(),
"azurerm_eventhub": resourceArmEventHub(),
"azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(),
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_rightsUpdate(t *testing.T)
}

func testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).eventhub.NamespacesClient
client := testAccProvider.Meta().(*ArmClient).eventhub.NamespacesClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

for _, rs := range s.RootModule().Resources {
@@ -144,7 +144,7 @@ func testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy(s *terraform.Stat
namespaceName := rs.Primary.Attributes["namespace_name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]

resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name)
resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return err
@@ -157,6 +157,9 @@ func testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy(s *terraform.Stat

func testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).eventhub.NamespacesClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

// Ensure we have enough information in state to look up in API
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
@@ -170,9 +173,7 @@ func testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName strin
return fmt.Errorf("Bad: no resource group found in state for Event Hub: %s", name)
}

conn := testAccProvider.Meta().(*ArmClient).eventhub.NamespacesClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name)
resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Bad: Event Hub Namespace Authorization Rule %q (namespace %q / resource group: %q) does not exist", name, namespaceName, resourceGroup)
299 changes: 299 additions & 0 deletions azurerm/resource_arm_eventhub_namespace_disaster_recovery_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
package azurerm

import (
"context"
"fmt"
"log"
"net/http"
"strconv"
"time"

"github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func resourceArmEventHubNamespaceDisasterRecoveryConfig() *schema.Resource {
return &schema.Resource{
Create: resourceArmEventHubNamespaceDisasterRecoveryConfigCreate,
Read: resourceArmEventHubNamespaceDisasterRecoveryConfigRead,
Update: resourceArmEventHubNamespaceDisasterRecoveryConfigUpdate,
Delete: resourceArmEventHubNamespaceDisasterRecoveryConfigDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateEventHubAuthorizationRuleName(),
},

"namespace_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateEventHubNamespaceName(),
},

"resource_group_name": azure.SchemaResourceGroupName(),

"partner_namespace_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceIDOrEmpty,
},

"alternate_name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateEventHubNamespaceName(),
},
},
}
}

func resourceArmEventHubNamespaceDisasterRecoveryConfigCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).eventhub.DisasterRecoveryConfigsClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for AzureRM EventHub Namespace Disaster Recovery Configs creation.")

name := d.Get("name").(string)
namespaceName := d.Get("namespace_name").(string)
resourceGroup := d.Get("resource_group_name").(string)

if features.ShouldResourcesBeImported() && d.IsNewResource() {
existing, err := client.Get(ctx, resourceGroup, namespaceName, name)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}
}

if existing.ID != nil && *existing.ID != "" {
return tf.ImportAsExistsError("azurerm_eventhub_namespace_disaster_recovery_config", *existing.ID)
}
}

parameters := eventhub.ArmDisasterRecovery{
ArmDisasterRecoveryProperties: &eventhub.ArmDisasterRecoveryProperties{
PartnerNamespace: utils.String(d.Get("partner_namespace_id").(string)),
},
}

if v, ok := d.GetOk("alternate_name"); ok {
parameters.ArmDisasterRecoveryProperties.AlternateName = utils.String(v.(string))
}

if _, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters); err != nil {
return fmt.Errorf("Error creating/updating EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
return fmt.Errorf("Error waiting for replication to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

read, err := client.Get(ctx, resourceGroup, namespaceName, name)
if err != nil {
return fmt.Errorf("Error reading EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}

if read.ID == nil {
return fmt.Errorf("Got nil ID for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q)", name, namespaceName, resourceGroup)
}

d.SetId(*read.ID)

return resourceArmEventHubNamespaceDisasterRecoveryConfigRead(d, meta)
}

func resourceArmEventHubNamespaceDisasterRecoveryConfigUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).eventhub.DisasterRecoveryConfigsClient
ctx := meta.(*ArmClient).StopContext

id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
return err
}

name := id.Path["disasterRecoveryConfigs"]
resourceGroup := id.ResourceGroup
namespaceName := id.Path["namespaces"]

if d.HasChange("partner_namespace_id") {
// break pairing
breakPair, err := client.BreakPairing(ctx, resourceGroup, namespaceName, name)
if breakPair.StatusCode != http.StatusOK {
return fmt.Errorf("Error issuing break pairing request for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
return fmt.Errorf("Error waiting for break pairing request to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}
}

parameters := eventhub.ArmDisasterRecovery{
ArmDisasterRecoveryProperties: &eventhub.ArmDisasterRecoveryProperties{
PartnerNamespace: utils.String(d.Get("partner_namespace_id").(string)),
},
}

if v, ok := d.GetOk("alternate_name"); ok {
parameters.ArmDisasterRecoveryProperties.AlternateName = utils.String(v.(string))
}

if _, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters); err != nil {
return fmt.Errorf("Error creating/updating EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
return fmt.Errorf("Error waiting for replication to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

return resourceArmEventHubNamespaceDisasterRecoveryConfigRead(d, meta)
}

func resourceArmEventHubNamespaceDisasterRecoveryConfigRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).eventhub.DisasterRecoveryConfigsClient
ctx := meta.(*ArmClient).StopContext

id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
return err
}

name := id.Path["disasterRecoveryConfigs"]
resourceGroup := id.ResourceGroup
namespaceName := id.Path["namespaces"]

resp, err := client.Get(ctx, resourceGroup, namespaceName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on Azure EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

d.Set("name", name)
d.Set("namespace_name", namespaceName)
d.Set("resource_group_name", resourceGroup)

if properties := resp.ArmDisasterRecoveryProperties; properties != nil {
d.Set("partner_namespace_id", properties.PartnerNamespace)
d.Set("alternate_name", properties.AlternateName)
}

return nil
}

func resourceArmEventHubNamespaceDisasterRecoveryConfigDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).eventhub.DisasterRecoveryConfigsClient
ctx := meta.(*ArmClient).StopContext

id, err := azure.ParseAzureResourceID(d.Id())
if err != nil {
return err
}

name := id.Path["disasterRecoveryConfigs"]
resourceGroup := id.ResourceGroup
namespaceName := id.Path["namespaces"]

breakPair, err := client.BreakPairing(ctx, resourceGroup, namespaceName, name)
if err != nil {
return fmt.Errorf("Error issuing break pairing request for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}
if breakPair.StatusCode != http.StatusOK {
return fmt.Errorf("Error breaking pairing for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if err := resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx, client, resourceGroup, namespaceName, name); err != nil {
return fmt.Errorf("Error waiting for break pairing request to complete for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

if _, err := client.Delete(ctx, resourceGroup, namespaceName, name); err != nil {
return fmt.Errorf("Error issuing delete request for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err)
}

// no future for deletion so wait for it to vanish
deleteWait := &resource.StateChangeConf{
Pending: []string{"200"},
Target: []string{"404"},
Timeout: 30 * time.Minute,
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := client.Get(ctx, resourceGroup, namespaceName, name)

if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return resp, strconv.Itoa(resp.StatusCode), nil
}
return nil, "nil", fmt.Errorf("Error polling for the status of the EventHub Namespace Disaster Recovery Configs %q deletion (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}

return resp, strconv.Itoa(resp.StatusCode), nil
},
}
if _, err := deleteWait.WaitForState(); err != nil {
return fmt.Errorf("Error waiting the deletion of EventHub Namespace Disaster Recovery Configs %q deletion (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}

// it can take some time for the name to become available again
// this is mainly here to enable updating the resource in place
nameFreeWait := &resource.StateChangeConf{
Pending: []string{"NameInUse"},
Target: []string{"None"},
Timeout: 30 * time.Minute,
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := client.CheckNameAvailability(ctx, resourceGroup, namespaceName, eventhub.CheckNameAvailabilityParameter{Name: utils.String(name)})
if err != nil {
return resp, "Error", fmt.Errorf("Error checking if the EventHub Namespace Disaster Recovery Configs %q name has been freed (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}

return resp, string(resp.Reason), nil
},
}
if _, err := nameFreeWait.WaitForState(); err != nil {
return fmt.Errorf("Error waiting the the EventHub Namespace Disaster Recovery Configs %q name to be available (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}

return nil
}

func resourceArmEventHubNamespaceDisasterRecoveryConfigWaitForState(ctx context.Context, client *eventhub.DisasterRecoveryConfigsClient, resourceGroup, namespaceName, name string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{string(eventhub.Accepted)},
Target: []string{string(eventhub.Succeeded)},
// Delay: 15 * time.Second,
Timeout: 30 * time.Minute,
MinTimeout: 30 * time.Second,
Refresh: func() (interface{}, string, error) {
read, err := client.Get(ctx, resourceGroup, namespaceName, name)
if err != nil {
return nil, "error", fmt.Errorf("Wait read EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): %v", name, namespaceName, resourceGroup, err)
}

if props := read.ArmDisasterRecoveryProperties; props != nil {
if props.ProvisioningState == eventhub.Failed {
return read, "failed", fmt.Errorf("Replication for EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q) failed!", name, namespaceName, resourceGroup)
}
return read, string(props.ProvisioningState), nil
}

return read, "nil", fmt.Errorf("Waiting for replication error EventHub Namespace Disaster Recovery Configs %q (Namespace %q / Resource Group %q): provisioning state is nil", name, namespaceName, resourceGroup)
},
}

_, err := stateConf.WaitForState()
return err
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(t *testing.T) {
resourceName := "azurerm_eventhub_namespace_disaster_recovery_config.test"
ri := tf.AccRandTimeInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(ri, testLocation(), testAltLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(t *testing.T) {
resourceName := "azurerm_eventhub_namespace_disaster_recovery_config.test"
ri := tf.AccRandTimeInt()

// skipping due to there being no way to delete a DRC once an alternate name has been set
// sdk bug: https://github.com/Azure/azure-sdk-for-go/issues/5893
t.Skip()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(ri, testLocation(), testAltLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_update(t *testing.T) {
resourceName := "azurerm_eventhub_namespace_disaster_recovery_config.test"
ri := tf.AccRandTimeInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(ri, testLocation(), testAltLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName),
),
},
{
Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated(ri, testLocation(), testAltLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(ri, testLocation(), testAltLocation()),
},
},
})
}

func testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).eventhub.DisasterRecoveryConfigsClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_eventhub_namespace_disaster_recovery_config" {
continue
}

name := rs.Primary.Attributes["name"]
namespaceName := rs.Primary.Attributes["namespace_name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]

resp, err := client.Get(ctx, resourceGroup, namespaceName, name)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Bad: EventHub Namespace Disaster Recovery Configs %q (namespace %q / resource group: %q): %+v", name, namespaceName, resourceGroup, err)
}
}
}

return nil
}

func testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).eventhub.DisasterRecoveryConfigsClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

// Ensure we have enough information in state to look up in API
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("Not found: %s", resourceName)
}

name := rs.Primary.Attributes["name"]
namespaceName := rs.Primary.Attributes["namespace_name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]

resp, err := client.Get(ctx, resourceGroup, namespaceName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Bad: EventHub Namespace Disaster Recovery Configs %q (namespace %q / resource group: %q) does not exist", name, namespaceName, resourceGroup)
}

return fmt.Errorf("Bad: EventHub Namespace Disaster Recovery Configs %q (namespace %q / resource group: %q): %+v", name, namespaceName, resourceGroup, err)
}

return nil
}
}

func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(rInt int, location string, altlocation string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_eventhub_namespace" "testa" {
name = "acctest-EHN-%[1]d-a"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace" "testb" {
name = "acctest-EHN-%[1]d-b"
location = "%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" {
name = "acctest-EHN-DRC-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
namespace_name = "${azurerm_eventhub_namespace.testa.name}"
partner_namespace_id = "${azurerm_eventhub_namespace.testb.id}"
}
`, rInt, location, altlocation)
}

func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(rInt int, location string, altlocation string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_eventhub_namespace" "testa" {
name = "acctest-EHN-%[1]d-a"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace" "testb" {
name = "acctest-EHN-%[1]d-b"
location = "%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" {
name = "${azurerm_eventhub_namespace.testa.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
namespace_name = "${azurerm_eventhub_namespace.testa.name}"
partner_namespace_id = "${azurerm_eventhub_namespace.testb.id}"
alternate_name = "acctest-EHN-DRC-%[1]d-alt"
}
`, rInt, location, altlocation)
}

func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated(rInt int, location string, altlocation string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_eventhub_namespace" "testa" {
name = "acctest-EHN-%[1]d-a"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace" "testb" {
name = "acctest-EHN-%[1]d-b"
location = "%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace" "testc" {
name = "acctest-EHN-%[1]d-c"
location = "%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" {
name = "acctest-EHN-DRC-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
namespace_name = "${azurerm_eventhub_namespace.testa.name}"
partner_namespace_id = "${azurerm_eventhub_namespace.testc.id}"
}
`, rInt, location, altlocation)
}

func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(rInt int, location string, altlocation string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_eventhub_namespace" "testa" {
name = "acctest-EHN-%[1]d-a"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace" "testb" {
name = "acctest-EHN-%[1]d-b"
location = "%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace" "testc" {
name = "acctest-EHN-%[1]d-c"
location = "%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
}
`, rInt, location, altlocation)
}
4 changes: 4 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
@@ -1253,6 +1253,10 @@
<a href="/docs/providers/azurerm/r/eventhub_authorization_rule.html">azurerm_eventhub_authorization_rule</a>
</li>

<li>
<a href="/docs/providers/azurerm/r/eventhub_namespace_disaster_recovery_config.html">azurerm_eventhub_namespace_disaster_recovery_config</a>
</li>

<li>
<a href="/docs/providers/azurerm/r/eventhub_consumer_group.html">azurerm_eventhub_consumer_group</a>
</li>
Original file line number Diff line number Diff line change
@@ -13,12 +13,12 @@ Manages an Authorization Rule for an Event Hub Namespace.
## Example Usage

```hcl
resource "azurerm_resource_group" "test" {
name = "resourceGroup1"
resource "azurerm_resource_group" "example" {
name = "resourcegroup"
location = "West US"
}
resource "azurerm_eventhub_namespace" "test" {
resource "azurerm_eventhub_namespace" "example" {
name = "acceptanceTestEventHubNamespace"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
@@ -30,7 +30,7 @@ resource "azurerm_eventhub_namespace" "test" {
}
}
resource "azurerm_eventhub_namespace_authorization_rule" "test" {
resource "azurerm_eventhub_namespace_authorization_rule" "example" {
name = "navi"
namespace_name = "${azurerm_eventhub_namespace.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
@@ -63,7 +63,7 @@ The following arguments are supported:

The following attributes are exported:

* `id` - The EventHub ID.
* `id` - The EventHub Namespace Authorization Rule ID.

* `primary_key` - The Primary Key for the Authorization Rule.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_eventhub_namespace_disaster_recovery_config"
sidebar_current: "docs-azurerm-resource-messaging-eventhub-namespace-disaster-recovery-config"
description: |-
Manages an Disaster Recovery Config for an Event Hub Namespace.
---

# azurerm_eventhub_namespace_disaster_recovery_config

Manages an Disaster Recovery Config for an Event Hub Namespace.

## Example Usage

```hcl
resource "azurerm_resource_group" "example" {
name = "eventhub-replication"
location = "West Europe"
}
resource "azurerm_eventhub_namespace" "primary" {
name = "eventhub-primary"
location = "${azurerm_resource_group.example.location}"
resource_group_name = "${azurerm_resource_group.example.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace" "secondary" {
name = "eventhub-secondary"
location = "West US"
resource_group_name = "${azurerm_resource_group.example.name}"
sku = "Standard"
}
resource "azurerm_eventhub_namespace_disaster_recovery_config" "example" {
name = "replicate-evenhub"
resource_group_name = "${azurerm_resource_group.example.name}"
namespace_name = "${azurerm_eventhub_namespace.primary.name}"
partner_namespace_id = "${azurerm_eventhub_namespace.secondary.id}"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Specifies the name of the Disaster Recovery Config. Changing this forces a new resource to be created.

* `namespace_name` - (Required) Specifies the name of the primary EventHub Namespace to replicate. Changing this forces a new resource to be created.

* `resource_group_name` - (Required) The name of the resource group in which the Disaster Recovery Config exists. Changing this forces a new resource to be created.

* `partner_namespace_id` - (Optional) The ID of the EventHub Namespace to replicate to.

* `alternate_name` - (Optional) An alternate name to use when the Disaster Recovery Config's name is the same as the replicated namespace's name.

* `wait_for_replication` - (Optional) Should the resource wait for replication upon creation? Defaults to `false`.

## Attributes Reference

The following attributes are exported:

* `id` - The EventHub Namespace Disaster Recovery Config ID.

## Import

EventHubs can be imported using the `resource id`, e.g.

```shell
terraform import azurerm_eventhub_namespace_disaster_recovery_config.config1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/disasterRecoveryConfigs/config1
```