Home

Awesome

Terraform OpenAI

GolangCI Lint GitHub release (latest by date) codecov

Terraform-ai, powered by OpenAI ChatGPT, simplifies the process of applying Terraform HCL files by providing an intelligent and interactive assistant.

Demo

asciicast

Usage

Prerequisites

terraform-ai requires an OpenAI API key or an Azure OpenAI Service API key and endpoint.

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

export OPENAI_API_KEY=<your OpenAI key>
export OPENAI_DEPLOYMENT_NAME=<your OpenAI deployment/model name. defaults to "gpt-3.5-turbo">

Following models are supported:

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.

Installation

Homebrew

Add to brew tap and install with:

brew tap hubs-ai/terraform-ai https://github.com/hubs-ai/terraform-ai
brew install terraform-ai

GitHub release

Flags and environment variables

Examples

Creating templates

terraform-ai "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

terraform-ai 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

Optional --require-confirmation flag

Acknowledgements and Credits

I found inspiration from the repository hosted at https://github.com/sozercan/kubectl-ai, and I would like to express my gratitude to @sozercan for their valuable creativity. Additionally, I want to acknowledge the work of @simongottschlag on the Azure OpenAI fork available at https://github.com/simongottschlag/azure-openai-gpt-slack-bot, which is built upon the foundation laid by https://github.com/PullRequestInc/go-gpt3.