Skip to content

Instantly share code, notes, and snippets.

@devops-school
Created April 3, 2023 04:23
Show Gist options
  • Save devops-school/b80beae09629dadd6dd993eca9fbde12 to your computer and use it in GitHub Desktop.
Save devops-school/b80beae09629dadd6dd993eca9fbde12 to your computer and use it in GitHub Desktop.

Revisions

  1. devops-school created this gist Apr 3, 2023.
    40 changes: 40 additions & 0 deletions aws.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Create a security group
    resource "aws_security_group" "web" {
    name_prefix = "web-sg"

    ingress {
    from_port = 22
    to_port = 22
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }

    ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }

    tags = {
    Name = "Web SG"
    }
    }

    # Create a key pair
    resource "aws_key_pair" "key" {
    key_name = "my-key"
    public_key = file("~/.ssh/id_rsa.pub")
    }

    # Launch an EC2 instance
    resource "aws_instance" "web" {
    ami = "ami-0c55b159cbfafe1f0"
    instance_type = "t2.micro"
    key_name = aws_key_pair.key.key_name
    vpc_security_group_ids = [aws_security_group.web.id]

    tags = {
    Name = "Web Instance"
    }
    }