Skip to content

Commit

Permalink
Merge pull request #272 from eemperor/devname
Browse files Browse the repository at this point in the history
Fixes device name usage for extra EBS volume
  • Loading branch information
eemperor committed Feb 9, 2021
2 parents ebe1a8a + c709559 commit 61113f4
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 188 deletions.
3 changes: 1 addition & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.0
current_version = 2.1.1
commit = True
message = Bumps version to {new_version}
tag = False
Expand All @@ -20,4 +20,3 @@ replace = Version: {new_version}
[bumpversion:file:modules/win-instance/watchmaker-win-instance.template.cfn.yaml]
search = Version: {current_version}
replace = Version: {new_version}

17 changes: 1 addition & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
ARCH ?= amd64
OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:'])
CURL ?= curl --fail -sSL
XARGS ?= xargs -I {}

BIN_DIR ?= ${HOME}/bin
PATH := $(BIN_DIR):$(PATH)

VERSION ?= $$(grep -E '^current_version' .bumpversion.cfg | sed 's/^.*= //')

MAKEFLAGS += --no-print-directory
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.SUFFIXES:
SHELL := /bin/bash

-include $(shell curl -sSL -o .tardigrade-ci "https://raw.githubusercontent.com/plus3it/tardigrade-ci/master/bootstrap/Makefile.bootstrap"; echo .tardigrade-ci)

guard/program/%:
@ which $* > /dev/null || $(MAKE) $*/install

cfn/%: FIND_CFN ?= find . $(FIND_EXCLUDES) -name '*.template.cfn.*' -type f
cfn/version: guard/program/yq
cfn/version:
$(FIND_CFN) | $(XARGS) bash -c "yq -e '.Metadata.Version | test(\"^$(VERSION)$$\")' {} > /dev/null || (echo '[{}]: BAD/MISSING Cfn Version Metadata'; exit 1)"

