4

Treating DevOps Like Skynet with ChatGPT

 1 year ago
source link: https://hackernoon.com/treating-devops-like-skynet-with-chatgpt
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Treating DevOps Like Skynet with ChatGPT

December 23rd 2022 New Story
5 min
by @erancloud

Eran Bibi

@erancloud

Eran Bibi is Co-Founder & Chief Product Officer at Firefly

Read this story in a terminal

Too Long; Didn't Read

ChatGPT has been dominating all of our feeds over the last week, and blowing people's minds. We took it for a test drive to see if it could do DevOps...you gotta see this in action.


People Mentioned

Elon Musk

@elonmusk007

featured image - Treating DevOps Like Skynet with ChatGPT
Your browser does not support theaudio element.
Read by Dr. One (en-US)
Audio Presented by

@erancloud

Eran Bibi

Eran Bibi is Co-Founder & Chief Product Officer at Firefly

About @erancloud
LEARN MORE ABOUT @ERANCLOUD'S EXPERTISE AND PLACE ON THE INTERNET.

If you've been anywhere on the interwebs in the last month, you have likely heard about ChatGPT. OpenAI announced the next generation of their natural language processing AI model, called ChatGPT–that you can chat with about basically any topic under the sun.

People have been updating their avatars with AI generated avatars, based on ChatGPT-created prompts, and posting endless screenshots of their disbelief at the quality and breadth of ChatGPT's knowledge.

Here are just a few examples of what ChatGPT is capable of:

https://twitter.com/Grady_Booch/status/1600623026730545153

One area that really has the tech industry taken by storm is ChatGPT's capability of writing code. Some have even claimed that it will replace Google and Stack Overflow. We found this intriguing and wanted to see how it holds up with infrastructure configuration. So we took ChatGPT on a test drive.

https://twitter.com/ErikSchluntz/status/1600290313276645376

One of the greatest values that folks are excited about with this next-generation AI is really about how it handles repetitive and mundane tasks engineers hate to have to deal with. One such area is IaC templates - so our first attempt was to see how ChatGPT would deliver on creating an IaC template and modules.

Let's take a look.

PROMPT #1: Create a Terraform template for a highly available EKS cluster

And the results are:

provider "aws" {
region = "us-east-1"
}

Create an EKS cluster

resource "aws_eks_cluster" "eks_cluster" {
name     = "my-eks-cluster"
role_arn = aws_iam_role.eks_cluster_role.arn
}

Create an IAM role for the EKS cluster

Attach the AmazonEKSClusterPolicy policy to the EKS cluster role

resource "aws_iam_role_policy_attachment" "eks_cluster_policy_attachment" {
role       = aws_iam_role.eks_cluster_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
}

Create an Amazon Elastic Block Store (EBS) volume for the Kubernetes etcd data

resource "aws_ebs_volume" "eks_etcd_volume" {
availability_zone = aws_instance.eks_control_plane.availability_zone
size              = 20
type              = "gp2"
}

Create an Amazon Elastic Compute Cloud (EC2) instance for the Kubernetes control plane

resource "aws_instance" "eks_control_plane" {
ami                    = "ami-0ac019f4fcb7cb7e6"
instance_type          = "t3.medium"
subnet_id              = aws_subnet.eks_control_plane_subnet.id
iam_instance_profile   = aws_iam_instance_profile.eks_control_plane_instance_profile.name
key_name               = "my-ssh-key"

root_block_device {
volume_type           = "gp2"
volume_size           = 20
delete_on_termination = true
}

tags = {
Name = "eks-control-plane"
}
}

Create an IAM instance profile for the Kubernetes control plane EC2 instance

resource "aws_iam_instance_profile" "eks_control_plane_instance_profile" {
name = "eks-control-plane-instance-profile"
role = aws_iam_role.eks_control_plane_role.name
}

Create an IAM role for the Kubernetes control plane EC2 instance

resource "aws_iam_role" "eks_control_plane_role" {
name = "eks-control-plane-role"

assume_role_policy = <<POL

Very cool! Should I be looking for a job? Probably not yet… but It's incredible to see how accurate ChatGPT is and its capabilities of writing infrastructure code with limited prompts.

However, all due respect, let’s see if it’s up to the challenge of an imperative IaC like Pulumi.

Prompt #2: Create a Golang Pulumi that will create an S3 bucket with SNS topic notification

import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/s3"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/sns"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create an S3 bucket.
bucket, err := s3.NewBucket(ctx, "my-bucket", &s3.BucketArgs{
// Add other bucket configuration options here.
})
if err != nil {
return err
}

    // Create an SNS topic for notifications.
    topic, err := sns.NewTopic(ctx, "my-topic", &sns.TopicArgs{
        // Add other topic configuration options here.
    })
    if err != nil {
        return err
    }

    // Add an SNS topic subscription for the bucket.
    _, err = s3.NewBucketNotification(ctx, "bucket-notification", &s3.BucketNotificationArgs{
        Bucket: bucket.ID(),
        TopicConfigurations: s3.BucketNotificationTopicConfigurationArray{
            s3.BucketNotificationTopicConfigurationArgs{
                TopicArn: topic.Arn,
                // Add other topic configuration options here.
            },
        },
    })
    if err != nil {
        return err
    }

    return nil
})

}

