Terraform code in AWS deploys the instance but not not running bash script. Script runs updates, deploys apache, creates small page etc. Everything works and instances is running. When connected to instance, there is no /var/www folder, so this tells me this is not being run. Manually entering the commands works, just not with script.
Any assistance is appreciated!
Here are my files… c1-versions.tf
Terraform Block
terraform {
required_version = "~> 1.7" # which means any version equal & above 0.14 like 0.15, 0.16 etc and < 1.xx
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.38"
}
}
}
Provider Block
provider "aws" {
region = "us-east-1"
}
/*
Note-1: AWS Credentials Profile (profile = "default") configured on your local desktop terminal
$HOME/.aws/credentials
*/
This is unfortunately more a cloud-init problem than a Terraform problem, since Terraform’s responsibility here is only to send the script you wrote to the AWS API. The script execution is done by cloud-init when your instance is booting.
Therefore you might get some more information by following the guide How to debug cloud-init.
Folks in this forum might still be able to offer suggestions about cloud-init, but since this is not really a Terraform-specific problem it might help to also ask this question in a cloud-init-specific forum, or in a more general forum where participants are more likely to be familiar with cloud-init, such as DevOps StackExchange.
From reading, am I understanding that ALL AWS linux AMIs use cloud-init. Reason I ask, person I’m taking the course with says “this code works”.
I’ve changed the AMI ID to another AWS linux destro but still fails.
Seems to me this would defeat the purpose if every Linux AMI forced cloud-init, then everything has to be manually installed?
I have not read How to debug cloud-init.
I did post the question to DevOps Stackexchange though.
Cloud-init is the de-facto standard used by most Linux distributions, but it is technically possible to use other software to handle initialization, and some more specialized AMIs do so. This user_data mechanism is really just a network API that any software in your VM can access, but it’s conventional in general-purpose Linux distributions to run cloud-init during boot, and for cloud-init to fetch this data and act on it.
Unless you build your own AMI or you choose an image that was built for a more specialist purpose, it’s likely that most third-party Linux AMIs (but not necessarily other platforms) will use cloud-init.
DevOps StackExchange had no replies to my post.
Crap, I’m on first lab of this Terraform course and can’t get the first lab completed. Makes me feel like I’m going to have other issues.
Being new to Terraform I know I’ll most likely never figure out how cloud-init works in conjunction with Terraform.
Twiddling thumbs