@@ -146,6 +146,155 @@ function Test-NewDeploymentFromTemplateSpec
146
146
}
147
147
}
148
148
149
+ function Test-NewSubscriptionDeploymentFromTemplateSpec
150
+ {
151
+ # Setup
152
+ $rgname = Get-ResourceGroupName
153
+ $rname = Get-ResourceName
154
+ $rglocation = " West US 2"
155
+ $subId = (Get-AzContext ).Subscription.SubscriptionId
156
+
157
+ try
158
+ {
159
+ # Prepare our RG and basic template spec:
160
+
161
+ New-AzResourceGroup - Name $rgname - Location $rglocation
162
+
163
+ $sampleTemplateJson = Get-Content - Raw - Path " subscription_level_template.json"
164
+ $basicCreatedTemplateSpec = New-AzTemplateSpec - ResourceGroupName $rgname - Name $rname - Location $rgLocation - Version " v1" - TemplateJson $sampleTemplateJson
165
+
166
+ $resourceId = $basicCreatedTemplateSpec.Id + " /versions/v1"
167
+
168
+ # Create deployment
169
+ $deployment = New-AzSubscriptionDeployment - Name $rname - TemplateSpecId $resourceId - TemplateParameterFile " subscription_level_parameters.json" - Location $rglocation
170
+
171
+ # Assert
172
+ Assert-AreEqual Succeeded $deployment.ProvisioningState
173
+
174
+ }
175
+
176
+ finally
177
+ {
178
+ # Cleanup
179
+ Clean - DeploymentAtSubscription $deployment
180
+ Clean - ResourceGroup $rgname
181
+ }
182
+ }
183
+
184
+ function Test-NewFailedSubscriptionDeploymentFromTemplateSpec
185
+ {
186
+ # Setup
187
+ $rgname = Get-ResourceGroupName
188
+ $rname = Get-ResourceName
189
+ $rglocation = " West US 2"
190
+ $subId = (Get-AzContext ).Subscription.SubscriptionId
191
+
192
+ try
193
+ {
194
+ # Prepare our RG and basic template spec:
195
+
196
+ New-AzResourceGroup - Name $rgname - Location $rglocation
197
+
198
+ # Use template that will fail at subscription scope
199
+ $sampleTemplateJson = Get-Content - Raw - Path " subscription_level_template.json"
200
+ $basicCreatedTemplateSpec = New-AzTemplateSpec - ResourceGroupName $rgname - Name $rname - Location $rgLocation - Version " v1" - TemplateJson $sampleTemplateJson
201
+
202
+ $resourceId = $basicCreatedTemplateSpec.Id + " /versions/v1"
203
+
204
+ # Create deployment
205
+ try {
206
+ $deployment = New-AzSubscriptionDeployment - Name $rname - TemplateSpecId $resourceId - TemplateParameterFile " subscription_level_parameters.json" - Location $rglocation
207
+ }
208
+ Catch {
209
+ Assert-True { $Error [0 ].Contains(" ResourceNotFound" )}
210
+ }
211
+
212
+ }
213
+
214
+ finally
215
+ {
216
+ # Cleanup
217
+ Clean - DeploymentAtSubscription $deployment
218
+ Clean - ResourceGroup $rgname
219
+ }
220
+ }
221
+
222
+ function Test-NewMGDeploymentFromTemplateSpec
223
+ {
224
+ # Setup
225
+ $rgname = Get-ResourceGroupName
226
+ $rname = Get-ResourceName
227
+ $managementGroupId = Get-ResourceName
228
+ $rglocation = " West US 2"
229
+ $subId = (Get-AzContext ).Subscription.SubscriptionId
230
+
231
+ try
232
+ {
233
+ # Create New MG
234
+ New-AzManagementGroup - GroupName $managementGroupId - ParentId " /providers/Microsoft.Management/managementGroups/AzDeploymentsPSTest"
235
+
236
+ # Prepare our RG and basic template spec:
237
+
238
+ New-AzResourceGroup - Name $rgname - Location $rglocation
239
+
240
+ $sampleTemplateJson = Get-Content - Raw - Path " simpleTemplate.json"
241
+ $basicCreatedTemplateSpec = New-AzTemplateSpec - ResourceGroupName $rgname - Name $rname - Location $rgLocation - Version " v1" - TemplateJson $sampleTemplateJson
242
+
243
+ $resourceId = $basicCreatedTemplateSpec.Id + " /versions/v1"
244
+
245
+ # Create deployment
246
+ $deployment = New-AzManagementGroupDeployment - ManagementGroupId $managementGroupId - Name $rname - TemplateSpecId $resourceId - TemplateParameterFile " simpleTemplateParams.json" - Location $rglocation
247
+
248
+ # Assert
249
+ Assert-AreEqual Succeeded $deployment.ProvisioningState
250
+
251
+ }
252
+
253
+ finally
254
+ {
255
+ # Cleanup
256
+ Remove-AzManagementGroupDeployment - ManagementGroup $managementGroupId - Name $rname
257
+ Clean - ResourceGroup $rgname
258
+ Remove-AzManagementGroup - GroupName $managementGroupId
259
+ }
260
+ }
261
+
262
+ function Test-NewTenantDeploymentFromTemplateSpec
263
+ {
264
+ # Setup
265
+ $rgname = Get-ResourceGroupName
266
+ $rname = Get-ResourceName
267
+ $rglocation = " West US 2"
268
+ $subId = (Get-AzContext ).Subscription.SubscriptionId
269
+
270
+ try
271
+ {
272
+ # Prepare our RG and basic template spec:
273
+
274
+ New-AzResourceGroup - Name $rgname - Location $rglocation
275
+
276
+ $sampleTemplateJson = Get-Content - Raw - Path " simpleTemplate.json"
277
+ $basicCreatedTemplateSpec = New-AzTemplateSpec - ResourceGroupName $rgname - Name $rname - Location $rgLocation - Version " v1" - TemplateJson $sampleTemplateJson
278
+
279
+ $resourceId = $basicCreatedTemplateSpec.Id + " /versions/v1"
280
+
281
+ # Create deployment
282
+ $deployment = New-AzTenantDeployment - Name $rname - TemplateSpecId $resourceId - TemplateParameterFile " simpleTemplateParams.json" - Location $rglocation
283
+
284
+ # Assert
285
+ Assert-AreEqual Succeeded $deployment.ProvisioningState
286
+
287
+ }
288
+
289
+ finally
290
+ {
291
+ # Cleanup
292
+ Clean - ResourceGroup $rgname
293
+ Remove-AzTenantDeployment - Name $rname
294
+ Clean - DeploymentAtTenant $rname
295
+ }
296
+ }
297
+
149
298
function Test-NewDeploymentFromTemplateObject
150
299
{
151
300
# Setup
0 commit comments