Quick Tips: Terraform Infrastructure as Code

Jul 13, 2020

You may have heard infrastructure as code(IaC), But do you know what infrastructure is? Why do we need infrastructure as code? What are the benefits of infrastructure as code? Is it safe and secure? 

 

What is Infrastructure as Code(IoC)?
Infrastructure as code (IaC) means to manage and upgrade your environments as infrastructure using configuration files. Terraform provides infrastructure as code for provisioning, compliance, and management across any public cloud, private data center, and third-party service.

Enables teams to write, share, manage, and automate any infrastructure using version control With automated policy enforcement for security, compliance, and operational best practices and Enable developers to provision their desired infrastructure from within their workflows.

IOC has a high impact on the Business perspective by providing Increased Productivity, Reduced Risk, Reduced Cost

 

Why do we use Infrastructure as Code(IoC)?

  • Terraform is a simple human-readable configuration language, to define the desired topology of infrastructure resources

  • VCS Integration
    Write, version, review, and collaborate on Terraform code using your preferred version control system

  • Workspaces
    Workspaces decompose monolithic infrastructure into smaller components, or "micro-infrastructures". These workspaces can be aligned to teams for role-based access control.

  • Variables
    Granular variables allow easy reuse of code and enable dynamic changes to scale resources and deploy new versions.

  • Runs
    Terraform uses two-phased provisioning a plan (dry run) & apply (execution). Plans can be inspected before execution to ensure expected behavior and safety.

  • Infrastructure State
    The state file is a record of currently provisioned resources. State files enable a versioned history of the infrastructure and are encrypted at rest. Versions can be inspected to see incremental changes.

  • Policy as Code
    Sentinel is a policy as a code framework to automate multi-cloud governance.

 

What are the benefits of Infrastructure as Code(IoC)?

  • Infrastructure as Code enables Infrastructure teams to test the applications in staging environments or development environment early - likely in the development cycle

  • Infrastructure as Code Saves You Time and Money

We can have a version history like when the infrastructure is upgraded and who has done it from the code itself. Else we have to ask to check the Infrastructure admin to look into logs and which is very time-consuming.
We can check it into version control and I get versioning. Now we can see an incremental history of who changed what

Use Infrastructure as Code to build update and manage any cloud, infrastructure, or services
Terraform makes it easy to re-use configurations for the environment for similar infrastructure, helping you avoid mistakes and save time.

We can use the same configuration code for the different staging Production and development environments.

Terraform supports many Providers to be built from just a simple and less line of code.

Major providers are as follows

  1. AWS
  2. Azure
  3. GitHub
  4. GitLab
  5. Google Cloud Platform
  6. VMWare
  7. Docker 
    and  200+ more.

A Simple example to create an Ec2 Instance with just a few lines of code.

resource "aws_instance" "ec2_instance" {
  ami = "ami-*******"
  instance_type = "t2.micro"
  vpc_security_group_ids = ["${aws_security_group.*****.id}"]
  key_name = "${aws_key_pair.****.id}"
  tags {
    Name = "New-EC2-Instance"
  }
}

But First, we have to write code for which provider we are writing our code.
To do so  here is the simple basic code to assign a provider

provider "aws" {
  region = "us-west-2"
  ## PROVIDE CREDENTIALS
}

Now to Create your Ec2 Instance in AWS. We have to run the commands.
So terraform has Four commands to check and apply the infrastructure changes,

  1. Init

  2. Plan

  3. Apply

  4. Destroy.

 

1. Init $ terraform init

We can understand from the name of the command that is used to initialize something.
So here terraform will be initialized in our code which will create some basic backend and tfstate files in folders for internal use.

2. Plan $ terraform plan

As we do compile in some code languages, it will check for the compilation errors and plan what is going to happen when we run the script to generate infrastructure code. It will show you what resources are going to be created and what will be the configuration.

3. Apply $ terraform apply

It is time to run the script and check what is being generated from the scripts. So the command will execute the script and apply the changes in our infrastructure, which will generate some resources for what we have written in the code. 

