Showing posts with label Microsoft Azure. Show all posts
Showing posts with label Microsoft Azure. Show all posts

April 3, 2025

Managing Multiple Azure Environments with Terraform

Introduction

Managing cloud infrastructure across multiple environments can be complex. Terraform simplifies this process using modules and workspaces, Allows us more efficient and scalable infrastructure management in any cloud. This guide explores leveraging Terraform modules in a multi-workspace setup for Microsoft Azure. 

Benefits of Terraform Modules and Workspaces

Terraform Modules: Enhancing Reusability

Modules allow infrastructure components to be defined once and reused across different environments. This reduces redundancy and enhances maintainability.


Terraform Workspaces: Isolating Environments

Workspaces create separate states for different environments, ensuring isolation and preventing conflicts between deployments. Utilizing Terraform variables further refines environment-specific configurations.


Structuring Terraform for Multi-Environment Deployment

A well-structured Terraform directory simplifies management across environments. Below is a recommended directory structure:


Directory Layout

$ tree complete-module/
.
├── README.md
├── main.tf
├── variables.tf
├── outputs.tf
├── ...
├── modules/
│   ├── nestedA/
│   │   ├── README.md
│   │   ├── variables.tf
│   │   ├── main.tf
│   │   ├── outputs.tf
│   ├── nestedB/
│   ├── .../
├── examples/
│   ├── exampleA/
│   │   ├── main.tf
│   ├── exampleB/
│   ├── .../

Creating a Reusable Terraform Module

Defining a Virtual Network Module:

 - modules/network/main.tf
resource "azurerm_virtual_network" "network" {
  name                = var.network_name
  location            = var.location
  resource_group_name = var.resource_group_name
  address_space       = var.address_space
}

 - modules/network/variables.tf

variable "network_name" {
  type = string
}

variable "location" {
  type = string
}

variable "resource_group_name" {
  type = string
}

variable "address_space" {
  type = list(string)
}

 - modules/network/outputs.tf

output "network_id" {
  value = azurerm_virtual_network.network.id
}

Utilizing the Module in the Main Configuration

- main.tf

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "4.16.0"
    }
  }

  backend "azurerm" {
    resource_group_name  = "terraform-state-rg"
    storage_account_name = "terraformstate"
    container_name       = "tfstate"
    key                  = "terraform.tfstate"
  }
}

provider "azurerm" {
  features {}
}

module "network" {
  source              = "./modules/network"
  network_name        = "my-network-${terraform.workspace}"
  location            = "East US"
  resource_group_name = "my-rg"
  address_space       = ["10.0.0.0/16"]
}

Managing Workspaces for Different Environments

Initializing and Creating Workspaces

Run the following commands to initialize Terraform and create new workspaces:

terraform init
terraform workspace new development
terraform workspace new staging
terraform workspace new production

Switch between workspaces:

terraform workspace select development

Applying Configuration to a Specific Workspace

terraform apply -var-file=environments/development.tfvars

Terraform plan output:

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.network.azurerm_virtual_network.network will be created
  + resource "azurerm_virtual_network" "network" {
      + address_space       = ["10.0.0.0/16"]
      + id                  = (known after apply)
      + location            = "East US"
      + name                = "my-network-default"
      + resource_group_name = "my-rg"
    }

Plan: 1 to add, 0 to change, 0 to destroy.


Terraform apply output:

module.network.azurerm_virtual_network.network: Creating...
module.network.azurerm_virtual_network.network: Creation complete after 30s ...

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

network_id = "/.../my-rg/.../Microsoft.Network/virtualNetworks/my-network-default"

Advantages of This Approach

  • Code Efficiency: Reusable modules minimize code duplication.
  • Environment Segregation: Workspaces ensure different state for different environment.
  • Scalability: With this approach we can easily add multiple environments as needed.

Reference links:


Conclusion

Using Terraform modules and workspaces in Azure streamlines environment management, improves reusability, and enhances scalability. This structured approach keeps infrastructure organized and adaptable to change.

Happy Terraforming!

August 26, 2021

Overview on adding custom columns in Azure Cosmos DB

Introduction

We recently implemented a console application for a Postal and Parcel company based out of Melbourne, Victoria, Australia. In this, we have to store the user's login track details to a Cosmos DB. So we needed to add few custom columns in the Azure Cosmos DB container to store this type of information.


In this blog, we will look into the overall structure of the Cosmos DB container and we will be creating few custom columns also.

Solution

  • The Cosmos DB is a schema-free and unstructured database. It means that we can store data without considering its format.
  • The Cosmos DB has tables as containers for the database.
  • The container stores data in JSON format. So, we can store JSON objects as an item in the container of Cosmos DB. 
  • We can add any number of custom columns and their values as a JSON property.
  • The Cosmos DB container requires only one mandatory property it's the Item ID ("id"). and the Item ID is a not null and unique field. It has 255 characters limit.

