Answer the question
In order to leave comments, you need to log in
Terraform does not respond to user_data changes. What's wrong?
There is a regular ec2 instance with user_data that is already working:
resource "aws_instance" "myWebServer" {
ami = "ami-0c6ebbd55ab05f070" # Ubuntu Linux AMI
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.webServerSG.id]
user_data = templatefile("externalScripts/user_data.tpl", {
name = "Leo",
names = ["Vasya", "Petya"]
})
tags = {
Name = "myWebServer"
}
resource "aws_instance" "myWebServer" {
ami = "ami-0c6ebbd55ab05f070" # Ubuntu Linux AMI
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.webServerSG.id]
user_data = templatefile("externalScripts/user_data.tpl", {
name = "Leo",
names = ["Vasya", "Petya", "MASHA"]
})
tags = {
Name = "myWebServer"
}
Answer the question
In order to leave comments, you need to log in
Most likely, here is your problem: https://github.com/hashicorp/terraform-provider-aw...
in short: in version 4.0 of the AWS provider for terraform, the following behavior is implemented: user data can be changed on the created (but turned off) instance and changing it should not cause the instance to be recreated. The documentation says that the instance should stop and start, but, as far as I understand, this does not happen for you.
Presumably, adding a random resource should help you solve the problem (for the resource re-creation trigger) https://registry.terraform.io/providers/hashicorp /... with the keeper as the result of the userdata template, and specifying it in depends_on for the instance resource
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question