Skip to content

Commit

Permalink
Merge pull request #159 from lorengordon/el-userdata
Browse files Browse the repository at this point in the history
Removes install of cfn-utils from userdata
  • Loading branch information
lorengordon authored Sep 16, 2019
2 parents be5a4d3 + 1149b29 commit 72c0b9f
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.15.7
current_version = 1.15.8
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
1 change: 0 additions & 1 deletion modules/lx-autoscale/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ resource "aws_cloudformation_stack" "watchmaker-lx-autoscale" {
AsgMetrics = "${join(",", var.AsgMetrics)}"
AsgNotificationTypes = "${join(",", var.AsgNotificationTypes)}"
AsgSnsArn = "${var.AsgSnsArn}"
CfnBootstrapUtilsUrl = "${var.CfnBootstrapUtilsUrl}"
CfnEndpointUrl = "${var.CfnEndpointUrl}"
CfnStackSignalTimeout = "${var.TimeoutInMinutes}"
CloudWatchAgentUrl = "${var.CloudWatchAgentUrl}"
Expand Down
6 changes: 0 additions & 6 deletions modules/lx-autoscale/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,6 @@ variable "CfnEndpointUrl" {
default = "https://cloudformation.us-east-1.amazonaws.com"
}

variable "CfnBootstrapUtilsUrl" {
type = "string"
description = "URL to aws-cfn-bootstrap-latest.tar.gz"
default = "https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz"
}

variable "ToggleCfnInitUpdate" {
type = "string"
description = "A/B toggle that forces a change to instance metadata, triggering the cfn-init update sequence"
Expand Down
2 changes: 0 additions & 2 deletions modules/lx-autoscale/watchmaker-lx-autoscale.params.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
ParameterValue: __ASGNOTIFICATION__
- ParameterKey: AsgSnsArn
ParameterValue: __ASGSNSARN__
- ParameterKey: CfnBootstrapUtilsUrl
ParameterValue: __CFNBOOTSTRAPUTILSURL__
- ParameterKey: CfnEndpointUrl
ParameterValue: __CFNENDPOINTURL__
- ParameterKey: CloudWatchAgentUrl
Expand Down
51 changes: 2 additions & 49 deletions modules/lx-autoscale/watchmaker-lx-autoscale.template.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ Metadata:
default: CloudFormation Configuration
Parameters:
- CfnEndpointUrl
- CfnBootstrapUtilsUrl
- CfnStackSignalTimeout
- CloudWatchAgentUrl
- CloudWatchAppLogs
Expand All @@ -206,7 +205,7 @@ Metadata:
default: Force Cfn Init Update
ToggleNewInstances:
default: Force New Instances
Version: 1.15.7
Version: 1.15.8
Outputs:
ScaleDownScheduledAction:
Condition: UseScheduledAction
Expand Down Expand Up @@ -323,12 +322,6 @@ Parameters:
(Optional) The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to send Asg events to.
NOTE: Must be defined in conjunction with AsgNotificationTypes.
Type: String
CfnBootstrapUtilsUrl:
AllowedPattern: '^http[s]?://.*\.tar\.gz$'
Default: >-
https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
Description: URL to aws-cfn-bootstrap-latest.tar.gz
Type: String
CfnEndpointUrl:
AllowedPattern: '^$|^http[s]?://.*$'
Default: 'https://cloudformation.us-east-1.amazonaws.com'
Expand Down Expand Up @@ -1025,47 +1018,7 @@ Resources:
export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt
export AWS_DEFAULT_REGION=${AWS::Region}
# Get pip
python3 -m ensurepip
# Add pip to path
hash pip 2> /dev/null || PATH="${!PATH}:/usr/local/bin"
# Upgrade pip and setuptools
PYPI_URL=${PypiIndexUrl}
PIP_PKG=pip
if [[ $(cat /proc/version | grep -o 'el.') == 'el6' ]]
then
PIP_PKG='pip<=19.1.*'
fi
python3 -m pip install --index-url="$PYPI_URL" --upgrade "$PIP_PKG" setuptools
# Fix python urllib3 warnings
yum -y install gcc python-devel libffi-devel openssl-devel
python3 -m pip install --index-url="$PYPI_URL" --upgrade cffi
python3 -m pip install --index-url="$PYPI_URL" --upgrade cryptography
if [[ $(rpm --quiet -q aws-cfn-bootstrap || pip show --quiet aws-cfn-bootstrap)$? -ne 0 ]]
then
# Get cfn utils
python3 -m pip install --index-url="$PYPI_URL" --upgrade --upgrade-strategy only-if-needed ${CfnBootstrapUtilsUrl}
# Fixup cfn utils
INITDIR=$(find -L /opt/aws/apitools/cfn-init/init -name redhat 2> /dev/null || echo /usr/init/redhat)
chmod 775 ${!INITDIR}/cfn-hup
ln -f -s ${!INITDIR}/cfn-hup /etc/rc.d/init.d/cfn-hup
chkconfig --add cfn-hup
chkconfig cfn-hup on
mkdir -p /opt/aws/bin
BINDIR=$(find -L /opt/aws/apitools/cfn-init -name bin 2> /dev/null || echo /usr/bin)
for SCRIPT in cfn-elect-cmd-leader cfn-get-metadata cfn-hup cfn-init cfn-send-cmd-event cfn-send-cmd-result cfn-signal
do
ln -s ${!BINDIR}/${!SCRIPT} /opt/aws/bin/${!SCRIPT} 2> /dev/null || echo Skipped symbolic link, /opt/aws/bin/${!SCRIPT} already exists
done
fi
# Remove gcc now that it is no longer needed
yum -y remove gcc --setopt=clean_requirements_on_remove=1
# Add cfn utils to path
# Ensure cfn utils are in path
hash cfn-signal 2> /dev/null || PATH="${!PATH}:/usr/local/bin:/opt/aws/bin"
# Execute cfn-init
Expand Down
1 change: 0 additions & 1 deletion modules/lx-instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ resource "aws_cloudformation_stack" "watchmaker-lx-instance" {
AppVolumeSize = "${var.AppVolumeSize}"
AppVolumeSnapshotId = "${var.AppVolumeSnapshotId}"
AppVolumeType = "${var.AppVolumeType}"
CfnBootstrapUtilsUrl = "${var.CfnBootstrapUtilsUrl}"
CfnEndpointUrl = "${var.CfnEndpointUrl}"
CfnStackSignalTimeout = "${var.TimeoutInMinutes}"
CloudWatchAgentUrl = "${var.CloudWatchAgentUrl}"
Expand Down
6 changes: 0 additions & 6 deletions modules/lx-instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,6 @@ variable "CfnEndpointUrl" {
default = "https://cloudformation.us-east-1.amazonaws.com"
}

variable "CfnBootstrapUtilsUrl" {
type = "string"
description = "URL to aws-cfn-bootstrap-latest.tar.gz"
default = "https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz"
}

variable "ToggleCfnInitUpdate" {
type = "string"
description = "A/B toggle that forces a change to instance metadata, triggering the cfn-init update sequence"
Expand Down
2 changes: 0 additions & 2 deletions modules/lx-instance/watchmaker-lx-instance.params.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
ParameterValue: __APPVOLUMESIZE__
- ParameterKey: AppVolumeType
ParameterValue: __APPVOLUMETYPE__
- ParameterKey: CfnBootstrapUtilsUrl
ParameterValue: __CFNBOOTSTRAPUTILSURL__
- ParameterKey: CfnEndpointUrl
ParameterValue: __CFNENDPOINTURL__
- ParameterKey: CloudWatchAgentUrl
Expand Down
51 changes: 2 additions & 49 deletions modules/lx-instance/watchmaker-lx-instance.template.cfn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,14 @@ Metadata:
default: CloudFormation Configuration
Parameters:
- CfnEndpointUrl
- CfnBootstrapUtilsUrl
- CfnStackSignalTimeout
- CloudWatchAgentUrl
- CloudWatchAppLogs
- ToggleCfnInitUpdate
ParameterLabels:
ToggleCfnInitUpdate:
default: Force Cfn Init Update
Version: 1.15.7
Version: 1.15.8
Outputs:
WatchmakerInstanceId:
Description: Instance ID
Expand Down Expand Up @@ -243,12 +242,6 @@ Parameters:
Default: gp2
Description: Type of EBS volume to create. Ignored if "AppVolumeDevice" is false
Type: String
CfnBootstrapUtilsUrl:
AllowedPattern: '^http[s]?://.*\.tar\.gz$'
Default: >-
https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
Description: URL to aws-cfn-bootstrap-latest.tar.gz
Type: String
CfnEndpointUrl:
AllowedPattern: '^$|^http[s]?://.*$'
Default: 'https://cloudformation.us-east-1.amazonaws.com'
Expand Down Expand Up @@ -858,47 +851,7 @@ Resources:
export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt
export AWS_DEFAULT_REGION=${AWS::Region}
# Get pip
python3 -m ensurepip
# Add pip to path
hash pip 2> /dev/null || PATH="${!PATH}:/usr/local/bin"
# Upgrade pip and setuptools
PYPI_URL=${PypiIndexUrl}
PIP_PKG=pip
if [[ $(cat /proc/version | grep -o 'el.') == 'el6' ]]
then
PIP_PKG='pip<=19.1.*'
fi
python3 -m pip install --index-url="$PYPI_URL" --upgrade "$PIP_PKG" setuptools
# Fix python urllib3 warnings
yum -y install gcc python-devel libffi-devel openssl-devel
python3 -m pip install --index-url="$PYPI_URL" --upgrade cffi
python3 -m pip install --index-url="$PYPI_URL" --upgrade cryptography
if [[ $(rpm --quiet -q aws-cfn-bootstrap || pip show --quiet aws-cfn-bootstrap)$? -ne 0 ]]
then
# Get cfn utils
python3 -m pip install --index-url="$PYPI_URL" --upgrade --upgrade-strategy only-if-needed ${CfnBootstrapUtilsUrl}
# Fixup cfn utils
INITDIR=$(find -L /opt/aws/apitools/cfn-init/init -name redhat 2> /dev/null || echo /usr/init/redhat)
chmod 775 ${!INITDIR}/cfn-hup
ln -f -s ${!INITDIR}/cfn-hup /etc/rc.d/init.d/cfn-hup
chkconfig --add cfn-hup
chkconfig cfn-hup on
mkdir -p /opt/aws/bin
BINDIR=$(find -L /opt/aws/apitools/cfn-init -name bin 2> /dev/null || echo /usr/bin)
for SCRIPT in cfn-elect-cmd-leader cfn-get-metadata cfn-hup cfn-init cfn-send-cmd-event cfn-send-cmd-result cfn-signal
do
ln -s ${!BINDIR}/${!SCRIPT} /opt/aws/bin/${!SCRIPT} 2> /dev/null || echo Skipped symbolic link, /opt/aws/bin/${!SCRIPT} already exists
done
fi
# Remove gcc now that it is no longer needed
yum -y remove gcc --setopt=clean_requirements_on_remove=1
# Add cfn utils to path
# Ensure cfn utils are in path
hash cfn-signal 2> /dev/null || PATH="${!PATH}:/usr/local/bin:/opt/aws/bin"
# Execute cfn-init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Metadata:
default: Force Cfn Init Update
ToggleNewInstances:
default: Force New Instances
Version: 1.15.7
Version: 1.15.8
Outputs:
ScaleDownScheduledAction:
Condition: UseScheduledAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Metadata:
ParameterLabels:
ToggleCfnInitUpdate:
default: Force Cfn Init Update
Version: 1.15.7
Version: 1.15.8
Outputs:
WatchmakerInstanceId:
Description: Instance ID
Expand Down
20 changes: 20 additions & 0 deletions tests/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ module "lx-instance-centos6" {
AmiDistro = "CentOS"
AppVolumeSize = "10"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_centos}"
DisableRollback = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t2.micro"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "25"
SecurityGroupIds = "${local.security_group}"
SubnetId = "${var.subnet_id}"
Expand All @@ -30,11 +32,13 @@ module "lx-instance-centos7" {
AmiDistro = "CentOS"
AppVolumeSize = "10"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_centos}"
DisableRollback = "true"
EbsOptimized = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.micro"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "25"
SecurityGroupIds = "${local.security_group}"
SubnetId = "${var.subnet_id}"
Expand All @@ -54,10 +58,12 @@ module "lx-autoscale-centos6" {
AsgNotificationTypes = "${var.AsgNotificationTypes}"
AsgSnsArn = "${aws_sns_topic.tf-aws-wam.arn}"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_centos}"
DisableRollback = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t2.micro"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "25"
SecurityGroupIds = "${local.security_group}"
SubnetIds = "${var.subnet_id}"
Expand All @@ -77,11 +83,13 @@ module "lx-autoscale-centos7" {
AsgNotificationTypes = "${var.AsgNotificationTypes}"
AsgSnsArn = "${aws_sns_topic.tf-aws-wam.arn}"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_centos}"
DisableRollback = "true"
EbsOptimized = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.micro"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "25"
SecurityGroupIds = "${local.security_group}"
SubnetIds = "${var.subnet_id}"
Expand All @@ -97,11 +105,13 @@ module "win-instance-2008R2" {
AmiId = "${data.aws_ami.windows2008R2.image_id}"
AppVolumeSize = "10"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_win}"
DisableRollback = "true"
EbsOptimized = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.medium"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "35"
SecurityGroupIds = "${local.security_group}"
SubnetId = "${var.subnet_id}"
Expand All @@ -116,11 +126,13 @@ module "win-instance-2012R2" {
AmiId = "${data.aws_ami.windows2012R2.image_id}"
AppVolumeSize = "10"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_win}"
DisableRollback = "true"
EbsOptimized = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.medium"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "35"
SecurityGroupIds = "${local.security_group}"
SubnetId = "${var.subnet_id}"
Expand All @@ -135,11 +147,13 @@ module "win-instance-2016" {
AmiId = "${data.aws_ami.windows2016.image_id}"
AppVolumeSize = "10"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_win}"
DisableRollback = "true"
EbsOptimized = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.medium"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "35"
SecurityGroupIds = "${local.security_group}"
SubnetId = "${var.subnet_id}"
Expand All @@ -157,11 +171,13 @@ module "win-autoscale-2008R2" {
AsgNotificationTypes = "${var.AsgNotificationTypes}"
AsgSnsArn = "${aws_sns_topic.tf-aws-wam.arn}"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_win}"
DisableRollback = "true"
EbsOptimized = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.medium"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "35"
SecurityGroupIds = "${local.security_group}"
SubnetIds = "${var.subnet_id}"
Expand All @@ -179,10 +195,12 @@ module "win-autoscale-2012R2" {
AsgNotificationTypes = "${var.AsgNotificationTypes}"
AsgSnsArn = "${aws_sns_topic.tf-aws-wam.arn}"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_win}"
DisableRollback = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.medium"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "35"
SecurityGroupIds = "${local.security_group}"
SubnetIds = "${var.subnet_id}"
Expand All @@ -200,10 +218,12 @@ module "win-autoscale-2016" {
AsgNotificationTypes = ["autoscaling:EC2_INSTANCE_LAUNCH", "autoscaling:EC2_INSTANCE_LAUNCH_ERROR", "autoscaling:EC2_INSTANCE_TERMINATE", "autoscaling:EC2_INSTANCE_TERMINATE_ERROR", "autoscaling:TEST_NOTIFICATION"]
AsgSnsArn = "${aws_sns_topic.tf-aws-wam.arn}"
CloudWatchAgentUrl = "${var.cloudwatch_agent_url_win}"
DisableRollback = "true"
InstanceRole = "${var.instance_role}"
InstanceType = "t3.medium"
KeyPairName = "${local.keypair_name}"
NoPublicIp = "false"
OnFailureAction = ""
RootVolumeSize = "35"
SecurityGroupIds = "${local.security_group}"
SubnetIds = "${var.subnet_id}"
Expand Down
6 changes: 0 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,6 @@ variable "CfnGetPipUrl" {
default = "https://bootstrap.pypa.io/2.6/get-pip.py"
}

variable "CfnBootstrapUtilsUrl" {
type = "string"
description = "URL to aws-cfn-bootstrap-latest.tar.gz"
default = "https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz"
}

variable "ToggleCfnInitUpdate" {
type = "string"
description = "A/B toggle that forces a change to instance metadata, triggering the cfn-init update sequence"
Expand Down

0 comments on commit 72c0b9f

Please sign in to comment.