From a84bb0dde939408ad1bc64e7da87115ebd0985b5 Mon Sep 17 00:00:00 2001 From: ChamakeNjefi Date: Sun, 8 Jan 2023 15:26:22 +0000 Subject: [PATCH] root & module --- ec2-instance/ec2.tf | 26 ++++++++++++++++++++++++++ ec2-instance/variable.tf | 15 +++++++++++++++ ec2.tf | 24 +++--------------------- 3 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 ec2-instance/ec2.tf create mode 100644 ec2-instance/variable.tf diff --git a/ec2-instance/ec2.tf b/ec2-instance/ec2.tf new file mode 100644 index 0000000..4c77eb8 --- /dev/null +++ b/ec2-instance/ec2.tf @@ -0,0 +1,26 @@ +# ----ec2-instance/ec2.tf # --------- + +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.27" + } + } + + required_version = ">= 0.14.9" +} + +provider "aws" { + profile = "default" + region = var.region +} + +resource "aws_instance" "app_server" { + ami = var.ami_id + instance_type = var.instance + + tags = { + Name = "MyAppServerInstance" + } +} diff --git a/ec2-instance/variable.tf b/ec2-instance/variable.tf new file mode 100644 index 0000000..e709da8 --- /dev/null +++ b/ec2-instance/variable.tf @@ -0,0 +1,15 @@ +# ----ec2-instance/ec2.tf # --------- + +variable "region" { + default = "us-west-2" +} + +variable "ami_id" { + type = string + default = "ami-0ceecbb0f30a902a6" +} + +variable "instance" { + type = string + default = "t2.micro" +} \ No newline at end of file diff --git a/ec2.tf b/ec2.tf index f55bdd8..888ee81 100644 --- a/ec2.tf +++ b/ec2.tf @@ -1,24 +1,6 @@ -terraform { - required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 3.27" - } - } +# ----root/ec2.tf # --------- - required_version = ">= 0.14.9" +module "ec2_instance" { + source = "./ec2-instance" } -provider "aws" { - profile = "default" - region = "us-west-2" -} - -resource "aws_instance" "app_server" { - ami = "ami-830c94e3" - instance_type = "t2.micro" - - tags = { - Name = "ExampleAppServerInstance" - } -}