I'm using terraform to automate creating an EC2 instance and installing LAMP stack. I'm using cloud-init for user data. AWS console shows the user data is rendered. However, the system log shows the commands are not executed. The system log shows different issues randomly it seems. Any insight is appreciated!
terraform 0.10.8 Amazon Linux AMI latest version
See below error sometimes during config phase.
Starting cloud-init: Cloud-init v. 0.7.6 running 'modules:config'
Loaded plugins: priorities, update-motd, upgrade-helper
/dev/fd/11: line 1: /sbin/plymouthd: No such file or directory
Sometimes see below warnings during cloud-init "init" phase.
cloud-init[2442]: util.py[WARNING]: Failed loading yaml
blob-init[2442]: util.py[WARNING]: Failed loading yaml blob
cloud-init[2442]: util.py[WARNING]: Failed at merging in cloud config part from part-001
Code below
resource "aws_instance" "ec2_min" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
vpc_security_group_ids = ["${data.aws_security_group.ec2_sg.id}"]
iam_instance_profile = "${var.instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
subnet_id = "${data.aws_subnet.subnet.id}"
key_name = "${aws_key_pair.ssh_key.key_name}"
user_data = "${data.template_file.lamp_install.rendered}"
tags {
Name = "${var.instance_name}"
}
}
data "template_file" "lamp_install" {
template = "${file("${var.cloud_init_conf}")}"
}
#cloud-config
repo_update: true
repo_upgrade: all
packages:
- httpd24
- php70
- mysql56-server
- php70-mysqlnd
runcmd:
- service httpd start
- chkconfig httpd on
- [ sh, -c, "usermod -a -G apache ec2-user" ]
- [ sh, -c, "chown -R ec2-user:apache /var/www" ]
- chmod 2775 /var/www
- [ find, /var/www, -type, d, -exec, chmod, 2775, {}, + ]
- [ find, /var/www, -type, f, -exec, chmod, 0664, {}, + ]
- service mysqld start
- chkconfig mysqld on