-
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.
New Resources: Notification Hubs (#1589)
* Making the messaging highlight consistent * New Resources: `azurerm_notification_hub` & `azurerm_notification_hub_namespace` * Fixing a merge conflict * Vendoring v18.0.0 of the Notification Hubs SDK * Sidebar: making the message highlight consistent * Adding placeholders for the documentation * Fixing Notification Hub Namespaces ``` $ acctests azurerm TestAccAzureRMNotificationHubNamespace_ === RUN TestAccAzureRMNotificationHubNamespace_importFree --- PASS: TestAccAzureRMNotificationHubNamespace_importFree (134.35s) === RUN TestAccAzureRMNotificationHubNamespace_free --- PASS: TestAccAzureRMNotificationHubNamespace_free (126.57s) === RUN TestAccAzureRMNotificationHubNamespace_updateSku --- PASS: TestAccAzureRMNotificationHubNamespace_updateSku (143.16s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 404.111s ``` * New Data Source: `azurerm_notification_hub_namespace` ``` $ acctests azurerm TestAccDataSourceAzureRMNotificationHubNamespace_free === RUN TestAccDataSourceAzureRMNotificationHubNamespace_free --- PASS: TestAccDataSourceAzureRMNotificationHubNamespace_free (130.03s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 130.081s ``` * New Resource `azurerm_notification_hub` ``` $ acctests azurerm TestAccAzureRMNotificationHub_basic === RUN TestAccAzureRMNotificationHub_basic --- PASS: TestAccAzureRMNotificationHub_basic (284.22s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 284.273s ``` * New Data Source: `azurerm_notification_hub` ``` ``` * Working around a bug where APNS/GCM credentials couldn't be removed Renaming the fields to better match the portal/terms used in Apple/Google Dev Portals * Better documenting the Token field * New Resource: `azurerm_notification_hub_authorization_rule` Tests pass: ``` ``` * Polling on our own, since the delete Future's broken Tests pass: ``` $ acctests azurerm TestAccAzureRMNotificationHubNamespace_ === RUN TestAccAzureRMNotificationHubNamespace_importFree --- PASS: TestAccAzureRMNotificationHubNamespace_importFree (71.04s) === RUN TestAccAzureRMNotificationHubNamespace_free --- PASS: TestAccAzureRMNotificationHubNamespace_free (73.17s) === RUN TestAccAzureRMNotificationHubNamespace_updateSku --- PASS: TestAccAzureRMNotificationHubNamespace_updateSku (86.43s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 230.677s ``` * Fixing a bug in the tests * Adding an acceptance test to ensure the access keys are set * Adding a link to the bug * Making SKU Name Force-New due to a difference in the API ``` azurerm_notification_hub_namespace.test: Error creating/updating Notification Hub Namesapce "acctestnhn-4049058900878420170" (Resource Group "acctestrg-4049058900878420170"): notificationhubs.NamespacesClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="Conflict" Message="Namespace acctestnhn-4049058900878420170 is in state Created. Cannot update the property" ``` * repeatidly triggering deletes * Removing dead code / adding a comment for why we re-trigger deletion * Moving the APNS Endpoints to Constants
- Loading branch information
1 parent
47dcdfb
commit 724bff9
Showing
43 changed files
with
6,722 additions
and
35 deletions.
There are no files selected for viewing
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
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,176 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceNotificationHub() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceNotificationHubRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"namespace_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"location": locationForDataSourceSchema(), | ||
|
||
"apns_credential": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"application_mode": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"bundle_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
// Team ID (within Apple & the Portal) == "AppID" (within the API) | ||
"team_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"token": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"gcm_credential": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"api_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: 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": tagsForDataSourceSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNotificationHubRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).notificationHubsClient | ||
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.Get(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Notification Hub %q was not found in Namespace %q / Resource Group %q", name, namespaceName, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) | ||
} | ||
|
||
credentials, err := client.GetPnsCredentials(ctx, resourceGroup, namespaceName, name) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving Credentials for Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("namespace_name", namespaceName) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*location)) | ||
} | ||
|
||
if props := credentials.PnsCredentialsProperties; props != nil { | ||
apns := flattenNotificationHubsDataSourceAPNSCredentials(props.ApnsCredential) | ||
if d.Set("apns_credential", apns); err != nil { | ||
return fmt.Errorf("Error setting `apns_credential`: %+v", err) | ||
} | ||
|
||
gcm := flattenNotificationHubsDataSourceGCMCredentials(props.GcmCredential) | ||
if d.Set("gcm_credential", gcm); err != nil { | ||
return fmt.Errorf("Error setting `gcm_credential`: %+v", err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func flattenNotificationHubsDataSourceAPNSCredentials(input *notificationhubs.ApnsCredential) []interface{} { | ||
if input == nil { | ||
return make([]interface{}, 0) | ||
} | ||
|
||
output := make(map[string]interface{}, 0) | ||
|
||
if bundleId := input.AppName; bundleId != nil { | ||
output["bundle_id"] = *bundleId | ||
} | ||
|
||
if endpoint := input.Endpoint; endpoint != nil { | ||
applicationEndpoints := map[string]string{ | ||
"https://api.push.apple.com:443/3/device": "Production", | ||
"https://api.development.push.apple.com:443/3/device": "Sandbox", | ||
} | ||
applicationMode := applicationEndpoints[*endpoint] | ||
output["application_mode"] = applicationMode | ||
} | ||
|
||
if keyId := input.KeyID; keyId != nil { | ||
output["key_id"] = *keyId | ||
} | ||
|
||
if teamId := input.AppID; teamId != nil { | ||
output["team_id"] = *teamId | ||
} | ||
|
||
if token := input.Token; token != nil { | ||
output["token"] = *token | ||
} | ||
|
||
return []interface{}{output} | ||
} | ||
|
||
func flattenNotificationHubsDataSourceGCMCredentials(input *notificationhubs.GcmCredential) []interface{} { | ||
if input == nil { | ||
return []interface{}{} | ||
} | ||
|
||
output := make(map[string]interface{}, 0) | ||
if props := input.GcmCredentialProperties; props != nil { | ||
if apiKey := props.GoogleAPIKey; apiKey != nil { | ||
output["api_key"] = *apiKey | ||
} | ||
} | ||
|
||
return []interface{}{output} | ||
} |
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,109 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceNotificationHubNamespace() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: resourceArmDataSourceNotificationHubNamespaceRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"location": locationForDataSourceSchema(), | ||
|
||
"sku": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"namespace_type": { | ||
Type: schema.TypeString, | ||
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": tagsForDataSourceSchema(), | ||
|
||
"servicebus_endpoint": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmDataSourceNotificationHubNamespaceRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).notificationNamespacesClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Notification Hub Namespace %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on Notification Hub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*location)) | ||
} | ||
|
||
sku := flattenNotificationHubDataSourceNamespacesSku(resp.Sku) | ||
if err := d.Set("sku", sku); err != nil { | ||
return fmt.Errorf("Error setting `sku`: %+v", err) | ||
} | ||
|
||
if props := resp.NamespaceProperties; props != nil { | ||
d.Set("enabled", props.Enabled) | ||
d.Set("namespace_type", props.NamespaceType) | ||
d.Set("servicebus_endpoint", props.ServiceBusEndpoint) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func flattenNotificationHubDataSourceNamespacesSku(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 | ||
} |
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,43 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMNotificationHubNamespace_free(t *testing.T) { | ||
dataSourceName := "data.azurerm_notification_hub_namespace.test" | ||
rInt := acctest.RandInt() | ||
location := testLocation() | ||
config := testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt, location) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "namespace_type", "NotificationHub"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sku.0.name", "Free"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt int, location string) string { | ||
resource := testAzureRMNotificationHubNamespace_free(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_notification_hub_namespace" "test" { | ||
name = "${azurerm_notification_hub_namespace.test.name}" | ||
resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" | ||
} | ||
`, resource) | ||
} |
Oops, something went wrong.