Skip to content
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

Decompile reference() functions with resource name references #2381

Merged
merged 3 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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]"
}
}
}
299 changes: 148 additions & 151 deletions src/Bicep.Decompiler.IntegrationTests/Working/keysinproperties/main.bicep
Original file line number Diff line number Diff line change
@@ -1,151 +1,148 @@
@allowed([
'Standard_LRS'
'Standard_GRS'
])
@description('Storage account type')
param storageAccountType string = 'Standard_LRS'

@description('Name of file share to be created')
param fileShareName string = 'sftpfileshare'

@description('Username to use for SFTP access')
param sftpUser string

@description('Password to use for SFTP access')
@secure()
param sftpPassword string

@description('Primary location for resources')
param location string = resourceGroup().location

var scriptName_var = 'createFileShare'
var identityName_var = 'scratch'
var roleDefinitionId = resourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
var roleDefinitionName_var = guid(identityName_var, roleDefinitionId)
var sftpContainerName = 'sftp'
var sftpContainerGroupName_var = 'sftp-group'
var sftpContainerImage = 'atmoz/sftp:latest'
var sftpEnvVariable = '${sftpUser}:${sftpPassword}:1001'
var storageAccountName_var = 'sftpstg${uniqueString(resourceGroup().id)}'

resource identityName 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: identityName_var
location: location
}

resource roleDefinitionName 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: roleDefinitionName_var
properties: {
roleDefinitionId: roleDefinitionId
principalId: reference(identityName_var).principalId
scope: resourceGroup().id
//@[4:9) [BCP073 (Warning)] The property "scope" is read-only. Expressions cannot be assigned to read-only properties. |scope|
principalType: 'ServicePrincipal'
}
dependsOn: [
identityName
]
}

resource storageAccountName 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName_var
location: location
sku: {
name: storageAccountType
}
kind: 'StorageV2'
properties: {}
dependsOn: [
roleDefinitionName
]
}

resource scriptName 'Microsoft.Resources/deploymentScripts@2019-10-01-preview' = {
name: scriptName_var
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${identityName.id}': {}
}
}
properties: {
forceUpdateTag: '1'
azPowerShellVersion: '3.0'
arguments: ' -storageAccountName ${storageAccountName_var} -fileShareName ${fileShareName} -resourceGroupName ${resourceGroup().name}'
scriptContent: '\n param(\n [string] $storageAccountName,\n [string] $fileShareName,\n [string] $resourceGroupName\n )\n Get-AzStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroupName | New-AzStorageShare -Name $fileShareName\n '
timeout: 'PT5M'
cleanupPreference: 'OnSuccess'
retentionInterval: 'P1D'
}
dependsOn: [
storageAccountName
]
}

resource sftpContainerGroupName 'Microsoft.ContainerInstance/containerGroups@2019-12-01' = {
name: sftpContainerGroupName_var
location: location
properties: {
containers: [
{
name: sftpContainerName
properties: {
image: sftpContainerImage
environmentVariables: [
{
name: 'SFTP_USERS'
value: sftpEnvVariable
}
]
resources: {
requests: {
cpu: 2
memoryInGB: 1
}
}
ports: [
{
port: 22
}
]
volumeMounts: [
{
mountPath: '/home/${sftpUser}/upload'
name: 'sftpvolume'
readOnly: false
}
]
}
}
]
osType: 'Linux'
ipAddress: {
type: 'Public'
ports: [
{
protocol: 'TCP'
port: 22
}
]
}
restartPolicy: 'OnFailure'
volumes: [
{
name: 'sftpvolume'
azureFile: {
readOnly: false
shareName: fileShareName
storageAccountName: storageAccountName_var
storageAccountKey: listKeys(storageAccountName_var, '2018-02-01').keys[0].value
}
}
]
}
dependsOn: [
scriptName
]
}

output containerIPv4Address string = sftpContainerGroupName.properties.ipAddress.ip
@allowed([
'Standard_LRS'
'Standard_GRS'
])
@description('Storage account type')
param storageAccountType string = 'Standard_LRS'

@description('Name of file share to be created')
param fileShareName string = 'sftpfileshare'

@description('Username to use for SFTP access')
param sftpUser string

@description('Password to use for SFTP access')
@secure()
param sftpPassword string

@description('Primary location for resources')
param location string = resourceGroup().location

var scriptName_var = 'createFileShare'
var identityName_var = 'scratch'
var roleDefinitionId = resourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
var roleDefinitionName_var = guid(identityName_var, roleDefinitionId)
var sftpContainerName = 'sftp'
var sftpContainerGroupName_var = 'sftp-group'
var sftpContainerImage = 'atmoz/sftp:latest'
var sftpEnvVariable = '${sftpUser}:${sftpPassword}:1001'
var storageAccountName_var = 'sftpstg${uniqueString(resourceGroup().id)}'

resource identityName 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: identityName_var
location: location
}

resource roleDefinitionName 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: roleDefinitionName_var
properties: {
roleDefinitionId: roleDefinitionId
principalId: identityName.properties.principalId
scope: resourceGroup().id
//@[4:9) [BCP073 (Warning)] The property "scope" is read-only. Expressions cannot be assigned to read-only properties. |scope|
principalType: 'ServicePrincipal'
}
}

resource storageAccountName 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName_var
location: location
sku: {
name: storageAccountType
}
kind: 'StorageV2'
properties: {}
dependsOn: [
roleDefinitionName
]
}

resource scriptName 'Microsoft.Resources/deploymentScripts@2019-10-01-preview' = {
name: scriptName_var
location: location
kind: 'AzurePowerShell'
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${identityName.id}': {}
}
}
properties: {
forceUpdateTag: '1'
azPowerShellVersion: '3.0'
arguments: ' -storageAccountName ${storageAccountName_var} -fileShareName ${fileShareName} -resourceGroupName ${resourceGroup().name}'
scriptContent: '\n param(\n [string] $storageAccountName,\n [string] $fileShareName,\n [string] $resourceGroupName\n )\n Get-AzStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroupName | New-AzStorageShare -Name $fileShareName\n '
timeout: 'PT5M'
cleanupPreference: 'OnSuccess'
retentionInterval: 'P1D'
}
dependsOn: [
storageAccountName
]
}

resource sftpContainerGroupName 'Microsoft.ContainerInstance/containerGroups@2019-12-01' = {
name: sftpContainerGroupName_var
location: location
properties: {
containers: [
{
name: sftpContainerName
properties: {
image: sftpContainerImage
environmentVariables: [
{
name: 'SFTP_USERS'
value: sftpEnvVariable
}
]
resources: {
requests: {
cpu: 2
memoryInGB: 1
}
}
ports: [
{
port: 22
}
]
volumeMounts: [
{
mountPath: '/home/${sftpUser}/upload'
name: 'sftpvolume'
readOnly: false
}
]
}
}
]
osType: 'Linux'
ipAddress: {
type: 'Public'
ports: [
{
protocol: 'TCP'
port: 22
}
]
}
restartPolicy: 'OnFailure'
volumes: [
{
name: 'sftpvolume'
azureFile: {
readOnly: false
shareName: fileShareName
storageAccountName: storageAccountName_var
storageAccountKey: listKeys(storageAccountName_var, '2018-02-01').keys[0].value
}
}
]
}
dependsOn: [
scriptName
]
}

output containerIPv4Address string = sftpContainerGroupName.properties.ipAddress.ip
Loading