Blog AI/ML Write Terraform plans faster with GitLab Duo Code Suggestions
Published on: January 24, 2024
3 min read

Write Terraform plans faster with GitLab Duo Code Suggestions

Follow this tutorial to learn how to use AI-powered code creation to manage your infrastructure with Terraform.

duo-blog-post.png

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.

GitLab Duo Code Suggestions accelerates your coding in up to 15 supported programming languages, including infrastructure as code (IaC) using Terraform.

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:

  1. Install the GitLab extension for your IDE of choice (read about supported IDE extensions.
  2. Authenticate the GitLab extension with GitLab.com or your GitLab self-hosted instance.
  3. Enable Code Suggestions in your Profile settings under the Preferences > Preferences menu. Search for Code Suggestions, toggle the checkbox, and click Save.
  4. Confirm that Code Suggestions is also enabled in your GitLab extensions settings in the IDE.
  5. 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.
  6. 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.

We want to hear from you

Enjoyed reading this blog post or have questions or feedback? Share your thoughts by creating a new topic in the GitLab community forum. Share your feedback

Ready to get started?

See what your team could do with a unified DevSecOps Platform.

Get free trial

Find out which plan works best for your team

Learn about pricing

Learn about what GitLab can do for your team

Talk to an expert