Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Ec2-module.tf/ec2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
profile = "default"
region = "us-east-1"
}

resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
instance_type = "t2.micro"

tags = {
Name = "ExampleAppServerInstance"
}
}

resource "random_string" "random" {
count = var.instance_count
length = 4
special = false
upper = false
}

resource "aws_instance" "app_server" {
ami = var.ami_id
instance_type = var.instance_type
count = var.instance_count

tags = {
Name = appserver-instance-aw${random_string.random[count.index].result}"
}
}
5 changes: 5 additions & 0 deletions Ec2-module.tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module "ec2_instance" {
source = "./ec2_module"
instance_type = "t2.micro"
instance_count = 3
}
14 changes: 14 additions & 0 deletions Ec2-module.tf/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}

provider "aws" {
profile = "default"
region = us-east-1
}
13 changes: 13 additions & 0 deletions Ec2-module.tf/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "instance_count" {
type = number
}

variable "ami_id" {
type = string
default "ami-0b5eea76982371e91"
}

variable "instance_type" {
type = string
default = "t2.micro"
}
24 changes: 0 additions & 24 deletions ec2.tf

This file was deleted.