diff --git a/azurerm/internal/services/notificationhub/data_source_notification_hub.go b/azurerm/internal/services/notificationhub/data_source_notification_hub.go index 5201572add81..f97da1f87c84 100644 --- a/azurerm/internal/services/notificationhub/data_source_notification_hub.go +++ b/azurerm/internal/services/notificationhub/data_source_notification_hub.go @@ -8,6 +8,7 @@ import ( "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/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -80,9 +81,7 @@ func dataSourceNotificationHub() *schema.Resource { }, }, - // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case - // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 - // "tags": tags.SchemaDataSource(), + "tags": tags.SchemaDataSource(), }, } } @@ -131,7 +130,7 @@ func dataSourceNotificationHubRead(d *schema.ResourceData, meta interface{}) err } } - return nil + return tags.FlattenAndSet(d, resp.Tags) } func flattenNotificationHubsDataSourceAPNSCredentials(input *notificationhubs.ApnsCredential) []interface{} { diff --git a/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace.go b/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace.go index dd6a018279ee..e7dbd0297a04 100644 --- a/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace.go +++ b/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace.go @@ -8,6 +8,7 @@ import ( "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/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -53,9 +54,7 @@ func dataSourceNotificationHubNamespace() *schema.Resource { Computed: true, }, - // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case - // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 - // "tags": tags.SchemaDataSource(), + "tags": tags.SchemaDataSource(), "servicebus_endpoint": { Type: schema.TypeString, @@ -101,7 +100,7 @@ func resourceArmDataSourceNotificationHubNamespaceRead(d *schema.ResourceData, m d.Set("servicebus_endpoint", props.ServiceBusEndpoint) } - return nil + return tags.FlattenAndSet(d, resp.Tags) } func flattenNotificationHubDataSourceNamespacesSku(input *notificationhubs.Sku) []interface{} { diff --git a/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go index e393be9ac470..0651beb565c2 100644 --- a/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go @@ -15,6 +15,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -135,9 +136,7 @@ func resourceArmNotificationHub() *schema.Resource { }, }, - // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case - // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 - // "tags": tags.Schema(), + "tags": tags.Schema(), }, } } @@ -171,6 +170,7 @@ func resourceArmNotificationHubCreateUpdate(d *schema.ResourceData, meta interfa ApnsCredential: expandNotificationHubsAPNSCredentials(d.Get("apns_credential").([]interface{})), GcmCredential: expandNotificationHubsGCMCredentials(d.Get("gcm_credential").([]interface{})), }, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if _, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters); err != nil { @@ -274,7 +274,7 @@ func resourceArmNotificationHubRead(d *schema.ResourceData, meta interface{}) er } } - return nil + return tags.FlattenAndSet(d, resp.Tags) } func resourceArmNotificationHubDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go index 894852a5fe27..afa06d86d5b2 100644 --- a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go @@ -17,6 +17,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -78,9 +79,7 @@ func resourceArmNotificationHubNamespace() *schema.Resource { DiffSuppressFunc: suppress.CaseDifference, }, - // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case - // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 - // "tags": tags.Schema(), + "tags": tags.Schema(), "servicebus_endpoint": { Type: schema.TypeString, @@ -126,6 +125,7 @@ func resourceArmNotificationHubNamespaceCreateUpdate(d *schema.ResourceData, met NamespaceType: notificationhubs.NamespaceType(namespaceType), Enabled: utils.Bool(enabled), }, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if _, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters); err != nil { return fmt.Errorf("Error creating/updating Notification Hub Namesapce %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -206,7 +206,7 @@ func resourceArmNotificationHubNamespaceRead(d *schema.ResourceData, meta interf d.Set("servicebus_endpoint", props.ServiceBusEndpoint) } - return nil + return tags.FlattenAndSet(d, resp.Tags) } func resourceArmNotificationHubNamespaceDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go index b0a9b9871aae..e3226e876986 100644 --- a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go @@ -20,6 +20,7 @@ func TestAccDataSourceAzureRMNotificationHubNamespace_free(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(data.ResourceName, "namespace_type", "NotificationHub"), resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, }, diff --git a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go index bbd7c64e3111..8e9403ba12f0 100644 --- a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go @@ -20,6 +20,7 @@ func TestAccDataSourceAzureRMNotificationHub_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(data.ResourceName, "apns_credential.#", "0"), resource.TestCheckResourceAttr(data.ResourceName, "gcm_credential.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, }, diff --git a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go index e511870cde39..e472cebdcd28 100644 --- a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go @@ -30,6 +30,41 @@ func TestAccAzureRMNotificationHubNamespace_free(t *testing.T) { }) } +func TestAccAzureRMNotificationHubNamespace_updateTag(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_free(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNotificationHubNamespace_withoutTag(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNotificationHubNamespace_free(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMNotificationHubNamespace_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -115,6 +150,32 @@ resource "azurerm_resource_group" "test" { 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" + + tags = { + env = "Test" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMNotificationHubNamespace_withoutTag(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +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 diff --git a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go index ab1c71f9f104..3265b113674a 100644 --- a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go @@ -32,6 +32,41 @@ func TestAccAzureRMNotificationHub_basic(t *testing.T) { }) } +func TestAccAzureRMNotificationHub_updateTag(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_notification_hub", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNotificationHubDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNotificationHub_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNotificationHub_withoutTag(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNotificationHub_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMNotificationHub_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -130,6 +165,38 @@ resource "azurerm_notification_hub_namespace" "test" { sku_name = "Free" } +resource "azurerm_notification_hub" "test" { + name = "acctestnh-%d" + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + tags = { + env = "Test" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMNotificationHub_withoutTag(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRGpol-%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" +} + resource "azurerm_notification_hub" "test" { name = "acctestnh-%d" namespace_name = azurerm_notification_hub_namespace.test.name diff --git a/website/docs/d/notification_hub.html.markdown b/website/docs/d/notification_hub.html.markdown index 7968d1852c1b..12c2c07d84de 100644 --- a/website/docs/d/notification_hub.html.markdown +++ b/website/docs/d/notification_hub.html.markdown @@ -42,6 +42,8 @@ output "id" { * `gcm_credential` - A `gcm_credential` block as defined below. +* `tags` - A mapping of tags to assign to the resource. + --- A `apns_credential` block exports: diff --git a/website/docs/d/notification_hub_namespace.html.markdown b/website/docs/d/notification_hub_namespace.html.markdown index 7b2b7b4d6c72..4cf357a67f61 100644 --- a/website/docs/d/notification_hub_namespace.html.markdown +++ b/website/docs/d/notification_hub_namespace.html.markdown @@ -41,6 +41,8 @@ output "servicebus_endpoint" { * `enabled` - Is this Notification Hub Namespace enabled? +* `tags` - A mapping of tags to assign to the resource. + --- A `sku` block exports the following: diff --git a/website/docs/r/notification_hub.html.markdown b/website/docs/r/notification_hub.html.markdown index 5a37c480f151..aa84cc3fdab9 100644 --- a/website/docs/r/notification_hub.html.markdown +++ b/website/docs/r/notification_hub.html.markdown @@ -56,6 +56,8 @@ The following arguments are supported: ~> **NOTE:** Removing the `gcm_credential` block will currently force a recreation of this resource [due to this bug in the Azure SDK for Go](https://github.com/Azure/azure-sdk-for-go/issues/2246) - we'll remove this limitation when the SDK bug is fixed. +* `tags` - (Optional) A mapping of tags to assign to the resource. + --- A `apns_credential` block contains: diff --git a/website/docs/r/notification_hub_namespace.html.markdown b/website/docs/r/notification_hub_namespace.html.markdown index e38ed7cb2730..021eb33aac8a 100644 --- a/website/docs/r/notification_hub_namespace.html.markdown +++ b/website/docs/r/notification_hub_namespace.html.markdown @@ -44,6 +44,8 @@ The following arguments are supported: * `enabled` - (Optional) Is this Notification Hub Namespace enabled? Defaults to `true`. +* `tags` - (Optional) A mapping of tags to assign to the resource. + ## Attributes Reference The following attributes are exported: