forked from vikas99341/Terraform-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bec1a4b
commit 8dfed50
Showing
403 changed files
with
9,934 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 @@ | ||
*/terraform.tfvars | ||
*/terraform.tfstate | ||
*/terraform.tfstate.backup | ||
*/.terraform | ||
*/mykey* |
Binary file not shown.
This file contains 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,39 @@ | ||
# terraform-course | ||
|
||
* These files are part of my Udemy course about Terraform | ||
* Course URL: https://www.udemy.com/learn-devops-infrastructure-automation-with-terraform/?couponCode=TERRAFORM_GIT | ||
|
||
# Compatibility | ||
|
||
* This is the >=terraform-0.12 branch. For compatibility with older versions, use the terraform-0.11 branch. | ||
|
||
# Demo overview | ||
Demo Directory | Description | ||
------------ | ------------- | ||
first-steps | First steps | ||
demo-1 | First steps: Launching an EC2 instance | ||
demo-2 | Using provisioner | ||
demo-2b | Using provisioner on a Windows instance | ||
demo-3 | Executing script locally | ||
demo-4 | Outputting | ||
demo-5 | Data Source | ||
demo-6 | Modules | ||
demo-7 | AWS VPC | ||
demo-8 | EC2 instance within VPC with securitygroup | ||
demo-9 | EC2 instance with EBS volumes | ||
demo-10 | Userdata and cloudinit | ||
demo-11 | Route53 (DNS) | ||
demo-12 | RDS | ||
demo-13 | IAM | ||
demo-14 | IAM Roles with S3 bucket | ||
demo-15 | Autoscaling | ||
demo-16 | Autoscaling with ELB (Elastic Load Balancer) | ||
demo-17 | Elastic Beanstalk PHP 7 stack with RDS | ||
demo-18 | Interpolations, VPC module | ||
demo-18b | Project structure, best practices | ||
packer-demo | Build AMIs with Packer | ||
jenkins-packer-demo | Demo with jenkins and Packer | ||
docker-demo-1 | Using ECR - The EC2 Container Registry | ||
docker-demo-2 | Using ECS - The EC2 Container Service | ||
docker-demo-3 | Using ECR/ECS with Jenkins in a complete workflow | ||
module-demo | Using ECS + ALB in 4 modules to show how developing terraform modules work |
This file contains 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,25 @@ | ||
resource "aws_launch_configuration" "example-launchconfig" { | ||
name_prefix = "example-launchconfig" | ||
image_id = var.AMIS[var.AWS_REGION] | ||
instance_type = "t2.micro" | ||
key_name = aws_key_pair.mykeypair.key_name | ||
security_groups = [aws_security_group.allow-ssh.id] | ||
} | ||
|
||
resource "aws_autoscaling_group" "example-autoscaling" { | ||
name = "example-autoscaling" | ||
vpc_zone_identifier = [aws_subnet.main-public-1.id, aws_subnet.main-public-2.id] | ||
launch_configuration = aws_launch_configuration.example-launchconfig.name | ||
min_size = 1 | ||
max_size = 2 | ||
health_check_grace_period = 300 | ||
health_check_type = "EC2" | ||
force_delete = true | ||
|
||
tag { | ||
key = "Name" | ||
value = "ec2 instance" | ||
propagate_at_launch = true | ||
} | ||
} | ||
|
59 changes: 59 additions & 0 deletions
59
others/terraform-wards/autoscaling-sns/autoscalingpolicy.tf
This file contains 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,59 @@ | ||
# scale up alarm | ||
|
||
resource "aws_autoscaling_policy" "example-cpu-policy" { | ||
name = "example-cpu-policy" | ||
autoscaling_group_name = aws_autoscaling_group.example-autoscaling.name | ||
adjustment_type = "ChangeInCapacity" | ||
scaling_adjustment = "1" | ||
cooldown = "300" | ||
policy_type = "SimpleScaling" | ||
} | ||
|
||
resource "aws_cloudwatch_metric_alarm" "example-cpu-alarm" { | ||
alarm_name = "example-cpu-alarm" | ||
alarm_description = "example-cpu-alarm" | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "CPUUtilization" | ||
namespace = "AWS/EC2" | ||
period = "120" | ||
statistic = "Average" | ||
threshold = "30" | ||
|
||
dimensions = { | ||
"AutoScalingGroupName" = aws_autoscaling_group.example-autoscaling.name | ||
} | ||
|
||
actions_enabled = true | ||
alarm_actions = [aws_autoscaling_policy.example-cpu-policy.arn] | ||
} | ||
|
||
# scale down alarm | ||
resource "aws_autoscaling_policy" "example-cpu-policy-scaledown" { | ||
name = "example-cpu-policy-scaledown" | ||
autoscaling_group_name = aws_autoscaling_group.example-autoscaling.name | ||
adjustment_type = "ChangeInCapacity" | ||
scaling_adjustment = "-1" | ||
cooldown = "300" | ||
policy_type = "SimpleScaling" | ||
} | ||
|
||
resource "aws_cloudwatch_metric_alarm" "example-cpu-alarm-scaledown" { | ||
alarm_name = "example-cpu-alarm-scaledown" | ||
alarm_description = "example-cpu-alarm-scaledown" | ||
comparison_operator = "LessThanOrEqualToThreshold" | ||
evaluation_periods = "2" | ||
metric_name = "CPUUtilization" | ||
namespace = "AWS/EC2" | ||
period = "120" | ||
statistic = "Average" | ||
threshold = "5" | ||
|
||
dimensions = { | ||
"AutoScalingGroupName" = aws_autoscaling_group.example-autoscaling.name | ||
} | ||
|
||
actions_enabled = true | ||
alarm_actions = [aws_autoscaling_policy.example-cpu-policy-scaledown.arn] | ||
} | ||
|
This file contains 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,8 @@ | ||
resource "aws_key_pair" "mykeypair" { | ||
key_name = "mykeypair" | ||
public_key = file(var.PATH_TO_PUBLIC_KEY) | ||
lifecycle { | ||
ignore_changes = [public_key] | ||
} | ||
} | ||
|
This file contains 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 @@ | ||
provider "aws" { | ||
region = var.AWS_REGION | ||
} | ||
|
This file contains 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,22 @@ | ||
resource "aws_security_group" "allow-ssh" { | ||
vpc_id = aws_vpc.main.id | ||
name = "allow-ssh" | ||
description = "security group that allows ssh and all egress traffic" | ||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
from_port = 22 | ||
to_port = 22 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
tags = { | ||
Name = "allow-ssh" | ||
} | ||
} | ||
|
This file contains 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,15 @@ | ||
# Uncomment if you want to have autoscaling notifications | ||
#resource "aws_sns_topic" "example-sns" { | ||
# name = "sg-sns" | ||
# display_name = "example ASG SNS topic" | ||
#} # email subscription is currently unsupported in terraform and can be done using the AWS Web Console | ||
# | ||
#resource "aws_autoscaling_notification" "example-notify" { | ||
# group_names = ["${aws_autoscaling_group.example-autoscaling.name}"] | ||
# topic_arn = "${aws_sns_topic.example-sns.arn}" | ||
# notifications = [ | ||
# "autoscaling:EC2_INSTANCE_LAUNCH", | ||
# "autoscaling:EC2_INSTANCE_TERMINATE", | ||
# "autoscaling:EC2_INSTANCE_LAUNCH_ERROR" | ||
# ] | ||
#} |
This file contains 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,21 @@ | ||
variable "AWS_REGION" { | ||
default = "eu-west-1" | ||
} | ||
|
||
variable "PATH_TO_PRIVATE_KEY" { | ||
default = "mykey" | ||
} | ||
|
||
variable "PATH_TO_PUBLIC_KEY" { | ||
default = "mykey.pub" | ||
} | ||
|
||
variable "AMIS" { | ||
type = map(string) | ||
default = { | ||
us-east-1 = "ami-13be557e" | ||
us-west-2 = "ami-06b94666" | ||
eu-west-1 = "ami-844e0bf7" | ||
} | ||
} | ||
|
This file contains 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 @@ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
} |
This file contains 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,117 @@ | ||
# Internet VPC | ||
resource "aws_vpc" "main" { | ||
cidr_block = "10.0.0.0/16" | ||
instance_tenancy = "default" | ||
enable_dns_support = "true" | ||
enable_dns_hostnames = "true" | ||
enable_classiclink = "false" | ||
tags = { | ||
Name = "main" | ||
} | ||
} | ||
|
||
# Subnets | ||
resource "aws_subnet" "main-public-1" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = "10.0.1.0/24" | ||
map_public_ip_on_launch = "true" | ||
availability_zone = "eu-west-1a" | ||
|
||
tags = { | ||
Name = "main-public-1" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "main-public-2" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = "10.0.2.0/24" | ||
map_public_ip_on_launch = "true" | ||
availability_zone = "eu-west-1b" | ||
|
||
tags = { | ||
Name = "main-public-2" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "main-public-3" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = "10.0.3.0/24" | ||
map_public_ip_on_launch = "true" | ||
availability_zone = "eu-west-1c" | ||
|
||
tags = { | ||
Name = "main-public-3" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "main-private-1" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = "10.0.4.0/24" | ||
map_public_ip_on_launch = "false" | ||
availability_zone = "eu-west-1a" | ||
|
||
tags = { | ||
Name = "main-private-1" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "main-private-2" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = "10.0.5.0/24" | ||
map_public_ip_on_launch = "false" | ||
availability_zone = "eu-west-1b" | ||
|
||
tags = { | ||
Name = "main-private-2" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "main-private-3" { | ||
vpc_id = aws_vpc.main.id | ||
cidr_block = "10.0.6.0/24" | ||
map_public_ip_on_launch = "false" | ||
availability_zone = "eu-west-1c" | ||
|
||
tags = { | ||
Name = "main-private-3" | ||
} | ||
} | ||
|
||
# Internet GW | ||
resource "aws_internet_gateway" "main-gw" { | ||
vpc_id = aws_vpc.main.id | ||
|
||
tags = { | ||
Name = "main" | ||
} | ||
} | ||
|
||
# route tables | ||
resource "aws_route_table" "main-public" { | ||
vpc_id = aws_vpc.main.id | ||
route { | ||
cidr_block = "0.0.0.0/0" | ||
gateway_id = aws_internet_gateway.main-gw.id | ||
} | ||
|
||
tags = { | ||
Name = "main-public-1" | ||
} | ||
} | ||
|
||
# route associations public | ||
resource "aws_route_table_association" "main-public-1-a" { | ||
subnet_id = aws_subnet.main-public-1.id | ||
route_table_id = aws_route_table.main-public.id | ||
} | ||
|
||
resource "aws_route_table_association" "main-public-2-a" { | ||
subnet_id = aws_subnet.main-public-2.id | ||
route_table_id = aws_route_table.main-public.id | ||
} | ||
|
||
resource "aws_route_table_association" "main-public-3-a" { | ||
subnet_id = aws_subnet.main-public-3.id | ||
route_table_id = aws_route_table.main-public.id | ||
} | ||
|
This file contains 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,21 @@ | ||
|
||
# cdktf and terraform ignores | ||
.terraform | ||
cdktf.out | ||
cdktf.log | ||
*terraform.*.tfstate* | ||
generated | ||
|
||
# src https://github.com/github/gitignore/blob/master/Go.gitignore | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out |
Oops, something went wrong.