cfn/lint: | guard/program/cfn-lint
$(FIND_CFN) | $(XARGS) cfn-lint -t {}
136 changes: 76 additions & 60 deletions modules/lx-autoscale/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions modules/lx-autoscale/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resource "aws_cloudformation_stack" "watchmaker-lx-autoscale" {
AppScriptShell = var.AppScriptShell
AppScriptUrl = var.AppScriptUrl
AppVolumeDevice = var.AppVolumeDevice
AppVolumeDeviceName = var.AppVolumeDeviceName
AppVolumeMountPath = var.AppVolumeMountPath
AppVolumeEncrypted = var.AppVolumeEncrypted
AppVolumeSize = var.AppVolumeSize
Expand Down
6 changes: 6 additions & 0 deletions modules/lx-autoscale/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ variable "AppVolumeDevice" {
default = false
}

variable "AppVolumeDeviceName" {
type = string
description = "(Optional) Device name to give to the extra EBS volume. Ignored if AppVolumeDevice is false"
default = "/dev/xvdf"
}

variable "AppVolumeEncrypted" {
type = bool
description = "(Optional) Controls whether the EBS volume will be encrypted"
Expand Down
2 changes: 2 additions & 0 deletions modules/lx-autoscale/watchmaker-lx-autoscale.params.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
ParameterValue: __APPSCRIPTURL__
- ParameterKey: AppVolumeDevice
ParameterValue: __APPVOLUMEDEVICE__
- ParameterKey: AppVolumeDeviceName
ParameterValue: __APPVOLUMEDEVICENAME__
- ParameterKey: AppVolumeEncrypted
ParameterValue: __APPVOLUMEENCRYPTED__
- ParameterKey: AppVolumeMountPath
Expand Down
19 changes: 13 additions & 6 deletions modules/lx-autoscale/watchmaker-lx-autoscale.template.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Metadata:
default: EC2 Application EBS Volume
Parameters:
- AppVolumeDevice
- AppVolumeDeviceName
- AppVolumeEncrypted
- AppVolumeMountPath
- AppVolumeSize
Expand Down Expand Up @@ -207,7 +208,7 @@ Metadata:
default: Force Cfn Init Update
ToggleNewInstances:
default: Force New Instances
Version: 2.1.0
Version: 2.1.1
Outputs:
ScaleDownScheduledAction:
Condition: UseScheduledAction
Expand Down Expand Up @@ -270,6 +271,13 @@ Parameters:
Decision whether to mount an extra EBS volume. Leave as default ("false")
to launch without an extra application volume
Type: String
AppVolumeDeviceName:
AllowedPattern: '/dev/xvd[f-k]'
Default: '/dev/xvdf'
Description: >-
Device name to be given to extra EBS volume. Ignored if "AppVolumeDevice"
is false
Type: String
AppVolumeEncrypted:
AllowedValues:
- 'false'
Expand Down Expand Up @@ -969,7 +977,7 @@ Resources:
VolumeType: gp2
- !If
- CreateAppVolume
- DeviceName: /dev/xvdf
- DeviceName: !Ref AppVolumeDeviceName
Ebs:
DeleteOnTermination: true
Encrypted: !Ref AppVolumeEncrypted
Expand Down Expand Up @@ -1013,13 +1021,12 @@ Resources:
#!/bin/bash -xe
# Format and mount app volume
APPVOL_DEVICE="$(ls /dev/xvdf /dev/nvme1n1 2> /dev/null || true)"
if [[ -n "$APPVOL_DEVICE" && "${AppVolumeDevice}" == "true" ]]
if [[ "${AppVolumeDevice}" == "true" ]]
then
MOUNT_VFSTYPE="auto"
MOUNT_OPTS="defaults,nofail"
cloud-init-per instance mkfsappvolume mkfs -t ext4 "$APPVOL_DEVICE"
grep -q "$APPVOL_DEVICE" /etc/fstab || printf "%s\t%s\t%s\t%s\t0\t2\n" "$APPVOL_DEVICE" "${AppVolumeMountPath}" "$MOUNT_VFSTYPE" "$MOUNT_OPTS" >> /etc/fstab
cloud-init-per instance mkfsappvolume mkfs -t ext4 "${AppVolumeDeviceName}"
grep -q "${AppVolumeDeviceName}" /etc/fstab || printf "%s\t%s\t%s\t%s\t0\t2\n" "${AppVolumeDeviceName}" "${AppVolumeMountPath}" "$MOUNT_VFSTYPE" "$MOUNT_OPTS" >> /etc/fstab
mkdir -p "${AppVolumeMountPath}"
mount -a
fi
Expand Down
1 change: 1 addition & 0 deletions modules/lx-instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ with an AWS CloudFormation template to deploy a Watchmaker Linux Instance.
| AppScriptShell | (Optional) Shell with which to execute the application script. Ignored if AppScriptUrl is blank | `string` | `"bash"` | no |
| AppScriptUrl | (Optional) S3 URL to the application script in an S3 bucket (s3://). Leave blank to launch without an application script. If specified, an appropriate InstanceRole is required | `string` | `null` | no |
| AppVolumeDevice | (Optional) Decision whether to mount an extra EBS volume. Leave as default (false) to launch without an extra application volume | `bool` | `false` | no |
| AppVolumeDeviceName | (Optional) Device name to be given to the extra EBS volume. Ignored if AppVolumeDevice is false | `string` | `"/dev/xvdf"` | no |
| AppVolumeEncrypted | (Optional) Controls whether the EBS volume will be encrypted. When KmsKeyId is specified, EBS encryption will be done using that, otherwise encrypted using AWS managed CMK | `bool` | `false` | no |
| AppVolumeMountPath | (Optional) Filesystem path to mount the extra app volume. Ignored if AppVolumeDevice is false | `string` | `"/opt/data"` | no |
| AppVolumeSize | (Optional) Size in GB of the EBS volume to create. Ignored if AppVolumeDevice is false | `string` | `"1"` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/lx-instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resource "aws_cloudformation_stack" "watchmaker-lx-instance" {
AppScriptShell = var.AppScriptShell
AppScriptUrl = var.AppScriptUrl
AppVolumeDevice = var.AppVolumeDevice
AppVolumeDeviceName = var.AppVolumeDeviceName
AppVolumeEncrypted = var.AppVolumeEncrypted
AppVolumeMountPath = var.AppVolumeMountPath
AppVolumeSize = var.AppVolumeSize
Expand Down
6 changes: 6 additions & 0 deletions modules/lx-instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ variable "AppVolumeDevice" {
default = false
}

variable "AppVolumeDeviceName" {
type = string
description = "(Optional) Device name to be given to the extra EBS volume. Ignored if AppVolumeDevice is false"
default = "/dev/xvdf"
}

variable "AppVolumeEncrypted" {
type = bool
description = "(Optional) Controls whether the EBS volume will be encrypted. When KmsKeyId is specified, EBS encryption will be done using that, otherwise encrypted using AWS managed CMK"
Expand Down
2 changes: 2 additions & 0 deletions modules/lx-instance/watchmaker-lx-instance.params.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
ParameterValue: __APPSCRIPTURL__
- ParameterKey: AppVolumeDevice
ParameterValue: __APPVOLUMEDEVICE__
- ParameterKey: AppVolumeDeviceName
ParameterValue: __APPVOLUMEDEVICENAME__
- ParameterKey: AppVolumeEncrypted
ParameterValue: __APPVOLUMEENCRYPTED__
- ParameterKey: AppVolumeMountPath
Expand Down
19 changes: 13 additions & 6 deletions modules/lx-instance/watchmaker-lx-instance.template.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Metadata:
default: EC2 Application EBS Volume
Parameters:
- AppVolumeDevice
- AppVolumeDeviceName
- AppVolumeEncrypted
- AppVolumeMountPath
- AppVolumeSize
Expand All @@ -163,7 +164,7 @@ Metadata:
ParameterLabels:
ToggleCfnInitUpdate:
default: Force Cfn Init Update
Version: 2.1.0
Version: 2.1.1
Outputs:
WatchmakerInstanceId:
Description: Instance ID
Expand Down Expand Up @@ -215,6 +216,13 @@ Parameters:
Decision on whether to mount an extra EBS volume. Leave as default
("false") to launch without an extra application volume
Type: String
AppVolumeDeviceName:
AllowedPattern: '/dev/xvd[f-k]'
Default: '/dev/xvdf'
Description: >-
Device name to be given to the extra EBS volume. Ignored if
"AppVolumeDevice" is false
Type: String
AppVolumeEncrypted:
AllowedValues:
- 'false'
Expand Down Expand Up @@ -797,7 +805,7 @@ Resources:
VolumeType: gp2
- !If
- CreateAppVolume
- DeviceName: /dev/xvdf
- DeviceName: !Ref AppVolumeDeviceName
Ebs:
DeleteOnTermination: true
Encrypted: !Ref AppVolumeEncrypted
Expand Down Expand Up @@ -867,13 +875,12 @@ Resources:
#!/bin/bash -xe
# Format and mount app volume
APPVOL_DEVICE="$(ls /dev/xvdf /dev/nvme1n1 2> /dev/null || true)"
if [[ -n "$APPVOL_DEVICE" && "${AppVolumeDevice}" == "true" ]]
if [[ "${AppVolumeDevice}" == "true" ]]
then
MOUNT_VFSTYPE="auto"
MOUNT_OPTS="defaults,nofail"
cloud-init-per instance mkfsappvolume mkfs -t ext4 "$APPVOL_DEVICE"
grep -q "$APPVOL_DEVICE" /etc/fstab || printf "%s\t%s\t%s\t%s\t0\t2\n" "$APPVOL_DEVICE" "${AppVolumeMountPath}" "$MOUNT_VFSTYPE" "$MOUNT_OPTS" >> /etc/fstab
cloud-init-per instance mkfsappvolume mkfs -t ext4 "${AppVolumeDeviceName}"
grep -q "${AppVolumeDeviceName}" /etc/fstab || printf "%s\t%s\t%s\t%s\t0\t2\n" "${AppVolumeDeviceName}" "${AppVolumeMountPath}" "$MOUNT_VFSTYPE" "$MOUNT_OPTS" >> /etc/fstab
mkdir -p "${AppVolumeMountPath}"
mount -a
fi
Expand Down
10 changes: 3 additions & 7 deletions modules/win-autoscale/watchmaker-win-autoscale.template.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Metadata:
default: Force Cfn Init Update
ToggleNewInstances:
default: Force New Instances
Version: 2.1.0
Version: 2.1.1
Outputs:
ScaleDownScheduledAction:
Condition: UseScheduledAction
Expand Down Expand Up @@ -881,28 +881,24 @@ Resources:
- UseWamStandalone
- !Sub |
# Download watchmaker standalone pkg
[Net.ServicePointManager]::SecurityProtocol = "Ssl3, Tls, Tls11, Tls12"
[Net.ServicePointManager]::SecurityProtocol = "Tls12"
(New-Object System.Net.WebClient).DownloadFile("${WatchmakerStandaloneUrl}", "c:\cfn\scripts\watchmaker.exe")
- !Sub
- |
[Net.ServicePointManager]::SecurityProtocol = "Tls12"
$BootstrapUrl = "${WatchmakerBootstrapper}"
$PythonUrl = "${PythonInstaller}"
$PypiUrl = "${PypiIndexUrl}"
# Get the host
$PypiHost="$(([System.Uri]$PypiUrl).Host)"
# Download bootstrap file
$BootstrapFile = "${!Env:Temp}\$(${!BootstrapUrl}.split('/')[-1])"
(New-Object System.Net.WebClient).DownloadFile("$BootstrapUrl", "$BootstrapFile")
# Install python
& "$BootstrapFile" -PythonUrl "$PythonUrl" -Verbose -ErrorAction Stop
# Install setup dependencies
python -m pip install --index-url="$PypiUrl" --trusted-host="$PypiHost" --upgrade pip setuptools
if (-not $?) { throw 'pip failed to install setup dependencies!' }
# Install watchmaker
pip install --index-url="$PypiUrl" --trusted-host="$PypiHost" --upgrade boto3 ${local_WatchmakerPkg}
if (-not $?) { throw 'pip failed to install watchmaker!' }
Expand Down
10 changes: 3 additions & 7 deletions modules/win-instance/watchmaker-win-instance.template.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Metadata:
ParameterLabels:
ToggleCfnInitUpdate:
default: Force Cfn Init Update
Version: 2.1.0
Version: 2.1.1
Outputs:
WatchmakerInstanceId:
Description: Instance ID
Expand Down Expand Up @@ -701,28 +701,24 @@ Resources:
- UseWamStandalone
- !Sub |
# Download watchmaker standalone pkg
[Net.ServicePointManager]::SecurityProtocol = "Ssl3, Tls, Tls11, Tls12"
[Net.ServicePointManager]::SecurityProtocol = "Tls12"
(New-Object System.Net.WebClient).DownloadFile("${WatchmakerStandaloneUrl}", "c:\cfn\scripts\watchmaker.exe")
- !Sub
- |
[Net.ServicePointManager]::SecurityProtocol = "Tls12"
$BootstrapUrl = "${WatchmakerBootstrapper}"
$PythonUrl = "${PythonInstaller}"
$PypiUrl = "${PypiIndexUrl}"
# Get the host
$PypiHost="$(([System.Uri]$PypiUrl).Host)"
# Download bootstrap file
$BootstrapFile = "${!Env:Temp}\$(${!BootstrapUrl}.split('/')[-1])"
(New-Object System.Net.WebClient).DownloadFile("$BootstrapUrl", "$BootstrapFile")
# Install python
& "$BootstrapFile" -PythonUrl "$PythonUrl" -Verbose -ErrorAction Stop
# Install setup dependencies
python -m pip install --index-url="$PypiUrl" --trusted-host="$PypiHost" --upgrade pip setuptools
if (-not $?) { throw 'pip failed to install setup dependencies!' }
# Install watchmaker
pip install --index-url="$PypiUrl" --trusted-host="$PypiHost" --upgrade boto3 ${local_WatchmakerPkg}
if (-not $?) { throw 'pip failed to install watchmaker!' }
Expand Down
20 changes: 0 additions & 20 deletions tests/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ data "aws_vpc" "this" {
default = "true"
}

data "aws_ami" "centos6" {
most_recent = true
owners = ["701759196663"]

filter {
name = "name"
values = ["*spel-minimal-centos-6*"]
}

filter {
name = "is-public"
values = ["true"]
}

filter {
name = "state"
values = ["available"]
}
}

data "aws_ami" "centos7" {
most_recent = true
owners = ["701759196663"]
Expand Down
Loading

0 comments on commit 61113f4

Please sign in to comment.