4. Destroy $ terraform destroy

This command is used when we want to remove or destroy the resource. After some time we don't need that resource then we just run the command which will destroy the resource. And your money is saved.

Building MCP Servers in .NET 10: A Practical Guide (STDIO + HTTP)
May 18, 2026

Why MCP servers?  LLMs are powerful—but they’re limited to what they can ‘see’. The Model Context Protocol (MCP) is an open protocol that standardizes how apps expose tools, resources, and prompts to AI clients so models can interact with real systems in a structured, discoverable way.  For .NET developers, this is especially useful because you can build MCP servers in C# using the official MCP C# SDK and run servers locally over stdio or remotely over HTTP.  MCP mental model (fast)  Host: The application that contains the AI experience (IDE/agent tool).  Client: The MCP-capable component inside the host that connects to servers.  Server: Your service that exposes tools/resources/prompts.  Choosing a transport: STDIO vs Streamable HTTP  STDIO (local): The client launches your server as a subprocess and communicates via stdin/stdout. Messages are newline-delimited JSON-RPC, and stdout must contain only protocol messages (logs must go to stderr).  Streamable HTTP (remote/scalable): Runs as an independent server reachable over HTTP. Validate the Origin header to reduce DNS rebinding risk and bind to localhost for local runs.  Part 1 — The fastest way: .NET 10 MCP Server Project Template  Microsoft provides a quickstart showing how to create a minimal MCP server using the .NET 10 SDK and the Microsoft.McpServer.ProjectTemplates template package.  This path is great for getting a working server quickly with correct wiring and sane defaults.  dotnet new install Microsoft.McpServer.ProjectTemplates Part 2 — Build a Minimal STDIO MCP Server (from scratch)  STDIO is ideal when your MCP server needs access to local machine resources and you want the simplest deployment path.  Below is a minimal server that uses Microsoft.Extensions.Hosting and exposes one tool (Echo).    Step A — Create project & add packages dotnet new console -n MyMcpServer cd MyMcpServer dotnet add package ModelContextProtocol dotnet add package Microsoft.Extensions.Hosting Note: Microsoft’s MCP server walkthrough shows the SDK approach using Microsoft.Extensions.Hosting and MCP server registration in the builder Step B — Program.cs (STDIO server + tool discovery) using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using ModelContextProtocol.Server; using System.ComponentModel; var builder = Host.CreateApplicationBuilder(args); // IMPORTANT: STDIO servers must keep stdout clean. // Route logs to stderr so they don't corrupt JSON-RPC output. builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace); builder.Services .AddMcpServer() .WithStdioServerTransport() .WithToolsFromAssembly(); await builder.Build().RunAsync(); [McpServerToolType] public static class EchoTools { [McpServerTool, Description("Echoes the message back to the client.")] public static string Echo([Description("Message to echo")] string message) => $"Hello from MCP (.NET 10): {message}"; } Why the stderr logging rule matters The MCP transport spec explicitly requires that in stdio, servers must not write non-protocol output to stdout; logs should go to stderr   Part 3 — Build a Remote MCP Server over Streamable HTTP (ASP.NET Core)  If you want a centrally hosted MCP server (team-wide tooling, enterprise integrations), use HTTP transport. MCP’s spec notes Streamable HTTP is the standard remote transport and includes security requirements like Origin validation. [modelconte...rotocol.io], [dometrain.com]Below is a minimal HTTP server exposing a demo Weather tool.  Step A — Create ASP.NET Core app & add MCP server support   dotnet new web -n MyHttpMcpServer cd MyHttpMcpServer dotnet add package ModelContextProtocol.AspNetCore Step B — Program.cs (HTTP MCP endpoint) using ModelContextProtocol.Server; using System.ComponentModel; var builder = WebApplication.CreateBuilder(args); builder.Services .AddMcpServer() .WithHttpTransport(options => { // Stateless mode is commonly recommended for simple remote servers // that don't need advanced server->client features. options.Stateless = true; }) .WithToolsFromAssembly(); var app = builder.Build(); // Exposes /mcp endpoint (or the configured MCP endpoint) app.MapMcp(); app.Run("http://localhost:3001"); [McpServerToolType] public static class WeatherTools { [McpServerTool, Description("Returns a sample weather status for a city.")] public static string GetWeather(string city) => $"Weather for {city}: Sunny (demo)"; } Security note (important): For Streamable HTTP, MCP recommends validating the Origin header to prevent DNS rebinding and binding locally to localhost when running locally   Part 4 — Coding standards & best practices for MCP servers  STDIO rule: stdout must be pure JSON-RPC Never log to stdout. Use stderr.  Standard: Configure logging to stderr as shown in the STDIO sample. Keep tools small + deterministic Tool methods should be short, validate input, and return structured outputs. Avoid tools that do “too much” (hard to reason about / secure). Validate inputs like public APIs Even though an LLM is “calling” the tool, treat it like an untrusted client: Validate required fields Constrain sizes Apply allowlists where possible Prefer “read-only” tools first Start with: search/read/query tools Then move to “write” tools with extra safety checks. Remote servers must follow transport security guidance Streamable HTTP transport includes security requirements like Origin validation to mitigate DNS rebinding risks Conclusion  .NET 10 makes it practical to build MCP servers using local STDIO transport for quick, secure local tooling, and Streamable HTTP for scalable, shared integrations.  Start with a small set of safe tools, add observability and security early, and expand capabilities over time. 

OpenAI Assistants Bot Using RAG
Feb 19, 2026

Introduction In modern AI applications, Retrieval-Augmented Generation (RAG) is one of the most powerful patterns for building intelligent assistants that go beyond generic responses. Instead of relying only on pre-trained knowledge, RAG allows your assistant to retrieve real data (files, database, CSV, APIs) and generate accurate, context-aware answers. In this blog, we will walk through how to build an OpenAI Assistants Bot using RAG, step by step.   What is RAG? RAG (Retrieval-Augmented Generation) is a technique where: Data is stored (files, DB, vector store) User asks a question Relevant data is retrieved AI generates response based on retrieved data Instead of hallucinating, AI gives real, data-backed answers Step 1 — Register on OpenAI Platform Open: https://platform.openai.com/ Important Notes: Create an account using your email If using for organization: Ask admin to add you to organization OpenAI provides: Personal account Organization account   Step 2 — Generate API Key Go to: Settings → API Keys Important: You need to manage two types of keys properly Type Usage Personal API Key For personal development Organization API Key For production / team usage Best Practice Never hardcode API keys Store in: .env file or Azure Key Vault `` Step 3 — Open Playground & Assistant Go to: OpenAI Dashboard → Playground → Assistants First time? It will prompt: Create a new Assistant OpenAI auto-generates: A random name You can rename it (recommended) What is an Assistant? An Assistant is: A configured AI agent With instructions With connected tools With uploaded data (RAG-ready) It acts as a "brain" that connects: Instructions Files APIs Conversations Step 4 — Add Data (Core of RAG) Example You are an AI assistant for an e-commerce store. Answer user questions based only on the provided data. Do not generate fake information. This is very important for RAG behavior. Now comes the most important part — giving data to your assistant. Supported Data Types PDF CSV TXT DOCX JSON Example: E-Commerce Data (CSV) If you have an e-commerce website, create CSV like: ProductId,Name,Category,Price,Stock 1,iPhone 15,Mobile,999,20 2,Samsung S23,Mobile,899,15 3,MacBook Pro,Laptop,1999,10 `` Upload Process Go to Assistant Open Files section Upload CSV / document Attach file to assistant How RAG Works in Assistants https://via.placeholder.com/1200x500?text=Assistant+RAG+Flow Flow: User asks:  “What is price of iPhone 15?” Assistant: Searches uploaded data Retrieves relevant content AI generates answer: “The price of iPhone 15 is $999” Step 5 — Call Assistant via API Example (C# style for you ): var client = new OpenAIClient("API_KEY"); var thread = await client.CreateThreadAsync(); await client.AddMessageAsync(thread.Id, "What is the price of iPhone 15?"); var response = await client.RunAssistantAsync(thread.Id, assistantId); Console.WriteLine(response); Conclusion OpenAI Assistants + RAG is one of the most powerful ways to build: Intelligent Context-aware Production-ready AI applications Instead of building complex pipelines, you can now: Upload data Configure assistant Start querying

