zapatilla
zapatilla

Reputation: 1833

How to manage several Terraform states

I am using Terraform to automatically deploy an Azure Resource Group with a VM. It's working great and now I'm onto my next step.

The purpose of my project is to provide users with a means to deploy their user-defined Azure RGs. So a typical user will use my portal to enter some details on a form about how they'd like their RG to be called, which location, username and SSH keys for the VM, etc., and then on the backend I'm populating a Terraform template with their input, then running terraform apply.

So far so good since I'm the only user.

When this goes into production, there'll be several users. They can create one or more resource groups and I was wondering how is best to handle this with Terraform. Should I just create one folder per user and RG (or some entry on a DB), so I can keep the state there? Or is there a better way to do this? I'll need this in order to do things like destroying a user resource, or checking a resource's status, etc.

I'm going with Terraform and I'd like to not have to use the Azure SDK if I can avoid it.

Upvotes: 1

Views: 147

Answers (1)

Francozen
Francozen

Reputation: 389

You could use a terraform backend https://www.terraform.io/docs/backends/index.html to store the state into the cloud storage solution of your choice. Using some $var to identify the deployment and this token as one of the URI element. For instance, user 'A' could have the state saved in gs://bucket/A/state , that did the trick for us using GCS.

Upvotes: 2

Related Questions