Skip to content

preetishmadalia/azuresql-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

azuresql-terraform

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 :

  1. Need Azure CLI installed on your local device.
  2. Need Terraform installed on your local device.
  3. Azure Subscription
  4. Azure Resource Group
  5. 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.

Pre-requisite Details

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.

Azure Key Vault

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.

singledb-implementation

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 :-

  1. SQL Server
  2. SQL Database with name - DemoDB
  3. Extended policy for SQL Server.
  4. Extended policy for SQL Database
  5. Storage Account to audit database and server policies.

mssqldb-failover-grp

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 :-

  1. SQL Server - Primary
  2. SQL Database with name - DemoDB
  3. Extended policy for SQL Server.
  4. Extended policy for SQL Database
  5. Storage Account to audit database and server policies.
  6. SQL Server - Secondary

TODO : Automated deployment of DDL statements.