Skip to content

In the dynamic landscape of cloud infrastructure management, Terraform has emerged as a powerful tool for automating infrastructure deployment. To further streamline this process and enhance user experience, a cutting-edge Terraform assistant has been developed leveraging the OpenAI API and the versatility of Go programming language.

Notifications You must be signed in to change notification settings

UtkarshUmre/Terraform-Assistant-OpenAI-Go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform OpenAI Assistant

Terraform-assistant, powered by OpenAI ChatGPT, enhances the process of applying Terraform HCL (HashiCorp Configuration Language) files. It provides an intelligent and interactive assistant, streamlining infrastructure provisioning and management with advanced language model capabilities.

Usage

Prerequisites

Before using terraform-assistant, obtain an API key from either OpenAI or Azure OpenAI Service.

Setting Up Environment Variables

For both OpenAI and Azure OpenAI, set the following environment variables:

On Unix/Linux/macOS:

export OPENAI_API_KEY=<your OpenAI key>
export OPENAI_DEPLOYMENT_NAME=<your deployment/model name (default: "gpt-3.5-turbo")>

On Windows:

set OPENAI_API_KEY=<your OpenAI key>
set OPENAI_DEPLOYMENT_NAME=<your deployment/model name (default: "gpt-3.5-turbo")>

Following models are supported:

  • code-davinci-002
  • text-davinci-003
  • gpt-3.5-turbo-0301 (deployment must be named gpt-35-turbo-0301 for Azure)
  • gpt-3.5-turbo
  • gpt-35-turbo-0301
  • gpt-4-0314
  • gpt-4-32k-0314

For Azure OpenAI Service, you can use the following environment variables:

export AZURE_OPENAI_ENDPOINT=<your Azure OpenAI endpoint, like "https://my-aoi-endpoint.openai.azure.com">

If AZURE_OPENAI_ENDPOINT variable is set, then it will use the Azure OpenAI Service. Otherwise, it will use OpenAI API.

Flags and Environment Variables

  • --require-confirmation flag or REQUIRE_CONFIRMATION environment varible can be set to prompt the user for confirmation before applying the manifest. Defaults to true.

  • --temperature flag or TEMPERATURE environment variable can be set between 0 and 1. Higher temperature will result in more creative completions. Lower temperature will result in more deterministic completions. Defaults to 0.

  • --working-dir flag or WORKING_DIR environment variable that can be set for the Terraform project path.

  • --exec-dir flag or EXEC_DIR environment variable that can be set for the Terraform executable binary file.

Examples

Creating templates

go run main.go "create micro ec2  ubuntu image 20.04 with name hello-future"

🦄 Attempting to store the following template:
resource "aws_instance" "hello_future" {
  ami           = "ami-0f65671a86f061fcd"
  instance_type = "t2.micro"
  tags = {
    Name = "hello-future"
  }
}
Use the arrow keys to navigate: ↓ ↑ → ←
? Would you like to apply this? [Reprompt/Apply/Don't Apply]:
+   Reprompt
  ▸ Apply
    Don't Apply

Init provider

go run main.go init "create aws provider in ohio"

🦄 Attempting to apply the following template:

provider "aws" {
  region  = "us-east-2"
  alias   = "Ohio"
}
Use the arrow keys to navigate: ↓ ↑ → ←
? Would you like to apply this? [Reprompt/Apply/Don't Apply]:
+   Reprompt
  ▸ Apply
    Don't Apply

Running Test Cases

Terraform-assistant includes test cases to ensure reliable functionality. To run these tests:

go test ./...

About

In the dynamic landscape of cloud infrastructure management, Terraform has emerged as a powerful tool for automating infrastructure deployment. To further streamline this process and enhance user experience, a cutting-edge Terraform assistant has been developed leveraging the OpenAI API and the versatility of Go programming language.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages