achahbar adnane
achahbar adnane

Reputation: 1

Provisioning VMs with Terraform on vSphere

I want to automate the creation of virtual machines with Terraform on vSphere, I have already made the scripts and they're pretty good at what they do.

i want a way to manage the state file, the thing is that once we create a VM it will be up for a very long time (years in some cases).

I want to reuse the same scripts to provision the VMs each time a team wants one, how should i approach this, should i delete the state file each time I have to re-run them, should i create a workspace each time I run the script ? should use a wrapper like Terragrunt ?

Any suggestions would be really helpful.

Thanks!

I delete the state file each time I have to create a new VM.

Upvotes: 0

Views: 59

Answers (1)

Marko E
Marko E

Reputation: 18203

You should definitely consider using remote state management. This means you would need to define a backend where the state file(s) will be stored. If you were to delete a state file for the infrastructure that was already deployed, you would lose the way to manage it at any point in the future, unless you import it into state again. I would probably not use the workspaces feature in this case, although it's a matter of preference. I would instead probably use a tfvars file per environment, as is explained in the workspaces docs. Terragrunt is just a wrapper, but it does not solve any of the questions you mention by default. One example is that it can help in cases where the projects have a lot of dependencies, but from your question it's unclear how complex the terraform code (modules?) is. Finally, you would also have to consider how to organize the separate state files per environment in the backend of your choice. That is where some of the dynamic features of terragrunt might be heplful.

Upvotes: 0

Related Questions