Here you need to specify user data content to terraform resource "aws_instance".
Here is the user data:
resource "aws_instance" "this" {
ami = "${local.ami_this_id}"
instance_type = "${var.instance_type}"
subnet_id = "${var.subnet_id}"
vpc_security_group_ids = "${var.security_group_ids}"
key_name = "${aws_key_pair.this.key_name}"
iam_instance_profile = "${var.ec2_instance_profile_id}"
user_data = data.template_file.user_data.rendered # <----- Specify userdata content
root_block_device {
volume_type = "${var.root_volume_type}"
volume_size = "${var.root_volume_size}"
delete_on_termination = true
}
}
then for S3 upload:
resource "local_file" "userdata_sh" {
content = data.template_file.user_data.rendered
filename = "your_local_userdata_sh_path"
}
resource "aws_s3_bucket_object" "object" {
bucket = "your_s3_bucket_name"
key = "userdata.sh"
source = "your_local_userdata_sh_path"
etag = "${filemd5("your_local_userdata_sh_path")}"
}
Interested to know about AWS? Come & join AWS Training provided by Intellipaat.