Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
!build finalized DSL wrapper module functions
Browse files Browse the repository at this point in the history
  • Loading branch information
scrthq committed Apr 29, 2018
1 parent bf41aa1 commit 1934347
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 31 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
@@ -1,10 +1,9 @@
# Changelog

***

<!-- TOC -->

- [Changelog](#changelog)
- [2.3.0](#230)
- [2.2.1](#221)
- [2.2.0](#220)
- [2.1.2](#212)
Expand All @@ -30,6 +29,12 @@

<!-- /TOC -->

## 2.3.0

- Added DSL wrapper to allow a different style of template building
- Added short aliases for all Condition and Intrinsic functions
- Removed private function Import-AWSSDK and added SDK import to PSM1

## 2.2.1

- Fixed [issue #25](https://github.com/scrthq/VaporShell/issues/25) by updating `Convert-SpecToFunction` to exclude common parameters from being added as properties to outputted resource and resource property objects
Expand Down
100 changes: 98 additions & 2 deletions VaporShell/DSL/VaporShell.DSL.psm1
Expand Up @@ -59,7 +59,7 @@ function Template {
$template.AddOutput($object)
}
foreach ($object in $script:templateObjects['Transforms']) {
Write-Verbose "Adding Transform '$($object.LogicalId)' to template"
Write-Verbose "Adding Include Location '$($object.Props.Parameters.Location)' to template"
$template.AddTransform($object)
}
foreach ($object in $script:templateObjects['Metadata']) {
Expand Down Expand Up @@ -203,5 +203,101 @@ function Output {
$script:templateObjects['Outputs'].Add($object) | Out-Null
}
}
function Condition {
[CmdletBinding()]
Param
(
[parameter(Mandatory = $true,Position = 0)]
[ValidateScript( {
if ($_ -match "^[a-zA-Z0-9]*$") {
$true
}
else {
$PSCmdlet.ThrowTerminatingError((New-VSError -String 'The LogicalID must be alphanumeric (a-z, A-Z, 0-9) and unique within the template.'))
}
})]
[System.String]
$LogicalId,
[parameter(Mandatory = $true,Position = 1)]
[ValidateScript( {
$allowedTypes = "Vaporshell.Condition.And","Vaporshell.Condition.Equals","Vaporshell.Condition.If","Vaporshell.Condition.Not","Vaporshell.Condition.Or"
if ([string]$($_.PSTypeNames) -match "($(($allowedTypes|ForEach-Object{[RegEx]::Escape($_)}) -join '|'))") {
$true
}
else {
$PSCmdlet.ThrowTerminatingError((New-VSError -String "This parameter only accepts the following types: $($allowedTypes -join ", "). The current types of the value are: $($_.PSTypeNames -join ", ")."))
}
})]
$Condition
)
Process {
$object = New-VaporCondition -LogicalId $LogicalId -Condition $Condition
$script:templateObjects['Conditions'].Add($object) | Out-Null
}
}
function Parameter {
[CmdletBinding()]
Param
(
[parameter(Mandatory = $true,Position = 0)]
[ValidateScript( {
if ($_ -match "^[a-zA-Z0-9]*$") {
$true
}
else {
$PSCmdlet.ThrowTerminatingError((New-VSError -String 'The LogicalID must be alphanumeric (a-z, A-Z, 0-9) and unique within the template.'))
}
})]
[System.String]
$LogicalId,
[parameter(Mandatory = $true,Position = 1)]
[System.Management.Automation.ScriptBlock]
$Properties
)
Process {
$scriptBlockString = "`$props = @{$($PSBoundParameters['Properties'].ToString())}; New-VaporParameter -LogicalId '$($PSBoundParameters['LogicalId'])' @props"
$newScriptBlock = [ScriptBlock]::Create($scriptBlockString)
$object = & $newScriptBlock
$script:templateObjects['Parameters'].Add($object) | Out-Null
}
}
function Metadata {
[CmdletBinding()]
Param
(
[parameter(Mandatory = $true,Position = 0)]
[ValidateScript( {
if ($_ -match "^[a-zA-Z0-9]*$") {
$true
}
else {
$PSCmdlet.ThrowTerminatingError((New-VSError -String 'The LogicalID must be alphanumeric (a-z, A-Z, 0-9) and unique within the template.'))
}
})]
[System.String]
$LogicalId,
[parameter(Mandatory = $true,Position = 1)]
[Hashtable]
$Metadata
)
Process {
$object = New-VaporMetadata -LogicalId $LogicalId -Metadata $Metadata -Verbose:$false
$script:templateObjects['Metadata'].Add($object) | Out-Null
}
}
function Transform {
[CmdletBinding()]
Param
(
[parameter(Mandatory = $true,Position = 0)]
[ValidatePattern("^s3:\/\/.*")]
[System.String]
$Location
)
Process {
$object = Add-Include -Location $Location -Verbose:$false
$script:templateObjects['Transforms'].Add($object) | Out-Null
}
}

Export-ModuleMember -Function Template,Resource,Mapping,CustomResource,Output
Export-ModuleMember -Function Template,Resource,Mapping,CustomResource,Output,Condition,Parameter,Metadata,Transform
25 changes: 0 additions & 25 deletions VaporShell/Private/Import-AWSSDK.ps1

This file was deleted.

2 changes: 2 additions & 0 deletions VaporShell/VaporShell.psm1
Expand Up @@ -29,6 +29,8 @@ foreach ($file in @($Public + $Private)) {
)
}
}

# Load AWS .NET SDK if not already loaded
if (!([AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.Location -like "*AWSSDK.CloudFormation.dll"})) {
if ($IsCoreCLR) {
Write-Verbose "Loading AWS SDK for *NetCore*!"
Expand Down
8 changes: 6 additions & 2 deletions deploy.psdeploy.ps1
Expand Up @@ -18,7 +18,9 @@ if(
$env:BHProjectName -and $env:BHProjectName.Count -eq 1 -and
$env:BHBuildSystem -ne 'Unknown' -and
$env:BHBranchName -eq "master" -and
$env:BHCommitMessage -match '!deploy'
$env:BHCommitMessage -match '!deploy' -and
$env:APPVEYOR_BUILD_WORKER_IMAGE -like '*2017*' -and
$env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null
)
{
Deploy Module {
Expand All @@ -36,7 +38,9 @@ else
"Skipping deployment: To deploy, ensure that...`n" +
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)" |
"`t* You are not building a Pull Request (Current: $ENV:APPVEYOR_PULL_REQUEST_NUMBER) `n" +
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage) `n" +
"`t* Your build image is Visual Studio 2017 (Current: $ENV:APPVEYOR_BUILD_WORKER_IMAGE)" |
Write-Host
}

Expand Down

0 comments on commit 1934347

Please sign in to comment.