AWS - Create Cloud Formation Stack

Octopus.Script exported 2017-02-06 by kirkholloway belongs to ‘AWS’ category.

Creates a Amazon Cloud Formation Stack with the template specified.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

AWS Secret Access Key

AWSSecretAccessKey

The secret access key to use when executing the script

AWS Access Key

AWSAccessKey

The access key to use when executing the script

AWS Region

AWSRegion =

The Amazon Region see (http://docs.aws.amazon.com/powershell/latest/reference/items/Get-AWSRegion.html) for further info

AWS Cloud Formation Stack Name

CloudFormationStackName

The name of the AWS Cloud Formation Stack

AWS Cloud Formation Capability

CloudFormationCapability = CAPABILITY_IAM

The capability required for the tempate see docs

Action on Failure

CloudFormationOnFailure = ROLLBACK

Defaults to ROLLBACK. See docs

Use AWS S3 storage for the Cloud Formation Template

UseS3ForCloudFormationTemplate

Whether to use S3 storage to source the Cloud Formation script. See docs

The Cloud Formation Template

CloudFormationTemplate

The Cloud Formation Template in the format, see docs

The location in S3 for the Cloud Formation Template

CloudFormationTemplateURL

null

Cloud Formation Parameters

CloudFormationParameters

See docs

Should be provided as a JSON formatted object.

e.g.{ "Key1": "Value1", "Key2": "Value2" }

Use AWS S3 Storage for Cloud Formation Stack Policy

UseS3ForStackPolicy

See docs

The URL for the Cloud Formation Policy in S3

CloudFormationStackPolicyURL

See docs

Delete Existing Stack

DeleteExistingStack = False

A boolean to state whether or not to delete the existing stack if one with the same name is found. If this is set to false and a stack with the same name is found, the step will fail.

Script body

Steps based on this template will execute the following PowerShell script.

#http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html

#Check for the PowerShell cmdlets
try{ 
    Import-Module AWSPowerShell -ErrorAction Stop
}catch{
    
    $modulePath = "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1"
    Write-Output "Unable to find the AWS module checking $modulePath" 
    
    try{
        Import-Module $modulePath
        
    }
    catch{
        throw "AWS PowerShell not found! Please make sure to install them from https://aws.amazon.com/powershell/" 
    }
}

function Confirm-CFNStackDeleted($credential, $stackName){
   do{
        $stack = $null
        try {
            $stack = Get-CFNStack -StackName $CloudFormationStackName -Credential $credential -Region $AWSRegion       
        }
        catch{}
        
        if($stack -ne $null){

			$stack | ForEach-Object {
				$progress = $_.StackStatus.ToString()
				$name = $_.StackName.ToString()

				Write-Host "Waiting for Cloud Formation Script to deleted. Stack Name: $name Operation status: $progress" 
         
				if($progress -ne "DELETE_COMPLETE" -and $progress -ne "DELETE_IN_PROGRESS"){                        
					$stack
					throw "Something went wrong deleting the Cloud Formation Template" 
				} 	 		
			} 
			 
            Start-Sleep -s 15
        }

    }until ($stack -eq $null)
}

function Confirm-CFNStackCompleted($credential, $stackName, $region){

    $awsValidStatusList = @()
    $awsValidStatusList += "CREATE_COMPLETE"
    $awsValidStatusList += "CREATE_IN_PROGRESS" 
    
    $awsFailedStatusList = @()
    $awsFailedStatusList += "CREATE_FAILED"
    $awsFailedStatusList += "UPDATE_FAILED"
    $awsFailedStatusList += "DELETE_SKIPPED"
    $awsFailedStatusList += "CREATE_FAILED"
    $awsFailedStatusList += "CREATE_FAILED"

	#http://docs.aws.amazon.com/powershell/latest/reference/Index.html
    #CREATE_COMPLETE | CREATE_FAILED | CREATE_IN_PROGRESS | DELETE_COMPLETE | DELETE_FAILED | DELETE_IN_PROGRESS | DELETE_SKIPPED | UPDATE_COMPLETE | UPDATE_FAILED | UPDATE_IN_PROGRESS.
	 
    do{
        $stack = Get-CFNStack -StackName $stackName -Credential $credential -Region $region  
		$complete = $false

		#Depending on the template sometimes there are multiple status per CFN template

		$stack | ForEach-Object {
			$progress = $_.StackStatus.ToString()
			$name = $_.StackName.ToString()

			Write-Host "Waiting for Cloud Formation Script to complete. Stack Name: $name Operation status: $progress" 
         
			if($progress -ne "CREATE_COMPLETE" -and $progress -ne "CREATE_IN_PROGRESS"){                        
				$stack
				throw "Something went wrong creating the Cloud Formation Template" 
			} 	 		
		}

		$inProgress = $stack | Where-Object { $_.StackStatus.ToString() -eq "CREATE_IN_PROGRESS" }
		
		if($inProgress.Count -eq 0){
			$complete = $true
		}
		 
        Start-Sleep -s 15

    }until ($complete -eq $true)
}

# Check the parameters.
if (-NOT $AWSSecretAccessKey) { throw "You must enter a value for 'AWS Access Key'." }
if (-NOT $AWSAccessKey) { throw "You must enter a value for 'AWS Secret Access Key'." }
if (-NOT $AWSRegion) { throw "You must enter a value for 'AWS Region'." }
if (-NOT $CloudFormationStackName) { throw "You must enter a value for 'AWS Cloud Formation Stack Name'." }  


#Reformat the CloudFormation parameters
$paramObject = ConvertFrom-Json $CloudFormationParameters
$cloudFormationParams = @()

$paramObject.psobject.properties | ForEach-Object { 
    $keyPair = New-Object -Type Amazon.CloudFormation.Model.Parameter
    $keyPair.ParameterKey = $_.Name
    $keyPair.ParameterValue = $_.Value

    $cloudFormationParams += $keyPair
} 

Write-Output "--------------------------------------------------"
Write-Output "AWS Region: $AWSRegion"
Write-Output "AWS Cloud Formation Stack Name: $CloudFormationStackName"
Write-Output "Use S3 for AWS Cloud Formation Script?: $UseS3ForCloudFormationTemplate"
Write-Output "Use S3 for AWS Cloud Formation Stack Policy?: $UseS3ForStackPolicy"
Write-Output "AWS Cloud Formation Script Url: $CloudFormationTemplateURL"
Write-Output "AWS Cloud Formation Stack Policy Url: $CloudFormationStackPolicyURL"
Write-Output "AWS Cloud Formation Parameters:"
Write-Output $cloudFormationParams
Write-Output "--------------------------------------------------"

#Set up the credentials and the dependencies
Set-DefaultAWSRegion -Region $AWSRegion
$credential = New-AWSCredentials -AccessKey $AWSAccessKey -SecretKey $AWSSecretAccessKey  

#Check to see if the stack exists
try{
    $stack = Get-CFNStack -StackName $CloudFormationStackName -Credential $credential -Region $AWSRegion    
}
catch{} #Do nothing as this will throw if the stack does not exist

if($stack -ne $null){
    if($DeleteExistingStack -eq $false) {
        Write-Output "Stack with name $CloudFormationStackName already exists. If you wish to automatically delete existing stacks, set 'Delete Existing Stack' to True."
        exit -1
    }
    Write-Output "Stack found, removing the existing Cloud Formation Stack"           
    
    Remove-CFNStack -Credential $credential -StackName $CloudFormationStackName -Region $AWSRegion -Force
    Confirm-CFNStackDeleted -credential $credential -stackName $CloudFormationStackName
}

if($UseS3ForCloudFormationTemplate -eq $true){   

    if (-NOT $CloudFormationTemplateURL) { throw "You must enter a value for 'AWS Cloud Formation Template'." } 

    if($UseS3ForStackPolicy -eq $true){
        Write-Output "Using Cloud Formation Stack Policy from $CloudFormationStackPolicyURL"
        New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateUrl $CloudFormationTemplateURL -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability -StackPolicyURL $CloudFormationStackPolicyURL
    }
    else {
        New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateUrl $CloudFormationTemplateURL -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability            
    }

    Confirm-CFNStackCompleted -credential $credential -stackName $CloudFormationStackName -region $AWSRegion
}
else{
    
    Write-Output "Using Cloud Formation script from Template"

    $validTemplate = Test-CFNTemplate -TemplateBody $CloudFormationTemplate -Region $AWSRegion  -Credential $credential
    $statusCode =  $validTemplate.HttpStatusCode.ToString()

    Write-Output "Validation Response: $statusCode"

    if($validTemplate.HttpStatusCode){

        if($UseS3ForStackPolicy -eq $true){
            Write-Output "Using Cloud Formation Stack Policy from $CloudFormationStackPolicyURL"
            New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateBody $CloudFormationTemplate -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability -StackPolicyURL $CloudFormationStackPolicyURL
        }
        else {
            New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateBody $CloudFormationTemplate -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability
        }

        Confirm-CFNStackCompleted -credential $credential -stackName $CloudFormationStackName -region $AWSRegion
    }
    else{
        throw "AWS Cloud Formation template is not valid"
    }         
}

$stack = Get-CFNStack -StackName $CloudFormationStackName -Credential $credential -Region $AWSRegion   

Set-OctopusVariable -name "AWSCloudFormationStack" -value $stack

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "d6d9d9db-e4ab-487c-967c-860bf8303052",
  "Name": "AWS - Create Cloud Formation Stack",
  "Description": "Creates a [Amazon Cloud Formation Stack](#http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html) with the template specified.\n\n- Requires the [AWS PowerShell cmdlets](http://aws.amazon.com/powershell/)",
  "Version": 50,
  "ExportedAt": "2017-02-06T22:56:26.736Z",
  "ActionType": "Octopus.Script",
  "Author": "kirkholloway",
  "Parameters": [
    {
      "Id": "13f780df-407d-48b9-b7d8-7bd92f47da38",
      "Name": "AWSSecretAccessKey",
      "Label": "AWS Secret Access Key",
      "HelpText": "The [secret access key](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html) to use when executing the script",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      },
      "Links": {}
    },
    {
      "Id": "520b8d18-fedd-49fc-a80c-957ea00fe532",
      "Name": "AWSAccessKey",
      "Label": "AWS Access Key",
      "HelpText": "The [access key](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html) to use when executing the script",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "ff776b86-a3f3-4d8c-b3e1-1e7ac629d503",
      "Name": "AWSRegion",
      "Label": "AWS Region",
      "HelpText": "The Amazon Region see (http://docs.aws.amazon.com/powershell/latest/reference/items/Get-AWSRegion.html) for further info",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "us-east-2|US East (Ohio)\nus-east-1|US East (N. Virginia)\nus-west-1|US West (N. California)\nus-west-2|US West (Oregon)\nca-central-1|Canada (Central)\nap-south-1|Asia Pacific (Mumbai)\nap-northeast-2|Asia Pacific (Seoul)\nap-southeast-1|Asia Pacific (Singapore)\nap-southeast-2|Asia Pacific (Sydney)\nap-northeast-1|Asia Pacific (Tokyo)\neu-central-1|EU (Frankfurt)\neu-west-1|EU (Ireland)\neu-west-2|EU (London)\nsa-east-1|South America (São Paulo)"
      },
      "Links": {}
    },
    {
      "Id": "772a57e1-824b-46bf-b652-31c27b3b8473",
      "Name": "CloudFormationStackName",
      "Label": "AWS Cloud Formation Stack Name",
      "HelpText": "The name of the AWS Cloud Formation Stack",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "8c6b8792-fc24-4f40-953e-4d8511b5e00d",
      "Name": "CloudFormationCapability",
      "Label": "AWS Cloud Formation Capability",
      "HelpText": "The capability required for the tempate see [docs](http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html)",
      "DefaultValue": "CAPABILITY_IAM",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "51433c58-fc29-4e73-aae0-5a40799fa16f",
      "Name": "CloudFormationOnFailure",
      "Label": "Action on Failure",
      "HelpText": "Defaults to ROLLBACK.  See [docs](http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html)",
      "DefaultValue": "ROLLBACK",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "a8919189-c361-4b05-ae4b-9aba650d9d0f",
      "Name": "UseS3ForCloudFormationTemplate",
      "Label": "Use AWS S3 storage for the Cloud Formation Template",
      "HelpText": "Whether to use S3 storage to source the Cloud Formation script.  See [docs](http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      },
      "Links": {}
    },
    {
      "Id": "7169c2f4-e1ff-45fa-99f1-7fcb49b1e313",
      "Name": "CloudFormationTemplate",
      "Label": "The Cloud Formation Template",
      "HelpText": "The Cloud Formation Template in the format, see [docs](http://aws.amazon.com/cloudformation/aws-cloudformation-templates/)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      },
      "Links": {}
    },
    {
      "Id": "48351ea3-fedb-43ec-b594-c2bbc11efb46",
      "Name": "CloudFormationTemplateURL",
      "Label": "The location in S3 for the Cloud Formation Template",
      "HelpText": null,
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "a01f0c6c-4a0c-4f32-9327-d6a22c10d10c",
      "Name": "CloudFormationParameters",
      "Label": "Cloud Formation Parameters",
      "HelpText": "See [docs](http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html)\n\nShould be provided as a JSON formatted object.\n\ne.g.`{ \"Key1\": \"Value1\", \"Key2\": \"Value2\" }`",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      },
      "Links": {}
    },
    {
      "Id": "ca922e15-fd36-4a0d-8717-660afc5e7aa9",
      "Name": "UseS3ForStackPolicy",
      "Label": "Use AWS S3 Storage for Cloud Formation Stack Policy",
      "HelpText": "See [docs](http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      },
      "Links": {}
    },
    {
      "Id": "869f2c5b-511f-4dee-bde7-30bee105b81d",
      "Name": "CloudFormationStackPolicyURL",
      "Label": "The URL for the Cloud Formation Policy in S3",
      "HelpText": "See [docs](http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "671b3717-d0b9-4285-915b-5a52ad52ff78",
      "Name": "DeleteExistingStack",
      "Label": "Delete Existing Stack",
      "HelpText": "A boolean to state whether or not to delete the existing stack if one with the same name is found. If this is set to false and a stack with the same name is found, the step will fail.",
      "DefaultValue": "False",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      },
      "Links": {}
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "#http://docs.aws.amazon.com/powershell/latest/reference/items/New-CFNStack.html\n\n#Check for the PowerShell cmdlets\ntry{ \n    Import-Module AWSPowerShell -ErrorAction Stop\n}catch{\n    \n    $modulePath = \"C:\\Program Files (x86)\\AWS Tools\\PowerShell\\AWSPowerShell\\AWSPowerShell.psd1\"\n    Write-Output \"Unable to find the AWS module checking $modulePath\" \n    \n    try{\n        Import-Module $modulePath\n        \n    }\n    catch{\n        throw \"AWS PowerShell not found! Please make sure to install them from https://aws.amazon.com/powershell/\" \n    }\n}\n\nfunction Confirm-CFNStackDeleted($credential, $stackName){\n   do{\n        $stack = $null\n        try {\n            $stack = Get-CFNStack -StackName $CloudFormationStackName -Credential $credential -Region $AWSRegion       \n        }\n        catch{}\n        \n        if($stack -ne $null){\n\n\t\t\t$stack | ForEach-Object {\n\t\t\t\t$progress = $_.StackStatus.ToString()\n\t\t\t\t$name = $_.StackName.ToString()\n\n\t\t\t\tWrite-Host \"Waiting for Cloud Formation Script to deleted. Stack Name: $name Operation status: $progress\" \n         \n\t\t\t\tif($progress -ne \"DELETE_COMPLETE\" -and $progress -ne \"DELETE_IN_PROGRESS\"){                        \n\t\t\t\t\t$stack\n\t\t\t\t\tthrow \"Something went wrong deleting the Cloud Formation Template\" \n\t\t\t\t} \t \t\t\n\t\t\t} \n\t\t\t \n            Start-Sleep -s 15\n        }\n\n    }until ($stack -eq $null)\n}\n\nfunction Confirm-CFNStackCompleted($credential, $stackName, $region){\n\n    $awsValidStatusList = @()\n    $awsValidStatusList += \"CREATE_COMPLETE\"\n    $awsValidStatusList += \"CREATE_IN_PROGRESS\" \n    \n    $awsFailedStatusList = @()\n    $awsFailedStatusList += \"CREATE_FAILED\"\n    $awsFailedStatusList += \"UPDATE_FAILED\"\n    $awsFailedStatusList += \"DELETE_SKIPPED\"\n    $awsFailedStatusList += \"CREATE_FAILED\"\n    $awsFailedStatusList += \"CREATE_FAILED\"\n\n\t#http://docs.aws.amazon.com/powershell/latest/reference/Index.html\n    #CREATE_COMPLETE | CREATE_FAILED | CREATE_IN_PROGRESS | DELETE_COMPLETE | DELETE_FAILED | DELETE_IN_PROGRESS | DELETE_SKIPPED | UPDATE_COMPLETE | UPDATE_FAILED | UPDATE_IN_PROGRESS.\n\t \n    do{\n        $stack = Get-CFNStack -StackName $stackName -Credential $credential -Region $region  \n\t\t$complete = $false\n\n\t\t#Depending on the template sometimes there are multiple status per CFN template\n\n\t\t$stack | ForEach-Object {\n\t\t\t$progress = $_.StackStatus.ToString()\n\t\t\t$name = $_.StackName.ToString()\n\n\t\t\tWrite-Host \"Waiting for Cloud Formation Script to complete. Stack Name: $name Operation status: $progress\" \n         \n\t\t\tif($progress -ne \"CREATE_COMPLETE\" -and $progress -ne \"CREATE_IN_PROGRESS\"){                        \n\t\t\t\t$stack\n\t\t\t\tthrow \"Something went wrong creating the Cloud Formation Template\" \n\t\t\t} \t \t\t\n\t\t}\n\n\t\t$inProgress = $stack | Where-Object { $_.StackStatus.ToString() -eq \"CREATE_IN_PROGRESS\" }\n\t\t\n\t\tif($inProgress.Count -eq 0){\n\t\t\t$complete = $true\n\t\t}\n\t\t \n        Start-Sleep -s 15\n\n    }until ($complete -eq $true)\n}\n\n# Check the parameters.\nif (-NOT $AWSSecretAccessKey) { throw \"You must enter a value for 'AWS Access Key'.\" }\nif (-NOT $AWSAccessKey) { throw \"You must enter a value for 'AWS Secret Access Key'.\" }\nif (-NOT $AWSRegion) { throw \"You must enter a value for 'AWS Region'.\" }\nif (-NOT $CloudFormationStackName) { throw \"You must enter a value for 'AWS Cloud Formation Stack Name'.\" }  \n\n\n#Reformat the CloudFormation parameters\n$paramObject = ConvertFrom-Json $CloudFormationParameters\n$cloudFormationParams = @()\n\n$paramObject.psobject.properties | ForEach-Object { \n    $keyPair = New-Object -Type Amazon.CloudFormation.Model.Parameter\n    $keyPair.ParameterKey = $_.Name\n    $keyPair.ParameterValue = $_.Value\n\n    $cloudFormationParams += $keyPair\n} \n\nWrite-Output \"--------------------------------------------------\"\nWrite-Output \"AWS Region: $AWSRegion\"\nWrite-Output \"AWS Cloud Formation Stack Name: $CloudFormationStackName\"\nWrite-Output \"Use S3 for AWS Cloud Formation Script?: $UseS3ForCloudFormationTemplate\"\nWrite-Output \"Use S3 for AWS Cloud Formation Stack Policy?: $UseS3ForStackPolicy\"\nWrite-Output \"AWS Cloud Formation Script Url: $CloudFormationTemplateURL\"\nWrite-Output \"AWS Cloud Formation Stack Policy Url: $CloudFormationStackPolicyURL\"\nWrite-Output \"AWS Cloud Formation Parameters:\"\nWrite-Output $cloudFormationParams\nWrite-Output \"--------------------------------------------------\"\n\n#Set up the credentials and the dependencies\nSet-DefaultAWSRegion -Region $AWSRegion\n$credential = New-AWSCredentials -AccessKey $AWSAccessKey -SecretKey $AWSSecretAccessKey  \n\n#Check to see if the stack exists\ntry{\n    $stack = Get-CFNStack -StackName $CloudFormationStackName -Credential $credential -Region $AWSRegion    \n}\ncatch{} #Do nothing as this will throw if the stack does not exist\n\nif($stack -ne $null){\n    if($DeleteExistingStack -eq $false) {\n        Write-Output \"Stack with name $CloudFormationStackName already exists. If you wish to automatically delete existing stacks, set 'Delete Existing Stack' to True.\"\n        exit -1\n    }\n    Write-Output \"Stack found, removing the existing Cloud Formation Stack\"           \n    \n    Remove-CFNStack -Credential $credential -StackName $CloudFormationStackName -Region $AWSRegion -Force\n    Confirm-CFNStackDeleted -credential $credential -stackName $CloudFormationStackName\n}\n\nif($UseS3ForCloudFormationTemplate -eq $true){   \n\n    if (-NOT $CloudFormationTemplateURL) { throw \"You must enter a value for 'AWS Cloud Formation Template'.\" } \n\n    if($UseS3ForStackPolicy -eq $true){\n        Write-Output \"Using Cloud Formation Stack Policy from $CloudFormationStackPolicyURL\"\n        New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateUrl $CloudFormationTemplateURL -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability -StackPolicyURL $CloudFormationStackPolicyURL\n    }\n    else {\n        New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateUrl $CloudFormationTemplateURL -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability            \n    }\n\n    Confirm-CFNStackCompleted -credential $credential -stackName $CloudFormationStackName -region $AWSRegion\n}\nelse{\n    \n    Write-Output \"Using Cloud Formation script from Template\"\n\n    $validTemplate = Test-CFNTemplate -TemplateBody $CloudFormationTemplate -Region $AWSRegion  -Credential $credential\n    $statusCode =  $validTemplate.HttpStatusCode.ToString()\n\n    Write-Output \"Validation Response: $statusCode\"\n\n    if($validTemplate.HttpStatusCode){\n\n        if($UseS3ForStackPolicy -eq $true){\n            Write-Output \"Using Cloud Formation Stack Policy from $CloudFormationStackPolicyURL\"\n            New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateBody $CloudFormationTemplate -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability -StackPolicyURL $CloudFormationStackPolicyURL\n        }\n        else {\n            New-CFNStack -Credential $credential -OnFailure $CloudFormationOnFailure -TemplateBody $CloudFormationTemplate -StackName $CloudFormationStackName -Region $AWSRegion -Parameter $cloudFormationParams -Capability $CloudFormationCapability\n        }\n\n        Confirm-CFNStackCompleted -credential $credential -stackName $CloudFormationStackName -region $AWSRegion\n    }\n    else{\n        throw \"AWS Cloud Formation template is not valid\"\n    }         \n}\n\n$stack = Get-CFNStack -StackName $CloudFormationStackName -Credential $credential -Region $AWSRegion   \n\nSet-OctopusVariable -name \"AWSCloudFormationStack\" -value $stack\n",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Package.PackageId": null
  },
  "Category": "AWS",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/aws-cloudformation-create.json",
  "Website": "/step-templates/d6d9d9db-e4ab-487c-967c-860bf8303052",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////9o0R/eLD/Nu0/erS95Qg+bhr95sv/vHh+r96/vjw+bFc/NSl+KI++82W+saI+KpNeDqM1wAAA41JREFUeNrsnG2XazAURiuo0Cr//9feliIvR3DvXJFZe3+a6XpW5+xWEpyY2w0AAAAAAAAAAAAAAAAAAADgf1J0bda/9N70q83a3enzUHWVjbR1sW0xp6sd6fPI72VmUt3zA+kymD6N5vnIBMrHsxHTjsUXOX0e+iVaTNU5Q0A/Q+k+4oAp+ixMbw6A4rGVVjGHR92ulNXWuTAlBNJN/FFyr5yy3qN9rawmF9IxR4hqX4U1WMplmGtruVBDuiuswbKkzaGhX+cfXsqbZlXXv0dsYR13nw9fLenGXD7f6U5Ony4yTpzyZLNMUcpMr0xNzfwdRRMR1/LP2cqMctNqKx1LZFydm2U022ueEtLL6HbHfmSRYRn4HDXaXyzU4XRkkZWK/+JlRBBBBBFEEEEEEUQQQQQRRBBB5B9uYJc7SyuLw+nI7R2ptKWJcywd18Utza0rnM4iN66M6qzS5E93Lf1zLaviUL/ISs/Nt6W00DEyuRgiP2Yxvrd15z/Y26ncG76jy1Ta5jEy/L0p/VMWy33woVm8UYN1Y9fqKrzfZ5iedtaV34+kNxHak2Wg2SSkY7djx/bQWkNP6nkE0lH3Lyx7D1aak1Z1erWJ+U130Vz0Sude7mZqv995nW7mZxJd27Sg5XQppuMdWY3xl1XXOge8MasWjZfund0KbvrkE9fK7OPNne+2U9YEWX3nemtSbvLv6LJ7gZ9X45yBl9ZxrZ9d3vjT8rz62tOsny7jXkpYPX9jQmvF8yF55TdaslGviZy1vAmfoTobsZztGNEv7qZZSr/6HRc/0yzlb3HiKhURRBBBBBFEEEEEEUQQQQQRRBD5XSLav38tllbVzeH02Ww/UWA+6XgsHdXFKc2vK5Quoz/duVRnlrb26crpizzXOVU3l2Zb5Pfe+d1OX8ViqW7qH9gt51K44bukr2XxrW54vMaoy7mxa/cgvPRVKcQG7uOCD58HLQLt3r17Iy6AqjYeDG7TUenWW+p9Ot/IOF/lwuHV1nk6o8M469PWXhtr+0BeX/x7Ue40W3xacfb2gXFxUZcX8TYB3Kyfp+GThsjKti2zgZuMiLshxW3gpiQyrn/DXhR/i1NqIte5pkUEEUQQQQQRRBBBBBFEEEEEEUR+g4jQUZBEqjqFO9mOiyeShoXvYoukZOG4GCLpWZgu83/vTNRidhlE0rYAAAAAAAAAAAAAAAAAAACAZPkjwAAMDi+bsnPP/wAAAABJRU5ErkJggg==",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Monday, February 6, 2017