Azure Terraform projects to automate database deployments. In this project we deploy Microsoft SQL database and implement database initialization scripts such as data account creation and assign roles.
Pre-requisites :
- Need Azure CLI installed on your local device.
- Need Terraform installed on your local device.
- Azure Subscription
- Azure Resource Group
- Azure KeyVault set up
Steps to execute : Below steps will work on any of the projects in this repo.
terraform init terraform plan terraform apply -auto-approve terraform destroy -auto-approve
terraform init initializes all the providers refereenced in the script.
terraform plan will show any possible errors in the scripts. Fix the scripts if there are any errors before moving forward.
terraform apply -auto-approve creates all the resources defined in scripts on your Azure resource group.
terraform destroy -auto-approve deletes all the resources defined in scripts on your Azure resource group.
In this example we assume that a resource group already exists so we use the data block. All the resources will be created in this resource group.
Create Azure Key Vault to store secrets such as database admin password. The purpose of this is to keep the admin password secure and not provision it at the time of database creation. There may be other patterns through which you can securely store passwords in kay vault. In this example we we use key vault and admin password using data blocks.
Refer to this folder for a single database deployment. Deploys a database server and a MS SQL database in your pre-defined resource group in singe region.
Populate variables defined in terraform.tfvars file.
All the resources to be created at defined in main.tf.
Resources created are :-
- SQL Server
- SQL Database with name - DemoDB
- Extended policy for SQL Server.
- Extended policy for SQL Database
- Storage Account to audit database and server policies.
Refer to this folder for a database deployment with failover group configuration. Deploys a database server and a MS SQL database in primary and secondary region. Database will be deployed only in primary region. With failover group enabled, database will automatically get replicated to secondary server. You can use this configration for deployment in same or different region.
Populate variables defined in terraform.tfvars file.
All the resources to be created at defined in main.tf.
Resources created are :-
- SQL Server - Primary
- SQL Database with name - DemoDB
- Extended policy for SQL Server.
- Extended policy for SQL Database
- Storage Account to audit database and server policies.
- SQL Server - Secondary