Skip to content

Commit f014852

Browse files
Update readme for -pre and -post TestResource scripts (Azure#17891)
Co-authored-by: Christopher Scott <[email protected]>
1 parent 87a0f16 commit f014852

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

eng/common/TestResources/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,49 @@ setx KEYVAULT_SKU ${env:KEYVAULT_SKU}
7777
setx AZURE_KEYVAULT_URL ${env:AZURE_KEYVAULT_URL}
7878
```
7979

80+
### Pre- and Post- Scripts
81+
82+
Sometimes creating test resources requires either some work to be done prior to or after the main test-resources.json script is executed.
83+
For these scenarios a `test-resources-pre.ps1` or `test-resources-post.ps1`, respectively, can be created in the same folder as the `test-resources.json` file.
84+
85+
For example, it may be necessary to create artifacts prior to provisioning the actual resource, such as a certificate.
86+
Typically the created artifact will need to be passed to `test-resources.json` to be used in the ARM template or as output (or both).
87+
88+
Below is an example of how `$templateFileParameters` can be used to pass data from the `pre-` script to `test-resources.json`.
89+
90+
**Snippet from `test-resources-pre.ps1`**
91+
```powershell
92+
$cert = New-X509Certificate2 -SubjectName '[email protected], CN=Azure SDK, OU=Azure SDK, O=Microsoft, L=Frisco, S=TX, C=US' -ValidDays 3652
93+
# Create new entries in $templateFileParameters
94+
$templateFileParameters['ConfidentialLedgerPrincipalPEM'] = Format-X509Certificate2 -Certificate $cert
95+
$templateFileParameters['ConfidentialLedgerPrincipalPEMPK'] = Format-X509Certificate2 -Type Pkcs8 -Certificate $cert
96+
```
97+
98+
**Snippet from the corresponding `test-resources.json`.**
99+
100+
Note that the values present in `$templateFileParameters` will map to parameters of the same name.
101+
```json
102+
{
103+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
104+
"contentVersion": "1.0.0.0",
105+
"parameters": {
106+
"_comment": "Other required parameters would go here... (this is not part of the actual test-resources.json)",
107+
"ConfidentialLedgerPrincipalPEM": {
108+
"type": "string",
109+
"metadata": {
110+
"description": "The certificate to configure as a certBasedSecurityPrincipal."
111+
}
112+
},
113+
"ConfidentialLedgerPrincipalPEMPK": {
114+
"type": "string",
115+
"metadata": {
116+
"description": "The certificate to configure as a certBasedSecurityPrincipal."
117+
}
118+
}
119+
},
120+
}
121+
```
122+
80123
### Cleaning up Resources
81124

82125
By default, resource groups are tagged with a `DeleteAfter` value and date according to the default or specified

0 commit comments

Comments
 (0)