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

How to Configure GitHub Advanced Security for Azure DevOps | How to Perform Security scan for Azure Repos using GitHub Advanced Security

GitHub Advanced Security for Azure DevOps brings the  secret scanning, dependency scanning  and  CodeQL code scanning  solutions already ava...