Skip to content

Commit

Permalink
Decompile reference() functions with resource name references (#2381)
Browse files Browse the repository at this point in the history
* Decompile reference() functions with resource name references

* Fix decompiler to use LF for newlines

* Fix test for LF
  • Loading branch information
anthony-c-martin authored Apr 23, 2021
1 parent 30dd5af commit 0d8b6fa
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void Decompiler_generates_expected_bicep_files_with_diagnostics(ExampleDa
var diagnostics = diagnosticsBySyntaxTree[syntaxTree];
var bicepOutput = filesToSave[syntaxTree.FileUri];

var sourceTextWithDiags = OutputHelper.AddDiagsToSourceText(bicepOutput, Environment.NewLine, diagnostics, diag => OutputHelper.GetDiagLoggingString(bicepOutput, outputDirectory, diag));
var sourceTextWithDiags = OutputHelper.AddDiagsToSourceText(bicepOutput, "\n", diagnostics, diag => OutputHelper.GetDiagLoggingString(bicepOutput, outputDirectory, diag));
File.WriteAllText(syntaxTree.FileUri.LocalPath + ".actual", sourceTextWithDiags);

sourceTextWithDiags.Should().EqualWithLineByLineDiffOutput(
Expand Down
32 changes: 32 additions & 0 deletions src/Bicep.Decompiler.IntegrationTests/Working/issue2380/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
targetScope = 'managementGroup'

@description('EnrollmentAccount used for subscription billing')
param enrollmentAccount string

@description('BillingAccount used for subscription billing')
param billingAccount string

@description('Alias to assign to the subscription')
param subscriptionAlias string

@description('Display name for the subscription')
param subscriptionDisplayName string

@allowed([
'Production'
'DevTest'
])
@description('Workload type for the subscription')
param subscriptionWorkload string = 'Production'

resource subscriptionAlias_resource 'Microsoft.Subscription/aliases@2020-09-01' = {
//@[82:333) [BCP135 (Error)] Scope "managementGroup" is not valid for this resource type. Permitted scopes: "tenant". |{\n name: subscriptionAlias\n properties: {\n workload: subscriptionWorkload\n displayName: subscriptionDisplayName\n billingScope: tenantResourceId('Microsoft.Billing/billingAccounts/enrollmentAccounts', billingAccount, enrollmentAccount)\n }\n}|
name: subscriptionAlias
properties: {
workload: subscriptionWorkload
displayName: subscriptionDisplayName
billingScope: tenantResourceId('Microsoft.Billing/billingAccounts/enrollmentAccounts', billingAccount, enrollmentAccount)
}
}

output subscriptionId string = subscriptionAlias_resource.properties.subscriptionId
60 changes: 60 additions & 0 deletions src/Bicep.Decompiler.IntegrationTests/Working/issue2380/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"enrollmentAccount": {
"type": "string",
"metadata": {
"description": "EnrollmentAccount used for subscription billing"
}
},
"billingAccount": {
"type": "string",
"metadata": {
"description": "BillingAccount used for subscription billing"
}
},
"subscriptionAlias": {
"type": "string",
"metadata": {
"description": "Alias to assign to the subscription"
}
},
"subscriptionDisplayName": {
"type": "string",
"metadata": {
"description": "Display name for the subscription"
}
},
"subscriptionWorkload": {
"type": "string",
"defaultValue": "Production",
"allowedValues": [
"Production",
"DevTest"
],
"metadata": {
"description": "Workload type for the subscription"
}
}
},
"resources": [
{
//"scope": "/",
"name": "[parameters('subscriptionAlias')]",
"type": "Microsoft.Subscription/aliases",
"apiVersion": "2020-09-01",
"properties": {
"workload": "[parameters('subscriptionWorkload')]",
"displayName": "[parameters('subscriptionDisplayName')]",
"billingScope": "[tenantResourceId('Microsoft.Billing/billingAccounts/enrollmentAccounts', parameters('billingAccount'), parameters('enrollmentAccount'))]"
}
}
],
"outputs": {
"subscriptionId": {
"type": "string",
"value": "[reference(parameters('subscriptionAlias')).subscriptionId]"
}
}
}
Loading

0 comments on commit 0d8b6fa

Please sign in to comment.