Skip to content

Commit

Permalink
Removed dependency on config file
Browse files Browse the repository at this point in the history
  • Loading branch information
briandenicola committed Aug 24, 2022
1 parent f45a3b3 commit da89421
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 70 deletions.
28 changes: 0 additions & 28 deletions bjd.Azure.Functions/bjd.Azure.Config.json

This file was deleted.

4 changes: 2 additions & 2 deletions bjd.Azure.Functions/bjd.Azure.Functions.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<package >
<metadata>
<id>bjd.Azure.Functions</id>
<version>1.0.15.2</version>
<version>1.0.17</version>
<authors>Brian Denicola</authors>
<owners>Brian Denicola</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>https://github.com/briandenicola/Azure</projectUrl>
<description>A series of Azure functions</description>
<releaseNotes>Get Storage Used by Azure Web Apps</releaseNotes>
<releaseNotes>Removed dependency on config file</releaseNotes>
<copyright>Copyright 2022</copyright>
<repository type="git" url="https://github.com/briandenicola/Azure.git" />
<dependencies/>
Expand Down
2 changes: 1 addition & 1 deletion bjd.Azure.Functions/bjd.Azure.Functions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@{

RootModule = 'bjd.Azure.Functions.psm1'
ModuleVersion = '1.0.15.2'
ModuleVersion = '1.0.17'
GUID = 'c2602a90-dd9a-437e-9a52-2efdf0e392a4'
Author = 'Brian Denicola'
CompanyName = 'Denicolafamily'
Expand Down
67 changes: 28 additions & 39 deletions bjd.Azure.Functions/bjd.Azure.Functions.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Set-Variable -Name config -Value (Get-Content -Raw (Join-Path -Path $PSScriptRoot -ChildPath "bjd.Azure.Config.json") | ConvertFrom-Json)

function Get-KubernetesSecret
{
param(
Expand Down Expand Up @@ -67,18 +65,6 @@ function Convert-CertificatetoBase64 {
return $base64Cert
}

function Get-AzAdminPassword {
Get-KeyVaultSecret -KeyVaultName $config.keyVault.VaultName -SecretName $config.keyVault.secrets.admin -CopytoClipboard
}

function Get-AzDevOpsToken {
Get-KeyVaultSecret -KeyVaultName $config.keyVault.VaultName -SecretName $config.keyVault.secrets.Token -CopytoClipboard
}

function Get-AzServicePrincipalSecret {
Get-KeyVaultSecret -KeyVaultName $config.keyVault.VaultName -SecretName $config.keyVault.secrets.Secret -CopytoClipboard
}

function Get-KeyVaultSecret {
param(
[string] $KeyVaultName,
Expand Down Expand Up @@ -111,23 +97,26 @@ function New-APIMHeader {

function Get-AzVPNStatus {
[CmdletBinding()]
param()
param(
[Parameter(Mandatory=$true, HelpMessage='Enter the Name of the VPN Connection')]
[string] $VPNConnectionName
)

$VPNConnectionName = $config.VPNConnectionName
Write-Verbose -Message ("[{0}] - Checking Connection status - {1} . . ." -f (Get-Date), $VPNConnectionName)
Get-NetIPAddress -InterfaceAlias $VPNConnectionName -ErrorAction SilentlyContinue
return $?
}

function Connect-ToAzureVPN {
function Connect-ToClassicAzureVPN {
[CmdletBinding()]
param (
param (
[Parameter(Mandatory=$true, HelpMessage='Enter the Name of the VPN Connection')]
[string] $VPNConnectionName,
[Parameter(Mandatory=$false, HelpMessage='Enter a valid Destination Prefix in the format `"w.x.y.z/a`"')]
[ValidatePattern("^(?:[0-9]{1,3}\.){3}[0-9]{1,3}\/[0-9]{1,2}$")]
[string[]] $RemoteNetworkPrefixs = @("10.1.0.0/16","10.2.0.0/16", "10.5.0.0/16", "10.25.0.0/16"),
[switch] $Disconnect
)
$VPNConnectionName = $config.VPNConnectionName

$VPNPhonebook = Join-Path -Path $ENV:APPDATA -ChildPath ("Microsoft\Network\Connections\Cm\{0}\{0}.pbk" -f $VPNConnectionName)

Expand Down Expand Up @@ -156,19 +145,27 @@ function Connect-ToAzureVPN {
function New-AzureVM {
param(
[Parameter(Mandatory=$true)]
[ValidateSet("BJD_APPS_Subscription", "BJD_AKS_Subscription", "BJD_Core_Subscription")]
[string] $SubscriptionName,

[Parameter(Mandatory=$true)]
[ValidateSet("Standard_B4ms", "Standard_B1ms", "Standard_DS3_v2", "Standard_F4s_v2")]
[string] $VMSize,

[Parameter(Mandatory=$false)]
[Parameter(Mandatory=$true)]
[string] $VnetResourceGroupName,

[Parameter(Mandatory=$false)]
[Parameter(Mandatory=$true)]
[string] $VnetName,


[Parameter(Mandatory=$false)]
[string] $SubnetName = "Servers",

[Parameter(Mandatory=$false)]
[string] $adminUser = "azureuser",

[Parameter(Mandatory=$false)]
[string] $timeZone = "Central Standard Time",

[switch] $Linux,
[switch] $DisableAADJoin
)
Expand All @@ -179,27 +176,19 @@ function New-AzureVM {
$vmNic = "{0}-nic" -f $vmName
$vmDisk = "{0}-osdrive" -f $vmName

$adminUser = $config.vmSettings.adminUser
$timeZone = $config.vmSettings.timeZone
$subnet = $config.vmSettings.subnet
$role = $config.vmSettings.role
$account = $config.vmSettings.account
$role = "Virtual Machine Administrator Login"
$account = (Get-AzAccessToken).UserId

$vmConfig = @{}
if( -not([string]::IsNullOrEmpty($VnetResourceGroupName)) -and -not([string]::IsNullOrEmpty($VnetName)) ){
$vmConfig.Add('ResourceGroupName',$VnetResourceGroupName)
$vmConfig.Add('VnetResourceGroupName', $VnetResourceGroupName)
$vmConfig.Add('VnetName', $VnetName)
$vmConfig.Add('Location', (Get-AzVirtualNetwork -Name $VnetName -ResourceGroupName $VnetResourceGroupName | Select-Object -ExpandProperty Location))
}
else {
$vmConfig = $config.vmSettings.AzureSettings | Where-Object { $_.SubscriptionName -eq $SubscriptionName }
}
$vmConfig.Add('ResourceGroupName',$VnetResourceGroupName)
$vmConfig.Add('VnetResourceGroupName', $VnetResourceGroupName)
$vmConfig.Add('VnetName', $VnetName)
$vmConfig.Add('Location', (Get-AzVirtualNetwork -Name $VnetName -ResourceGroupName $VnetResourceGroupName | Select-Object -ExpandProperty Location))

New-AzResourceGroup -Name $vmConfig.ResourceGroupName -Location $vmConfig.Location

$vnet = Get-AzVirtualNetwork -Name $vmConfig.VnetName -ResourceGroupName $vmConfig.VnetResourceGroupName
$subnetId = Get-AzVirtualNetworkSubnetConfig -Name $subnet -VirtualNetwork $vnet | Select-Object -Expand id
$subnetId = Get-AzVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $vnet | Select-Object -Expand id

$startTime = Get-Date

Expand Down Expand Up @@ -395,7 +384,7 @@ $FuncsToExport = @(
"Get-AzDevOpsToken",
"Get-AzServicePrincipalSecret",
"New-APIMHeader",
"Connect-ToAzureVPN",
"Connect-ToAClassicAzureVPN",
"Convert-CertificatetoBase64",
"Get-AzVPNStatus",
"Split-AzResourceID",
Expand Down

0 comments on commit da89421

Please sign in to comment.