In this article I will demonstrate how one can create different environments for development needs through terraform modules. Modules provide great extensibility and code reuse. In this example I will use an appservice resource on Azure cloud.
The result of the deployment will be two different resource groups with two app services. The code of the demonstration is located at the bottom of the page.
You should first init your module. Navigate to the module folder and perform init
cd modules; terraform init
cd .. ; terraform init
Then validate your terraform code
terraform validate
The last step is to apply your configuration
terraform apply
You may encounter an error during the creation of the resources because of the app service name. It should be globally unique.
Change your name and perform a terraform apply again. Terraform will read your .tfstate file and will only implement the differences on infrastructure.
After the successful run you will see the green result output from terraform cli.
On Azure there should be two resource groups created. One for prod environment and one for test.
Inside each resource group there should be a different app service the one that it is created through the module according with the settings provided.
Terraform is one of the best automation providers for DevOps purposes used by hundred of Engineers. It is an open source tool that can be used by anyone for free. In this article I will explain how to deploy windows and linux virtual machines on Azure using a Terraform template.
First things first you will need to have the az cli installed. Then you will have to set your subscription on your current powershell session.
az account set --subscription "12abc123-4567-1234-12345-asdr4334fsd"
Then you will need to create an app role assignment for your subscription. This will be used from terraform for the provision of the resources.
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/12abc123-4567-1234-12345-asdr4334fsd"
That’s all. You can now deploy your resources through terraform. In the links below I have provided my Github repository along with instructions for the template use.
A tricky part of the deployment is the vm image selection. In order to locate the available azure images names you can use:
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here:
Cookie Policy