* working on workflow

* workig document workfow

* dotnet lint rules

* test python workflow

* test python workflow

* test python workflow

* pr_python

* pr_worflow check pyhton and dotnet

* test workflow

* test workflow

* test workflow

* test workflow

* test pyhton

* test pyhton

* test python

* pr_doc workflow

* docs check

* docs check

* docs check

* pr_workflow

* pr_workflow

* pr_workflow

* pr_workflow

* link check edit

* link check edit

* link check edit

* link check edit

* link check edit

* link check edit

* corrections to pr md files

* cspell configuration

* cspell configuration

* cspell configuration

* cspell configuration

* doc file update and add config for markdown-link-check

* doc file update and add config for markdown-link-check

* change folder structure for linter config files

* fix documentation

* fix documentation

* resolve document misspell

* resolve editorconfig for markdwon

* resolve editorconfig for markdwon

* resolve editorconfig for markdwon

* powershell test sample

* powershell test sample

* fix dotnet issue

* powershell changes

* storage account and bicep helpers

* storage account and bicep helpers

* PowerShell Storage Account test sample

* PowerShell Storage Account test sample

* PowerShell Storage Account test sample

* PowerShell Storage Account test sample

* PowerShell Storage Account test sample

* code cleanup

* updated documentation

* updated documentation

* updated test file

* remove .pylintrc
This commit is contained in:
Dilmurod Makhamadaliev 2022-10-28 10:54:14 -04:00 коммит произвёл GitHub
Родитель b91971ace4
Коммит 7d729a3ae8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 240 добавлений и 241 удалений

Просмотреть файл

Просмотреть файл

@ -1,28 +1,27 @@
function Deploy-BicepFeature([string]$path, $params, $resourceGroupName){
# Bicep Feature receives three parameters.
# 1. Bicep file path. 2. parameters 3. resourceGroupName
function Deploy-BicepFeature([string]$path, $params){
# armPath will be assigned for same bicep file name with json extension
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($path)
$folder = Split-Path $path
$armPath = Join-Path -Path $folder -ChildPath "$fileName.json"
# az bicep build will create arm template from bicep file.
# Arm template will same as bicep name with json extension
Write-Host "Transpiling Bicep to Arm"
az bicep build --file $path
$code = $?
if ($code -eq "True") {
$location = $params.location
$deploymentName = $params.deploymentName
Write-Host "Deploying ARM Template ($deploymentName) to $location"
if ([string]::IsNullOrEmpty($resourceGroupName)) {
New-AzSubscriptionDeployment -Name "$deploymentName" -Location "$location" -TemplateFile "$armPath" -TemplateParameterObject $params -SkipTemplateParameterPrompt
}
else{
New-AzResourceGroupDeployment -Name "$deploymentName" -ResourceGroupName "$resourceGroupName" -TemplateFile "$armPath" -TemplateParameterObject $params -SkipTemplateParameterPrompt
}
}
$deploymentName = $params.resourceGroupName
# TODO: Bicep code deploys using subscription deployment. Required to add other deployment types
# 1. TenantDeployment 2.ResourceGroupDeployment 3. ManagementGroupDeployment 4. SubscriptionDeployment
New-AzSubscriptionDeployment -Name "$deploymentName" -Location "$location" -TemplateFile "$armPath" -TemplateParameterObject $params -SkipTemplateParameterPrompt
Write-Host "Removing Arm template json"
rm "$armPath"
Remove-Item "$armPath"
}
function Remove-BicepFeature($resourceGroupName){

Просмотреть файл

@ -0,0 +1,17 @@
function Get-StorageAccountExists([string]$resourceGroupName, [string]$storageAccountName){
$resource = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
return ($null -ne $resource)
}
function Get-StorageAccountKind([string]$resourceGroupName, [string]$storageAccountName) {
$resource = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
return $resource.Kind
}
function Get-StorageAccountSku([string]$resourceGroupName, [string]$storageAccountName) {
$resource = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
return $resource.Sku.Name
}
Export-ModuleMember -Function `
Get-StorageAccountExists, Get-StorageAccountKind, Get-StorageAccountSku

Просмотреть файл

@ -2,7 +2,7 @@
This framework is intended to work as a testing framework for Azure deployment features by using [Bicep](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview?tabs=bicep).
In order to see how you can work with this framework you can find one sample bicep file in the folder [samples](./examples/sample.bicep)
In order to see how you can work with this framework you can find one sample bicep file in the folder [samples](./samples/dotnet/samples/pwsh/resourceGroup.bicep)
that will be deployed by using one PowerShell script.
Process is the following:

Просмотреть файл

@ -28,7 +28,8 @@
"onboardsupport",
"MSRC",
"msrc",
"Benchpress"
"Benchpress",
"pwsh"
],
"version": "0.2",
"patterns": [

Просмотреть файл

@ -0,0 +1,80 @@
# How to test PowerShell Test Sample Code
Following instruction shows how to run StorageAccount.Tests.ps1 file
File is located under following directory: `/samples/dotnet/samples/pwsh/Test`
Run the test `.\StorageAccount.Tests.ps1`
Storage Account deployment uses two bicep files:
- `storageAccountDeploy.bicep` - to deploy resource group and storage account module. This is an actual deployment file
- `storageAccount.bicep` - storage account bicep file which is called by `storageAccountDeploy.bicep` as a module file
`StorageAccount.Tests.ps1` - Content.
```powershell
#repo root path
$ROOT_PATH = $PSScriptRoot | split-path -parent | split-path -parent | split-path -parent | split-path -parent | split-path -parent
BeforeAll {
Import-Module -Name $ROOT_PATH/Benchpress/Helpers/Azure/StorageAcccount.psm1
Import-Module -Name $ROOT_PATH/Benchpress/Helpers/Azure/Bicep.psm1
}
#global variables with required values for the tests. script keyword is used to avoid powershell megalinter complain for global keyword
$script:storageAccountName = 'mystnamebicepv2'
$script:resourceGroupName = 'rg-test-bicep'
Describe 'Spin up , Tear down Storage Account' {
it 'Should deploy a bicep file.' {
#bicep file path
$bicepPath = "$ROOT_PATH/samples/dotnet/samples/pwsh/storageAccountDeploy.bicep"
#required parameters for storage account deployment
$params = @{
resourceGroupName = "rg-test-bicep"
location = "eastus"
storageName = "mystnamebicepv2"
}
#Calling Deploy-BicepFeature helper to deploy resources
$deployment = Deploy-BicepFeature $bicepPath $params
#checking the return state from deployment
$deployment.ProvisioningState | Should -Be 'Succeeded'
}
it 'Should check storage account exist' {
#Calling StorageAccount helper method to check expected storage account exist
$storageAccount = Get-StorageAccountExists $resourceGroupName $storageAccountName
#assert return value from StorageAccount helper
$storageAccount | Should -Not -BeNullOrEmpty -ErrorAction Stop
}
it 'Should Check Storage Sku Name'{
#Calling StorageAccount helper method to check for expected storage Sku
$getStorageAccountSku = Get-StorageAccountSku $resourceGroupName $storageAccountName
#assert return value from StorageAccount helper
$getStorageAccountSku | Should -Be "Standard_LRS"
}
it 'Should Check Storage Kind'{
#Calling StorageAccount helper method to check for expected storage Kind
$getStorageAccountKind = Get-StorageAccountKind $resourceGroupName $storageAccountName
#assert return value from StorageAccount helper
$getStorageAccountKind | Should -Be "StorageV2"
}
it 'Delete Deployed Resources'{
#Call Bicep helper to remove deployed resources
Remove-BicepFeature $resourceGroupName
}
}
#EOF
```

Просмотреть файл

@ -1,36 +0,0 @@
BeforeAll {
. $PSScriptRoot/BenchPress/Helpers/Azure/ResourceGroup.psm1
. $PSScriptRoot/BenchPress/Helpers/Azure/Bicep.psm1
}
Describe 'Verify Resource Group Exists' {
it 'Should contain a resource group named tflintrules' {
#arrange
$rgName = "tflintrules"
#act
$exists = Get-ResourceGroupExists($rgName)
#assert
$exists | Should -Be $true
}
}
Describe 'Spin up , Tear down Resource Group' {
it 'Should deploy a bicep file.' {
#arrange
$bicepPath = "./main.bicep"
$params = @{
name = "rgtestocw11"
location = "westus"
environment = "ocwtest"
}
#act
$deployment = Deploy-BicepFeature $bicepPath $params
#assert
$deployment.ProvisioningState | Should -Be "Succeeded"
#clean up
Remove-BicepFeature $params
}
}

Просмотреть файл

@ -1,185 +0,0 @@
@description('The name of you Virtual Machine.')
param vmName string = 'simpleLinuxVM'
@description('Username for the Virtual Machine.')
param adminUsername string
@description('Type of authentication to use on the Virtual Machine. SSH key is recommended.')
@allowed([
'sshPublicKey'
'password'
])
param authenticationType string = 'password'
@description('SSH Key or password for the Virtual Machine. SSH key is recommended.')
@secure()
param adminPasswordOrKey string
@description('Unique DNS Name for the Public IP used to access the Virtual Machine.')
param dnsLabelPrefix string = toLower('simplelinuxvm-${uniqueString(resourceGroup().id)}')
@description('The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version.')
@allowed([
'12.04.5-LTS'
'14.04.5-LTS'
'16.04.0-LTS'
'18.04-LTS'
])
param ubuntuOSVersion string = '18.04-LTS'
@description('Location for all resources.')
param location string = resourceGroup().location
@description('The size of the VM')
param vmSize string = 'Standard_B2s'
@description('Name of the VNET')
param virtualNetworkName string = 'vNet'
@description('Name of the subnet in the virtual network')
param subnetName string = 'Subnet'
@description('Name of the Network Security Group')
param networkSecurityGroupName string = 'SecGroupNet'
var publicIPAddressName = '${vmName}PublicIP'
var networkInterfaceName = '${vmName}NetInt'
var osDiskType = 'Standard_LRS'
var subnetAddressPrefix = '10.1.0.0/24'
var addressPrefix = '10.1.0.0/16'
var linuxConfiguration = {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: '/home/${adminUsername}/.ssh/authorized_keys'
keyData: adminPasswordOrKey
}
]
}
}
resource nic 'Microsoft.Network/networkInterfaces@2020-06-01' = {
name: networkInterfaceName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: subnet.id
}
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: publicIP.id
}
}
}
]
networkSecurityGroup: {
id: nsg.id
}
}
}
resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
name: networkSecurityGroupName
location: location
properties: {
securityRules: [
{
name: 'SSH'
properties: {
priority: 1000
protocol: 'Tcp'
access: 'Allow'
direction: 'Inbound'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
destinationPortRange: '22'
}
}
]
}
}
resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
name: virtualNetworkName
location: location
properties: {
addressSpace: {
addressPrefixes: [
addressPrefix
]
}
}
}
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = {
parent: vnet
name: subnetName
properties: {
addressPrefix: subnetAddressPrefix
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
resource publicIP 'Microsoft.Network/publicIPAddresses@2020-06-01' = {
name: publicIPAddressName
location: location
sku: {
name: 'Basic'
}
properties: {
publicIPAllocationMethod: 'Dynamic'
publicIPAddressVersion: 'IPv4'
dnsSettings: {
domainNameLabel: dnsLabelPrefix
}
idleTimeoutInMinutes: 4
}
}
resource vm 'Microsoft.Compute/virtualMachines@2020-06-01' = {
name: vmName
location: location
properties: {
hardwareProfile: {
vmSize: vmSize
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
managedDisk: {
storageAccountType: osDiskType
}
}
imageReference: {
publisher: 'Canonical'
offer: 'UbuntuServer'
sku: ubuntuOSVersion
version: 'latest'
}
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
}
]
}
osProfile: {
computerName: vmName
adminUsername: adminUsername
adminPassword: adminPasswordOrKey
linuxConfiguration: ((authenticationType == 'password') ? null : linuxConfiguration)
}
}
}
output adminUsername string = adminUsername
output hostname string = publicIP.properties.dnsSettings.fqdn
output sshCommand string = 'ssh ${adminUsername}@${publicIP.properties.dnsSettings.fqdn}'

Просмотреть файл

@ -0,0 +1,42 @@
$ROOT_PATH = $PSScriptRoot | split-path -parent | split-path -parent | split-path -parent | split-path -parent | split-path -parent
BeforeAll {
Import-Module -Name $ROOT_PATH/Benchpress/Helpers/Azure/ResourceGroup.psm1
Import-Module -Name $ROOT_PATH/Benchpress/Helpers/Azure/Bicep.psm1
}
Describe 'Verify Resource Group Exists' {
it 'Should contain a resource group named rg-test-bicep' {
#arrange
$rgName = "rg-test-bicep"
#act
$exists = Get-ResourceGroupExists($rgName)
#assert
$exists | Should -Be $true
}
}
Describe 'Spin up , Tear down Resource Group' {
it 'Should deploy a bicep file.' {
#get bicep file path
$bicepPath = "$ROOT_PATH/samples/dotnet/samples/pwsh/resourceGroup.bicep"
#pass required bicep parameteres
$params = @{
resourceGroupName = "rg-test-bicep"
location = "eastus"
environment = "ocwtest"
}
#deploy bicep suing bicep helper
$deployment = Deploy-BicepFeature $bicepPath $params
#assert deployment succeeded or not
$deployment.ProvisioningState | Should -Be "Succeeded"
#clean up deployed resources
Remove-BicepFeature $params.resourceGroupName
}
}

Просмотреть файл

@ -0,0 +1,62 @@
#repo root path
$ROOT_PATH = $PSScriptRoot | split-path -parent | split-path -parent | split-path -parent | split-path -parent | split-path -parent
BeforeAll {
Import-Module -Name $ROOT_PATH/Benchpress/Helpers/Azure/StorageAcccount.psm1
Import-Module -Name $ROOT_PATH/Benchpress/Helpers/Azure/Bicep.psm1
}
#global variables with required values for the tests. script keyword is used to avoid powershell megalinter complain for global keyword
$script:storageAccountName = 'mystnamebicepv2'
$script:resourceGroupName = 'rg-test-bicep'
Describe 'Spin up , Tear down Storage Account' {
it 'Should deploy a bicep file.' {
#bicep file path
$bicepPath = "$ROOT_PATH/samples/dotnet/samples/pwsh/storageAccountDeploy.bicep"
#required parameters for storage account deployment
$params = @{
resourceGroupName = "rg-test-bicep"
location = "eastus"
storageName = "mystnamebicepv2"
}
#Calling Deploy-BicepFeature helper to deploy resources
$deployment = Deploy-BicepFeature $bicepPath $params
#checking the return state from deployment
$deployment.ProvisioningState | Should -Be 'Succeeded'
}
it 'Should check storage account exist' {
#Calling StorageAccount helper method to check expected storage account exist
$storageAccount = Get-StorageAccountExists $resourceGroupName $storageAccountName
#assert return value from StorageAccount helper
$storageAccount | Should -Not -BeNullOrEmpty -ErrorAction Stop
}
it 'Should Check Storage Sku Name'{
#Calling StorageAccount helper method to check for expected storage Sku
$getStorageAccountSku = Get-StorageAccountSku $resourceGroupName $storageAccountName
#assert return value from StorageAccount helper
$getStorageAccountSku | Should -Be "Standard_LRS"
}
it 'Should Check Storage Kind'{
#Calling StorageAccount helper method to check for expected storage Kind
$getStorageAccountKind = Get-StorageAccountKind $resourceGroupName $storageAccountName
#assert return value from StorageAccount helper
$getStorageAccountKind | Should -Be "StorageV2"
}
it 'Delete Deployed Resources'{
#Call Bicep helper to remove deployed resources
Remove-BicepFeature $resourceGroupName
}
}

Просмотреть файл

@ -1,12 +1,12 @@
targetScope = 'subscription'
param name string
param resourceGroupName string
param location string
param environment string
// https://docs.microsoft.com/en-us/azure/templates/microsoft.resources/resourcegroups?tabs=bicep
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: name
name: resourceGroupName
location: location
tags: {
EnvironmentName: environment

Просмотреть файл

@ -1,8 +1,8 @@
param storageAccountName string = 'strgtest'
param location string = resourceGroup().location
param name string
param location string
resource sa 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName
name: name
location: location
sku: {
name: 'Standard_LRS'

Просмотреть файл

@ -0,0 +1,19 @@
targetScope='subscription'
param resourceGroupName string
param location string
param storageName string
resource newRG 'Microsoft.Resources/resourceGroups@2021-01-01' = {
name: resourceGroupName
location: location
}
module storageAcct 'storageAccount.bicep' = {
name: 'storageModule'
scope: newRG
params: {
location: location
name: storageName
}
}