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 = <Deployed via Terraform" | 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 ![](https://github.com/easyawslearn/Terraform-Tutorial/workflows/terraform-tutorials-ci/badge.svg) 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 ================================================ THIS IS MY WEB Server Deployed on AWS EC2 Intance using Terraform Script ================================================ 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 = <Deployed via Terraform" | 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 ![](https://github.com/easyawslearn/Terraform-Tutorial/workflows/terraform-tutorials-ci/badge.svg) 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 "

Deployed via Terraform

" | 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 = <Deployed via Terraform" | 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) | `` | 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 = <Deployed ELB Instance Example 1" | 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 = <Deployed ELB Instance Example 2" | 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 = <Deployed via Terraform" | 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 = <Deployed via Terraform" | 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 = <= 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" } }