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

notificationhub to 2.0 #5722

Merged
merged 4 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -355,10 +355,7 @@ resource "azurerm_notification_hub_namespace" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
namespace_type = "NotificationHub"

sku {
name = "Free"
}
sku_name = "Free"
}

resource "azurerm_notification_hub" "test" {
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ resource "azurerm_notification_hub_namespace" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
namespace_type = "NotificationHub"

sku {
name = "Free"
}
sku_name = "Free"
}

resource "azurerm_notification_hub" "test" {
Expand All @@ -144,10 +141,10 @@ func testAccAzureRMNotificationHub_requiresImport(data acceptance.TestData) stri
%s

resource "azurerm_notification_hub" "import" {
name = "${azurerm_notification_hub.test.name}"
namespace_name = "${azurerm_notification_hub.test.namespace_name}"
resource_group_name = "${azurerm_notification_hub.test.resource_group_name}"
location = "${azurerm_notification_hub.test.location}"
name = azurerm_notification_hub.test.name
namespace_name = azurerm_notification_hub.test.namespace_name
resource_group_name = azurerm_notification_hub.test.resource_group_name
location = azurerm_notification_hub.test.location
}
`, template)
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ resource "azurerm_notification_hub_namespace" "example" {
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
namespace_type = "NotificationHub"

sku_name = "Free"
sku_name = "Free"
}

resource "azurerm_notification_hub" "example" {
Expand Down
13 changes: 2 additions & 11 deletions website/docs/r/notification_hub_namespace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ resource "azurerm_notification_hub_namespace" "example" {
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
namespace_type = "NotificationHub"

sku_name = "Free"
sku_name = "Free"
}
```

Expand All @@ -41,18 +40,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.
* `sku_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.

* `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