Skip to content

Commit 9e96c00

Browse files
committed
adding alias target resource id in command and its test case
1 parent 34745ec commit 9e96c00

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/RecordsTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public RecordsTests(Xunit.Abstractions.ITestOutputHelper output)
2626
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
2727
}
2828

29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestAliasRecordSet()
32+
{
33+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-AliasRecordSet");
34+
}
35+
2936
[Fact]
3037
[Trait(Category.AcceptanceType, Category.CheckIn)]
3138
public void TestRecordSetCrud()

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/RecordsTests.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,48 @@ function Test-RecordSetCrud
8585
Remove-AzureRmResourceGroup -Name $resourceGroup.ResourceGroupName -Force
8686
}
8787

88+
<#
89+
.SYNOPSIS
90+
Test Alias Record Set
91+
#>
92+
function Test-AliasRecordSet
93+
{
94+
$zoneName = Get-RandomZoneName
95+
$recordName = getAssetname
96+
$subscription = getSubscription
97+
$resourceGroup = TestSetup-CreateResourceGroup
98+
$recordType = "A"
99+
$zone = $resourceGroup | New-AzureRmDnsZone -Name $zoneName
100+
101+
# non alias record
102+
$record = $zone | New-AzureRmDnsRecordSet -Name $recordName -Ttl 100 -RecordType $recordType -DnsRecords @()
103+
$record = $record | Add-AzureRmDnsRecordConfig -Ipv4Address 1.1.1.1
104+
$record = $record | Add-AzureRmDnsRecordConfig -Ipv4Address 2.2.2.2
105+
$record = $record | Set-AzureRmDnsRecordSet
106+
107+
# alias record pointing to non-alias record
108+
$aliasRecordName = "alias" + $(getAssetname)
109+
$aliasResourceId = "/subscriptions/$subscription/resourceGroups/$($resourceGroup.ResourceGroupName)/providers/Microsoft.Network/dnszones/$zoneName/$($record.RecordType)/$($record.Name)"
110+
$createdRecord = New-AzureRmDnsRecordSet -Name $aliasRecordName -ZoneName $zoneName -ResourceGroupName $resourceGroup.ResourceGroupName -RecordType $recordType -AliasTargetResourceId $aliasResourceId
111+
112+
Assert-NotNull $createdRecord
113+
Assert-AreEqual $zoneName $createdRecord.ZoneName
114+
Assert-AreEqual $aliasRecordName $createdRecord.Name
115+
Assert-AreEqual $resourceGroup.ResourceGroupName $createdRecord.ResourceGroupName
116+
117+
$aliasRecord = $zone | Get-AzureRmDnsRecordSet -Name $aliasRecordName -RecordType $recordType
118+
$nonaliasRecord = $zone | Get-AzureRmDnsRecordSet -Name $recordName -RecordType $recordType
119+
Assert-AreEqual $aliasResourceId $aliasRecord.AliasTargetResourceId
120+
121+
$nonaliasRecord | Remove-AzureRmDnsRecordSet
122+
123+
Assert-ThrowsLike { Get-AzureRmDnsRecordSet -Name $recordName -ZoneName $zoneName -ResourceGroupName $resourceGroup.ResourceGroupName -RecordType $recordType } "*does not exist*"
124+
Assert-ThrowsLike { Get-AzureRmDnsRecordSet -Name $aliasRecordName -ZoneName $zoneName -ResourceGroupName $resourceGroup.ResourceGroupName -RecordType $recordType } "*does not exist*"
125+
126+
Remove-AzureRmDnsZone -Name $zoneName -ResourceGroupName $resourceGroup.ResourceGroupName -Confirm:$false
127+
Remove-AzureRmResourceGroup -Name $resourceGroup.ResourceGroupName -Force
128+
}
129+
88130
<#
89131
.SYNOPSIS
90132
Full Record Set CRUD cycle trims terminating dot from zone name

