Reputation: 33
I am trying to update my already existing launch template on AWS using Terraform. Below is the config for Terraform.
resource "aws_launch_template" "update" {
name = data.aws_launch_template.config.name
image_id = data.aws_ami.ubuntu.id
instance_type = "c5.large"
// arn = data.aws_launch_template.config.arn
}
On passing the name it is throwing error 400 with the below error.
Error: InvalidLaunchTemplateName.AlreadyExistsException: Launch template name already in use.
I want the same launch template with just update version. Couldn't able to find any documentation on terraform official website for modifying templates. Or am I missing something?
OS - macOS Catalina
Terraform version - v0.12.21
Upvotes: 2
Views: 4567
Reputation: 8947
One thing to note about terraform in general is that it wants to own the entire lifecycle of any resources it manages.
In your example, aws_launch_template.update
with that name already exists, so terraform says, essentially, "I don't own this resource, so I shouldn't change it."
This is actually a pretty nice benefit because it means that terraform wont (or at least shouldn't) overwrite or delete resources that it doesn't know about.
Now, since you are referencing an existing launch template, I would recommend bringing it under terraform's ownership (that's assuming you're allowed to do so). To do this, I would recommend
Hard-coding the launch template's name in the resource itself, rather than referencing it via data
, and
Importing the resource by running a command like so
terraform import aws_launch_template.update lt-12345678
Where you would replace lt-12345678
with your actual launch template ID. This will bring the resource under terraform's ownership and actually allow updates via terraform code.
Just be careful that you're not stepping on the toes of someone else's resources, if you are in a context where this was created by someone else.
Upvotes: 5