|
1 | 1 | # Working with Infrastructure as Code (IaC) using GitHub Copilot |
2 | 2 |
|
3 | | -GitHub Copilot for the MSSQL extension brings AI-powered assistance directly into your SQL development workflow within Visual Studio Code. This integration enables developers to work more efficiently with SQL Server, Azure SQL, and Microsoft Fabric databases by: |
| 3 | +Infrastructure as Code (IaC) enables teams to define, provision, and manage cloud infrastructure using code, bringing the benefits of version control, automation, and repeatability to infrastructure management. |
4 | 4 |
|
5 | | -- **Writing and optimizing queries** - Generate SQL queries from natural language descriptions and receive AI-recommended improvements for performance |
6 | | -- **Exploring and designing schemas** - Understand, design, and evolve database schemas using intelligent, code-first guidance with contextual suggestions for relationships and constraints |
7 | | -- **Understanding existing code** - Get natural language explanations of stored procedures, views, and functions to help you understand business logic quickly |
8 | | -- **Generating test data** - Create realistic, schema-aware sample data to support testing and development environments |
9 | | -- **Analyzing security** - Receive recommendations to avoid SQL injection, excessive permissions, and other security vulnerabilities |
10 | | -- **Accelerating development** - Scaffold backend components and data access layers based on your database context |
| 5 | +Tools like Terraform and Bicep make it easier to describe and deploy cloud resources declaratively — but writing and maintaining IaC files can still be time-consuming and error-prone. |
11 | 6 |
|
12 | | -This powerful combination allows you to focus on solving problems rather than memorizing SQL syntax, making database development more intuitive and productive. |
| 7 | +This is where GitHub Copilot shines. Why Use GitHub Copilot for IaC? |
| 8 | + |
| 9 | +GitHub Copilot can help you write, refactor, and understand IaC templates faster. By leveraging natural language prompts and contextual awareness, Copilot can: |
| 10 | + |
| 11 | +- **Generate infrastructure templates from plain-language descriptions** - Simply describe the resource you need — for example, “create an Azure storage account with a private endpoint” — and Copilot will suggest the Terraform or Bicep code to do it. |
| 12 | +- **Reduce syntax errors and boilerplate** - Copilot understands the structure and schema of Terraform and Bicep resources, minimizing typos and repetitive declarations. |
| 13 | +- **Speed up resource creation** - It can quickly scaffold complete configurations, including providers, variables, modules, and outputs. |
| 14 | +- **Improve readability and maintainability** - Copilot can add comments, generate variable documentation, and suggest consistent naming conventions. |
| 15 | +- **Support iterative learning and experimentation** - Instead of memorizing every resource property, you can explore and refine configurations interactively within your editor. |
| 16 | + |
| 17 | +GitHub Copilot doesn’t replace understanding Terraform or Bicep — it enhances your workflow by reducing friction and helping you focus on design and intent rather than syntax. |
13 | 18 |
|
14 | 19 | ## Scenario |
15 | 20 |
|
16 | | -Now that your application supports multiple database systems including SQL Server, you want to explore how GitHub Copilot can help you interact with your SQL Server database directly from VS Code. You'll use the GitHub Copilot for MSSQL extension to generate queries and explore your data using natural language. |
| 21 | +You application has a database, a website and an API. While everything is hosted locally in our repo, we want to deploy it to Azure and create an automated way to deploy our Infrastructure as Code. Making our application less prone to human deployment errors and introducing continuous integration/continuous delivery (CI/CD) into our ways of working. We will create either a Bicep or Terraform configuration file and a GitHub Actions workflow to deploy to Azure. You can choose to build a Terraform configuration file or a Bicep file (or both!), navigate to the section below that you prefer to try! |
| 22 | + |
| 23 | +[!NOTE] The same workflow can apply to other cloud providers - Copilot can suggest Terraform code for AWS, GCP, and more. |
17 | 24 |
|
18 | 25 | ## Prerequisites |
19 | 26 |
|
20 | 27 | Good news! We've already set up everything you need for this exercise: |
21 | 28 |
|
22 | | -- SQL Server Express is installed and running locally |
23 | | - - With pets database populated with data |
24 | | -- The **GitHub Copilot for MSSQL** extension is installed in VS Code |
25 | | -- A SQL Server connection has been pre-registered in your environment |
26 | | - |
27 | | -You're ready to connect and start querying right away! |
28 | | - |
29 | | -## Understanding GitHub Copilot for MSSQL |
| 29 | +- GitHub Copilot enabled in your IDE |
| 30 | +- HashiCorp Terraform (for .tf files) extension in VSCode |
| 31 | +- Bicep (for .bicep files) extension in VSCode |
30 | 32 |
|
31 | | -The GitHub Copilot for MSSQL extension brings AI-powered assistance to your database work. It can: |
| 33 | +## Creating a new Terraform Configuration with Copilot |
32 | 34 |
|
33 | | -- Generate SQL queries from natural language descriptions |
34 | | -- Explain existing queries in plain English |
35 | | -- Suggest query optimizations and best practices |
36 | | -- Help explore database schemas and relationships |
37 | | -- Convert natural language questions into executable SQL |
| 35 | +Now that your environment is ready, let’s use GitHub Copilot to help you create your first Terraform configuration file. |
38 | 36 |
|
39 | | -This integration makes working with databases more intuitive, especially when you're exploring unfamiliar schemas or need to write complex queries |
| 37 | +Terraform enables you to define your infrastructure declaratively — specifying what you want, not how to build it. |
| 38 | +Copilot enhances this experience by suggesting Terraform code directly in your editor as you describe your desired infrastructure in natural language. |
0 commit comments