On AWS, since ami_from_instance exist in terraform, why should Packer be required to generate AMIs?
On AWS, since ami_from_instance exist in terraform, why should Packer be required to generate AMIs?
Terraform allows provisionning aws infrastructures with custom ansible scripts.
Since the function ami_from_instance from terraform,
allow convert an Instance into an AMI, and aws_instance the opposit.
I am quite new to that tools and I might not understand their subtilities but why should the common pattern of using Packer to generate the ami instanciated by Terraform be used ?
aws_ami_from_instance
@ydaetskcoR it is probably a good answer in that it starts to describe a detailed way to avoid packer
– user1767316
Aug 31 at 15:14
Why do you want to avoid Packer though? Despite it being technically possible to do it with Terraform I don't think it's a good approach and I don't know of anyone that promotes doing so.
– ydaetskcoR
Aug 31 at 15:50
@ydaetskcoR Because learning a single tool should cost less, and because I find efficient Terraform's write-plan-create steps and its restart habilities at dev time.
– user1767316
Sep 1 at 21:13
2 Answers
2
I am not going to repeat what "ydaetskcoR" had already mentioned. Grt points. Another usecase that Packer really does is sharing the AMI With multiple accounts. In our setup, we create AMI in one account and shared it other accounts to be used. Packer is specifically build to create AMI's and so has many features than the simple Terraform's ami_from_instance. My 2 cents
Because Packer creates an AMI with Configuration as Code, you will have a reproducible recipe for how you AMI's are created.
If you would use Terraforms ami_from_instance
you instead creates clones of an non-reproducible source, thus creating snowflake servers (all are slightly different).
ami_from_instance
Also on important feature of a public cloud is autoscaling and for that you want to start off with AMI's that includes as much as possible so the startup time is small. This makes a pre-baked AMI better than a generic with a initialisation script that installs and configure all adaptations to you production environment.
This isn't strictly true. You could use Terraform to spin up an instance just as Packer does and then use a remote provisioner to configure it as Packer does. You'd then need something that would tear down the instance without deregistering the AMI (a
terraform destroy
will deregister the AMI) but it is workable. Just strictly worse at it than Packer for little gain (avoiding writing a short Packer JSON config).– ydaetskcoR
Sep 3 at 7:31
terraform destroy
Sure, but it's like using a chainsaw to hit nails. It kind of works, but most likely you will cut your self.
– Rickard von Essen
Sep 3 at 7:56
Yep, I agree it's not a good tool for it but I don't think your answer as is really explains why because it is technically possible to achieve the same thing. In general I think it's more of an opinion based question where some opinions are wrong ;)
– ydaetskcoR
Sep 3 at 8:06
@RickardvonEssen yes it is using chainsaw to hit nails, but since you need to master you shainsaw anyway, it migth be better to do all with your running schainsaw, since the Packer "hammer" still need some investment to be mastered (learning to use it and to debug it still has a cost)
– user1767316
Nov 15 at 10:07
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I'm not sure this is going to get a good answer because it's probably subjective but Packer is specifically targeted at creating images and handles the lifecycle of the thing it's creating the image of in a nicer fashion than Terraform's
aws_ami_from_instance
resource. To do the same as Packer with Terraform you'd need to define an instance resource, then the ami_from_instance resource and then somehow destroy the instance afterwards because Terraform will start it back up. Running a Terraform destroy against both the instance and ami_from_instance will deregister the AMI.– ydaetskcoR
Aug 31 at 14:52