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

GitHub Actions CICD Pipeline to Create Docker Image and Push Docker Image into Amazon ECR | Integration GitHub Actions with AWS ECR

Please find steps for integrating AWS ECR with GitHub Actions: Pre-requisites: Make sure a Project is setup in GitHub  with Dockerfile Creat...