Skip to content

Commit

Permalink
notificationhub to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored and tombuildsstuff committed Feb 13, 2020
1 parent b9b3dc1 commit 0760ba8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,9 @@ func resourceArmNotificationHubNamespace() *schema.Resource {

"location": azure.SchemaLocation(),

"sku": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider",
ConflictsWith: []string{"sku_name"},
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(notificationhubs.Basic),
string(notificationhubs.Free),
string(notificationhubs.Standard),
}, false),
},
},
},
},

"sku_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"sku"},
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(notificationhubs.Basic),
string(notificationhubs.Free),
Expand Down Expand Up @@ -121,25 +95,8 @@ func resourceArmNotificationHubNamespaceCreateUpdate(d *schema.ResourceData, met
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

// Remove in 2.0
var sku notificationhubs.Sku

if inputs := d.Get("sku").([]interface{}); len(inputs) != 0 {
input := inputs[0].(map[string]interface{})
v := input["name"].(string)

sku = notificationhubs.Sku{
Name: notificationhubs.SkuName(v),
}
} else {
// Keep in 2.0
sku = notificationhubs.Sku{
Name: notificationhubs.SkuName(d.Get("sku_name").(string)),
}
}

if sku.Name == "" {
return fmt.Errorf("either 'sku_name' or 'sku' must be defined in the configuration file")
sku := notificationhubs.Sku{
Name: notificationhubs.SkuName(d.Get("sku_name").(string)),
}

name := d.Get("name").(string)
Expand Down Expand Up @@ -236,11 +193,6 @@ func resourceArmNotificationHubNamespaceRead(d *schema.ResourceData, meta interf
}

if sku := resp.Sku; sku != nil {
// Remove in 2.0
if err := d.Set("sku", flattenNotificationHubNamespacesSku(sku)); err != nil {
return fmt.Errorf("Error setting 'sku': %+v", err)
}

if err := d.Set("sku_name", string(sku.Name)); err != nil {
return fmt.Errorf("Error setting 'sku_name': %+v", err)
}
Expand Down Expand Up @@ -292,20 +244,6 @@ func resourceArmNotificationHubNamespaceDelete(d *schema.ResourceData, meta inte
return nil
}

// Remove in 2.0
func flattenNotificationHubNamespacesSku(input *notificationhubs.Sku) []interface{} {
outputs := make([]interface{}, 0)
if input == nil {
return outputs
}

output := map[string]interface{}{
"name": string(input.Name),
}
outputs = append(outputs, output)
return outputs
}

func notificationHubNamespaceStateRefreshFunc(ctx context.Context, client *notificationhubs.NamespacesClient, resourceGroupName string, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.Get(ctx, resourceGroupName, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tests
import (
"fmt"
"net/http"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -31,41 +30,6 @@ func TestAccAzureRMNotificationHubNamespace_free(t *testing.T) {
})
}

// Remove in 2.0
func TestAccAzureRMNotificationHubNamespace_freeClassic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_notification_hub_namespace", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNotificationHubNamespace_freeClassic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNotificationHubNamespaceExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

// Remove in 2.0
func TestAccAzureRMNotificationHubNamespace_freeNotDefined(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_notification_hub_namespace", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNotificationHubNamespace_freeNotDefined(data),
ExpectError: regexp.MustCompile("either 'sku_name' or 'sku' must be defined in the configuration file"),
},
},
})
}

func TestAccAzureRMNotificationHubNamespace_requiresImport(t *testing.T) {
if !features.ShouldResourcesBeImported() {
t.Skip("Skipping since resources aren't required to be imported")
Expand Down Expand Up @@ -158,42 +122,6 @@ resource "azurerm_notification_hub_namespace" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMNotificationHubNamespace_freeClassic(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_notification_hub_namespace" "test" {
name = "acctestnhn-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
namespace_type = "NotificationHub"
sku {
name = "Free"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMNotificationHubNamespace_freeNotDefined(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_notification_hub_namespace" "test" {
name = "acctestnhn-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
namespace_type = "NotificationHub"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMNotificationHubNamespace_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMNotificationHubNamespace_free(data)
return fmt.Sprintf(`
Expand Down
6 changes: 6 additions & 0 deletions website/docs/guides/2.0-upgrade-guide.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ The `load_balancer_backend_address_pools_ids` field in the `ip_configuration` bl

The `load_balancer_inbound_nat_rules_ids` field in the `ip_configuration` block will been removed. This has been replaced by the `azurerm_network_interface_nat_rule_association` resource.

## Resource: `azurerm_notification_hub_namespace`

The deprecated `sku` block has been replaced by the `sku_name` field and will be removed.

The `sku_name` field will become Required.

### Resource: `azurerm_packet_capture`

The `azurerm_packet_capture` resource will be deprecated in favour of a new resources `azurerm_network_packet_capture`.
Expand Down
8 changes: 0 additions & 8 deletions website/docs/r/notification_hub_namespace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,10 @@ The following arguments are supported:

* `namespace_type` - (Required) The Type of Namespace - possible values are `Messaging` or `NotificationHub`. Changing this forces a new resource to be created.

* `sku` - (Optional **Deprecated**)) A `sku` block as described below.

* `sku_name` - (Optional) The name of the SKU to use for this Notification Hub Namespace. Possible values are `Free`, `Basic` or `Standard`. Changing this forces a new resource to be created.

* `enabled` - (Optional) Is this Notification Hub Namespace enabled? Defaults to `true`.

----

A `sku` block contains:

* `name` - (Required) The name of the SKU to use for this Notification Hub Namespace. Possible values are `Free`, `Basic` or `Standard`. Changing this forces a new resource to be created.

## Attributes Reference

The following attributes are exported:
Expand Down

0 comments on commit 0760ba8

Please sign in to comment.