Friday, February 8, 2019

Terraform EC2 Example - How to create EC2 instance using Terraform

Creating EC2 instance using Terraform is relatively easier. Here below is the code:
Everything created using terraform is called a resource.
resource "aws_instance" "myFirstInstrance" {
  ami           = "ami-916f59f4"


  key_name = "my_key"
  instance_type = "t2.micro"
  security_groups= [ "security_jenkins_port"]

  tags= {
    Name = "jenkins_instance"
  }


}

resource "aws_security_group" "security_jenkins_port" {
  name        = "security_jenkins_port"
  description = "security group for jenkins"

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

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

 # outbound from jenkis server
  egress {
    from_port   = 0
    to_port     = 65535
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags= {
    Name = "security_jenkins_port"
  }
}

No comments:

Post a Comment

DevOps Bootcamp Oct 2024 Schedule | DevOps & AWS Azure Cloud Coaching by Coach AK | DevOps and Cloud Computing Online Classes

  (Lot of new topics covered like GitHub Actions, Helm, Prometheus and Grafana..) The DevOps requirements in the IT market space is expected...