Terraform-ai, powered by OpenAI ChatGPT, simplifies the process of applying Terraform HCL files by providing an intelligent and interactive assistant.
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:
code-davinci-002text-davinci-003gpt-3.5-turbo-0301(deployment must be namedgpt-35-turbo-0301for Azure)gpt-3.5-turbogpt-35-turbo-0301gpt-4-0314gpt-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.
Add to brew tap and install with:
brew tap hubs-ai/terraform-ai https://github.com/hubs-ai/terraform-ai brew install terraform-ai- Download the binary from GitHub releases.
-
--require-confirmationflag orREQUIRE_CONFIRMATIONenvironment varible can be set to prompt the user for confirmation before applying the manifest. Defaults to true. -
--temperatureflag orTEMPERATUREenvironment 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-dirflag orWORKING_DIRenvironment variable that can be set for the Terraform project path. -
--exec-dirflag orEXEC_DIRenvironment variable that can be set for the Terraform executable binary file.
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 Applyterraform-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 ApplyI 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.