-
Notifications
You must be signed in to change notification settings - Fork 0
Terraform Modules #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| variable "access_key" { | ||
| description = "Access key to AWS console" | ||
| type = Secret | ||
|
|
||
| } | ||
| variable "secret_key" { | ||
| description = "Secret key to AWS console" | ||
| type = secret_key | ||
| } | ||
|
|
||
| variable "region" { | ||
| type = string | ||
| } | ||
|
|
||
| variable "instance_name" { | ||
| description = "Value of the Name tag for the EC2 instance" | ||
| type = string | ||
| } | ||
|
|
||
| variable "instance_name" { | ||
| description = "Name of the instance to be created" | ||
| type = string | ||
| } | ||
|
|
||
| variable "instance_type" { | ||
| description = "type of instance " | ||
| default = "t2.micro" | ||
| } | ||
|
|
||
| variable "subnet_id" { | ||
| description = "The VPC subnet the instance(s) will be created in" | ||
| type = string | ||
| } | ||
|
|
||
| variable "ami_id" { | ||
| description = "The AMI to use" | ||
| type = string | ||
| } | ||
|
|
||
| variable "number_of_instances" { | ||
| description = "number of instances to be created" | ||
| default = 1 | ||
| } | ||
|
|
||
|
|
||
| variable "ami_key_pair_name" { | ||
| description = "name of your keypair" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| provider "aws" { | ||
| access_key = "${var.access_key}" | ||
| secret_key = "${var.secret_key}" | ||
| region = "${var.region}" | ||
| } | ||
|
|
||
| resource "aws_instance" "ec2_instance" { | ||
| ami = "${var.ami_id}" | ||
| count = "${var.number_of_instances}" | ||
| subnet_id = "${var.subnet_id}" | ||
| instance_type = "${var.instance_type}" | ||
| key_name = "${var.ami_key_pair_name}" | ||
| security_groups = [ "value" ] | ||
|
|
||
|
|
||
| tags = { | ||
| Name = "${var.instance_name}" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| output "Private_ip" { | ||
| value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2instance.*.private_ip) | ||
| } | ||
|
|
||
| output "Public_ip" { | ||
| value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2instance.*.private_ip) | ||
| } | ||
|
|
||
|
|
||
| output "public_dns" { | ||
| value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_eip.eip.*.public_dns) | ||
| } | ||
|
|
||
| output "private_dns" { | ||
| value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_instance.ec2instance.*.private_dns) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| access_key = "Access Key of IAM User" | ||
| secret_key = "Secret Key of IAM User" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| resource "aws_lb" "alb" { | ||
| name = "${var.alb_name}" | ||
| internal = true | ||
| load_balancer_type = "applcation" | ||
| security_groups = ["value"] | ||
| subnets = [ "value" ] | ||
| enable_http2 = false | ||
| enable_deletion_protection = false | ||
|
|
||
| tags = { | ||
| name = "${var.alb_name}" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| resource "aws_lb_target_group" "target_group" { | ||
| name = "${var.tg_name}" | ||
| port = 80 | ||
| protocol = "HTTP" | ||
| target_type = "instance" | ||
| vpc_id = [] | ||
|
|
||
| health_check { | ||
| path = "/" | ||
| protocol = "HTTP" | ||
| matcher = "200" | ||
| interval = 15 | ||
| healthy_threshold = 3 | ||
| timeout = 3 | ||
| unhealthy_threshold = 3 | ||
| } | ||
|
|
||
| } | ||
|
|
||
| resource "aws_lb_target_group_attachment" "tg_atch" { | ||
| target_group_arn = aws_lb_target_group.target_group.arn | ||
| target_id = aws_lb_target_group.target_group.id | ||
| port = 80 | ||
| } | ||
|
|
||
| resource "aws_lb_listener" "front_end" { | ||
| load_balancer_arn = aws_lb.alb.arn | ||
| port = "80" | ||
| protocol = "HTTP" | ||
|
|
||
| default_action { | ||
| type = "forward" | ||
| target_group_arn = aws_lb_target_group.target_group.arn | ||
| } | ||
|
|
||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| output "alb_id" { | ||
| value = aws_lb.lb.dns_name | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| variable "alb_name" { | ||
| description ="name of the application load balancer" | ||
| type = string | ||
| } | ||
|
|
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| resource "aws_security_group" "security_group" { | ||
|
|
||
| name = "${var.security_group}" | ||
| vpc_id = [value] | ||
|
|
||
| ingress = [ { | ||
| cidr_blocks = [ "value" ] | ||
| description = "value" | ||
| from_port = 1 | ||
| ipv6_cidr_blocks = [ "value" ] | ||
| prefix_list_ids = [ "value" ] | ||
| protocol = "value" | ||
| security_groups = ["value"] | ||
| self = false | ||
| to_port = 1 | ||
| } ] | ||
|
|
||
| egress = [ { | ||
| cidr_blocks = [ "value" ] | ||
| description = "value" | ||
| from_port = 1 | ||
| ipv6_cidr_blocks = [ "value" ] | ||
| prefix_list_ids = [ "value" ] | ||
| protocol = "value" | ||
| security_groups = [ "value" ] | ||
| self = false | ||
| to_port = 1 | ||
| } ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| output "security_group" { | ||
| value = aws_security_group.security_group.id | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| variable "security_group" { | ||
| description = "name of the sequrity group" | ||
| type = string | ||
| } |
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| # Terraform | ||
| # Terraform |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Ignore .terraform directory | ||
| .terraform/ | ||
|
|
||
| # Ignore any generated files | ||
| *.tfstate | ||
| *.tfstate.backup | ||
| *.tfvars | ||
|
|
||
| # Ignore any override files | ||
| override.tf | ||
| override.tf.json | ||
| *_override.tf | ||
| *_override.tf.json | ||
|
|
||
| # Ignore any local files | ||
| terraform.tfstate | ||
| terraform.tfstate.backup | ||
|
|
||
| # Ignore any plan files | ||
| *.tfplan | ||
|
|
||
| # Ignore any log files | ||
| *.log | ||
| *.out | ||
| *.aux | ||
|
|
||
| # Ignore any .DS_Store files (macOS specific) | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| terraform { | ||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 4.16" | ||
| } | ||
| } | ||
|
|
||
| required_version = ">= 1.2.0" | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = "us-east-1" | ||
| } | ||
|
|
||
|
|
||
|
|
||
| resource "aws_instance" "ec2_instance" { | ||
| ami = var.ami_id | ||
| subnet_id = var.subnet_id | ||
| instance_type = var.instance_type | ||
|
|
||
| #key_name = var.ami_key_pair_name | ||
| #security_groups = aws_security_group.security_group.id | ||
| #count = var.number_of_instances | ||
|
|
||
|
|
||
| tags = { | ||
| Name = "${var.instance_name}" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| resource "aws_eip" "elastic_ip" { | ||
| instance = aws_instance.ec2_instance.id | ||
| vpc = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| output "Private_ip" { | ||
| value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_ip) | ||
| } | ||
|
|
||
| output "Public_ip" { | ||
| value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_ip) | ||
| } | ||
|
|
||
|
|
||
| #output "public_dns" { | ||
| # value = zipmap(aws_instance.ec2instance.*.tags.Name, aws_eip.eip.*.public_dns) | ||
| #} | ||
|
|
||
|
|
||
| output "private_dns" { | ||
| value = zipmap(aws_instance.ec2_instance.*.tags.Name, aws_instance.ec2_instance.*.private_dns) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| access_key = "Access Key of IAM User" | ||
| secret_key = "Secret Key of IAM User" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|
|
||
| variable "region" { | ||
| type = string | ||
| default = "us-east-1" | ||
| } | ||
|
|
||
| variable "instance_name" { | ||
| description = "Name of the instance to be created" | ||
| type = string | ||
| default = "hostapace_ec2" | ||
| } | ||
|
|
||
| variable "instance_type" { | ||
| description = "type of instance " | ||
| default = "t2.micro" | ||
| } | ||
|
|
||
| variable "subnet_id" { | ||
| description = "The VPC subnet the instance(s) will be created in" | ||
| type = string | ||
| } | ||
|
|
||
| variable "ami_id" { | ||
| description = "The AMI to use" | ||
| type = string | ||
| default = "ami-006dcf34c09e50022" | ||
| } | ||
|
|
||
| variable "number_of_instances" { | ||
| description = "number of instances to be created" | ||
| default = 1 | ||
| } | ||
|
|
||
|
|
||
| variable "ami_key_pair_name" { | ||
| description = "name of your keypair" | ||
| default = "./mykeypair.pem" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| resource "aws_lb" "alb" { | ||
| name = "${var.alb_name}" | ||
| internal = true | ||
| load_balancer_type = "applcation" | ||
| security_groups = aws_security_group.security_group.id | ||
| subnets = [ "value" ] | ||
| enable_http2 = false | ||
| enable_deletion_protection = false | ||
|
|
||
| tags = { | ||
| name = "${var.alb_name}" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| resource "aws_lb_target_group" "target_group" { | ||
| name = "${var.tg_name}" | ||
| port = 80 | ||
| protocol = "HTTP" | ||
| target_type = "instance" | ||
| vpc_id = [] | ||
|
|
||
| health_check { | ||
| path = "/" | ||
| protocol = "HTTP" | ||
| matcher = "200" | ||
| interval = 15 | ||
| healthy_threshold = 3 | ||
| timeout = 3 | ||
| unhealthy_threshold = 3 | ||
| } | ||
|
|
||
| } | ||
|
|
||
| resource "aws_lb_target_group_attachment" "tg_atch" { | ||
| target_group_arn = aws_lb_target_group.target_group.arn | ||
| target_id = aws_lb_target_group.target_group.id | ||
| port = 80 | ||
| } | ||
|
|
||
| resource "aws_lb_listener" "front_end" { | ||
| load_balancer_arn = aws_lb.alb.arn | ||
| port = "80" | ||
| protocol = "HTTP" | ||
|
|
||
| default_action { | ||
| type = "forward" | ||
| target_group_arn = aws_lb_target_group.target_group.arn | ||
| } | ||
|
|
||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| output "alb_id" { | ||
| value = aws_lb.lb.dns_name | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| variable "alb_name" { | ||
| description ="name of the application load balancer" | ||
| type = string | ||
| } | ||
|
|
Empty file.
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RashRAJ we can take this out as it would be defined by the module user e.g.
#2