Exploring the Latest Features in C# 10
Jun 19, 2025

Exploring the Latest Features in C# 10 C# 10, the latest version of the C# programming language, brings exciting new features and enhancements that aim to improve developer productivity, code readability, and overall language capabilities. In this blog post, we'll take a closer look at some of the notable features introduced in C# 10. 1. Record Types Improvements Record types, introduced in C# 9, have proven to be a valuable addition for simplifying immutable data structures. In C# 10, record types receive enhancements that make them even more powerful. Example:   csharpCopy code public record Person { public string FirstName { get; init; } public string LastName { get; init; } } // C# 10 allows you to simplify the instantiation of record types var person = new Person { FirstName = "John", LastName = "Doe" }; In C# 10, you can use the with expression to create a copy of a record with modified values more concisely:   csharpCopy code var updatedPerson = person with { FirstName = "Jane" }; This syntax improves the readability of code when updating record instances. 2. Parameter Null Checking C# 10 introduces the notnull modifier for parameters, enabling developers to enforce non-null arguments at the call site. This can lead to more robust code by catching potential null reference exceptions early. Example: public void ProcessData(notnull string data) { // The 'data' parameter is guaranteed to be non-null within this method } The notnull modifier serves as a contract, making it clear that the method does not accept null arguments. 3. Global Usings C# 10 simplifies the process of importing namespaces by introducing global usings. Now, you can include common namespaces globally, reducing the need to include them in each file. Example: // C# 10 global using global using System; global using System.Collections.Generic; class Program { static void Main() { List<string> myList = new(); // ... } } By using global usings, you can make your code more concise and improve overall code readability. 4. File-scoped Namespace Declarations C# 10 introduces file-scoped namespace declarations, allowing you to define namespaces directly at the file level. This simplifies the organization of code and reduces the need for excessive indentation. Example:   csharpCopy code // File-scoped namespace declaration namespace MyNamespace; class MyClass { // ... } This feature promotes cleaner code structure, making it easier to navigate and maintain. 5. Extended Property Patterns C# 10 enhances property patterns, enabling more expressive and concise matching when working with switch statements and patterns. Example:   csharpCopy code public class Point { public int X { get; set; } public int Y { get; set; } } var point = new Point { X = 5, Y = 10 }; // C# 10 extended property patterns var result = point switch { { X: 0, Y: 0 } => "Origin", { X: var x, Y: var y } when x == y => "Diagonal", _ => "Unknown" }; These improvements make pattern matching even more powerful and expressive. Conclusion C# 10 introduces several features and enhancements that aim to make the language more expressive, concise, and developer-friendly. By leveraging these new capabilities, developers can write cleaner, more maintainable code. As always, staying updated with the latest language features empowers developers to make the most of the tools at their disposal. Explore these features in your projects and embrace the evolution of C# for a more enjoyable and efficient development experience.

Kishan Parmar

About the Author

Kishan Parmar

Team Leader at MagnusMinds IT Solution
Team Leader with a demonstrated history of working in the computer software industry. Skilled in Asp.net MVC 4.0, C#, WPF Development, Terraform, Infrastructure as a code, AWS, Azure, IONIC, Node JS, Asp. Net Core, Web API MVC, .NET Core Web API, Application Programming Interfaces, and Raspberry Pi.
Strong engineering professional with a Bachelor of Engineering (B.E.) focused on Computer Engineering.