Create ECS instance, VPC & Security group using Tarraform

#### Please note each section is a breakdown of the codes for simplicity it can be merged together as a single code as well with some minor changes #### The aim is to assist in Create ECS instance, VPC & Security group using Tarraform


provider "aws" {
  access_key = "xxxxx"
  secret_key = "xxxx"
  region     = "us-east-2a"
}

resource "aws_instance" "Jenkins" {
  ami           = "ami-03d62b340566461c7"
  instance_type = "t2.micro"

############## Creating EC2 instance with Security Group ############
provider "aws" {
  region = "us-east-2"
}
resource "aws_instance" "Jenkins" {
  ami             = "ami-03d62b340566461c7"
  instance_type   = "t2.micro"
  key_name        = "DevOps-key"
  security_groups = [ "DevOps-Sec" ]
  tags = {
    Name = "HelloWorld"
  }
}
################### Creating a VPC, subnet and Security Group #############
provider "aws" {
  region = "us-east-2"
}
resource "aws_vpc" "lloyd-env" {
  cidr_block = "10.0.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support = true

  tags= {
    Name = "lloyd-env"
  }
}
resource "aws_subnet" "subnet-uno" {
  cidr_block = "10.0.1.0/24"
  vpc_id = "${aws_vpc.lloyd-env.id}"
  availability_zone = "us-east-2a"
  tags = {
    Name = "subnet-uno"

  }
}
resource "aws_security_group" "lloydtest1" {
  name           = "lloydtest1"
  description    = "allow-all-sg"
  vpc_id         = "${aws_vpc.lloyd-env.id}"

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

  egress {
   from_port = 0
   to_port   = 0
   protocol  = "-1"
   cidr_blocks = ["0.0.0.0/0"]
  }
}

Comments

Popular posts from this blog

Push command for NetWorker Client Upgrade

Factors Affecting Users’ Sense of Security and Trust in Integrating Electronic health record to the cloud

Basic Elastic Cloud Storage Troubleshooting Commands