Skip to content

Instantly share code, notes, and snippets.

@scrthq
Last active March 8, 2019 05:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scrthq/b9e90747e1ed218634619f2373a4ee4d to your computer and use it in GitHub Desktop.
Save scrthq/b9e90747e1ed218634619f2373a4ee4d to your computer and use it in GitHub Desktop.
VaporShell Snippets
# Recreation of the example found here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-document.html
$ssmDocContent = [PSCustomObject]@{
schemaVersion = "1.2"
description = "Join instances to an AWS Directory Service domain."
parameters = @{
directoryId = @{
type = "String"
description = "(Required) The ID of the AWS Directory Service directory."
}
directoryName = @{
type = "String"
description = "(Required) The name of the directory; for example, test.example.com"
}
dnsIpAddresses = @{
type = "StringList"
default = @()
description = "(Optional) The IP addresses of the DNS servers in the directory. Required when DHCP is not configured. Learn more at http://docs.aws.amazon.com/directoryservice/latest/simple-ad/join_get_dns_addresses.html"
allowedPattern = "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
}
}
runtimeConfig = @{
"aws:domainJoin" = @{
properties = @{
directoryId = "{{ directoryId }}"
directoryName = "{{ directoryName }}"
dnsIpAddresses = "{{ dnsIpAddresses }}"
}
}
}
}
$template = Initialize-Vaporshell -Description "AWS Domain Join SSM Doc"
$ssmDoc = New-VSSSMDocument -LogicalId 'document' -Content $ssmDocContent
$template.AddResource($ssmDoc)
$template.ToJson() # Creates the JSON string template seen below
$template.ToYaml() # Creates the YAML string template seen below (if cfn-flip is installed)
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Testing SSM docs",
"Resources": {
"document": {
"Type": "AWS::SSM::Document",
"Properties": {
"Content": {
"schemaVersion": "1.2",
"description": "Join instances to an AWS Directory Service domain.",
"parameters": {
"dnsIpAddresses": {
"allowedPattern": "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",
"description": "(Optional) The IP addresses of the DNS servers in the directory. Required when DHCP is not configured. Learn more at http://docs.aws.amazon.com/directoryservice/latest/simple-ad/join_get_dns_addresses.html",
"default": [
],
"type": "StringList"
},
"directoryName": {
"type": "String",
"description": "(Required) The name of the directory; for example, test.example.com"
},
"directoryId": {
"type": "String",
"description": "(Required) The ID of the AWS Directory Service directory."
}
},
"runtimeConfig": {
"aws:domainJoin": {
"properties": {
"dnsIpAddresses": "{{ dnsIpAddresses }}",
"directoryName": "{{ directoryName }}",
"directoryId": "{{ directoryId }}"
}
}
}
}
}
}
}
}
AWSTemplateFormatVersion: '2010-09-09'
Description: Testing SSM docs
Resources:
document:
Type: AWS::SSM::Document
Properties:
Content:
schemaVersion: '1.2'
description: Join instances to an AWS Directory Service domain.
parameters:
dnsIpAddresses:
allowedPattern: ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
description: >-
(Optional) The IP addresses of the DNS servers in the directory. Required
when DHCP is not configured. Learn more at http://docs.aws.amazon.com/directoryservice/latest/simple-ad/join_get_dns_addresses.html
default: []
type: StringList
directoryName:
type: String
description: (Required) The name of the directory; for example, test.example.com
directoryId:
type: String
description: (Required) The ID of the AWS Directory Service directory.
runtimeConfig:
aws:domainJoin:
properties:
dnsIpAddresses: '{{ dnsIpAddresses }}'
directoryName: '{{ directoryName }}'
directoryId: '{{ directoryId }}'
$ssmDocContent = [PSCustomObject]@{
schemaVersion = "1.2"
description = "Join instances to an AWS Directory Service domain."
parameters = @{
directoryId = @{
type = "String"
description = "(Required) The ID of the AWS Directory Service directory."
}
directoryName = @{
type = "String"
description = "(Required) The name of the directory; for example, test.example.com"
}
dnsIpAddresses = @{
type = "StringList"
default = @()
description = "(Optional) The IP addresses of the DNS servers in the directory. Required when DHCP is not configured. Learn more at http://docs.aws.amazon.com/directoryservice/latest/simple-ad/join_get_dns_addresses.html"
allowedPattern = "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
}
}
runtimeConfig = @{
"aws:domainJoin" = @{
properties = @{
directoryId = "{{ directoryId }}"
directoryName = "{{ directoryName }}"
dnsIpAddresses = "{{ dnsIpAddresses }}"
}
}
}
}
New-SSMDocument -Content ($ssmDocContent | ConvertTo-Json -Depth 10)
@sheldonhull
Copy link

This is for schema 1.2, this can easily be modified thanks to your work to 2.2 schema. Just need to figure out if I use AWSPowershell to then upload to AWS or vaporshell has a "publish" type of command for the doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment