New Module Creation for our own Infrastructure

Hi Team,
I am new to terraform ,have been assigned to create modules in terraform for installation of piece of softwares and service restarts , could you please suggest me with this

  1. Installation of tomcat software on RedHat Linux Operating System which is residing in VMware ESX Cluster
  2. Instance recycle (Tomcat) restarts

Thanks in Advance

In my experience that’s not really a good use case for Terraform. Chef, Puppet, Salt, Ansible… those are tools which are good for installing software and managing services.

Agreed totally with @kpfleming. The ideal way to deal with this in a system involving Terraform is:

  • Use imaging software to prepare custom machine images that already contain the software you need, configured to launch immediately on boot if appropriate. For example, you could use HashiCorp Packer.
  • Use Terraform to create and manage virtual machines that boot up using those custom machine images, so that they’ll start their useful work immediately without any further configuration.
  • If the software in the VM requires access to information not known until Terraform runs, use a platform-specific mechanism such as AWS’s user_data to pass those in as data, and have the software in your images retrieve that data from the platform’s user data service during boot.

Notice that in the above case there is no need to coordinate a reboot because the imaging process and the final boot process are already separated by a boot sequence. In this model we replace rebooting with taking an image of the configured temporary machine after the configuration steps have completed and then booting an entirely separate new long-lived machine from that image.

If you wanted to do this with the combination of HashiCorp Packer and HashiCorp Terraform then I expect your work here would be to write a Packer template that describes the installation of Tomcat, and then separately a Terraform module that expects a virtual machine image id or disk image id (depending on your target VM platform) as an input variable. You could either use shell scripts directly in Packer to orchestrate your Tomcat installation, or if the installation steps are more complex then you can configure Packer to run configuration management software like Chef, Puppet, Salt, or Ansible as @kpfleming suggested.

To use that then, you’d have a build process that you run each time you need to produce a new machine image, and then you can update the Terraform configuration to refer to your new image and run terraform apply to replace your existing machines with new machines running the new image.