Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Latest commit

 

History

History
70 lines (43 loc) · 3.55 KB

infrastructure-as-code.md

File metadata and controls

70 lines (43 loc) · 3.55 KB

Create Infrastructure as Code

This project is implemented using 3 main services in Azure: Functions, Event Hub and CosmosDB using Terraform to provision the required environment in Azure for this project.

The flow is triggered and controlled by a Github Action. The action contains a set of tasks that are organized logically to evaluate Terraform scripts and to provision the infrastructure on Azure.

Environment Resources

The infrastructure provisioned by Terraform includes:

Service Description
Resource Group Contains all the resources for the solution
Event Hub To ingest and distribute data to the functions. The script will create four event hubs - (validator, receipt, transfer, saga-reply)
Functions Serverless compute services. This includes Durable functions
CosmosDB multi-model database service for operational and analytics workloads. The script will create five collectiosn - validator, receipt, orchestrator, transfer, saga

Prerequisites:

IAC Folder structure

There are six Terraform (.tf) scripts to create this environment:

Script Description
main.tf main file with the environment definition
variables.tf variables used in the main script
backend.tf backend used by Terraform
version.tf minimun Terraform version required
provider.tf required providers required by Terraform
terraform.tfvars the file with the required values to create the environment

The only scripts that must need a change are terraform.tfvars as it is used to customize the infrastructure names and some of those names are required to be unique global identifiers and backend.tf to set the Azure Storage account values for preserving the state.

1. Create the Service Principal

  1. By using Azure CLI, in case you need it, you need to create an Azure Service Principal
az ad sp create-for-rbac --name "myApp" --role contributor --scopes /subscriptions/your-subscription-id --sdk-auth

Service Principal

You'll need from here the clientId, clientSecret, subscriptionId and tenantId

2. Azure Storage SAS token

From an already created Azure Storage Account, you'll need access to create a new blob file for Terraform state persistance. To set this account in the backend.tf file.

In the portal, got to the Storage account and generate a Shared access signature.

Storage SAS

Now that you already have these five values it's time to go to Github.

3. Generate Github Secrets

In the Github Settings tab, create five secrets with the following names.

Github secrets

After the creation of those secrets you'll need to push changes in the master branch making sure the changes are being reflected in the iac folder to let the corresponding Github Action be triggered. A succesful result will be demonstrated in the workflow of TerraformCI/CD action.

Github secrets