How to Use the AIAC (Artificial Intelligence Infrastructure-as-Code Generator)

Jun 26, 2021 | Educational

Welcome to the world of AIAC, an innovative command line tool designed to generate Infrastructure-as-Code (IaC) templates, configurations, utilities, and more using Large Language Models (LLMs) like OpenAI, Amazon Bedrock, and Ollama. In this article, we will explore how to get started with AIAC, use it effectively, and troubleshoot common issues.

Description

AIAC serves as a powerful library and command line tool to generate a variety of infrastructure code with ease. It allows you to leverage the capabilities of LLM providers to create seamlessly composed requests tailored to your needs. With AIAC, you can automate complex infrastructure setup and management tasks with straightforward commands.

Use Cases and Example Prompts

  • Generate IaC:
    • aiac terraform for a highly available EKS
    • aiac pulumi golang for an S3 with SNS notification
    • aiac cloudformation for a NeptuneDB
  • Generate Configuration Files:
    • aiac dockerfile for a secured nginx
    • aiac k8s manifest for a MongoDB deployment
  • Generate CI/CD Pipelines:
    • aiac jenkins pipeline for building Node.js
    • aiac github action that plans and applies Terraform and sends a Slack notification
  • Command Line Builder:
    • aiac kubectl that gets ExternalIPs of all nodes
    • aiac awscli that lists instances with public IP address and Name
  • Query Builder:
    • aiac mongo query that aggregates all documents by created date
    • aiac sql query that counts the appearances of each row in one table in another table based on an ID column

Instructions

Installation

You can install AIAC using various methods:

  • Via brew:
    brew tap gofireflyio/aiac
    brew install aiac
  • Using Docker:
    docker pull ghcr.io/gofireflyio/aiac
  • Using Go:
    go install github.com/gofireflyio/aiac/v5@latest
  • Cloning from the repository:
    git clone https://github.com/gofireflyio/aiac.git
    go build

Configuration

AIAC uses a TOML configuration file. By default, it looks for a configuration file in the user’s XDG_CONFIG_HOME directory. Here’s an example configuration file:

default_backend = official_openai

[backends.official_openai]
type = openai
api_key = YOUR_API_KEY
default_model = gpt-4o

[backends.aws_staging]
type = bedrock
aws_profile = staging
aws_region = eu-west-2

Usage

Once configured, you can start generating code effortlessly. You can interact with AIAC through the command line interface or as a Go library. Here are some typical command line usages:

  • Listing Models:
    aiac -b aws_prod --list-models
  • Generating Code:
    aiac terraform for AWS EC2

Via Docker

Running AIAC through Docker follows the same commands as above, just launch it within the Docker container.

Example Output

Here’s an example of generating a Dockerfile:

FROM node:latest
WORKDIR /usr/src/app
COPY package*.json . 
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "node", "index.js" ]

Troubleshooting

If you encounter issues, most errors typically stem from the LLM provider’s API. Common errors include:

  • insufficient_quota: You have exceeded your quota. This may require you to upgrade your plan with OpenAI.
  • tokens Rate limit reached: Implement throttling, as described in the [OpenAI guidance](https://platform.openai.com/docs/guides/rate-limits/request-increase).

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox