Repository: easyawslearn/Terraform-Tutorial
Branch: master
Commit: 65d0164f2f21
Files: 120
Total size: 91.8 KB
Directory structure:
gitextract__u4gpojy/
├── .github/
│ └── workflows/
│ └── terraform.yml
├── .gitignore
├── EC2withJenkins/
│ ├── README.md
│ ├── ec2_jenkins.tf
│ ├── provider.tf
│ ├── security_group.tf
│ └── variables.tf
├── README.md
├── Software-provision/
│ ├── .gitignore
│ ├── README.md
│ ├── aws-instance-server-configure.tf
│ ├── index.html
│ ├── provider.tf
│ ├── terraform.pem
│ └── variables.tf
├── Terraform-aws-route53/
│ ├── instance.tf
│ ├── route53.tf
│ ├── variables.tf
│ └── vpc.tf
├── aws-instance-example.tf
├── aws-instance-first-script/
│ ├── .gitignore
│ ├── Jenkinsfile
│ ├── README.md
│ ├── aws-instance-example.tf
│ ├── provider.tf
│ └── variables.tf
├── ebs-with-userdata/
│ ├── README.md
│ ├── ebs_volume.tf
│ ├── instance.tf
│ ├── security_group.tf
│ ├── variables.tf
│ ├── volume.sh
│ └── vpc.tf
├── kms_policy.json.tpl
├── main.tf
├── provider.tf
├── terraform-aws-autoscaling/
│ ├── main.tf
│ └── variables.tf
├── terraform-aws-ebs/
│ ├── ebs_volume.tf
│ ├── instance.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-ec2-userdata/
│ ├── apache_config.sh
│ ├── output.tf
│ ├── provider.tf
│ ├── security_group.tf
│ ├── user-data-file-input.tf
│ ├── user_data.tf
│ └── variables.tf
├── terraform-aws-ec2-with-vpc/
│ ├── instance.tf
│ ├── provider.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-elasticsearch/
│ ├── README.md
│ ├── iam_role_policy.tf
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
├── terraform-aws-elb-alb/
│ ├── elb.tf
│ ├── instances.tf
│ ├── route53.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-iam/
│ ├── iam/
│ │ ├── aws_iam_group.tf
│ │ └── main.tf
│ └── iam_role_with_instance/
│ ├── instance.tf
│ ├── main.tf
│ ├── s3_bucket.tf
│ └── variables.tf
├── terraform-aws-private-public-ip/
│ ├── instance.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-rds-dynamoDb/
│ └── dynamodb.tf
├── terraform-aws-rds-mariaDb/
│ ├── instance.tf
│ ├── mariadb.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-sns/
│ ├── example/
│ │ ├── .terraform.lock.hcl
│ │ ├── example.tf
│ │ └── version.tf
│ ├── main.tf
│ ├── python/
│ │ └── hello-python.py
│ └── variable.tf
├── terraform-aws-vpc/
│ ├── internet-gateway.tf
│ ├── nat.tf
│ ├── private_subnets.tf
│ ├── public_subnets.tf
│ ├── route_table.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-data-source/
│ ├── .gitignore
│ ├── README.md
│ ├── aws-data-source-example.tf
│ ├── provider.tf
│ └── variables.tf
├── terraform-for-each-example/
│ ├── main.tf
│ └── provider.tf
├── terraform-module/
│ ├── main.tf
│ └── variables.tf
├── terraform-output/
│ ├── .gitignore
│ ├── README.md
│ ├── arn.txt
│ ├── aws-instance-example.tf
│ ├── ip_list.txt
│ ├── output.tf
│ ├── provider.tf
│ └── variables.tf
├── terraform-remote-state/
│ ├── .gitignore
│ ├── README.md
│ ├── aws-remote-state-example.tf
│ ├── backend.tf
│ ├── provider.tf
│ └── variables.tf
└── terraform-variables/
├── provider.tf
├── terraform-variable-example.tf
└── variables.tf
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/terraform.yml
================================================
name: terraform-tutorials-ci
on: [push, pull_request]
env:
AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Set up Terraform
uses: marocchino/setup-terraform@v1
with:
version: "0.12.15"
- name: Build module 'aws-instance-first-script'
run: cd aws-instance-first-script && terraform init && terraform validate && terraform plan
- name: Build module 'aws-EC2-with-jenkins'
run: cd EC2withJenkins && terraform init && terraform validate && terraform plan
- name: Build module 'aws-Application-Load-Balancer'
run: cd terraform-aws-elb-alb && terraform init && terraform validate && terraform plan
================================================
FILE: .gitignore
================================================
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# .tfvars files
*.tfvars
================================================
FILE: EC2withJenkins/README.md
================================================
# Terraform-Tutorial # Jenkins Install in EC2 Instance
Terraform Tutorial is the set of examples of [Terraform](https://www.terraform.io/) modules that is building the EC2 Instance with jenkins
infrastructure resources on AWS Cloud.
To learn about module, follow the readme of each module.
## Developing
- **Terraform**: v0.11.14
- **Terraform Docs**: https://www.terraform.io/docs/configuration-0-11/index.html
## Usage
```hcl
module "ec2_instance" {
source = "git::https://github.com/easyawslearn/Terraform-Tutorial.git/EC2withJenkins"
region = "us-west-2"
key-name = "ec2-demo"
instance_type = "t2.micro"
}
```
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| region | AWS region | string | us-east-1 | yes |
| key-name | ec2 access key name | string | ec2-demo | yes |
| instance_type | ec2 instance_type | string | t2.micro | yes |
================================================
FILE: EC2withJenkins/ec2_jenkins.tf
================================================
resource "aws_instance" "ec2_jenkins" {
ami = "${lookup(var.ami_id, var.region)}"
instance_type = "${var.instance_type}"
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
# key name
key_name = "${var.key_name}"
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
yum install java-1.8.0-openjdk-devel -y
curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
yum install -y jenkins
systemctl start jenkins
systemctl status jenkins
systemctl enable jenkins
EOF
tags = {
Name = "Ec2-User-data"
}
}
================================================
FILE: EC2withJenkins/provider.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
================================================
FILE: EC2withJenkins/security_group.tf
================================================
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
#vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 80 allowed from any IP
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 80 allowed from any IP
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: EC2withJenkins/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-00dc79254d0461090"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
================================================
FILE: README.md
================================================
# Terraform-Tutorial

Terraform Tutorial is the set of examples of [Terraform](https://www.terraform.io/) modules that is building the infrastructure resources
on AWS Cloud.
To learn about module, follow the readme of each module.
## Developing
- **Terraform**: v0.11.14
- **Terraform Docs**: https://www.terraform.io/docs/configuration-0-11/index.html
- **Youtube Channel for subscription**: https://www.youtube.com/channel/UCck6BsJ0H8C8C8JVgSS1b8Q?view_as=subscriber
- **Terraform Tutorial in English**: https://www.youtube.com/watch?v=5WykrpB7qS4&list=PL_OdF9Z6GmVaRD6e6sYLQO_WYqTKcj3aj
- **Terraform Tutorial in Hindi**: https://www.youtube.com/watch?v=LNYQXLf60N4&list=PL_OdF9Z6GmVY9QfBfNUua_X2c2mT65SAX
================================================
FILE: Software-provision/.gitignore
================================================
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# .tfvars files
*.tfvars
================================================
FILE: Software-provision/README.md
================================================
# Terraform-Tutorial
Terraform Tutorial with all the Live Example
================================================
FILE: Software-provision/aws-instance-server-configure.tf
================================================
resource "aws_instance" "web-server" {
ami = "${lookup(var.ami_id, var.region)}"
instance_type = "t2.micro"
key_name = "terraform"
provisioner "file" {
source = "index.html"
destination = "/tmp/index.html"
}
provisioner "remote-exec" {
inline = [
"sudo yum install -y httpd;sudo cp /tmp/index.html /var/www/html/",
"sudo service httpd restart",
"sudo service httpd status"
]
}
connection {
user = "ec2-user"
private_key = "${file("${var.private_key_path}")}"
host = "${aws_instance.web-server.public_ip}"
}
}
================================================
FILE: Software-provision/index.html
================================================
<HTML>
<HEAD>
THIS IS MY WEB Server Deployed on AWS EC2 Intance using Terraform Script
</HEAD>
</HTML>
================================================
FILE: Software-provision/provider.tf
================================================
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
version = "~> 2.0"
}
================================================
FILE: Software-provision/terraform.pem
================================================
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAjwPLx8LUEWbq9K84qM7J39Ksl8gtAtKczKuduC6xfEygjfznhjG73wp1qAKG
pfKJJS20r/mShYbWsnKRojjM+tU0Jm76gTzpOwXYG3eWA4bsoAOdZtWyKPnl1scb/SP5X5Fdvtka
baeVbz+lekX7c540wTGWzf4AuZjTs29A/PUYWKW9sOwsth4WgSHDuNdQznU0EgXhzuV7a9z4FlrR
+SZ400g6ONs2hfT7o4sqSGu8JcVnJUyQY0lY1Sgnkw0g0KGdyP2ZA6dIHcNutcYnRXNmspIRfdG9
79BDKeYNsdU/U0hk1YLAe8j7vH0Iq3oMCU5FdRUr5ITSD4Xt5M9zAQIDAQABAoIBAHwJ1c+PKjFh
qvzHkIPQvoRzC6ClTGy7UKWvXx7k2KkvKL2dkQzxy7k6MCuk7TW28r4dMy7BbhSDi2jAN5GUZCxV
iGKhNIGs27iGbBX+lUy/1DFAkV8kjt49R9wNWzgl4F7EDKO/Vs2uYMxZTmOLmPiBSc4Z/WryF5zh
cROatanudwmNKH/Mg+Wj9TuOFS5b5Lir0H0xfip+SHRbjWQAd8xp3RqYl82HzHbrJKbkVNiLqrd2
7IIkbfd6wMKtacruROLofNgDUSHr7050aIh/dgQIOXK08qAdlGRceQ/wUJsQVZqCta4alnu7lQTi
4lATrnincZM8RZL9dBayMIKXGLECgYEA2hvv6mtZIQYmZeC1Z/anpcE0PQUunuvahKliTbRa4yKw
6EHC/I8fZPNSFhqHnCml88k6ptaTDH13zqFF7CrcD2JqhRTjHkFZGP3u6sP63BJ2QJFOVglwvk9Y
7fr2BHKNIOdyHOpZccHOaIxXN6EY3CUyH+5RBmOY1HfDuM1Trc0CgYEAp9woN4NKL0e25PxEhgnD
vlNRHEPT5ltHTSqiQUjK63OP36A8WF/cGhJUXtXuAXVWcFIfMRh9g+XsYaFtvCDYykPsRYlZJQYV
KRncAVk29qyfJe11zvOD99uo+wro/V+dXRQkbgtFrcOYF3eBmAuVCWi+Eyp5pm/cgZbY/JRDRgUC
gYEAlbwYORb5WXKfadGauITdEy5QbpPgLbo9ilW+5xmqS8TFLq327uxS4TsqX4JXFx6Aj5zWZzNo
QGrilTiiiD/kU6t89WAhi+PRBxdNrl5dGjiSdkFLRkW04PIYW0ivHN6HhM9fx/oa7b3ftmaiec5f
AsOGZeV2Oqylfze5ZmWPzQECgYEAjG5XBvpDmgJ5NGEIQsrwg83YUbk9Eb7Ti+9bBxsLCKgJeaDo
W1b3IKitBRocoAO2aQmLJtvCRhKZC6St1XH1bGIezJ33gk3wbg5ATLCClyQbkPN0V8rKYRXX7Q5X
lYHkePZc8+NiS9kS6K8GMFmgOdrzCb3DQEbdR10X81dmYLECgYAhsgAbZNzrXAO+E3ooTJgIyZLW
QxB74kDIxTNFgUL+U01l70x92aY03TofLFare+9jGuNdDmLjzqbTswz/AXK8FUkxbRo8R18ldpoz
gvgh56v8VYulsULRphNeKoXJG3CTRmQEjDgrKYRSzHed3nVnRctT0iUAg/zAbUpzOIhdgg==
-----END RSA PRIVATE KEY-----
================================================
FILE: Software-provision/variables.tf
================================================
variable "access_key" {}
variable "secret_key" {}
variable "region" {
default = "us-east-1"
}
variable "private_key_path" {
default = "terraform.pem"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn"
}
}
================================================
FILE: Terraform-aws-route53/instance.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
resource "aws_instance" "IP_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
private_ip = "10.0.1.10"
# key name
key_name = var.key_name
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "Private_IP"
}
}
resource "aws_eip" "eip" {
instance = aws_instance.IP_example.id
vpc = true
}
output "public_ip" {
value = aws_instance.IP_example.public_ip
}
================================================
FILE: Terraform-aws-route53/route53.tf
================================================
resource "aws_route53_zone" "easy_aws" {
name = "easyaws.in"
tags = {
Environment = "dev"
}
}
resource "aws_route53_record" "www" {
zone_id = aws_route53_zone.easy_aws.zone_id
name = "www.easyaws.in"
type = "A"
ttl = "300"
records = [aws_eip.eip.public_ip]
}
output "name_server"{
value=aws_route53_zone.easy_aws.name_servers
}
================================================
FILE: Terraform-aws-route53/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "device_name" {
type = "string"
default = "/dev/xvdh"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: Terraform-aws-route53/vpc.tf
================================================
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc_demo.id
tags = {
Name = "internet-gateway-demo"
}
}
resource "aws_subnet" "public_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_route_table" "route-public" {
vpc_id = aws_vpc.vpc_demo.id
route {
cidr_block = "10.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.route-public.id
}
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 80 allowed from any IP
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: aws-instance-example.tf
================================================
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
version = "~> 2.0"
}
resource "aws_instance" "my_web_server" {
ami = "${lookup(var.ami_id, var.region)}"
instance_type = "t2.micro"
}
================================================
FILE: aws-instance-first-script/.gitignore
================================================
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# .tfvars files
*.tfvars
================================================
FILE: aws-instance-first-script/Jenkinsfile
================================================
pipeline {
parameters {
string(name: 'environment', defaultValue: 'terraform', description: 'Workspace/environment file to use for deployment')
booleanParam(name: 'autoApprove', defaultValue: false, description: 'Automatically run apply after generating plan?')
}
environment {
AWS_ACCESS_KEY_ID = credentials('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
}
agent any
options {
timestamps ()
ansiColor('xterm')
}
stages {
stage('checkout') {
steps {
script{
dir("terraform")
{
git "https://github.com/easyawslearn/Terraform-Tutorial.git"
}
}
}
}
stage('Plan') {
steps {
sh 'pwd;cd terraform/aws-instance-first-script ; terraform init -input=false'
sh 'pwd;cd terraform/aws-instance-first-script ; terraform workspace new ${environment}'
sh 'pwd;cd terraform/aws-instance-first-script ; terraform workspace select ${environment}'
sh "pwd;cd terraform/aws-instance-first-script ;terraform plan -input=false -out tfplan "
sh 'pwd;cd terraform/aws-instance-first-script ;terraform show -no-color tfplan > tfplan.txt'
}
}
stage('Approval') {
when {
not {
equals expected: true, actual: params.autoApprove
}
}
steps {
script {
def plan = readFile 'terraform/aws-instance-first-script/tfplan.txt'
input message: "Do you want to apply the plan?",
parameters: [text(name: 'Plan', description: 'Please review the plan', defaultValue: plan)]
}
}
}
stage('Apply') {
steps {
sh "pwd;cd terraform/aws-instance-first-script ; terraform apply -input=false tfplan"
}
}
}
}
================================================
FILE: aws-instance-first-script/README.md
================================================
# aws-instance-first-script

A Terraform module for creating AWS EC2 instance.
## Usage
```hcl
module "ec2_instance" {
source = "git::https://github.com/easyawslearn/Terraform-Tutorial.git//aws-instance-first-script"
region = "us-west-2"
}
```
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| region | AWS region | string | us-east-1 | yes |
================================================
FILE: aws-instance-first-script/aws-instance-example.tf
================================================
resource "aws_instance" "web1" {
ami = "${lookup(var.ami_id, var.region)}"
instance_type = "t2.micro"
}
================================================
FILE: aws-instance-first-script/provider.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
================================================
FILE: aws-instance-first-script/variables.tf
================================================
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn"
}
}
================================================
FILE: ebs-with-userdata/README.md
================================================
# aws-instance-with-ebs-volume
A Terraform module for creating AWS EC2 instance with userdata for creating EBS.
## Usage
```hcl
module "ec2_instance" {
source = "git::https://github.com/easyawslearn/Terraform-Tutorial.git/ebc-with-userdata"
region = "us-west-2"
key-name = "ec2-demo"
instance_type = "t2.micro"
ebs_size = "20"
}
```
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| region | AWS region | string | us-east-1 | yes |
| key-name | ec2 access key name | string | ec2-demo | yes |
| instance_type | ec2 instance_type | string | t2.micro | yes |
| ebs_size | EBS volume size | string | 20 | yes |
================================================
FILE: ebs-with-userdata/ebs_volume.tf
================================================
resource "aws_ebs_volume" "ebs_volume" {
availability_zone = "us-east-1a"
size = var.ebs_size
type = "gp2"
tags = {
Name = "ebs-volume-terraform-demo"
}
}
resource "aws_volume_attachment" "ebc_volume_attachment" {
device_name = var.device_name
volume_id = aws_ebs_volume.ebs_volume.id
instance_id = aws_instance.ebs_instance_example.id
}
data "template_file" "init" {
template = "${file("volume.sh")}"
vars = {
device_name = var.device_name
}
}
================================================
FILE: ebs-with-userdata/instance.tf
================================================
provider "aws" {
region = var.region
version = "~> 2.0"
}
resource "aws_instance" "ebs_instance_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
# key name
key_name = var.key_name
# User data passing through template rendering
user_data = data.template_file.init.rendered
tags = {
Name = "EBS with userdata"
}
}
================================================
FILE: ebs-with-userdata/security_group.tf
================================================
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 80 allowed from any IP
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: ebs-with-userdata/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "device_name" {
type = "string"
default = "/dev/xvdh"
}
variable "ebs_size" {
type = "string"
default = "20"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: ebs-with-userdata/volume.sh
================================================
#!/bin/bash -xe
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
sleep 30
sudo mkdir -p /data
sleep 30
sudo mkfs.ext4 ${device_name}
sudo mount ${device_name} /data
================================================
FILE: ebs-with-userdata/vpc.tf
================================================
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc_demo.id
tags = {
Name = "internet-gateway-demo"
}
}
resource "aws_subnet" "public_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_route_table" "route-public" {
vpc_id = aws_vpc.vpc_demo.id
route {
cidr_block = "10.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.route-public.id
}
================================================
FILE: kms_policy.json.tpl
================================================
{
"Version": "2012-10-17",
"Id": "kms-key-policy",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::${account_id}:root","Service": "logs.us-east-1.amazonaws.com"},
"Action": "kms:*",
"Resource": "*"
}
]
}
================================================
FILE: main.tf
================================================
data "template_file" "kms_policy" {
template = "${file("${kms_policy.json.tpl")}"
vars {
account_id = "${var.account_id}"
}
}
resource "aws_kms_key" "key" {
policy = "${data.template_file.kms_policy.rendered}"
}
resource "aws_cloudwatch_log_group" "yada" {
name = "vijay"
kms_key_id = aws_kms_key.key.arn
}
================================================
FILE: provider.tf
================================================
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
version = "~> 2.0"
}
================================================
FILE: terraform-aws-autoscaling/main.tf
================================================
provider "aws" {
region = var.region
}
resource "aws_launch_configuration" "launch_config" {
name = "web_config"
image_id = lookup(var.ami_id, var.region)
instance_type = "t2.micro"
key_name = var.key_name
security_groups = [ var.security_grpup_id]
}
resource "aws_autoscaling_group" "example_autoscaling" {
name = "autoscaling-terraform-test"
max_size = 2
min_size = 1
health_check_grace_period = 300
health_check_type = "EC2"
desired_capacity = 1
force_delete = true
launch_configuration = aws_launch_configuration.launch_config.name
availability_zones = ["us-east-1a","us-east-1b"]
# vpc_zone_identifier = [aws_subnet.example1.id, aws_subnet.example2.id]
}
resource "aws_autoscaling_policy" "asp" {
name = "asp-terraform-test"
scaling_adjustment = 1
adjustment_type = "ChangeInCapacity"
cooldown = 300
policy_type = "SimpleScaling"
autoscaling_group_name = aws_autoscaling_group.example_autoscaling.name
}
resource "aws_cloudwatch_metric_alarm" "aws_cloudwatch_metric_alarm" {
alarm_name = "terraform-test-cloudwatch"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "120"
statistic = "Average"
threshold = "30"
alarm_description = "This metric monitors ec2 cpu utilization"
dimensions = {
AutoScalingGroupName = aws_autoscaling_group.example_autoscaling.name
}
actions_enabled = true
alarm_actions = [aws_autoscaling_policy.asp.arn]
}
resource "aws_sns_topic" "user_updates" {
name = "user-updates-topic"
display_name = "example auto scaling"
}
resource "aws_autoscaling_notification" "example_notifications" {
group_names = [aws_autoscaling_group.example_autoscaling.name]
notifications = [
"autoscaling:EC2_INSTANCE_LAUNCH",
"autoscaling:EC2_INSTANCE_TERMINATE",
"autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
"autoscaling:EC2_INSTANCE_TERMINATE_ERROR",
]
topic_arn = aws_sns_topic.user_updates.arn
}
================================================
FILE: terraform-aws-autoscaling/variables.tf
================================================
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-04d29b6f966df1537"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "subnets" {
type = list(string)
default = ["subnet-59b98303","subnet-0d7cb232"]
}
variable "azs" {
type = list(string)
default = ["us-east-1a","us-east-1b"]
}
variable "security_grpup_id" {
type = "string"
default = "sg-53623a20"
}
================================================
FILE: terraform-aws-ebs/ebs_volume.tf
================================================
resource "aws_ebs_volume" "ebs_volume" {
availability_zone = "us-east-1a"
size = 20
type = "gp2"
tags = {
Name = "ebs-volume-terraform-demo"
}
}
resource "aws_volume_attachment" "ebc_volume_attachment" {
device_name = "/dev/xvdh"
volume_id = aws_ebs_volume.ebs_volume.id
instance_id = aws_instance.ebs_instance_example.id
}
================================================
FILE: terraform-aws-ebs/instance.tf
================================================
provider "aws" {
region = var.region
}
resource "aws_instance" "ebs_instance_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
# key name
key_name = var.key_name
tags = {
Name = "Ec2-with-VPC"
}
}
================================================
FILE: terraform-aws-ebs/security_group.tf
================================================
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: terraform-aws-ebs/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: terraform-aws-ebs/vpc.tf
================================================
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc_demo.id
tags = {
Name = "internet-gateway-demo"
}
}
resource "aws_subnet" "public_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_route_table" "route-public" {
vpc_id = aws_vpc.vpc_demo.id
route {
cidr_block = "10.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.route-public.id
}
================================================
FILE: terraform-aws-ec2-userdata/apache_config.sh
================================================
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
================================================
FILE: terraform-aws-ec2-userdata/output.tf
================================================
output "public_ip" {
value = "${aws_instance.user_data_example.public_ip}"
}
output "user_data_example_input_file" {
value = "${aws_instance.user_data_example_input_file.public_ip}"
}
================================================
FILE: terraform-aws-ec2-userdata/provider.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
================================================
FILE: terraform-aws-ec2-userdata/security_group.tf
================================================
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
#vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 80 allowed from any IP
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: terraform-aws-ec2-userdata/user-data-file-input.tf
================================================
resource "aws_instance" "user_data_example_input_file" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
# subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
# key name
key_name = var.key_name
user_data = "${file("apache_config.sh")}"
tags = {
Name = "Ec2-User-data-with-file"
}
}
================================================
FILE: terraform-aws-ec2-userdata/user_data.tf
================================================
resource "aws_instance" "user_data_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
# subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
# key name
key_name = var.key_name
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "Ec2-User-data"
}
}
================================================
FILE: terraform-aws-ec2-userdata/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
================================================
FILE: terraform-aws-ec2-with-vpc/instance.tf
================================================
resource "aws_instance" "web" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
# Public Subnet assign to instance
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids=[aws_security_group.allow_ssh.id]
# key name
key_name = var.key_name
tags = {
Name = "Ec2-with-VPC"
}
}
================================================
FILE: terraform-aws-ec2-with-vpc/provider.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
================================================
FILE: terraform-aws-ec2-with-vpc/security_group.tf
================================================
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: terraform-aws-ec2-with-vpc/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: terraform-aws-ec2-with-vpc/vpc.tf
================================================
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc_demo.id
tags = {
Name = "internet-gateway-demo"
}
}
resource "aws_subnet" "public_1" {
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_route_table" "route-public" {
vpc_id = aws_vpc.vpc_demo.id
route {
cidr_block = "10.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.route-public.id
}
================================================
FILE: terraform-aws-elasticsearch/README.md
================================================
# Terraform-Tutorial
## Introduction
This module will create:
- Elasticsearch cluster with the specified node count in aws
- Elasticsearch domain policy that accepts a list of IAM role ARNs from which to permit management traffic to the cluster
__NOTE:__ To enable [zone awareness](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-managedomains.html#es-managedomains-zoneawareness) to deploy Elasticsearch nodes into two different Availability Zones, you need to set `zone_awareness_enabled` to `true`
If you don't enable zone awareness, Amazon ES places an endpoint into only one subnet.
## Usage
Basic [example](examples/basic)
```hcl
module "elasticsearch" {
source = "git::https://github.com/easyawslearn/Terraform-Tutorial/terraform-aws-elasticsearch.git"
domain_name = "eg"
elasticsearch_version = "6.5"
zone_awareness_enabled = "false"
instance_type = "t2.small.elasticsearch"
instance_count = 2
encrypt_at_rest_enabled = true
advanced_options {
"rest.action.multi.allow_explicit_index" = "true"
}
}
```
## Developing
- **Terraform**: v0.11.14
- **Terraform Docs**: https://www.terraform.io/docs/configuration-0-11/index.html
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| advanced_options | Key-value string pairs to specify advanced configuration options | map(string) | `<map>` | no |
| automated_snapshot_start_hour | Hour at which automated snapshots are taken, in UTC | number | `0` | no |
| availability_zone_count | Number of Availability Zones for the domain to use. | number | `2` | no |
| dedicated_master_count | Number of dedicated master nodes in the cluster | number | `0` | no |
| dedicated_master_enabled | Indicates whether dedicated master nodes are enabled for the cluster | bool | `false` | no |
| dedicated_master_type | Instance type of the dedicated master nodes in the cluster | string | `t2.small.elasticsearch` | no |
| ebs_iops | The baseline input/output (I/O) performance of EBS volumes attached to data nodes. Applicable only for the Provisioned IOPS EBS volume type | number | `0` | no |
| ebs_volume_size | EBS volumes for data storage in GB | number | `0` | no |
| ebs_volume_type | Storage type of EBS volumes | string | `gp2` | no |
| elasticsearch_version | Version of Elasticsearch to deploy | string | `6.5` | no |
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
| encrypt_at_rest_enabled | Whether to enable encryption at rest | bool | `true` | no |
| encrypt_at_rest_kms_key_id | The KMS key ID to encrypt the Elasticsearch domain with. If not specified, then it defaults to using the AWS/Elasticsearch service KMS key | string | `` | no |
| instance_count | Number of data nodes in the cluster | number | `4` | no |
| instance_type | Elasticsearch instance type for data nodes in the cluster | string | `t2.small.elasticsearch` | no |
| log_publishing_application_cloudwatch_log_group_arn | ARN of the CloudWatch log group to which log for ES_APPLICATION_LOGS needs to be published | string | `` | no |
| log_publishing_application_enabled | Specifies whether log publishing option for ES_APPLICATION_LOGS is enabled or not | bool | `false` | no |
| log_publishing_index_cloudwatch_log_group_arn | ARN of the CloudWatch log group to which log for INDEX_SLOW_LOGS needs to be published | string | `` | no |
| log_publishing_index_enabled | Specifies whether log publishing option for INDEX_SLOW_LOGS is enabled or not | bool | `false` | no |
| log_publishing_search_cloudwatch_log_group_arn | ARN of the CloudWatch log group to which log for SEARCH_SLOW_LOGS needs to be published | string | `` | no |
| log_publishing_search_enabled | Specifies whether log publishing option for SEARCH_SLOW_LOGS is enabled or not | bool | `false` | no |
| domain_name | Name of the application | string | - | yes |
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
| node_to_node_encryption_enabled | Whether to enable node-to-node encryption | bool | `false` | no |
| zone_awareness_enabled | Enable zone awareness for Elasticsearch cluster | bool | `true` | no |
## Outputs
| Name | Description |
|------|-------------|
| domain_arn | ARN of the Elasticsearch domain |
| domain_endpoint | Domain-specific endpoint used to submit index, search, and data upload requests |
| domain_hostname | Elasticsearch domain hostname to submit index, search, and data upload requests |
| domain_id | Unique identifier for the Elasticsearch domain |
| elasticsearch_user_iam_role_arn | The ARN of the IAM role to allow access to Elasticsearch cluster |
| elasticsearch_user_iam_role_name | The name of the IAM role to allow access to Elasticsearch cluster |
## References
For additional context, refer to some of these links.
- [What is Amazon Elasticsearch Service](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/what-is-amazon-elasticsearch-service.html) - Complete description of Amazon Elasticsearch Service
- [Amazon Elasticsearch Service Access Control](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-ac.html) - Describes several ways of controlling access to Elasticsearch domains
- [VPC Support for Amazon Elasticsearch Service Domains](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-vpc.html) - Describes Elasticsearch Service VPC Support and VPC architectures with and without zone awareness
- [Creating and Configuring Amazon Elasticsearch Service Domains](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html) - Provides a complete description on how to create and configure Amazon Elasticsearch Service (Amazon ES) domains
- [Kibana and Logstash](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-kibana.html) - Describes some considerations for using Kibana and Logstash with Amazon Elasticsearch Service
- [Control Access to Amazon Elasticsearch Service Domain](https://aws.amazon.com/blogs/security/how-to-control-access-to-your-amazon-elasticsearch-service-domain/) - Describes how to Control Access to Amazon Elasticsearch Service Domain
- [elasticsearch_domain](https://www.terraform.io/docs/providers/aws/r/elasticsearch_domain.html) - Terraform reference documentation for the `elasticsearch_domain` resource
- [elasticsearch_domain_policy](https://www.terraform.io/docs/providers/aws/r/elasticsearch_domain_policy.html) - Terraform reference documentation for the `elasticsearch_domain_policy` resource
================================================
FILE: terraform-aws-elasticsearch/iam_role_policy.tf
================================================
# Role that pods can assume for access to elasticsearch and kibana
resource "aws_iam_role" "elasticsearch_user" {
name = "module.user_label.id"
assume_role_policy = join("", data.aws_iam_policy_document.assume_role.*.json)
description = "IAM Role to assume to access the Elasticsearch module.label.id cluster"
tags = {
tag-key = "tag-value"
}
}
data "aws_iam_policy_document" "assume_role" {
statement {
actions = [
"sts:AssumeRole"
]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
principals {
type = "AWS"
identifiers = ["*"]
}
effect = "Allow"
}
}
data "aws_iam_policy_document" "default" {
statement {
actions = ["es:*", ]
resources = [
join("", aws_elasticsearch_domain.default.*.arn),
"${join("", aws_elasticsearch_domain.default.*.arn)}/*"
]
principals {
type = "AWS"
identifiers = ["*"]
}
}
}
resource "aws_elasticsearch_domain_policy" "default" {
domain_name = "easyaws"
access_policies = join("", data.aws_iam_policy_document.default.*.json)
}
================================================
FILE: terraform-aws-elasticsearch/main.tf
================================================
provider "aws" {
region = var.region
version = "~> 2.0"
}
resource "aws_elasticsearch_domain" "default" {
domain_name = var.domain_name
elasticsearch_version = var.elasticsearch_version
advanced_options = var.advanced_options
ebs_options {
ebs_enabled = var.ebs_volume_size > 0 ? true : false
volume_size = var.ebs_volume_size
volume_type = var.ebs_volume_type
iops = var.ebs_iops
}
encrypt_at_rest {
enabled = var.encrypt_at_rest_enabled
kms_key_id = var.encrypt_at_rest_kms_key_id
}
cluster_config {
instance_count = var.instance_count
instance_type = var.instance_type
dedicated_master_enabled = var.dedicated_master_enabled
dedicated_master_count = var.dedicated_master_count
dedicated_master_type = var.dedicated_master_type
zone_awareness_enabled = var.zone_awareness_enabled
zone_awareness_config {
availability_zone_count = var.availability_zone_count
}
}
node_to_node_encryption {
enabled = var.node_to_node_encryption_enabled
}
snapshot_options {
automated_snapshot_start_hour = var.automated_snapshot_start_hour
}
log_publishing_options {
enabled = var.log_publishing_index_enabled
log_type = "INDEX_SLOW_LOGS"
cloudwatch_log_group_arn = var.log_publishing_index_cloudwatch_log_group_arn
}
log_publishing_options {
enabled = var.log_publishing_search_enabled
log_type = "SEARCH_SLOW_LOGS"
cloudwatch_log_group_arn = var.log_publishing_search_cloudwatch_log_group_arn
}
log_publishing_options {
enabled = var.log_publishing_application_enabled
log_type = "ES_APPLICATION_LOGS"
cloudwatch_log_group_arn = var.log_publishing_application_cloudwatch_log_group_arn
}
tags = {
Domain = "TestDomain"
}
}
================================================
FILE: terraform-aws-elasticsearch/output.tf
================================================
output "domain_arn" {
value = join("", aws_elasticsearch_domain.default.*.arn)
description = "ARN of the Elasticsearch domain"
}
output "domain_id" {
value = join("", aws_elasticsearch_domain.default.*.domain_id)
description = "Unique identifier for the Elasticsearch domain"
}
output "domain_endpoint" {
value = join("", aws_elasticsearch_domain.default.*.endpoint)
description = "Domain-specific endpoint used to submit index, search, and data upload requests"
}
output "elasticsearch_user_iam_role_name" {
value = join(",", aws_iam_role.elasticsearch_user.*.name)
description = "The name of the IAM role to allow access to Elasticsearch cluster"
}
output "elasticsearch_user_iam_role_arn" {
value = join(",", aws_iam_role.elasticsearch_user.*.arn)
description = "The ARN of the IAM role to allow access to Elasticsearch cluster"
}
================================================
FILE: terraform-aws-elasticsearch/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-2"
}
variable "domain_name" {
type = string
default = "easyaws"
description = "name of Elasticsearch Domain"
}
variable "elasticsearch_version" {
type = string
default = "6.5"
description = "Version of Elasticsearch to deploy"
}
variable "instance_type" {
type = string
default = "t2.small.elasticsearch"
description = "Elasticsearch instance type for data nodes in the cluster"
}
variable "instance_count" {
type = number
description = "Number of data nodes in the cluster"
default = 1
}
variable "zone_awareness_enabled" {
type = bool
default = true
description = "Enable zone awareness for Elasticsearch cluster"
}
variable "availability_zone_count" {
type = number
default = 2
description = "Number of Availability Zones for the domain to use."
}
variable "ebs_volume_size" {
type = number
description = "EBS volumes for data storage in GB"
default = 20
}
variable "ebs_volume_type" {
type = string
default = "gp2"
description = "Storage type of EBS volumes"
}
variable "ebs_iops" {
type = number
default = 0
description = "The baseline input/output (I/O) performance of EBS volumes attached to data nodes. Applicable only for the Provisioned IOPS EBS volume type"
}
variable "encrypt_at_rest_enabled" {
type = bool
default = false
description = "Whether to enable encryption at rest"
}
variable "encrypt_at_rest_kms_key_id" {
type = string
default = ""
description = "The KMS key ID to encrypt the Elasticsearch domain with. If not specified, then it defaults to using the AWS/Elasticsearch service KMS key"
}
variable "log_publishing_index_enabled" {
type = bool
default = false
description = "Specifies whether log publishing option for INDEX_SLOW_LOGS is enabled or not"
}
variable "log_publishing_search_enabled" {
type = bool
default = false
description = "Specifies whether log publishing option for SEARCH_SLOW_LOGS is enabled or not"
}
variable "log_publishing_application_enabled" {
type = bool
default = false
description = "Specifies whether log publishing option for ES_APPLICATION_LOGS is enabled or not"
}
variable "log_publishing_index_cloudwatch_log_group_arn" {
type = string
default = ""
description = "ARN of the CloudWatch log group to which log for INDEX_SLOW_LOGS needs to be published"
}
variable "log_publishing_search_cloudwatch_log_group_arn" {
type = string
default = ""
description = "ARN of the CloudWatch log group to which log for SEARCH_SLOW_LOGS needs to be published"
}
variable "log_publishing_application_cloudwatch_log_group_arn" {
type = string
default = ""
description = "ARN of the CloudWatch log group to which log for ES_APPLICATION_LOGS needs to be published"
}
variable "automated_snapshot_start_hour" {
type = number
description = "Hour at which automated snapshots are taken, in UTC"
default = 0
}
variable "dedicated_master_enabled" {
type = bool
default = false
description = "Indicates whether dedicated master nodes are enabled for the cluster"
}
variable "dedicated_master_count" {
type = number
description = "Number of dedicated master nodes in the cluster"
default = 0
}
variable "dedicated_master_type" {
type = string
default = "t2.small.elasticsearch"
description = "Instance type of the dedicated master nodes in the cluster"
}
variable "advanced_options" {
type = map(string)
default = {}
description = "Key-value string pairs to specify advanced configuration options"
}
variable "node_to_node_encryption_enabled" {
type = bool
default = false
description = "Whether to enable node-to-node encryption"
}
================================================
FILE: terraform-aws-elb-alb/elb.tf
================================================
provider "aws" {
region = var.region
}
resource "aws_lb" "elb_example" {
name = "elb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.elb_sg.id]
subnets = [aws_subnet.public_1.id,aws_subnet.public_2.id]
enable_deletion_protection = true
tags = {
Environment = "elb-example"
}
}
resource "aws_lb_listener" "front_end" {
load_balancer_arn = aws_lb.elb_example.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.test.arn
}
}
resource "aws_lb_target_group" "test" {
name = "tf-example-lb-tg"
port = 80
protocol = "HTTP"
target_type="instance"
vpc_id = aws_vpc.vpc_demo.id
}
resource "aws_lb_target_group_attachment" "test" {
target_group_arn = aws_lb_target_group.test.arn
target_id = aws_instance.elb_instance_example1.id
port = 80
}
resource "aws_lb_target_group_attachment" "test1" {
target_group_arn = aws_lb_target_group.test.arn
target_id = aws_instance.elb_instance_example2.id
port = 80
}
output "elb_example" {
description = "The DNS name of the ELB"
value = aws_lb.elb_example.dns_name
}
================================================
FILE: terraform-aws-elb-alb/instances.tf
================================================
resource "aws_instance" "elb_instance_example1" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.elb_sg.id]
# key name
key_name = var.key_name
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed ELB Instance Example 1</h1>" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "EC2-Instance-1"
}
}
resource "aws_instance" "elb_instance_example2" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.elb_sg.id]
# key name
key_name = var.key_name
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed ELB Instance Example 2</h1>" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "EC2-Instance-1"
}
}
================================================
FILE: terraform-aws-elb-alb/route53.tf
================================================
resource "aws_route53_zone" "easy_aws" {
name = "easyaws.in"
tags = {
Environment = "dev"
}
}
resource "aws_route53_record" "www" {
zone_id = aws_route53_zone.easy_aws.zone_id
name = "www.easyaws.in"
type = "A"
alias {
name = aws_lb.elb_example.dns_name
zone_id = aws_lb.elb_example.zone_id
evaluate_target_health = true
}
}
output "name_server"{
value=aws_route53_zone.easy_aws.name_servers
}
================================================
FILE: terraform-aws-elb-alb/security_group.tf
================================================
resource "aws_security_group" "elb_sg" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 22 allowed from any IP
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: terraform-aws-elb-alb/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
us-east-2 = "ami-02ccb28830b645a41"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: terraform-aws-elb-alb/vpc.tf
================================================
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc_demo.id
tags = {
Name = "internet-gateway-demo"
}
}
resource "aws_subnet" "public_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_subnet" "public_2" {
availability_zone = "us-east-1b"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.2.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_route_table" "route-public" {
vpc_id = aws_vpc.vpc_demo.id
route {
cidr_block = "10.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.route-public.id
}
resource "aws_route_table_association" "public_2" {
subnet_id = aws_subnet.public_2.id
route_table_id = aws_route_table.route-public.id
}
================================================
FILE: terraform-aws-iam/iam/aws_iam_group.tf
================================================
resource "aws_iam_group" "admin" {
name = "developer-admin-group"
}
resource "aws_iam_policy_attachment" "admin-attach" {
name = "admin-attachment"
groups = [aws_iam_group.admin.name]
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}
# Customer Policy Attachment
resource "aws_iam_group" "custom_admin" {
name = "developer-admin-grp-custom-policy-example"
}
resource "aws_iam_group_policy" "Custom_developer_admin_policy" {
name = "my_developer_policy"
group = aws_iam_group.custom_admin.name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "*",
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_user_group_membership" "admin-users" {
user = aws_iam_user.demo-user.name
groups = [
aws_iam_group.admin.name
]
}
resource "aws_iam_user_group_membership" "admin-users1" {
user = aws_iam_user.demo-user1.name
groups = [
aws_iam_group.admin.name
]
}
resource "aws_iam_user" "demo-user" {
name = "demo-user"
}
resource "aws_iam_user" "demo-user1" {
name = "demo-user1"
}
================================================
FILE: terraform-aws-iam/iam/main.tf
================================================
provider "aws" {
region = "eu-west-1"
}
================================================
FILE: terraform-aws-iam/iam_role_with_instance/instance.tf
================================================
resource "aws_instance" "iam_role_instance_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
iam_instance_profile = aws_iam_instance_profile.ec2_profile.name
# key name
key_name = var.key_name
# User data passing through template rendering
tags = {
Name = "Roles with Ec2"
}
}
output "public_ip" {
value = aws_instance.iam_role_instance_example.public_ip
}
================================================
FILE: terraform-aws-iam/iam_role_with_instance/main.tf
================================================
provider "aws" {
region = var.region
}
resource "aws_iam_role" "s3_access_role" {
name = "s3-access-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_instance_profile" "ec2_profile" {
name = "ec2_profile"
role = aws_iam_role.s3_access_role.name
}
resource "aws_iam_role_policy" "s3_bcuket_access_policy" {
name = "s3_bcuket_access_policy"
role = aws_iam_role.s3_access_role.id
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:*"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::iambucketdemo-dfredf",
"arn:aws:s3:::iambucketdemo-dfredf/*"
]
}
]
}
EOF
}
================================================
FILE: terraform-aws-iam/iam_role_with_instance/s3_bucket.tf
================================================
resource "aws_s3_bucket" "iam_demo_bucket_name" {
bucket = "iambucketdemo-dfredf"
acl="private"
tags = {
Name = "My bucket"
Environment = "Demo"
}
}
================================================
FILE: terraform-aws-iam/iam_role_with_instance/variables.tf
================================================
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-04d29b6f966df1537"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
================================================
FILE: terraform-aws-private-public-ip/instance.tf
================================================
provider "aws" {
region = var.region
version = "~> 2.0"
}
resource "aws_instance" "IP_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
private_ip = "10.0.1.10"
# key name
key_name = var.key_name
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "Private_IP"
}
}
resource "aws_eip" "eip" {
instance = aws_instance.IP_example.id
vpc = true
}
output "public_ip" {
value = aws_instance.IP_example.public_ip
}
================================================
FILE: terraform-aws-private-public-ip/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "device_name" {
type = "string"
default = "/dev/xvdh"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: terraform-aws-private-public-ip/vpc.tf
================================================
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.vpc_demo.id
tags = {
Name = "internet-gateway-demo"
}
}
resource "aws_subnet" "public_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_route_table" "route-public" {
vpc_id = aws_vpc.vpc_demo.id
route {
cidr_block = "10.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.route-public.id
}
resource "aws_security_group" "allow_ssh" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 80 allowed from any IP
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: terraform-aws-rds-dynamoDb/dynamodb.tf
================================================
provider "aws" {
region = "us-east-1"
version = "~> 2.0"
}
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "DynamoDB-Terraform"
billing_mode = "PROVISIONED"
read_capacity = 20
write_capacity = 20
hash_key = "UserId"
range_key = "Name"
attribute {
name = "UserId"
type = "S"
}
attribute {
name = "Name"
type = "S"
}
ttl {
attribute_name = "TimeToExist"
enabled = false
}
global_secondary_index {
name = "UserTitleIndex"
hash_key = "UserId"
range_key = "Name"
write_capacity = 10
read_capacity = 10
projection_type = "INCLUDE"
non_key_attributes = ["UserId"]
}
tags = {
Name = "dynamodb-table"
Environment = "Training"
}
}
================================================
FILE: terraform-aws-rds-mariaDb/instance.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
resource "aws_instance" "rds_example" {
ami = lookup(var.ami_id, var.region)
instance_type = var.instance_type
subnet_id = aws_subnet.public_1.id
# Security group assign to instance
vpc_security_group_ids = [aws_security_group.allow_ssh_http.id]
availability_zone="us-east-1a"
# key name
key_name = var.key_name
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "RDS_MariaDB_Example"
}
}
output "public_ip" {
value = aws_instance.rds_example.public_ip
}
================================================
FILE: terraform-aws-rds-mariaDb/mariadb.tf
================================================
resource "aws_db_parameter_group" "default" {
name = "mariadb"
family = "mariadb10.2"
parameter {
name = "max_allowed_packet"
value = "16777216"
}
}
resource "aws_db_subnet_group" "default" {
name = "main"
subnet_ids = [aws_subnet.private_1.id, aws_subnet.private_2.id]
tags = {
Name = "My DB subnet group"
}
}
resource "aws_db_instance" "default" {
allocated_storage = 20
storage_type = "gp2"
engine = "mariadb"
engine_version = "10.2.21"
instance_class = "db.t2.micro"
name = "mydb"
username = "root"
password = "foobarbaz"
parameter_group_name = "mariadb"
db_subnet_group_name=aws_db_subnet_group.default.name
vpc_security_group_ids=[aws_security_group.db.id]
availability_zone=aws_subnet.private_1.availability_zone
}
output "end_point" {
value = aws_db_instance.default.endpoint
}
================================================
FILE: terraform-aws-rds-mariaDb/security_group.tf
================================================
resource "aws_security_group" "allow_ssh_http" {
name = "allow_SSH_http"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
# SSH Port 80 allowed from any IP
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "db" {
name = "allow_SSH"
description = "Allow SSH inbound traffic"
vpc_id = aws_vpc.vpc_demo.id
ingress {
# SSH Port 22 allowed from any IP
from_port = 3306
to_port = 3306
protocol = "tcp"
security_groups =[aws_security_group.allow_ssh_http.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
================================================
FILE: terraform-aws-rds-mariaDb/variables.tf
================================================
variable "region" {
type = "string"
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn75gd33"
}
}
variable "instance_type" {
type = "string"
default = "t2.micro"
}
variable "device_name" {
type = "string"
default = "/dev/xvdh"
}
variable "key_name" {
type = "string"
default = "ec2-demo"
}
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: terraform-aws-rds-mariaDb/vpc.tf
================================================
######
# VPC
######
#terraform version >= 12
############
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.vpc_demo.id}"
tags = {
Name = "internet-gateway-demo"
}
}
resource "aws_subnet" "private_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = false
cidr_block = "10.0.4.0/24"
tags = {
Name = "private_1-demo"
}
}
resource "aws_subnet" "private_2" {
availability_zone = "us-east-1b"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = false
cidr_block = "10.0.5.0/24"
tags = {
Name = "private_2-demo"
}
}
resource "aws_subnet" "private_3" {
availability_zone = "us-east-1c"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = false
cidr_block = "10.0.6.0/24"
tags = {
Name = "private_3-demo"
}
}
resource "aws_subnet" "public_1" {
availability_zone = "us-east-1a"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_subnet" "public_2" {
vpc_id = aws_vpc.vpc_demo.id
availability_zone = "us-east-1b"
map_public_ip_on_launch = true
cidr_block = "10.0.2.0/24"
tags = {
Name = "public_2-demo"
}
}
resource "aws_subnet" "public_3" {
availability_zone = "us-east-1c"
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.3.0/24"
tags = {
Name = "public_3-demo"
}
}
resource "aws_route_table" "route-public" {
vpc_id = "${aws_vpc.vpc_demo.id}"
route {
cidr_block = "10.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = "${aws_subnet.public_1.id}"
route_table_id = "${aws_route_table.route-public.id}"
}
resource "aws_route_table_association" "public_2" {
subnet_id = "${aws_subnet.public_2.id}"
route_table_id = "${aws_route_table.route-public.id}"
}
resource "aws_route_table_association" "public_3" {
subnet_id = "${aws_subnet.public_3.id}"
route_table_id = "${aws_route_table.route-public.id}"
}
resource "aws_route_table" "route_private" {
vpc_id = "${aws_vpc.vpc_demo.id}"
tags = {
Name = "private-route-table-demo"
}
}
resource "aws_route_table_association" "private_1" {
subnet_id = "${aws_subnet.private_1.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
resource "aws_route_table_association" "private_2" {
subnet_id = "${aws_subnet.private_2.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
resource "aws_route_table_association" "private_3" {
subnet_id = "${aws_subnet.private_3.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
================================================
FILE: terraform-aws-sns/example/.terraform.lock.hcl
================================================
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "4.22.0"
constraints = ">= 3.1.15"
hashes = [
"h1:KOsejPSvd2eEfuhtbLilFMnQZlaOJ53p7/NR+4qSibo=",
"zh:299efb8ba733b7742f0ef1c5c5467819e0c7bf46264f5f36ba6b6674304a5244",
"zh:4db198a41d248491204d4ca644662c32f748177d5cbe01f3c7adbb957d4d77f0",
"zh:62ebc2b05b25eafecb1a75f19d6fc5551faf521ada9df9e5682440d927f642e1",
"zh:636b590840095b4f817c176034cf649f543c0ce514dc051d6d0994f0a05c53ef",
"zh:8594bd8d442288873eee56c0b4535cbdf02cacfcf8f6ddcf8cd5f45bb1d3bc80",
"zh:8e18a370949799f20ba967eec07a84aaedf95b3ee5006fe5af6eae13fbf39dc3",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:aa968514231e404fb53311d8eae2e8b6bde1fdad1f4dd5a592ab93d9cbf11af4",
"zh:af8e5c48bf36d4fff1a6fca760d5b85f14d657cbdf95e9cd5e898c68104bad31",
"zh:d8a75ba36bf8b6f2e49be5682f48eccb6c667a4484afd676ae347213ae208622",
"zh:dd7c419674a47e587dabe98b150a8f1f7e31c248c68e8bf5e9ca0a400b5e2c4e",
"zh:fdeb6314a2ce97489bbbece59511f78306955e8a23b02cbd1485bd04185a3673",
]
}
================================================
FILE: terraform-aws-sns/example/example.tf
================================================
provider "aws" {
region = "eu-west-1"
}
module "sns_cloudwatch" {
source = "github.com/easyawslearn/Terraform-Tutorial/terraform-aws-sns"
cloudwatch_event_rule_name = "capture-aws-sign-in"
description = "Capture each AWS Console Sign In"
sns_name = "mysns"
sns_display_name = "demosns"
lambda_function_name = "S3cloudHub_Test_Lambda_Function"
lambda_function_runtime = "python3.8"
}
================================================
FILE: terraform-aws-sns/example/version.tf
================================================
# Terraform version
terraform {
required_version = ">= 0.14.11"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.1.15"
}
}
}
================================================
FILE: terraform-aws-sns/main.tf
================================================
provider "aws" {
region = var.region
}
resource "aws_cloudwatch_event_rule" "default" {
count = var.enabled == true ? 1 : 0
name = var.cloudwatch_event_rule_name
description = var.description
event_pattern = <<EOF
{
"detail-type": [
"AWS Console Sign In via CloudTrail"
]
}
EOF
role_arn = var.role_arn
is_enabled = var.is_enabled
}
resource "aws_cloudwatch_event_target" "default" {
count = var.enabled == true ? 1 : 0
rule = aws_cloudwatch_event_rule.default.*.name[0]
target_id = var.target_id
arn = aws_sns_topic.this[count.index].arn
input_path = var.input_path != "" ? var.input_path : null
role_arn = var.target_role_arn
}
resource "aws_sns_topic" "this" {
count = var.enabled ? 1 : 0
name = var.sns_name
display_name = var.sns_display_name
kms_master_key_id = var.kms_master_key_id
delivery_policy = var.delivery_policy
fifo_topic = var.fifo_topic
content_based_deduplication = var.content_based_deduplication
}
resource "aws_sns_topic_subscription" "this" {
for_each = var.enabled ? var.subscribers : {}
topic_arn = join("", aws_sns_topic.this.*.arn)
protocol = var.subscribers[each.key].protocol
endpoint = aws_lambda_function.terraform_lambda_func.arn
endpoint_auto_confirms = var.subscribers[each.key].endpoint_auto_confirms
raw_message_delivery = var.subscribers[each.key].raw_message_delivery
}
resource "aws_sns_topic_policy" "default" {
count = var.sns_topic_policy_enabled ? 1 : 0
arn = aws_sns_topic.this[count.index].arn
policy = data.aws_iam_policy_document.sns_topic_policy[count.index].json
}
data "aws_iam_policy_document" "sns_topic_policy" {
count = var.sns_topic_policy_enabled ? 1 : 0
statement {
effect = "Allow"
actions = ["SNS:Publish"]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
resources = [aws_sns_topic.this[count.index].arn]
}
}
resource "aws_iam_role" "lambda_role" {
name = "S3cloudHub_Test_Lambda_Function_Role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_policy" "iam_policy_for_lambda" {
name = "aws_iam_policy_for_terraform_aws_lambda_role"
path = "/"
description = "AWS IAM Policy for managing aws lambda role"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "attach_iam_policy_to_iam_role" {
role = aws_iam_role.lambda_role.name
policy_arn = aws_iam_policy.iam_policy_for_lambda.arn
}
data "archive_file" "zip_the_python_code" {
type = "zip"
source_dir = "${path.module}/python/"
output_path = "${path.module}/python/hello-python.zip"
}
resource "aws_lambda_function" "terraform_lambda_func" {
filename = "${path.module}/python/hello-python.zip"
function_name = var.lambda_function_name
role = aws_iam_role.lambda_role.arn
handler = "index.lambda_handler"
runtime = var.lambda_function_runtime
depends_on = [aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role]
}
================================================
FILE: terraform-aws-sns/python/hello-python.py
================================================
def lambda_handler(event, context):
message = 'Hello {} !'.format(event['key1'])
return {
'message' : message
}
================================================
FILE: terraform-aws-sns/variable.tf
================================================
variable "region" {
type = string
default = "eu-west-1"
}
variable "enabled" {
type = bool
default = true
}
variable "sns_topic_policy_enabled" {
type = bool
default = true
}
variable "lambda_function_name" {
type = string
default = ""
}
variable "lambda_function_runtime" {
type = string
default = ""
}
variable "sns_display_name" {
type = string
default = ""
}
variable "cloudwatch_event_rule_name" {
type = string
default = ""
description = "Name (e.g. `app` or `cluster`)."
}
variable "description" {
type = string
default = ""
description = "The description for the rule."
}
variable "role_arn" {
type = string
default = ""
description = "The Amazon Resource Name (ARN) associated with the role that is used for target invocation."
}
variable "is_enabled" {
type = bool
default = true
description = "Whether the rule should be enabled (defaults to true)."
}
variable "target_id" {
type = string
default = "SendToSNS"
description = "The Amazon Resource Name (ARN) associated with the role that is used for target invocation."
}
variable "arn" {
type = string
default = ""
description = "The Amazon Resource Name (ARN) associated with the role that is used for target invocation."
}
variable "input_path" {
type = string
default = ""
description = "The value of the JSONPath that is used for extracting part of the matched event when passing it to the target."
}
variable "target_role_arn" {
type = string
default = ""
description = "The Amazon Resource Name (ARN) of the IAM role to be used for this target when the rule is triggered. Required if ecs_target is used."
}
variable "input_paths" {
type = map(any)
default = {}
description = "Key value pairs specified in the form of JSONPath (for example, time = $.time)"
}
variable "sns_name" {
type = string
default = ""
description = "Name (e.g. `app` or `cluster`)."
}
variable "subscribers" {
type = map(object({
protocol = string
# The protocol to use. The possible values for this are: sqs, sms, lambda, application. (http or https are partially supported, see below) (email is an option but is unsupported, see below).
endpoint = string
# The endpoint to send data to, the contents will vary with the protocol. (see below for more information)
endpoint_auto_confirms = bool
# Boolean indicating whether the end point is capable of auto confirming subscription e.g., PagerDuty (default is false)
raw_message_delivery = bool
# Boolean indicating whether or not to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property) (default is false)
}))
description = "Required configuration for subscibres to SNS topic."
default = {}
}
variable "allowed_aws_services_for_sns_published" {
type = list(string)
description = "AWS services that will have permission to publish to SNS topic. Used when no external JSON policy is used"
default = []
}
variable "kms_master_key_id" {
type = string
description = "The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK."
default = "alias/aws/sns"
}
variable "encryption_enabled" {
type = bool
description = "Whether or not to use encryption for SNS Topic. If set to `true` and no custom value for KMS key (kms_master_key_id) is provided, it uses the default `alias/aws/sns` KMS key."
default = true
}
variable "sqs_queue_kms_master_key_id" {
type = string
description = "The ID of an AWS-managed customer master key (CMK) for Amazon SQS Queue or a custom CMK"
default = "alias/aws/sqs"
}
variable "sqs_queue_kms_data_key_reuse_period_seconds" {
type = number
description = "The length of time, in seconds, for which Amazon SQS can reuse a data key to encrypt or decrypt messages before calling AWS KMS again"
default = 300
}
variable "allowed_iam_arns_for_sns_publish" {
type = list(string)
description = "IAM role/user ARNs that will have permission to publish to SNS topic. Used when no external json policy is used."
default = []
}
variable "sns_topic_policy_json" {
type = string
description = "The fully-formed AWS policy as JSON"
default = ""
}
variable "sqs_dlq_enabled" {
type = bool
description = "Enable delivery of failed notifications to SQS and monitor messages in queue."
default = false
}
variable "sqs_dlq_max_message_size" {
type = number
description = "The limit of how many bytes a message can contain before Amazon SQS rejects it. An integer from 1024 bytes (1 KiB) up to 262144 bytes (256 KiB). The default for this attribute is 262144 (256 KiB)."
default = 262144
}
variable "sqs_dlq_message_retention_seconds" {
type = number
description = "The number of seconds Amazon SQS retains a message. Integer representing seconds, from 60 (1 minute) to 1209600 (14 days)."
default = 1209600
}
variable "delivery_policy" {
type = string
description = "The SNS delivery policy as JSON."
default = null
}
variable "fifo_topic" {
type = bool
description = "Whether or not to create a FIFO (first-in-first-out) topic"
default = false
}
variable "fifo_queue_enabled" {
type = bool
description = "Whether or not to create a FIFO (first-in-first-out) queue"
default = false
}
variable "content_based_deduplication" {
type = bool
description = "Enable content-based deduplication for FIFO topics"
default = false
}
variable "redrive_policy_max_receiver_count" {
type = number
description = "The number of times a message is delivered to the source queue before being moved to the dead-letter queue. When the ReceiveCount for a message exceeds the maxReceiveCount for a queue, Amazon SQS moves the message to the dead-letter-queue."
default = 5
}
variable "redrive_policy" {
type = string
description = "The SNS redrive policy as JSON. This overrides `var.redrive_policy_max_receiver_count` and the `deadLetterTargetArn` (supplied by `var.fifo_queue = true`) passed in by the module."
default = null
}
================================================
FILE: terraform-aws-vpc/internet-gateway.tf
================================================
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.vpc_demo.id}"
tags = {
Name = "internet-gateway-demo"
}
}
================================================
FILE: terraform-aws-vpc/nat.tf
================================================
resource "aws_eip" "nat" {
vpc = true
}
resource "aws_nat_gateway" "nat_gw" {
allocation_id = "${aws_eip.nat.id}"
subnet_id = "${aws_subnet.public_1.id}"
depends_on = ["aws_internet_gateway.gw"]
}
resource "aws_route_table" "route_private" {
vpc_id = "${aws_vpc.vpc_demo.id}"
route {
cidr_block = "10.0.0.0/0"
gateway_id = "${aws_nat_gateway.nat_gw.id}"
}
tags = {
Name = "private-route-table-demo"
}
}
resource "aws_route_table_association" "private_1" {
subnet_id = "${aws_subnet.private_1.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
resource "aws_route_table_association" "private_2" {
subnet_id = "${aws_subnet.private_2.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
resource "aws_route_table_association" "private_3" {
subnet_id = "${aws_subnet.private_3.id}"
route_table_id = "${aws_route_table.route_private.id}"
}
================================================
FILE: terraform-aws-vpc/private_subnets.tf
================================================
resource "aws_subnet" "private_1" {
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = false
cidr_block = "10.0.4.0/24"
tags = {
Name = "private_1-demo"
}
}
resource "aws_subnet" "private_2" {
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = false
cidr_block = "10.0.5.0/24"
tags = {
Name = "private_2-demo"
}
}
resource "aws_subnet" "private_3" {
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = false
cidr_block = "10.0.6.0/24"
tags = {
Name = "private_3-demo"
}
}
================================================
FILE: terraform-aws-vpc/public_subnets.tf
================================================
resource "aws_subnet" "public_1" {
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.1.0/24"
tags = {
Name = "public_1-demo"
}
}
resource "aws_subnet" "public_2" {
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.2.0/24"
tags = {
Name = "public_2-demo"
}
}
resource "aws_subnet" "public_3" {
vpc_id = aws_vpc.vpc_demo.id
map_public_ip_on_launch = true
cidr_block = "10.0.3.0/24"
tags = {
Name = "public_3-demo"
}
}
================================================
FILE: terraform-aws-vpc/route_table.tf
================================================
resource "aws_route_table" "route-public" {
vpc_id = "${aws_vpc.vpc_demo.id}"
route {
cidr_block = "10.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
tags = {
Name = "public-route-table-demo"
}
}
resource "aws_route_table_association" "public_1" {
subnet_id = "${aws_subnet.public_1.id}"
route_table_id = "${aws_route_table.route-public.id}"
}
resource "aws_route_table_association" "public_2" {
subnet_id = "${aws_subnet.public_2.id}"
route_table_id = "${aws_route_table.route-public.id}"
}
resource "aws_route_table_association" "public_3" {
subnet_id = "${aws_subnet.public_3.id}"
route_table_id = "${aws_route_table.route-public.id}"
}
================================================
FILE: terraform-aws-vpc/variables.tf
================================================
variable "cidr" {
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
type = string
default = "10.0.0.0/16"
}
variable "instance_tenancy" {
description = "A tenancy option for instances launched into the VPC"
type = string
default = "default"
}
variable "enable_dns_hostnames" {
description = "Should be true to enable DNS hostnames in the VPC"
type = bool
default = true
}
variable "enable_dns_support" {
description = "Should be true to enable DNS support in the VPC"
type = bool
default = true
}
variable "enable_classiclink" {
description = "Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic."
type = bool
default = false
}
variable "tags" {
description = "A map of tags to add to all resources"
type = string
default = "Vpc-custom-demo"
}
================================================
FILE: terraform-aws-vpc/vpc.tf
================================================
######
# VPC
######
#terraform version >= 12
############
resource "aws_vpc" "vpc_demo" {
cidr_block = var.cidr
instance_tenancy = var.instance_tenancy
enable_dns_hostnames = var.enable_dns_hostnames
enable_dns_support = var.enable_dns_support
enable_classiclink = var.enable_classiclink
tags = {
Name = var.tags
}
}
================================================
FILE: terraform-data-source/.gitignore
================================================
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# .tfvars files
*.tfvars
================================================
FILE: terraform-data-source/README.md
================================================
# Terraform-Tutorial
Terraform Tutorial with all the Live Example
================================================
FILE: terraform-data-source/aws-data-source-example.tf
================================================
data "aws_vpc" "selected" {
filter {
name = "tag:Name"
values = ["Default"]
}
}
resource "aws_subnet" "example" {
vpc_id = "${data.aws_vpc.selected.id}"
cidr_block = "172.31.0.0/20"
}
================================================
FILE: terraform-data-source/provider.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
================================================
FILE: terraform-data-source/variables.tf
================================================
variable "access_key" {}
variable "secret_key" {}
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn"
}
}
================================================
FILE: terraform-for-each-example/main.tf
================================================
variable "vpc_id" {
description = "ID for the AWS VPC where a security group is to be created."
}
variable "subnet_numbers" {
description = "List of 8-bit numbers of subnets of base_cidr_block that should be granted access."
default = [1, 2, 3, 4, 5, 6]
}
data "aws_vpc" "example" {
id = var.vpc_id
}
resource "aws_security_group" "example" {
name = "for_each_example"
description = "Allows access from friendly subnets"
vpc_id = var.vpc_id
ingress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = [
for num in var.subnet_numbers:
cidrsubnet(data.aws_vpc.example.cidr_block, 8, num)
]
}
}
================================================
FILE: terraform-for-each-example/provider.tf
================================================
provider "aws" {
region = "us-east-1"
}
================================================
FILE: terraform-module/main.tf
================================================
# Demostration of pass agruments in module using variable
module "module-example" {
source = "github.com/Patelvijaykumar/terraform-aws-instance-template.git"
region = "${var.region}"
ami_id = "${var.ami_id}"
instance_type = "${var.instance_type}"
tag = "${var.tag}"
}
# # Demostration of pass agruments in module
# module "module-example" {
# source = "github.com/Patelvijaykumar/terraform-aws-instance-template.git"
#
# region = "us-east-1"
# ami_id = "ami-035b3c7efe6d061d5"
# instance_type = "t2.micro"
# tag = "module example"
#
# }
output "instance_public_ip_address"{
value="${module.module-example.instance_ip}"
}
================================================
FILE: terraform-module/variables.tf
================================================
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
default = "ami-035b3c7efe6d061d5"
}
variable "instance_type" {
default = "t2.micro"
}
variable "tag" {
default = "t2.micro"
}
================================================
FILE: terraform-output/.gitignore
================================================
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# .tfvars files
*.tfvars
================================================
FILE: terraform-output/README.md
================================================
# Terraform-Tutorial
Terraform Tutorial with all the Live Example
================================================
FILE: terraform-output/arn.txt
================================================
arn:aws:ec2:us-east-1:150843920836:instance/i-0d2877106f7377c0c
================================================
FILE: terraform-output/aws-instance-example.tf
================================================
resource "aws_instance" "web-server" {
ami = "${lookup(var.ami_id, var.region)}"
instance_type = "t2.micro"
provisioner "local-exec" {
command = "echo ${aws_instance.web-server.private_ip} >> ip_list.txt"
}
provisioner "local-exec" {
command = "echo ${aws_instance.web-server.arn} >> arn.txt"
}
}
================================================
FILE: terraform-output/ip_list.txt
================================================
172.31.84.95
172.31.45.49
================================================
FILE: terraform-output/output.tf
================================================
output "public_ip" {
value = "${aws_instance.web-server.public_ip}"
}
================================================
FILE: terraform-output/provider.tf
================================================
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
version = "~> 2.0"
}
================================================
FILE: terraform-output/variables.tf
================================================
variable "access_key" {}
variable "secret_key" {}
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn"
}
}
================================================
FILE: terraform-remote-state/.gitignore
================================================
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# .tfvars files
*.tfvars
================================================
FILE: terraform-remote-state/README.md
================================================
# Terraform-Tutorial
Terraform Tutorial with all the Live Example
================================================
FILE: terraform-remote-state/aws-remote-state-example.tf
================================================
resource "aws_s3_bucket" "bucket" {
bucket = "my-tf-test-bucket-abc"
acl = "private"
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
================================================
FILE: terraform-remote-state/backend.tf
================================================
terraform {
required_version = ">= 0.11.0"
backend "s3" {
bucket = "backup-state-terraform"
key = "terraform/test"
region = "us-east-1"
dynamodb_table = "backend-test"
}
}
================================================
FILE: terraform-remote-state/provider.tf
================================================
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
================================================
FILE: terraform-remote-state/variables.tf
================================================
variable "access_key" {}
variable "secret_key" {}
variable "region" {
default = "us-east-1"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2 = "ami-132b3c7efe6sdfdsfd"
eu-central-1 = "ami-9787h5h6nsn"
}
}
================================================
FILE: terraform-variables/provider.tf
================================================
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
version = "~> 2.0"
}
================================================
FILE: terraform-variables/terraform-variable-example.tf
================================================
provider "aws" {
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
version = "~> 2.0"
}
resource "aws_instance" "my_web_server" {
ami = "${lookup(var.ami_id, var.region)}"
instance_type = "t2.micro"
}
================================================
FILE: terraform-variables/variables.tf
================================================
variable "access_key" { }
variable "secret_key" { }
variable "region" {
default="us-east-1"
}
variable "instance_type" {
default="t2.micro"
}
variable "ami_id" {
type = "map"
default = {
us-east-1 = "ami-035b3c7efe6d061d5"
eu-west-2= "ami-132b3c7efe6sdfdsfd"
eu-central-1="ami-9787h5h6nsn"
}
}
gitextract__u4gpojy/
├── .github/
│ └── workflows/
│ └── terraform.yml
├── .gitignore
├── EC2withJenkins/
│ ├── README.md
│ ├── ec2_jenkins.tf
│ ├── provider.tf
│ ├── security_group.tf
│ └── variables.tf
├── README.md
├── Software-provision/
│ ├── .gitignore
│ ├── README.md
│ ├── aws-instance-server-configure.tf
│ ├── index.html
│ ├── provider.tf
│ ├── terraform.pem
│ └── variables.tf
├── Terraform-aws-route53/
│ ├── instance.tf
│ ├── route53.tf
│ ├── variables.tf
│ └── vpc.tf
├── aws-instance-example.tf
├── aws-instance-first-script/
│ ├── .gitignore
│ ├── Jenkinsfile
│ ├── README.md
│ ├── aws-instance-example.tf
│ ├── provider.tf
│ └── variables.tf
├── ebs-with-userdata/
│ ├── README.md
│ ├── ebs_volume.tf
│ ├── instance.tf
│ ├── security_group.tf
│ ├── variables.tf
│ ├── volume.sh
│ └── vpc.tf
├── kms_policy.json.tpl
├── main.tf
├── provider.tf
├── terraform-aws-autoscaling/
│ ├── main.tf
│ └── variables.tf
├── terraform-aws-ebs/
│ ├── ebs_volume.tf
│ ├── instance.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-ec2-userdata/
│ ├── apache_config.sh
│ ├── output.tf
│ ├── provider.tf
│ ├── security_group.tf
│ ├── user-data-file-input.tf
│ ├── user_data.tf
│ └── variables.tf
├── terraform-aws-ec2-with-vpc/
│ ├── instance.tf
│ ├── provider.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-elasticsearch/
│ ├── README.md
│ ├── iam_role_policy.tf
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
├── terraform-aws-elb-alb/
│ ├── elb.tf
│ ├── instances.tf
│ ├── route53.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-iam/
│ ├── iam/
│ │ ├── aws_iam_group.tf
│ │ └── main.tf
│ └── iam_role_with_instance/
│ ├── instance.tf
│ ├── main.tf
│ ├── s3_bucket.tf
│ └── variables.tf
├── terraform-aws-private-public-ip/
│ ├── instance.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-rds-dynamoDb/
│ └── dynamodb.tf
├── terraform-aws-rds-mariaDb/
│ ├── instance.tf
│ ├── mariadb.tf
│ ├── security_group.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-aws-sns/
│ ├── example/
│ │ ├── .terraform.lock.hcl
│ │ ├── example.tf
│ │ └── version.tf
│ ├── main.tf
│ ├── python/
│ │ └── hello-python.py
│ └── variable.tf
├── terraform-aws-vpc/
│ ├── internet-gateway.tf
│ ├── nat.tf
│ ├── private_subnets.tf
│ ├── public_subnets.tf
│ ├── route_table.tf
│ ├── variables.tf
│ └── vpc.tf
├── terraform-data-source/
│ ├── .gitignore
│ ├── README.md
│ ├── aws-data-source-example.tf
│ ├── provider.tf
│ └── variables.tf
├── terraform-for-each-example/
│ ├── main.tf
│ └── provider.tf
├── terraform-module/
│ ├── main.tf
│ └── variables.tf
├── terraform-output/
│ ├── .gitignore
│ ├── README.md
│ ├── arn.txt
│ ├── aws-instance-example.tf
│ ├── ip_list.txt
│ ├── output.tf
│ ├── provider.tf
│ └── variables.tf
├── terraform-remote-state/
│ ├── .gitignore
│ ├── README.md
│ ├── aws-remote-state-example.tf
│ ├── backend.tf
│ ├── provider.tf
│ └── variables.tf
└── terraform-variables/
├── provider.tf
├── terraform-variable-example.tf
└── variables.tf
SYMBOL INDEX (1 symbols across 1 files) FILE: terraform-aws-sns/python/hello-python.py function lambda_handler (line 1) | def lambda_handler(event, context):
Condensed preview — 120 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (111K chars).
[
{
"path": ".github/workflows/terraform.yml",
"chars": 911,
"preview": "name: terraform-tutorials-ci\n\non: [push, pull_request]\n\nenv:\n AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key }}\n AWS_SE"
},
{
"path": ".gitignore",
"chars": 114,
"preview": "# Local .terraform directories\n**/.terraform/*\n\n# .tfstate files\n*.tfstate\n*.tfstate.*\n\n# .tfvars files\n*.tfvars\n"
},
{
"path": "EC2withJenkins/README.md",
"chars": 932,
"preview": "# Terraform-Tutorial # Jenkins Install in EC2 Instance\n\n\nTerraform Tutorial is the set of examples of [Terraform](https:"
},
{
"path": "EC2withJenkins/ec2_jenkins.tf",
"chars": 956,
"preview": "\r\nresource \"aws_instance\" \"ec2_jenkins\" {\r\n ami = \"${lookup(var.ami_id, var.region)}\"\r\n instance_type = \"${v"
},
{
"path": "EC2withJenkins/provider.tf",
"chars": 72,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n version = \"~> 2.0\"\r\n}\r\n"
},
{
"path": "EC2withJenkins/security_group.tf",
"chars": 765,
"preview": "resource \"aws_security_group\" \"allow_ssh\" {\r\n name = \"allow_SSH\"\r\n description = \"Allow SSH inbound traffic\"\r\n "
},
{
"path": "EC2withJenkins/variables.tf",
"chars": 324,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "README.md",
"chars": 813,
"preview": "# Terraform-Tutorial\n\n"
},
{
"path": "Software-provision/.gitignore",
"chars": 114,
"preview": "# Local .terraform directories\n**/.terraform/*\n\n# .tfstate files\n*.tfstate\n*.tfstate.*\n\n# .tfvars files\n*.tfvars\n"
},
{
"path": "Software-provision/README.md",
"chars": 66,
"preview": "# Terraform-Tutorial\nTerraform Tutorial with all the Live Example\n"
},
{
"path": "Software-provision/aws-instance-server-configure.tf",
"chars": 641,
"preview": "\r\nresource \"aws_instance\" \"web-server\" {\r\n ami = \"${lookup(var.ami_id, var.region)}\"\r\n instance_type = \"t2.m"
},
{
"path": "Software-provision/index.html",
"chars": 108,
"preview": "<HTML>\r\n<HEAD>\r\nTHIS IS MY WEB Server Deployed on AWS EC2 Intance using Terraform Script\r\n</HEAD>\r\n</HTML>\r\n"
},
{
"path": "Software-provision/provider.tf",
"chars": 150,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n access_key = \"${var.access_key}\"\r\n secret_key = \"${var.secret_key}\""
},
{
"path": "Software-provision/terraform.pem",
"chars": 1696,
"preview": "-----BEGIN RSA PRIVATE KEY-----\r\nMIIEpAIBAAKCAQEAjwPLx8LUEWbq9K84qM7J39Ksl8gtAtKczKuduC6xfEygjfznhjG73wp1qAKG\r\npfKJJS20r"
},
{
"path": "Software-provision/variables.tf",
"chars": 353,
"preview": "variable \"access_key\" {}\r\nvariable \"secret_key\" {}\r\nvariable \"region\" {\r\n default = \"us-east-1\"\r\n}\r\nvariable \"private_k"
},
{
"path": "Terraform-aws-route53/instance.tf",
"chars": 898,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n version = \"~> 2.0\"\r\n}\r\n\r\n\r\nresource \"aws_instance\" \"IP_example\" {"
},
{
"path": "Terraform-aws-route53/route53.tf",
"chars": 382,
"preview": "resource \"aws_route53_zone\" \"easy_aws\" {\r\n name = \"easyaws.in\"\r\n\r\n tags = {\r\n Environment = \"dev\"\r\n }\r\n}\r\n\r\nresour"
},
{
"path": "Terraform-aws-route53/variables.tf",
"chars": 1511,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "Terraform-aws-route53/vpc.tf",
"chars": 1696,
"preview": "resource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block = var.cidr\r\n instance_tenancy = var.instance_tenancy\r\n ena"
},
{
"path": "aws-instance-example.tf",
"chars": 283,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n access_key = \"${var.access_key}\"\r\n secret_key = \"${var.secret_key}\""
},
{
"path": "aws-instance-first-script/.gitignore",
"chars": 114,
"preview": "# Local .terraform directories\n**/.terraform/*\n\n# .tfstate files\n*.tfstate\n*.tfstate.*\n\n# .tfvars files\n*.tfvars\n"
},
{
"path": "aws-instance-first-script/Jenkinsfile",
"chars": 2245,
"preview": "\r\npipeline {\r\n\r\n parameters {\r\n string(name: 'environment', defaultValue: 'terraform', description: 'Workspace"
},
{
"path": "aws-instance-first-script/README.md",
"chars": 518,
"preview": "# aws-instance-first-script\n\n}\"\r\n instance_type = \"t2.micro\"\r"
},
{
"path": "aws-instance-first-script/provider.tf",
"chars": 68,
"preview": "provider \"aws\" {\n region = \"${var.region}\"\n version = \"~> 2.0\"\n}\n"
},
{
"path": "aws-instance-first-script/variables.tf",
"chars": 227,
"preview": "variable \"region\" {\n default = \"us-east-1\"\n}\n\nvariable \"ami_id\" {\n type = \"map\"\n\n default = {\n us-east-1 = \"ami"
},
{
"path": "ebs-with-userdata/README.md",
"chars": 691,
"preview": "# aws-instance-with-ebs-volume\n\nA Terraform module for creating AWS EC2 instance with userdata for creating EBS.\n\n## Usa"
},
{
"path": "ebs-with-userdata/ebs_volume.tf",
"chars": 530,
"preview": "resource \"aws_ebs_volume\" \"ebs_volume\" {\r\n availability_zone = \"us-east-1a\"\r\n size = var.ebs_size\r\n type"
},
{
"path": "ebs-with-userdata/instance.tf",
"chars": 552,
"preview": "provider \"aws\" {\r\n region = var.region\r\n version = \"~> 2.0\"\r\n}\r\n\r\nresource \"aws_instance\" \"ebs_instance_example"
},
{
"path": "ebs-with-userdata/security_group.tf",
"chars": 613,
"preview": "resource \"aws_security_group\" \"allow_ssh\" {\r\n name = \"allow_SSH\"\r\n description = \"Allow SSH inbound traffic\"\r\n "
},
{
"path": "ebs-with-userdata/variables.tf",
"chars": 1581,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "ebs-with-userdata/volume.sh",
"chars": 204,
"preview": "#!/bin/bash -xe\r\nexec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1\r\nsleep 30\r\nsudo mkdir -"
},
{
"path": "ebs-with-userdata/vpc.tf",
"chars": 1081,
"preview": "resource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block = var.cidr\r\n instance_tenancy = var.instance_tenancy\r\n ena"
},
{
"path": "kms_policy.json.tpl",
"chars": 311,
"preview": "{\n \"Version\": \"2012-10-17\",\n \"Id\": \"kms-key-policy\",\n \"Statement\": [\n {\n \"Sid\": \"Enable IAM User Permissions\""
},
{
"path": "main.tf",
"chars": 328,
"preview": "data \"template_file\" \"kms_policy\" {\n template = \"${file(\"${kms_policy.json.tpl\")}\"\n\n vars {\n account_id = \"${var.ac"
},
{
"path": "provider.tf",
"chars": 150,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n access_key = \"${var.access_key}\"\r\n secret_key = \"${var.secret_key}\""
},
{
"path": "terraform-aws-autoscaling/main.tf",
"chars": 2391,
"preview": "provider \"aws\" {\r\n region = var.region\r\n}\r\n\r\nresource \"aws_launch_configuration\" \"launch_config\" {\r\n name "
},
{
"path": "terraform-aws-autoscaling/variables.tf",
"chars": 677,
"preview": "variable \"region\" {\r\n default = \"us-east-1\"\r\n}\r\n\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = {\r\n us-east-1 "
},
{
"path": "terraform-aws-ebs/ebs_volume.tf",
"chars": 389,
"preview": "resource \"aws_ebs_volume\" \"ebs_volume\" {\r\n availability_zone = \"us-east-1a\"\r\n size = 20\r\n type "
},
{
"path": "terraform-aws-ebs/instance.tf",
"chars": 420,
"preview": "provider \"aws\" {\r\n region = var.region\r\n}\r\n\r\nresource \"aws_instance\" \"ebs_instance_example\" {\r\n ami = lookup"
},
{
"path": "terraform-aws-ebs/security_group.tf",
"chars": 438,
"preview": "resource \"aws_security_group\" \"allow_ssh\" {\r\n name = \"allow_SSH\"\r\n description = \"Allow SSH inbound traffic\"\r\n "
},
{
"path": "terraform-aws-ebs/variables.tf",
"chars": 1433,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "terraform-aws-ebs/vpc.tf",
"chars": 1081,
"preview": "resource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block = var.cidr\r\n instance_tenancy = var.instance_tenancy\r\n ena"
},
{
"path": "terraform-aws-ec2-userdata/apache_config.sh",
"chars": 197,
"preview": "#! /bin/bash\r\nsudo yum update -y\r\nsudo yum install -y httpd.x86_64\r\nsudo service httpd start\r\nsudo service httpd enable\r"
},
{
"path": "terraform-aws-ec2-userdata/output.tf",
"chars": 194,
"preview": "output \"public_ip\" {\r\n value = \"${aws_instance.user_data_example.public_ip}\"\r\n}\r\noutput \"user_data_example_input_file\" "
},
{
"path": "terraform-aws-ec2-userdata/provider.tf",
"chars": 78,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n version = \"~> 2.0\"\r\n}\r\n"
},
{
"path": "terraform-aws-ec2-userdata/security_group.tf",
"chars": 614,
"preview": "resource \"aws_security_group\" \"allow_ssh\" {\r\n name = \"allow_SSH\"\r\n description = \"Allow SSH inbound traffic\"\r\n "
},
{
"path": "terraform-aws-ec2-userdata/user-data-file-input.tf",
"chars": 441,
"preview": "\r\nresource \"aws_instance\" \"user_data_example_input_file\" {\r\n ami = lookup(var.ami_id, var.region)\r\n instance"
},
{
"path": "terraform-aws-ec2-userdata/user_data.tf",
"chars": 627,
"preview": "\r\nresource \"aws_instance\" \"user_data_example\" {\r\n ami = lookup(var.ami_id, var.region)\r\n instance_type = var"
},
{
"path": "terraform-aws-ec2-userdata/variables.tf",
"chars": 413,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "terraform-aws-ec2-with-vpc/instance.tf",
"chars": 387,
"preview": "resource \"aws_instance\" \"web\" {\r\n ami = lookup(var.ami_id, var.region)\r\n instance_type = var.instance_type\r\n"
},
{
"path": "terraform-aws-ec2-with-vpc/provider.tf",
"chars": 72,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n version = \"~> 2.0\"\r\n}\r\n"
},
{
"path": "terraform-aws-ec2-with-vpc/security_group.tf",
"chars": 438,
"preview": "resource \"aws_security_group\" \"allow_ssh\" {\r\n name = \"allow_SSH\"\r\n description = \"Allow SSH inbound traffic\"\r\n "
},
{
"path": "terraform-aws-ec2-with-vpc/variables.tf",
"chars": 1433,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "terraform-aws-ec2-with-vpc/vpc.tf",
"chars": 1077,
"preview": "resource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block = var.cidr\r\n instance_tenancy = var"
},
{
"path": "terraform-aws-elasticsearch/README.md",
"chars": 6746,
"preview": "# Terraform-Tutorial\r\n\r\n\r\n## Introduction\r\n\r\nThis module will create:\r\n- Elasticsearch cluster with the specified node c"
},
{
"path": "terraform-aws-elasticsearch/iam_role_policy.tf",
"chars": 1215,
"preview": "\r\n# Role that pods can assume for access to elasticsearch and kibana\r\nresource \"aws_iam_role\" \"elasticsearch_user\" {\r\n "
},
{
"path": "terraform-aws-elasticsearch/main.tf",
"chars": 1991,
"preview": "provider \"aws\" {\r\n region = var.region\r\n version = \"~> 2.0\"\r\n}\r\n\r\nresource \"aws_elasticsearch_domain\" \"default\" {\r\n "
},
{
"path": "terraform-aws-elasticsearch/output.tf",
"chars": 914,
"preview": "\r\noutput \"domain_arn\" {\r\n value = join(\"\", aws_elasticsearch_domain.default.*.arn)\r\n description = \"ARN of the E"
},
{
"path": "terraform-aws-elasticsearch/variables.tf",
"chars": 4089,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-2\"\r\n}\r\n\r\nvariable \"domain_name\" {\r\n type = strin"
},
{
"path": "terraform-aws-elb-alb/elb.tf",
"chars": 1338,
"preview": "provider \"aws\" {\r\n region = var.region\r\n}\r\n\r\nresource \"aws_lb\" \"elb_example\" {\r\n name = \"elb\"\r\n interna"
},
{
"path": "terraform-aws-elb-alb/instances.tf",
"chars": 1272,
"preview": "resource \"aws_instance\" \"elb_instance_example1\" {\r\n ami = lookup(var.ami_id, var.region)\r\n instance_type = v"
},
{
"path": "terraform-aws-elb-alb/route53.tf",
"chars": 500,
"preview": "resource \"aws_route53_zone\" \"easy_aws\" {\r\n name = \"easyaws.in\"\r\n\r\n tags = {\r\n Environment = \"dev\"\r\n }\r\n}\r\n\r\nresour"
},
{
"path": "terraform-aws-elb-alb/security_group.tf",
"chars": 610,
"preview": "resource \"aws_security_group\" \"elb_sg\" {\r\n name = \"allow_SSH\"\r\n description = \"Allow SSH inbound traffic\"\r\n vp"
},
{
"path": "terraform-aws-elb-alb/variables.tf",
"chars": 1432,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "terraform-aws-elb-alb/vpc.tf",
"chars": 1490,
"preview": "resource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block = var.cidr\r\n instance_tenancy = var.instance_tenancy\r\n ena"
},
{
"path": "terraform-aws-iam/iam/aws_iam_group.tf",
"chars": 1154,
"preview": "resource \"aws_iam_group\" \"admin\" {\r\n name = \"developer-admin-group\"\r\n}\r\n\r\nresource \"aws_iam_policy_attachment\" \"admin-a"
},
{
"path": "terraform-aws-iam/iam/main.tf",
"chars": 49,
"preview": "provider \"aws\" {\r\n region = \"eu-west-1\"\r\n}\r\n"
},
{
"path": "terraform-aws-iam/iam_role_with_instance/instance.tf",
"chars": 441,
"preview": "\r\nresource \"aws_instance\" \"iam_role_instance_example\" {\r\n ami = lookup(var.ami_id, var.region)\r\n instance_ty"
},
{
"path": "terraform-aws-iam/iam_role_with_instance/main.tf",
"chars": 978,
"preview": "provider \"aws\" {\r\n region = var.region\r\n}\r\n\r\nresource \"aws_iam_role\" \"s3_access_role\" {\r\n name = \"s3-access-role\"\r"
},
{
"path": "terraform-aws-iam/iam_role_with_instance/s3_bucket.tf",
"chars": 190,
"preview": "resource \"aws_s3_bucket\" \"iam_demo_bucket_name\" {\r\n bucket = \"iambucketdemo-dfredf\"\r\n acl=\"private\"\r\n\r\n tags = "
},
{
"path": "terraform-aws-iam/iam_role_with_instance/variables.tf",
"chars": 399,
"preview": "variable \"region\" {\r\n default = \"us-east-1\"\r\n}\r\n\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = {\r\n us-east-1 "
},
{
"path": "terraform-aws-private-public-ip/instance.tf",
"chars": 891,
"preview": "provider \"aws\" {\r\n region = var.region\r\n version = \"~> 2.0\"\r\n}\r\n\r\nresource \"aws_instance\" \"IP_example\" {\r\n ami"
},
{
"path": "terraform-aws-private-public-ip/variables.tf",
"chars": 1511,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "terraform-aws-private-public-ip/vpc.tf",
"chars": 1696,
"preview": "resource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block = var.cidr\r\n instance_tenancy = var.instance_tenancy\r\n ena"
},
{
"path": "terraform-aws-rds-dynamoDb/dynamodb.tf",
"chars": 870,
"preview": "provider \"aws\" {\r\n region = \"us-east-1\"\r\n version = \"~> 2.0\"\r\n}\r\n\r\nresource \"aws_dynamodb_table\" \"basic-dynamod"
},
{
"path": "terraform-aws-rds-mariaDb/instance.tf",
"chars": 829,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n version = \"~> 2.0\"\r\n}\r\n\r\n\r\nresource \"aws_instance\" \"rds_example\" "
},
{
"path": "terraform-aws-rds-mariaDb/mariadb.tf",
"chars": 968,
"preview": "resource \"aws_db_parameter_group\" \"default\" {\r\n name = \"mariadb\"\r\n family = \"mariadb10.2\"\r\n\r\n parameter {\r\n name"
},
{
"path": "terraform-aws-rds-mariaDb/security_group.tf",
"chars": 1088,
"preview": "resource \"aws_security_group\" \"allow_ssh_http\" {\r\n name = \"allow_SSH_http\"\r\n description = \"Allow SSH inbound t"
},
{
"path": "terraform-aws-rds-mariaDb/variables.tf",
"chars": 1511,
"preview": "variable \"region\" {\r\n type = \"string\"\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {\r\n type = \"map\"\r\n default = "
},
{
"path": "terraform-aws-rds-mariaDb/vpc.tf",
"chars": 3286,
"preview": "######\r\n# VPC\r\n######\r\n#terraform version >= 12\r\n############\r\nresource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block "
},
{
"path": "terraform-aws-sns/example/.terraform.lock.hcl",
"chars": 1184,
"preview": "# This file is maintained automatically by \"terraform init\".\n# Manual edits may be lost in future updates.\n\nprovider \"re"
},
{
"path": "terraform-aws-sns/example/example.tf",
"chars": 407,
"preview": "provider \"aws\" {\n region = \"eu-west-1\"\n}\n\nmodule \"sns_cloudwatch\" {\n source = \"github.com/easyawslearn/Terraform-Tutor"
},
{
"path": "terraform-aws-sns/example/version.tf",
"chars": 175,
"preview": "# Terraform version\nterraform {\n required_version = \">= 0.14.11\"\n\n required_providers {\n aws = {\n source = \"h"
},
{
"path": "terraform-aws-sns/main.tf",
"chars": 3595,
"preview": "provider \"aws\" {\n region = var.region\n}\n\nresource \"aws_cloudwatch_event_rule\" \"default\" {\n count = var.enabled == tr"
},
{
"path": "terraform-aws-sns/python/hello-python.py",
"chars": 127,
"preview": "def lambda_handler(event, context):\n message = 'Hello {} !'.format(event['key1'])\n return {\n 'message' : messa"
},
{
"path": "terraform-aws-sns/variable.tf",
"chars": 6363,
"preview": "variable \"region\" {\n type = string\n default = \"eu-west-1\"\n}\n\nvariable \"enabled\" {\n type = bool\n default = true"
},
{
"path": "terraform-aws-vpc/internet-gateway.tf",
"chars": 135,
"preview": "resource \"aws_internet_gateway\" \"gw\" {\r\n vpc_id = \"${aws_vpc.vpc_demo.id}\"\r\n\r\n tags = {\r\n Name = \"internet-gateway-"
},
{
"path": "terraform-aws-vpc/nat.tf",
"chars": 965,
"preview": "resource \"aws_eip\" \"nat\" {\r\n vpc = true\r\n}\r\n\r\nresource \"aws_nat_gateway\" \"nat_gw\" {\r\n allocation_id = \"${aws_eip."
},
{
"path": "terraform-aws-vpc/private_subnets.tf",
"chars": 567,
"preview": "resource \"aws_subnet\" \"private_1\" {\r\n vpc_id = aws_vpc.vpc_demo.id\r\n map_public_ip_on_launch = false\r\n cidr_block"
},
{
"path": "terraform-aws-vpc/public_subnets.tf",
"chars": 558,
"preview": "resource \"aws_subnet\" \"public_1\" {\r\n vpc_id = aws_vpc.vpc_demo.id\r\n map_public_ip_on_launch = true\r\n cidr_block ="
},
{
"path": "terraform-aws-vpc/route_table.tf",
"chars": 730,
"preview": "resource \"aws_route_table\" \"route-public\" {\r\n vpc_id = \"${aws_vpc.vpc_demo.id}\"\r\n\r\n route {\r\n cidr_block = \"10.0.0."
},
{
"path": "terraform-aws-vpc/variables.tf",
"chars": 1018,
"preview": "variable \"cidr\" {\r\n description = \"The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS"
},
{
"path": "terraform-aws-vpc/vpc.tf",
"chars": 436,
"preview": "######\r\n# VPC\r\n######\r\n#terraform version >= 12\r\n############\r\nresource \"aws_vpc\" \"vpc_demo\" {\r\n cidr_block "
},
{
"path": "terraform-data-source/.gitignore",
"chars": 114,
"preview": "# Local .terraform directories\n**/.terraform/*\n\n# .tfstate files\n*.tfstate\n*.tfstate.*\n\n# .tfvars files\n*.tfvars\n"
},
{
"path": "terraform-data-source/README.md",
"chars": 66,
"preview": "# Terraform-Tutorial\nTerraform Tutorial with all the Live Example\n"
},
{
"path": "terraform-data-source/aws-data-source-example.tf",
"chars": 234,
"preview": "data \"aws_vpc\" \"selected\" {\r\n\r\n filter {\r\n name = \"tag:Name\"\r\n values = [\"Default\"]\r\n }\r\n}\r\n\r\nresource \"aws_su"
},
{
"path": "terraform-data-source/provider.tf",
"chars": 78,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n version = \"~> 2.0\"\r\n}\r\n"
},
{
"path": "terraform-data-source/variables.tf",
"chars": 288,
"preview": "variable \"access_key\" {}\r\nvariable \"secret_key\" {}\r\nvariable \"region\" {\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {"
},
{
"path": "terraform-for-each-example/main.tf",
"chars": 695,
"preview": "variable \"vpc_id\" {\r\n description = \"ID for the AWS VPC where a security group is to be created.\"\r\n}\r\n\r\nvariable \"subne"
},
{
"path": "terraform-for-each-example/provider.tf",
"chars": 49,
"preview": "provider \"aws\" {\r\n region = \"us-east-1\"\r\n}\r\n"
},
{
"path": "terraform-module/main.tf",
"chars": 844,
"preview": "# Demostration of pass agruments in module using variable\r\nmodule \"module-example\" {\r\n source = \"github.com/Patelvijayk"
},
{
"path": "terraform-module/variables.tf",
"chars": 216,
"preview": "variable \"region\" {\r\n default = \"us-east-1\"\r\n}\r\n\r\nvariable \"ami_id\" {\r\n default = \"ami-035b3c7efe6d061d5\"\r\n}\r\n\r\nvariab"
},
{
"path": "terraform-output/.gitignore",
"chars": 114,
"preview": "# Local .terraform directories\n**/.terraform/*\n\n# .tfstate files\n*.tfstate\n*.tfstate.*\n\n# .tfvars files\n*.tfvars\n"
},
{
"path": "terraform-output/README.md",
"chars": 66,
"preview": "# Terraform-Tutorial\nTerraform Tutorial with all the Live Example\n"
},
{
"path": "terraform-output/arn.txt",
"chars": 64,
"preview": "arn:aws:ec2:us-east-1:150843920836:instance/i-0d2877106f7377c0c\n"
},
{
"path": "terraform-output/aws-instance-example.tf",
"chars": 343,
"preview": "resource \"aws_instance\" \"web-server\" {\r\n ami = \"${lookup(var.ami_id, var.region)}\"\r\n instance_type = \"t2.mic"
},
{
"path": "terraform-output/ip_list.txt",
"chars": 26,
"preview": "172.31.84.95\n172.31.45.49\n"
},
{
"path": "terraform-output/output.tf",
"chars": 75,
"preview": "output \"public_ip\" {\r\n value = \"${aws_instance.web-server.public_ip}\"\r\n}\r\n"
},
{
"path": "terraform-output/provider.tf",
"chars": 150,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n access_key = \"${var.access_key}\"\r\n secret_key = \"${var.secret_key}\""
},
{
"path": "terraform-output/variables.tf",
"chars": 288,
"preview": "variable \"access_key\" {}\r\nvariable \"secret_key\" {}\r\nvariable \"region\" {\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {"
},
{
"path": "terraform-remote-state/.gitignore",
"chars": 114,
"preview": "# Local .terraform directories\n**/.terraform/*\n\n# .tfstate files\n*.tfstate\n*.tfstate.*\n\n# .tfvars files\n*.tfvars\n"
},
{
"path": "terraform-remote-state/README.md",
"chars": 66,
"preview": "# Terraform-Tutorial\nTerraform Tutorial with all the Live Example\n"
},
{
"path": "terraform-remote-state/aws-remote-state-example.tf",
"chars": 175,
"preview": "\r\nresource \"aws_s3_bucket\" \"bucket\" {\r\n bucket = \"my-tf-test-bucket-abc\"\r\n acl = \"private\"\r\n\r\n tags = {\r\n Name "
},
{
"path": "terraform-remote-state/backend.tf",
"chars": 206,
"preview": "terraform {\r\n required_version = \">= 0.11.0\"\r\n backend \"s3\" {\r\n bucket = \"backup-state-terraform\"\r\n key = \"te"
},
{
"path": "terraform-remote-state/provider.tf",
"chars": 78,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n version = \"~> 2.0\"\r\n}\r\n"
},
{
"path": "terraform-remote-state/variables.tf",
"chars": 288,
"preview": "variable \"access_key\" {}\r\nvariable \"secret_key\" {}\r\nvariable \"region\" {\r\n default = \"us-east-1\"\r\n}\r\nvariable \"ami_id\" {"
},
{
"path": "terraform-variables/provider.tf",
"chars": 150,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n access_key = \"${var.access_key}\"\r\n secret_key = \"${var.secret_key}\""
},
{
"path": "terraform-variables/terraform-variable-example.tf",
"chars": 283,
"preview": "provider \"aws\" {\r\n region = \"${var.region}\"\r\n access_key = \"${var.access_key}\"\r\n secret_key = \"${var.secret_key}\""
},
{
"path": "terraform-variables/variables.tf",
"chars": 312,
"preview": "variable \"access_key\" { }\r\nvariable \"secret_key\" { }\r\nvariable \"region\" {\r\ndefault=\"us-east-1\"\r\n}\r\nvariable \"instance_ty"
}
]
About this extraction
This page contains the full source code of the easyawslearn/Terraform-Tutorial GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 120 files (91.8 KB), approximately 29.9k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.