Skip to content

[DeviceProvisioningService] Allow tags in IoT DPS create cmdlet #13411

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

Merged
merged 1 commit into from
Nov 6, 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 @@ -49,8 +49,15 @@ function Test-AzureIotDpsLifeCycle
# Create or Update Resource Group
$resourceGroup = New-AzResourceGroup -Name $ResourceGroupName -Location $Location

# Add Tags to Iot Hub Device Provisioning Service
$tags = @{}
$tags.Add($Tag1Key, $Tag1Value)

# Create Iot Hub Device Provisioning Service
$newIotDps1 = New-AzIoTDps -ResourceGroupName $ResourceGroupName -Name $IotDpsName -Location $Location
$newIotDps1 = New-AzIoTDps -ResourceGroupName $ResourceGroupName -Name $IotDpsName -Location $Location -Tag $tags
Assert-True { $newIotDps1.Name -eq $IotDpsName }
Assert-True { $newIotDps1.Tags.Count -eq 1 }
Assert-True { $newIotDps1.Tags.Item($Tag1Key) -eq $Tag1Value }

# Get Iot Hub Device Provisioning Service
$iotDps = Get-AzIoTDps -ResourceGroupName $ResourceGroupName -Name $IotDpsName
Expand All @@ -62,13 +69,6 @@ function Test-AzureIotDpsLifeCycle
$updatedIotDps1 = Get-AzIoTDps -ResourceGroupName $ResourceGroupName -Name $IotDpsName | Update-AzIotDps -AllocationPolicy $NewAllocationPolicy
Assert-True { $updatedIotDps1.Properties.AllocationPolicy -eq $NewAllocationPolicy }

# Add Tags to Iot Hub Device Provisioning Service
$tags = @{}
$tags.Add($Tag1Key, $Tag1Value)
$updatedIotDps2 = Update-AzIoTDps -ResourceGroupName $ResourceGroupName -Name $IotDpsName -Tag $tags
Assert-True { $updatedIotDps2.Tags.Count -eq 1 }
Assert-True { $updatedIotDps2.Tags.Item($Tag1Key) -eq $Tag1Value }

# Add more Tags to Iot Hub Device Provisioning Service
$tags.Clear()
$tags.Add($Tag2Key, $Tag2Value)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Allow tags in IoT Device Provisioning Service create cmdlet.

## Version 0.8.0
* Update devices provisioning service sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
namespace Microsoft.Azure.Commands.Management.DeviceProvisioningServices
{
using System;
using System.Collections;
using System.Linq;
using System.Management.Automation;
using Azure.Management.Internal.Resources;
using Azure.Management.Internal.Resources.Models;
using Microsoft.Azure.Commands.Management.DeviceProvisioningServices.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.DeviceProvisioningServices.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using DPSResources = Microsoft.Azure.Commands.Management.DeviceProvisioningServices.Properties.Resources;

[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "IoTDeviceProvisioningService", DefaultParameterSetName = ResourceParameterSet, SupportsShouldProcess = true)]
Expand Down Expand Up @@ -68,6 +71,12 @@ public class NewAzureRmIoTDeviceProvisioningService : IotDpsBaseCmdlet
[ValidateSet(new string[] { "S1" }, IgnoreCase = true)]
public string SkuName { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "IoT Device Provisioning Service instance tags. Property bag in key-value pairs in the form of a hash table.")]
[ValidateNotNullOrEmpty]
public Hashtable Tag { get; set; }

public override void ExecuteCmdlet()
{
if (ShouldProcess(Name, DPSResources.AddDeviceProvisioningService))
Expand Down Expand Up @@ -115,6 +124,11 @@ public override void ExecuteCmdlet()
provisioningServiceDescription.Sku = new IotDpsSkuInfo(IotDpsSku.S1);
}

if (this.IsParameterBound(c => c.Tag))
{
provisioningServiceDescription.Tags = this.Tag.Cast<DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
}

IotDpsCreateOrUpdate(this.ResourceGroupName, this.Name, provisioningServiceDescription);
this.WriteObject(IotDpsUtils.ToPSProvisioningServiceDescription(GetIotDpsResource(this.ResourceGroupName, this.Name)), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Create an Azure IoT Hub device provisioning service.

```
New-AzIoTDeviceProvisioningService [-ResourceGroupName] <String> [-Name] <String> [-Location <String>]
[-AllocationPolicy <String>] [-SkuName <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
[-Confirm] [<CommonParameters>]
[-AllocationPolicy <String>] [-SkuName <String>] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -25,7 +25,9 @@ For an introduction to Azure IoT Hub Device Provisioning Service, see https://do

### Example 1
```
PS C:\> New-AzIoTDeviceProvisioningService -ResourceGroupName "myresourcegroup" -Name "myiotdps"
PS C:\> $tags = @{}
PS C:\> $tags.Add('key1','value1')
PS C:\> New-AzIoTDeviceProvisioningService -ResourceGroupName "myresourcegroup" -Name "myiotdps" -Tag $tags

ResourceGroupName : myresourcegroup
Name : myiotdps
Expand All @@ -35,13 +37,13 @@ ServiceOperationsHostName : myiotdps.azure-devices-provisioning.net
IotHubs : 0
State : Active
AllocationPolicy : Hashed
Tags : {}
Tags : {[key1, value1]}
SkuName : S1
SkuTier : Standard
Etag : AAAAAAAT52k=
```

Create an Azure IoT Hub device provisioning service with the standard pricing tier S1, in the region of the resource group.
Create an Azure IoT Hub device provisioning service with the standard pricing tier S1 and tags, in the region of the resource group.

### Example 2
```
Expand Down Expand Up @@ -157,6 +159,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Tag
IoT Device Provisioning Service instance tags. Property bag in key-value pairs in the form of a hash table.

```yaml
Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

Expand Down