diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e1d4d28 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ + +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +# example.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +*.bak +*.lock* \ No newline at end of file diff --git a/ec2.tf b/ec2.tf index f55bdd8..13cd87f 100644 --- a/ec2.tf +++ b/ec2.tf @@ -1,24 +1,3 @@ -terraform { - required_providers { - aws = { - source = "hashicorp/aws" - version = "~> 3.27" - } - } - - required_version = ">= 0.14.9" -} - -provider "aws" { - profile = "default" - region = "us-west-2" -} - -resource "aws_instance" "app_server" { - ami = "ami-830c94e3" - instance_type = "t2.micro" - - tags = { - Name = "ExampleAppServerInstance" - } -} +module "my-ec2" { + source = "./my-ec2" +} \ No newline at end of file diff --git a/my-ec2/main.tf b/my-ec2/main.tf new file mode 100644 index 0000000..d0de177 --- /dev/null +++ b/my-ec2/main.tf @@ -0,0 +1,8 @@ +resource "aws_instance" "app_server" { + ami = var.ami_id + instance_type = var.instance + + tags = { + Name = var.tag_name + } +} \ No newline at end of file diff --git a/my-ec2/providers.tf b/my-ec2/providers.tf new file mode 100644 index 0000000..f249f8c --- /dev/null +++ b/my-ec2/providers.tf @@ -0,0 +1,15 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.27" + } + } + + required_version = ">= 0.14.9" +} + +provider "aws" { + profile = "default" + region = "us-east-2" +} \ No newline at end of file diff --git a/my-ec2/variabels.tf b/my-ec2/variabels.tf new file mode 100644 index 0000000..dced15e --- /dev/null +++ b/my-ec2/variabels.tf @@ -0,0 +1,14 @@ +variable "ami_id" { + type = string + default = "ami-0e820afa569e84cc1" +} + +variable "instance" { + type = string + default = "t2.micro" +} + +variable "tag_name" { + type = string + default = "ProjectEC2" +} \ No newline at end of file