Terraform is an industry-standard for infrastructure orchestration. It can, however, be daunting and time-consuming to learn how to create infrastructure resources, especially when using Terraform providers you are unfamiliar with. That is where GitLab Duo Code Suggestions and AI-powered code creation comes in.
By combining IaC with Terraform, infrastructure teams can adopt new Terraform providers/modules quickly and move changes to production faster. The combination also reduces the onboarding time for new users of Terraform or developers who are new to a code base by maintaining the context of the code base and dependencies in its suggestions. Instead of spending hours reading through documentation, you only need to review the given suggestions and update as necessary.
In this post, you will learn how to set up GitLab Duo Code Suggestions for Terraform.
How to set up GitLab Duo Code Suggestions for Terraform
Follow these 6 steps to get started:
- Install the GitLab extension for your IDE of choice (read about supported IDE extensions.
- Authenticate the GitLab extension with GitLab.com or your GitLab self-hosted instance.
- Enable Code Suggestions in your Profile settings under the Preferences > Preferences menu. Search for Code Suggestions, toggle the checkbox, and click Save.
- Confirm that Code Suggestions is also enabled in your GitLab extensions settings in the IDE.
- If you are using Visual Studio Code and Neovim, third-party extension support is needed to use Terraform with Code Suggestions. For VS Code, you can install the official Terraform extension from HashiCorp.
- To test and apply your Terraform plans, install Terraform in your terminal and any necessary provider SDKs.
Creating your plans
Once you have all the prerequisites in place, all you need to do next is create a Terraform file ending with
.tf and prompt GitLab Duo with comments describing what you want. Suggestions will be displayed while maintaining context. Even when no prompt is provided, GitLab Duo will suggest other Terraform resources you might be interested in based on the current context in your plans.
Let's see this in action with GitLab Duo helping with a Terraform plan for provisioning a load balancer with four instances and other necessary resources on the Google Cloud Platform.
Get started with Code Suggestions and Terraform today
Try Code Suggestions today and accelerate your software development. Code Suggestions is also available for self-managed GitLab (needs to be enabled by an administrator). Code Suggestions uses best-in-class large language models, and non-public customer data is never used as training data.