Creating an item with custom columns

First, we need to pass a JSON format object to create a new item as shown below. 

 {    

   "id": "1",    

   "User name": "Aniket Chauhan",    

   "Email Address": "aniket.chauhan@binaryrepublik.com",    

   "Logged Date Time": "2021-07-09T09:07:19.2825515Z",    

}   

Now when we save this new item it will be stored with some system-generated fields as shown below. 


Here, the User name, Email Address, and Logged Date Time properties are custom columns.
When we create an item in the cosmos DB container it generates 5 extra properties.
  1. _rid: The resource ID (_rid) is a unique identifier that is used internally for navigation and placement of the resource.
  2. _self: It is the unique addressable URI for the item.
  3. _etag: Entity tag(_etag) used for optimistic concurrency control.
  4. _attachments: It specifies the addressable path for the attachment resource.
  5. _ts: It stores the timestamp of the last update of the item.
Note: We can also pass the GUID for the "id" field as per our requirement.

Conclusion

This is how we can add custom columns in Cosmos DB. Hope this helps, good day!


If you have any questions you can reach out our SharePoint Consulting team here.

December 18, 2020

Binary Republik Proud to be Named a Global Leader on 2020 Clutch 1000!



Here at Binary Republik, we know it’s been a difficult year all around. Despite the conditions, we’re proud to report we’ve maintained our standards of quality and service as a leading Microsoft Technology Consulting company. We made sure that our clients had access to cutting edge technology and were able to get acclimated to a new normal.

As a wonderful way to wrap up the year, we’ve been featured in the Clutch 1000, an exclusive list of the top 1% of vendors on their platform. Clutch is a B2B market research authority that uses a one-of-a-kind ranking formula to identify key players in the services space.

We are thrilled to have been chosen as one of the top Microsoft Technology Consulting company and it proclaims our dedication and quality of the work we deliver to Microsoft ISVs, MSPs, MVPs, and more - Jaldeep Patel, Global Director, Binary Republik

We couldn’t have earned this award without the help of our wonderful clients. Take a look at some of
the kind words they had to share about our work when interviewed by the Clutch team:

“The most impressive aspect of Binary Republik was the size of both their team and their knowledgebase. Many firms only specialized in custom development or system architecture. Other firms didn't have an expert for every subject, but with Binary Republik we knew that someone on their team would be able to help us find an answer. Because of their size, they are also able to get back to us quickly while still maintaining genuine communication and professional relationship.”
                                                            – Web Applications Developer, Community College

“Binary has a great team that is focused on helping customers to solve their problems. They come to the table with an open mind and give realistic honest solutions and suggestions. They estimate and on-time delivery is unmatched”
                                                             – VP of Product & Engineering, Inkriti

“Like many companies, we've had varying degrees of success with offshore & outsourcing, especially outside Europe. However, Binary Republik displayed none of the negative aspects typically experienced with offshore vendors whilst remaining significantly more competitive than onshore vendor partners.”
                                                             – Product Manager, Education Services Company

We’re honored to be recognized by Clutch and our clients, and look forward to even more success in
2021! If you’re new to Binary Republik, contact us today to learn more about our award-winning
strategy and how it can help fuel your success in the new year!

August 29, 2019

Create file on SFTP server using Web Service and Rest API from SharePoint Online

Sometimes, we need to deal with third party tools/applications from SharePoint Online. To deal with third party tools/applications, we may need a medium like SFTP server to pass data from SharePoint Online to third party tools/applications. In this blog, we are going to showcase - how to create xml/text file on SFTP server from SharePoint Online.

First, let's understand what's SFTP server and how it can be used to transfer data from SharePoint Online.

What is SFTP server?

SFTP - Secure File Transfer Protocol server, is popular method of transferring files between two remote systems over a secure connection. In this blog, we will see how to transfer data from one remote server (SharePoint Online) to another remote server (Workday).

Create file on SFTP server using Rest API & Web Service in SharePoint Online:

We can follow below steps to create file on SFTP server:

Step 1: Create a page in SharePoint Online and add custom button using HTML and JavaScript file. On Custom button click event, JavaScript file would call web service to create file on SFTP server.

Step 2: Create a web service (c#) using Visual studio.
  • Install “SSH.NET” package to deal with the SFTP server.
  • Find below code to connect SFTP server.

var client = new SftpClient("Server URL", "User Name", "Password");
client.Connect();
  • Then, stores incoming data into memory.

byte[] bArray = Encoding.UTF8.GetBytes(dataURL);
var memory = new MemoryStream(bArray);
    • Now, Upload/Create a file on SFTP server.

    client.UploadFile(memory, "/Folder path /File Name", null);
    • At the end, close the connection with SFTP server.

    client.Disconnect();
    client.Dispose();
      • The complete code for SFTP server integration is as below:

      [WebMethod]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json)]   
      public string UploadFileToFTP(string data)
      {
           var client = new SftpClient("Server URL", "User Name", "Password");
           client.Connect();
           byte[] bArray = Encoding.UTF8.GetBytes(dataURL);
           var memory = new MemoryStream(bArray);
           client.UploadFile(memory, "/Folder path /File Name", null);
           client.Disconnect();
           client.Dispose();
      }
      

      Step 3: Publish this web service on Microsoft Azure platform.

      Step 4: Add following code to JavaScript reference file in SharePoint Online. In this step, we would get data from SharePoint Online list and pass data to web service to create file on SFTP server.

      function MoveFileToSFTP()
      {
           var DataURL = "'ServerURL'/FTPFileUpload.asmx/UploadFileToFTP";
           var request = new XMLHttpRequest();
           var Data = JSON.stringify(data);
           var params = "data="+Data+"";
           request.open('POST', DataURL, true);
           request.onreadystatechange = function() {
              var responsetext = request.responseText;
       if (request.readyState==4)
       {
          alert("File has been created successfully on SFTP server.");
       }
           };
           request.setRequestHeader("Content-type", "application/x-www-  form-urlencoded");
           request.setRequestHeader("Content-length", params.length);
           request.setRequestHeader("Connection", "close");
           request.send(params);
      }
      
      This way, we can upload files to SFTP from SharePoint Online programmatically.

      If you have any questions you can reach out our SharePoint Consulting team here.

      July 25, 2019

      SharePoint Online Integration with Workday through SFTP

      Sometimes, we need to deal with third party tools/applications from SharePoint Online. To deal with third party tools/applications, we may need a medium like SFTP server to pass data from SharePoint Online to third party tools/applications. In this blog, we are going to showcase - how to create xml/text file on SFTP server from SharePoint Online.

      First, let's understand what's SFTP server and how it can be used to transfer data from SharePoint Online.

      What is SFTP server?

      SFTP - Secure File Transfer Protocol server, is popular method of transferring files between two remote systems over a secure connection. In this blog, we will see how to transfer data from one application - SharePoint Online to another remote server application (e.g. Workday).

      Create file on SFTP server using Rest API & Web Service in SharePoint Online:

      We can follow below steps to create file on SFTP server:

      Step 1: Create a page in SharePoint Online and add custom button using HTML and JavaScript file. On Custom button click event, JavaScript file would call web service to create file on SFTP server.

      Step 2: Create a web service (c#) using Visual studio.
      • Install “SSH.NET” package to deal with the SFTP server.
      • Find below code to connect SFTP server.

      var client = new SftpClient("Server URL", "User Name", "Password");
      client.Connect();
      • Then, stores incoming data into memory.

      byte[] bArray = Encoding.UTF8.GetBytes(dataURL);
      var memory = new MemoryStream(bArray);
        • Now, Upload/Create a file on SFTP server.

        client.UploadFile(memory, "/Folder path /File Name", null);
        • At the end, close the connection with SFTP server.

        client.Disconnect();
        client.Dispose();
          • The complete code for SFTP server integration is as below:

          [WebMethod]
          [ScriptMethod(ResponseFormat = ResponseFormat.Json)]   
          public string UploadFileToFTP(string data)
          {
               var client = new SftpClient("Server URL", "User Name", "Password");
               client.Connect();
               byte[] bArray = Encoding.UTF8.GetBytes(dataURL);
               var memory = new MemoryStream(bArray);
               client.UploadFile(memory, "/Folder path /File Name", null);
               client.Disconnect();
               client.Dispose();
          }
          

          Step 3: Publish this web service on Microsoft Azure platform.

          Step 4: Add following code to JavaScript reference file in SharePoint Online. In this step, we would get data from SharePoint Online list and pass data to web service to create file on SFTP server.

          function MoveFileToSFTP()
          {
               var DataURL = "'ServerURL'/FTPFileUpload.asmx/UploadFileToFTP";
               var request = new XMLHttpRequest();
               var Data = JSON.stringify(data);
               var params = "data="+Data+"";
               request.open('POST', DataURL, true);
               request.onreadystatechange = function() {
                  var responsetext = request.responseText;
           if (request.readyState==4)
           {
              alert("File has been created successfully on SFTP server.");
           }
               };
               request.setRequestHeader("Content-type", "application/x-www-  form-urlencoded");
               request.setRequestHeader("Content-length", params.length);
               request.setRequestHeader("Connection", "close");
               request.send(params);
          }
          
          This way, we can upload files to SFTP from SharePoint Online programmatically.

          If you have any questions you can reach out our SharePoint Consulting team here.