src/ResourceManager/Dns/Commands.Dns/Records/NewAzureDnsRecordSet.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,43 @@ namespace Microsoft.Azure.Commands.Dns
2727
/// </summary>
2828
[Cmdlet(VerbsCommon.New, "AzureRmDnsRecordSet", SupportsShouldProcess = true),
2929
OutputType(typeof(DnsRecordSet))]
30-
public class NewAzureDnsRecordSet : DnsBaseCmdlet
30+
public class NewAzureRmDnsRecordSet : DnsBaseCmdlet
3131
{
3232
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the records inthis record set (relative to the name of the zone and without a terminating dot).")]
3333
[ValidateNotNullOrEmpty]
3434
public string Name { get; set; }
3535

3636
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The zone in which to create the record set (without a terminating dot).", ParameterSetName = "Fields")]
37+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The zone in which to create the record set (without a terminating dot).", ParameterSetName = "AliasFields")]
3738
[ValidateNotNullOrEmpty]
3839
public string ZoneName { get; set; }
3940

4041
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group to which the zone belongs.", ParameterSetName = "Fields")]
42+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group to which the zone belongs.", ParameterSetName = "AliasFields")]
4143
[ResourceGroupCompleter]
4244
[ValidateNotNullOrEmpty]
4345
public string ResourceGroupName { get; set; }
4446

4547
[Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The DnsZone object representing the zone in which to create the record set.", ParameterSetName = "Object")]
48+
[Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The DnsZone object representing the zone in which to create the record set.", ParameterSetName = "AliasObject")]
4649
[ValidateNotNullOrEmpty]
4750
public DnsZone Zone { get; set; }
4851

49-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The TTL value of all the records in this record set.")]
52+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The TTL value of all the records in this record set.", ParameterSetName = "Fields")]
53+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The TTL value of all the records in this record set.", ParameterSetName = "Object")]
54+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The TTL value of all the records in this record set.", ParameterSetName = "AliasObject")]
55+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The TTL value of all the records in this record set.", ParameterSetName = "AliasFields")]
5056
[ValidateNotNullOrEmpty]
5157
public uint Ttl { get; set; }
5258

5359
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The type of DNS records in this record set.")]
5460
[ValidateNotNullOrEmpty]
5561
public RecordType RecordType { get; set; }
5662

63+
[Parameter(Mandatory = true, HelpMessage = "Alias Target Resource Id.", ParameterSetName = "AliasFields")]
64+
[Parameter(Mandatory = true, HelpMessage = "Alias Target Resource Id.", ParameterSetName = "AliasObject")]
65+
public string AliasTargetResourceId { get; set; }
66+
5767
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents resource tags.")]
5868
public Hashtable Metadata { get; set; }
5969

@@ -64,9 +74,6 @@ public class NewAzureDnsRecordSet : DnsBaseCmdlet
6474
[Parameter(Mandatory = false, HelpMessage = "Do not fail if the record set already exists.")]
6575
public SwitchParameter Overwrite { get; set; }
6676

67-
[Parameter(Mandatory = false, HelpMessage = "Alias Target Resource Id.")]
68-
public string AliasTargetResourceId { get; set; }
69-
7077
public override void ExecuteCmdlet()
7178
{
7279
string zoneName = null;
@@ -78,12 +85,12 @@ public override void ExecuteCmdlet()
7885
throw new System.ArgumentException(ProjectResources.Error_AddRecordSOA);
7986
}
8087

81-
if (ParameterSetName == "Fields")
88+
if (ParameterSetName == "Fields" || ParameterSetName == "AliasFields")
8289
{
8390
zoneName = this.ZoneName;
8491
resourceGroupname = this.ResourceGroupName;
8592
}
86-
else if (ParameterSetName == "Object")
93+
else if (ParameterSetName == "Object" || ParameterSetName == "AliasObject")
8794
{
8895
zoneName = this.Zone.Name;
8996
resourceGroupname = this.Zone.ResourceGroupName;

0 commit comments

Comments
 (0)