2

I have a Terraform script for make a deploy of Ubuntu.

resource "aws_instance" "runner" {
  instance_type = "${var.instance_type}"
  ami = "${var.ami}"
  user_data =   "${data.template_file.deploy.rendered}"
}

data "template_file" "deploy" {
  template = "${file("cloudinit.tpl")}"

}

My cloudinit.tpl:

#cloud-config
runcmd:
  - apt-get update
  - sleep 30
  - apt-get install -y  awscli

I can't find any issue on cloud-init.log and can't find user-data.log file in /var/log to understand why user-data is not working.

kenlukas
  • 3,616
  • 9
  • 25
  • 36
Brygom
  • 818
  • 1
  • 12
  • 31
  • 1
    Why the sleep? Can you post the relevant part of `/var/log/cloud-init-output.log`? If you view the user data for the instance in the AWS console what does it show? – ydaetskcoR Aug 16 '19 at 08:21
  • I use sleep for wait to update finish, in ```/var/log/cloud-init-output.log``` i have this: ```E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?``` – Brygom Aug 16 '19 at 17:52
  • There's btw. also [`packages`](https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages), which also runs `apt-get update` automatically for you. – StephenKing Aug 16 '19 at 18:16

1 Answers1

0

Cloud-init has a special command for system update which carry on about consistency

#cloud-config
package_update: true
package_upgrade: true
packages: ['awscli']

runcmd:
  - aws --version

Than you may see command output in the log file, for Ubuntu it is /var/log/cloud-init-output.log

Roman Shishkin
  • 2,097
  • 20
  • 21