Skip to content
TheChatArchiveThe Chat Archive
Metallama-2-13b-chat· MetaHugging Face Arena Human Preference 55K

can u write me a sample terraform script to create a AWS EC2 instance

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Metallama-2-70b-chat’s answer.
  1. User

    can u write me a sample terraform script to create a AWS EC2 instance

  2. Meta Assistant

    Sure, here is a sample Terraform script that creates an AWS EC2 instance:

    provider "aws" {
      region = "us-west-2"
    }
    
    resource "aws_instance" "example" {
      ami           = "ami-12345678"
      instance_type = "t2.micro"
      vpc_security_group_ids = [aws_security_group.example.id]
    
      # Specify the key pair to use for the instance
      key_name   = "my-key-pair"
    
      # Specify the network interface for the instance
      network_interface {
        device_name = "eth0"
    
        # Specify the associate public IP address
        associate_public_ip_address = true
      }
    }
    
    resource "aws_security_group" "example" {
      name        = "example"
      description = "Example security group"
    
      # Allow inbound traffic on port 22 from anywhere
      ingress {
        from_port   = 22
        to_port     = 22
        protocol    = "tcp"
        cidr_blocks = ["0.0.0.0/0"]
      }
    }
    

    This script creates an EC2 instance with the specified instance type, AMIs, security group, and key pair. The aws_instance resource creates the EC2 instance, and the aws_security_group resource creates the security group.

    Please note that you will need to replace the ami, instance_type, vpc_security_group_ids, key_name, and network_interface values with your own desired values. Also, you need to have the AWS credentials set up on your system to use the aws provider.

    You can run this script using the following command:

    terraform apply
    

    This will create the EC2 instance and security group in your AWS account.

    You can also use the terraform destroy command to destroy the resources created by this script.

    terraform destroy
    

    Please note that this script is just an example and you should not use it in production without proper testing and validation.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.