Terraform: cloud-config.yaml script not running on initial EC2 boot









up vote
-1
down vote

favorite












I've created a cloudinit script called "cloud-config.yaml". I want to have ths script executed for each EC2 instance that is launched from my Terraformm launch configuration definition. Everything works except the cloudinit script does not execute on the newly created instances. I'm not sure what I am doing wrong. Any help on where I should look would be appreciated.



Below are the snippets of my code:



#cloud-config

#Enable byobu by default for all system users
byobu_by_default: system

# Update apt database on first boot
# (ie run apt-get update)
#
# Default: true
#
apt_update: false

# Upgrade the instance on first boot
# (ie run apt-get upgrade)
#
# Default: false
#
apt_upgrade: true

#Create user accounts
users:
- name: demo
- sudo: ['ALL=(ALL) NOPASSWD:ALL']
- groups: sudo
- shell: /bin/bash

# Install additional packages on first boot
#
# Default: none
#
# if packages are specified, this apt_update will be set to true
#
packages:
- apache2
- mariadb-client
- software-properties-common
- php
- libapache2-mod-php
- php-mysql
- curl
- wget
- awscli

# Run additional commands on first boot
runcmd:
- ufw disable
- aws s3 sync s3://terraform-web-files/ /var/www/html --recursive


/**************************************************************************
PUBLIC Launch Configuration
***************************************************************************/

//Define the Launch Configuration
resource "aws_launch_configuration" "terraform-public-lc"
image_id = "$var.ami"
instance_type = "$var.instance_type"
security_groups = ["$aws_security_group.tf-public-sg.id"]
key_name = "$var.key_name"
associate_public_ip_address = true

user_data = "$path.module/../../../../Development/services/web-app/cloud-config.yaml"

lifecycle
create_before_destroy = true











share|improve this question

















  • 2




    What do the cloud-init log files under /var/log/ show?
    – ydaetskcoR
    Nov 10 at 17:52










  • Reading through the logs I found my error. Thank you!
    – Scott Chaffee
    Nov 14 at 19:37










  • Was the error something another user might find? If so you should consider self answering so others might be able to solve the same problem at a later date.
    – ydaetskcoR
    Nov 14 at 20:40














up vote
-1
down vote

favorite












I've created a cloudinit script called "cloud-config.yaml". I want to have ths script executed for each EC2 instance that is launched from my Terraformm launch configuration definition. Everything works except the cloudinit script does not execute on the newly created instances. I'm not sure what I am doing wrong. Any help on where I should look would be appreciated.



Below are the snippets of my code:



#cloud-config

#Enable byobu by default for all system users
byobu_by_default: system

# Update apt database on first boot
# (ie run apt-get update)
#
# Default: true
#
apt_update: false

# Upgrade the instance on first boot
# (ie run apt-get upgrade)
#
# Default: false
#
apt_upgrade: true

#Create user accounts
users:
- name: demo
- sudo: ['ALL=(ALL) NOPASSWD:ALL']
- groups: sudo
- shell: /bin/bash

# Install additional packages on first boot
#
# Default: none
#
# if packages are specified, this apt_update will be set to true
#
packages:
- apache2
- mariadb-client
- software-properties-common
- php
- libapache2-mod-php
- php-mysql
- curl
- wget
- awscli

# Run additional commands on first boot
runcmd:
- ufw disable
- aws s3 sync s3://terraform-web-files/ /var/www/html --recursive


/**************************************************************************
PUBLIC Launch Configuration
***************************************************************************/

//Define the Launch Configuration
resource "aws_launch_configuration" "terraform-public-lc"
image_id = "$var.ami"
instance_type = "$var.instance_type"
security_groups = ["$aws_security_group.tf-public-sg.id"]
key_name = "$var.key_name"
associate_public_ip_address = true

user_data = "$path.module/../../../../Development/services/web-app/cloud-config.yaml"

lifecycle
create_before_destroy = true











share|improve this question

















  • 2




    What do the cloud-init log files under /var/log/ show?
    – ydaetskcoR
    Nov 10 at 17:52










  • Reading through the logs I found my error. Thank you!
    – Scott Chaffee
    Nov 14 at 19:37










  • Was the error something another user might find? If so you should consider self answering so others might be able to solve the same problem at a later date.
    – ydaetskcoR
    Nov 14 at 20:40












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I've created a cloudinit script called "cloud-config.yaml". I want to have ths script executed for each EC2 instance that is launched from my Terraformm launch configuration definition. Everything works except the cloudinit script does not execute on the newly created instances. I'm not sure what I am doing wrong. Any help on where I should look would be appreciated.



Below are the snippets of my code:



#cloud-config

#Enable byobu by default for all system users
byobu_by_default: system

# Update apt database on first boot
# (ie run apt-get update)
#
# Default: true
#
apt_update: false

# Upgrade the instance on first boot
# (ie run apt-get upgrade)
#
# Default: false
#
apt_upgrade: true

#Create user accounts
users:
- name: demo
- sudo: ['ALL=(ALL) NOPASSWD:ALL']
- groups: sudo
- shell: /bin/bash

# Install additional packages on first boot
#
# Default: none
#
# if packages are specified, this apt_update will be set to true
#
packages:
- apache2
- mariadb-client
- software-properties-common
- php
- libapache2-mod-php
- php-mysql
- curl
- wget
- awscli

# Run additional commands on first boot
runcmd:
- ufw disable
- aws s3 sync s3://terraform-web-files/ /var/www/html --recursive


/**************************************************************************
PUBLIC Launch Configuration
***************************************************************************/

//Define the Launch Configuration
resource "aws_launch_configuration" "terraform-public-lc"
image_id = "$var.ami"
instance_type = "$var.instance_type"
security_groups = ["$aws_security_group.tf-public-sg.id"]
key_name = "$var.key_name"
associate_public_ip_address = true

user_data = "$path.module/../../../../Development/services/web-app/cloud-config.yaml"

lifecycle
create_before_destroy = true











share|improve this question













I've created a cloudinit script called "cloud-config.yaml". I want to have ths script executed for each EC2 instance that is launched from my Terraformm launch configuration definition. Everything works except the cloudinit script does not execute on the newly created instances. I'm not sure what I am doing wrong. Any help on where I should look would be appreciated.



Below are the snippets of my code:



#cloud-config

#Enable byobu by default for all system users
byobu_by_default: system

# Update apt database on first boot
# (ie run apt-get update)
#
# Default: true
#
apt_update: false

# Upgrade the instance on first boot
# (ie run apt-get upgrade)
#
# Default: false
#
apt_upgrade: true

#Create user accounts
users:
- name: demo
- sudo: ['ALL=(ALL) NOPASSWD:ALL']
- groups: sudo
- shell: /bin/bash

# Install additional packages on first boot
#
# Default: none
#
# if packages are specified, this apt_update will be set to true
#
packages:
- apache2
- mariadb-client
- software-properties-common
- php
- libapache2-mod-php
- php-mysql
- curl
- wget
- awscli

# Run additional commands on first boot
runcmd:
- ufw disable
- aws s3 sync s3://terraform-web-files/ /var/www/html --recursive


/**************************************************************************
PUBLIC Launch Configuration
***************************************************************************/

//Define the Launch Configuration
resource "aws_launch_configuration" "terraform-public-lc"
image_id = "$var.ami"
instance_type = "$var.instance_type"
security_groups = ["$aws_security_group.tf-public-sg.id"]
key_name = "$var.key_name"
associate_public_ip_address = true

user_data = "$path.module/../../../../Development/services/web-app/cloud-config.yaml"

lifecycle
create_before_destroy = true








amazon-web-services terraform cloud-init terraform-template-file






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 20:40









Scott Chaffee

173




173







  • 2




    What do the cloud-init log files under /var/log/ show?
    – ydaetskcoR
    Nov 10 at 17:52










  • Reading through the logs I found my error. Thank you!
    – Scott Chaffee
    Nov 14 at 19:37










  • Was the error something another user might find? If so you should consider self answering so others might be able to solve the same problem at a later date.
    – ydaetskcoR
    Nov 14 at 20:40












  • 2




    What do the cloud-init log files under /var/log/ show?
    – ydaetskcoR
    Nov 10 at 17:52










  • Reading through the logs I found my error. Thank you!
    – Scott Chaffee
    Nov 14 at 19:37










  • Was the error something another user might find? If so you should consider self answering so others might be able to solve the same problem at a later date.
    – ydaetskcoR
    Nov 14 at 20:40







2




2




What do the cloud-init log files under /var/log/ show?
– ydaetskcoR
Nov 10 at 17:52




What do the cloud-init log files under /var/log/ show?
– ydaetskcoR
Nov 10 at 17:52












Reading through the logs I found my error. Thank you!
– Scott Chaffee
Nov 14 at 19:37




Reading through the logs I found my error. Thank you!
– Scott Chaffee
Nov 14 at 19:37












Was the error something another user might find? If so you should consider self answering so others might be able to solve the same problem at a later date.
– ydaetskcoR
Nov 14 at 20:40




Was the error something another user might find? If so you should consider self answering so others might be able to solve the same problem at a later date.
– ydaetskcoR
Nov 14 at 20:40

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232981%2fterraform-cloud-config-yaml-script-not-running-on-initial-ec2-boot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232981%2fterraform-cloud-config-yaml-script-not-running-on-initial-ec2-boot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo