Ever since Terraform was first launched by HashiCorp, infrastructure teams have been quick to leverage its functionality. Because deploying infrastructure via code became so much easier and error-free. This surely became a great way to deploy new infrastructure with custom configurations, but what about managing cloud infrastructure that is already defined?
Can Terraform be used to make changes to them? Or can it be used to deploy the same configurations to new environments? It maybe possible, but it’s not the preferred approach anyone follows.
Unfortunately managing existing resources is slightly complicated with Terraform. You will have to do a terraform-import and define a resource block in terraform configuration with complete resource metadata. This however is a complex process where you have to manually apply the import command for all resources that belong to a project.
Terraformer, a CLI tool developed by Waze SRE and made open-source soon after, became quickly popular because of its capabilities of overcoming these challenges.
Terraformer can do the reverse of what Terraform does. With Terraformer, you can generate tf/json and tfstate files (terraform files) based on your infrastructure’s existing configurations. The same can be done to your existing Squadcast resources too. Follow this guide to use Terraformer with Squadcast: https://developers.squadcast.com/terraform/tutorial/how-to-use-terraformer/
This is beneficial mainly for customers or users who have initially configured their Squadcast account using our API or Web UI. They can indeed use Terraformer to generate Terraform state files based on their account’s configuration. And they can continue to use Terraform going forward to manage their resources via IaC (Infrastructure as Code).
To generate Terraform files for your existing Squadcast configuration, you can use our Squadcast implementation of Terraformer.
You can either go to the following URL and download the appropriate binary for your OS: https://github.com/SquadcastHub/terraformer/releases
Or you can run one of the below commands from the terminal to download the appropriate binaries:
Go to the downloaded folder and run the below command to make the binary executable:
Move this executable to /usr/local/bin by running the below command:
Create a new directory in your home folder. Inside this directory, create a new file called versions.tf and add the following code:
And then initiate Terraform by running the following command:
Use Terraformer to import resources:
This will create a new generated folder with all terraform files (including statefiles) based on the previous command.
Go to /generated/squadcast/<RESOURCE_NAME>/<REGION>/provider.tf
Add source = "SquadcastHub/squadcast" to squadcast inside required_providers
Update version in required_providers by removing .exe (Windows users only)
First change path to this directory by running the following command:
And then run the following command:
Update generated files as per your requirement and apply the changes using following commands:
Now you’re good to go! In just a few simple steps you’ve converted your entire Squadcast configuration into Infrastructure as Code. You can now use this code file to manage all resources on Squadcast such as adding users in bulk, defining roles to users, deploying the entire configuration to another environment, and much more.
Squadcast is an incident management tool that’s purpose-built for SRE. Get rid of unwanted alerts, receive relevant notifications and integrate with popular ChatOps tools. Work in collaboration using virtual incident war rooms and use automation to eliminate toil.