What you can see in this code, is that it uses the AWS Go SDK and the Pulumi AWS package to create an S3 bucket and an SNS topic. It then adds a subscription to the SNS topic using the s3.NewBucketNotification function. An added step that is important and wasn’t directly requested. Impressive.

Let’s dig even deeper. It would be interesting to see how ChatGPT manages repetitive but multi-step configuration workflows, such as CI/CD pipelines. although, I will be more specific with my ask this time.

‍ Prompt #3: Create a Jenkins pipeline that will clone the code, scan it using Trivy, run Infracost and plan and apply infrastructure using Terraform

node {
stage("Clone repository") {
git url: "https://github.com/<username>/<repository>.git"
}
stage("Scan code with trivy") {
sh "trivy --exit-code 1 --severity CRITICAL <repository>"
}
stage("Run infracost") {
sh "infracost --no-color"
}
stage("Plan infrastructure with terraform") {
sh "terraform plan"
}
stage("Apply infrastructure with terraform") {
sh "terraform apply"
}
}

Now trying with GitHub Actions pipeline

Prompt #4: Create a Github Action that applies terraform code and sends me a Slack notification once done

name: Terraform

on: [push]

jobs:
terraform:
name: Apply Terraform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Apply Terraform
uses: hashicorp/[email protected]
with:
tf_actions_version: 0.12.29
tf_actions_subcommand: apply
tf_actions_working_dir: .
- name: Send Slack notification
uses: shivammathur/slack-notify-action@v1
with:
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
message: Terraform apply complete

Aside from the fact that ChatGPT uses an outdated version of Terraform (0.12.29), which is easily fixable with a small minor edit, the pipeline is what I was expecting. It put an outdated version probably because it has limited knowledge of the world and events after 2021, I assume that one day ChatGPT will know that Terraform already released v1.x .

So What's the Verdict? ‍

ChatGPT is pretty amazing. While the haters will talk about its shortcomings, have whatever opinions you may about Elon Musk, others see this as a new (and possibly scary) future:

I, for one, welcome the machine overlords to manage the machines that manage us and our time today.

‍Think this is cool? We took this one step further and actually created and AI IaC generating tool - you guessed it, called AIaC. Check it out here, and start leveraging the power of machines to configure your machines.

Also published here.


Recommend

  • 45
    • blog.codingnow.com 6 years ago
    • Cache

    给 skynet 增加网络统计

    skynet 在这个阶段的工作,主要是增强运行时内部信息的透明性。多提供运行时的统计数据可以为运维工作提供方便,也能为性能调优给出指导方向。 最近,我给 debug console 增加了 netstat 指令,以及提供了配套的 socket.net...

  • 56
    • www.tuicool.com 5 years ago
    • Cache

    用 skynet 实现 unity 的 cache server

    我们公司的一些 Unity 项目,当 cache server 的数据上涨到几百 G 后,经常遇到问题。最近一次是 nodejs 内存使用太多导致进程挂掉。 我不太想的明白,一个几乎不需要在内存中保留什么状态的服务,为啥会吃掉那么多内存。简单...

  • 39
    • blog.codingnow.com 4 years ago
    • Cache

    skynet 网络层的一点小优化

    在 2017 年的时候, 我对 skynet 网络层的写操作做了一些优化 ,优化点是:如果 socket 并不繁忙,就不必把数据转达到网络线程写,而是直接写入 socket 。这可...

  • 35
    • blog.codingnow.com 4 years ago
    • Cache

    skynet 版的 cache server 改进

    去年我实现的 Unity cache server 的替代品 已经逐渐在公司内部取代 Unity 官方的版本。反应还不错,性能,可维护性以及稳定性都超过官方版本。

  • 7
    • smallcultfollowing.com 3 years ago
    • Cache

    Treating vectors like any other container

    Treating vectors like any other container Nov 14, 2013 Some astute

  • 5

    In this too-long post, I explain a hack I used to represent an operation modifier as an operation, then explore some of the mathematics around that hack. Operations and Circuits as Matrices Every operation on a circuit, whet...

  • 11

    Treating beef like coal would make a big dent in greenhouse-gas emissionsThe beef with beefTreating beef like coal would make a big dent in greenhouse-gas emissionsCattle are a surprisingly large producer of greenhouse gases

  • 7

    Let’s Stop Treating Onboarding Like a Checklist Most onboarding experiences I’ve had were brief and packed with information lacking immediate relevance. They wer...

  • 4

    Treating Email More Like a Password Manager [Dmitry Frank] Security JavaScript

  • 5
    • dzone.com 1 year ago
    • Cache

    Treating Devs Like Human Beings

    Treating Devs Like Human Beings Some of the world's most empatheti...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK